3 # Copyright 2016 Intel Corporation.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Unittest for yardstick.benchmark.scenarios.networking.vsperf.Vsperf
24 from yardstick.benchmark.scenarios.networking import vsperf
27 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess')
28 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh')
29 @mock.patch("__builtin__.open", return_value=None)
30 class VsperfTestCase(unittest.TestCase):
35 "ip": "10.229.47.137",
42 'testname': 'rfc2544_p2p_continuous',
43 'traffic_type': 'continuous',
45 'bidirectional': 'True',
48 'trafficgen_port1': 'eth1',
49 'trafficgen_port2': 'eth3',
50 'external_bridge': 'br-ex',
51 'conf-file': 'vsperf-yardstick.conf',
52 'setup-script': 'setup_yardstick.sh',
55 'metrics': 'throughput_rx_fps',
56 'throughput_rx_fps': 500000,
61 def test_vsperf_setup(self, mock_open, mock_ssh, mock_subprocess):
62 p = vsperf.Vsperf(self.args, self.ctx)
63 mock_ssh.SSH().execute.return_value = (0, '', '')
64 mock_subprocess.call().execute.return_value = None
67 self.assertIsNotNone(p.client)
68 self.assertEqual(p.setup_done, True)
70 def test_vsperf_teardown(self, mock_open, mock_ssh, mock_subprocess):
71 p = vsperf.Vsperf(self.args, self.ctx)
73 # setup() specific mocks
74 mock_ssh.SSH().execute.return_value = (0, '', '')
75 mock_subprocess.call().execute.return_value = None
78 self.assertIsNotNone(p.client)
79 self.assertEqual(p.setup_done, True)
82 self.assertEqual(p.setup_done, False)
84 def test_vsperf_run_ok(self, mock_open, mock_ssh, mock_subprocess):
85 p = vsperf.Vsperf(self.args, self.ctx)
87 # setup() specific mocks
88 mock_ssh.SSH().execute.return_value = (0, '', '')
89 mock_subprocess.call().execute.return_value = None
91 # run() specific mocks
92 mock_ssh.SSH().execute.return_value = (0, '', '')
93 mock_ssh.SSH().execute.return_value = (0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
98 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
100 def test_vsperf_run_falied_vsperf_execution(self, mock_open, mock_ssh, mock_subprocess):
101 p = vsperf.Vsperf(self.args, self.ctx)
103 # setup() specific mocks
104 mock_ssh.SSH().execute.return_value = (0, '', '')
105 mock_subprocess.call().execute.return_value = None
107 # run() specific mocks
108 mock_ssh.SSH().execute.return_value = (1, '', '')
111 self.assertRaises(RuntimeError, p.run, result)
113 def test_vsperf_run_falied_csv_report(self, mock_open, mock_ssh, mock_subprocess):
114 p = vsperf.Vsperf(self.args, self.ctx)
116 # setup() specific mocks
117 mock_ssh.SSH().execute.return_value = (0, '', '')
118 mock_subprocess.call().execute.return_value = None
120 # run() specific mocks
121 mock_ssh.SSH().execute.return_value = (0, '', '')
122 mock_ssh.SSH().execute.return_value = (1, '', '')
125 self.assertRaises(RuntimeError, p.run, result)
131 if __name__ == '__main__':