summaryrefslogtreecommitdiff
path: root/tests/TestSuite_queue_start_stop.py
blob: 360ed85915fa06f9574b0afcbc774eee2ce09329 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# BSD LICENSE
#
# Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in
#     the documentation and/or other materials provided with the
#     distribution.
#   * Neither the name of Intel Corporation nor the names of its
#     contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



"""
DPDK Test suite.

Test queue start stop Feature

"""

import dts
import time
import re
import os
from test_case import TestCase
from pmd_output import PmdOutput
from settings import FOLDERS
from packet import Packet, sniff_packets, load_sniff_packets, strip_pktload

#
#
# Test class.
#


class TestQueueStartStop(TestCase):
    #
    #
    #
    # Test cases.
    #

    def set_up_all(self):
        """
        Run at the start of each test suite.
        """
        self.ports = self.dut.get_ports(self.nic)
        self.verify(len(self.ports) >= 1, "Insufficient number of ports.")

    def set_up(self):
        """
        Run before each test case.
        """
        try:
            patch_file = FOLDERS["Depends"] + r'/macfwd_log.patch'
        except:
            self.logger.warning(str(FOLDERS))
            patch_file = r'dep/macfwd_log.patch'
            FOLDERS["Depends"] = 'dep'
        patch_dst = "/tmp/"

        # dpdk patch and build
        try:
            self.dut.session.copy_file_to(patch_file, patch_dst)
            self.patch_hotfix_dpdk(patch_dst + "macfwd_log.patch", True)
            self.dut.build_dpdk_apps('./app/test-pmd')
        except Exception, e:
            raise IOError("dpdk setup failure: %s" % e)

    def check_forwarding(self, ports, nic, pktSize=64, received=True):
        self.send_packet(ports[0], ports[1], self.nic, pktSize, received)

    def send_packet(self, txPort, rxPort, nic, pktSize=64, received=True):
        """
        Send packages according to parameters.
        """
        rxitf = self.tester.get_interface(self.tester.get_local_port(rxPort))
        txitf = self.tester.get_interface(self.tester.get_local_port(txPort))

        dmac = self.dut.get_mac_address(txPort)

        pkt = Packet(pkt_type="UDP", pkt_len=pktSize)
        inst = sniff_packets(rxitf)
        pkt.config_layer('ether', {'dst': dmac})
        pkt.send_pkt(tx_port=txitf)
        sniff_pkts = load_sniff_packets(inst)

        if received:
            res = strip_pktload(sniff_pkts[0], layer="L4")
            self.verify("58 58 58 58 58 58 58 58" in res, "receive queue not work as expected")
        else:
            self.verify(len(sniff_pkts) == 0, "stop queue not work as expected")

    def patch_hotfix_dpdk(self, patch_dir, on = True):
        """
        This function is to apply or remove patch for dpdk.
        patch_dir: the abs path of the patch
        on: True for apply, False for remove
        """
        try:
            if on:
                self.dut.send_expect("patch -p0 < %s" % patch_dir, "#")
            else:
                self.dut.send_expect("patch -p0 -R < %s" % patch_dir, "#")
        except Exception, e:
            raise ValueError("patch_hotfix_dpdk failure: %s" % e)

    def test_queue_start_stop(self):
        """
        queue start/stop test
        """
        #dpdk start
        try:
            self.dut.send_expect("./app/test-pmd/testpmd -c 0xf -n 4 -- -i --portmask=0x1 --port-topology=loop", "testpmd>", 120)
            self.dut.send_expect("set fwd mac", "testpmd>")
            self.dut.send_expect("start", "testpmd>")
            self.check_forwarding([0, 0], self.nic)
        except Exception, e:
            raise IOError("dpdk start and first forward failure: %s" % e)

            # stop rx queue test
        try:
            print "test stop rx queue"
            self.dut.send_expect("stop", "testpmd>")
            self.dut.send_expect("port 0 rxq 0 stop", "testpmd>")
            self.dut.send_expect("start", "testpmd>")
            self.check_forwarding([0, 0], self.nic, received=False)

            # start rx queue test
            print "test start rx queue stop tx queue"
            self.dut.send_expect("stop", "testpmd>")
            self.dut.send_expect("port 0 rxq 0 start", "testpmd>")
            self.dut.send_expect("port 0 txq 0 stop", "testpmd>")
            self.dut.send_expect("start", "testpmd>")
            self.check_forwarding([0, 0], self.nic, received=False)
            out = self.dut.get_session_output()
        except Exception, e:
            raise IOError("queue start/stop forward failure: %s" % e)

        self.verify("ports 0 queue 0 receive 1 packages" in out, "start queue revice package failed, out = %s"%out)

        try:
            # start tx queue test
            print "test start rx and tx queue"
            self.dut.send_expect("stop", "testpmd>")
            self.dut.send_expect("port 0 txq 0 start", "testpmd>")
            self.dut.send_expect("start", "testpmd>")
            self.check_forwarding([0, 0], self.nic)
        except Exception, e:
            raise IOError("queue start/stop forward failure: %s" % e)

    def tear_down(self):
        """
        Run after each test case.
        """
        patch_dst = "/tmp/"

        try:
            self.dut.send_expect("stop", "testpmd>")
            self.dut.send_expect("quit", "testpmd>")
        except:
            print "Failed to quit testpmd"

        self.dut.kill_all()

        try:
            self.patch_hotfix_dpdk(patch_dst + "macfwd_log.patch", False)
        except Exception, e:
            print "patch_hotfix_dpdk remove failure :%s" %e

    def tear_down_all(self):
        """
        Run after each test suite.
        """
        self.dut.kill_all()
        self.dut.send_expect("rm -rf ./app/test-pmd/testpmd", "#")
        self.dut.send_expect("rm -rf ./app/test-pmd/*.o", "#")
        self.dut.send_expect("rm -rf ./app/test-pmd/build", "#")