3 ##############################################################################
4 # Copyright (c) 2015 ZTE and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.networking.pktgen.Pktgen
14 from __future__ import absolute_import
19 import yardstick.common.utils as utils
20 from yardstick.benchmark.scenarios.networking import pktgen_dpdk
23 class PktgenDPDKLatencyTestCase(unittest.TestCase):
30 'key_filename': 'mykey.key'
35 'key_filename': 'mykey.key',
36 'ipaddr': '172.16.0.138'
40 self._mock_ssh = mock.patch(
41 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
42 self.mock_ssh = self._mock_ssh.start()
43 self._mock_time = mock.patch(
44 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.time')
45 self.mock_time = self._mock_time.start()
47 self.addCleanup(self._stop_mock)
51 self._mock_time.stop()
53 def test_pktgen_dpdk_successful_setup(self):
56 'options': {'packetsize': 60},
58 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
61 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
62 self.assertIsNotNone(p.server)
63 self.assertIsNotNone(p.client)
64 self.assertTrue(p.setup_done)
66 def test_pktgen_dpdk_successful_get_port_ip(self):
69 'options': {'packetsize': 60},
71 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
72 p.server = self.mock_ssh.SSH.from_node()
74 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
76 utils.get_port_ip(p.server, "eth1")
78 self.mock_ssh.SSH.from_node().execute.assert_called_with(
79 "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ")
81 def test_pktgen_dpdk_unsuccessful_get_port_ip(self):
84 'options': {'packetsize': 60},
87 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
88 p.server = self.mock_ssh.SSH.from_node()
90 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
91 self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1")
93 def test_pktgen_dpdk_successful_get_port_mac(self):
96 'options': {'packetsize': 60},
98 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
99 p.server = self.mock_ssh.SSH.from_node()
101 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
103 utils.get_port_mac(p.server, "eth1")
105 self.mock_ssh.SSH.from_node().execute.assert_called_with(
106 "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ")
108 def test_pktgen_dpdk_unsuccessful_get_port_mac(self):
111 'options': {'packetsize': 60},
114 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
115 p.server = self.mock_ssh.SSH.from_node()
117 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
118 self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1")
120 def test_pktgen_dpdk_successful_no_sla(self):
123 'options': {'packetsize': 60},
127 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
129 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
130 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
133 # with python 3 we get float, might be due python division changes
134 # AssertionError: {'avg_latency': 132.33333333333334} != {
135 # 'avg_latency': 132}
136 delta = result['avg_latency'] - 132
137 self.assertLessEqual(delta, 1)
139 def test_pktgen_dpdk_successful_sla(self):
142 'options': {'packetsize': 60},
143 'sla': {'max_latency': 100}
147 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
149 sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
150 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
154 self.assertEqual(result, {"avg_latency": 100})
156 def test_pktgen_dpdk_unsuccessful_sla(self):
159 'options': {'packetsize': 60},
160 'sla': {'max_latency': 100}
164 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
166 p.server = self.mock_ssh.SSH.from_node()
167 p.client = self.mock_ssh.SSH.from_node()
169 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
170 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
171 self.assertRaises(AssertionError, p.run, result)
173 def test_pktgen_dpdk_unsuccessful_script_error(self):
176 'options': {'packetsize': 60},
177 'sla': {'max_latency': 100}
181 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
183 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
184 self.assertRaises(RuntimeError, p.run, result)
191 if __name__ == '__main__':