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
19 from __future__ import absolute_import
21 from unittest import mock
26 from yardstick.benchmark.scenarios.networking import vsperf
29 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess')
30 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh')
31 @mock.patch("yardstick.benchmark.scenarios.networking.vsperf.open",
33 class VsperfTestCase(unittest.TestCase):
38 "ip": "10.229.47.137",
45 'testname': 'p2p_rfc2544_continuous',
46 'traffic_type': 'continuous',
48 'bidirectional': 'True',
50 'trafficgen_port1': 'eth1',
51 'trafficgen_port2': 'eth3',
52 'external_bridge': 'br-ex',
53 'conf_file': 'vsperf-yardstick.conf',
54 'setup_script': 'setup_yardstick.sh',
55 'test_params': 'TRAFFICGEN_DURATION=30;',
58 'metrics': 'throughput_rx_fps',
59 'throughput_rx_fps': 500000,
64 def test_vsperf_setup(self, mock_ssh, mock_subprocess):
65 p = vsperf.Vsperf(self.args, self.ctx)
66 mock_ssh.SSH().execute.return_value = (0, '', '')
67 mock_subprocess.call().execute.return_value = None
70 self.assertIsNotNone(p.client)
71 self.assertEqual(p.setup_done, True)
73 def test_vsperf_teardown(self, mock_ssh, mock_subprocess):
74 p = vsperf.Vsperf(self.args, self.ctx)
76 # setup() specific mocks
77 mock_ssh.SSH().execute.return_value = (0, '', '')
78 mock_subprocess.call().execute.return_value = None
81 self.assertIsNotNone(p.client)
82 self.assertEqual(p.setup_done, True)
85 self.assertEqual(p.setup_done, False)
87 def test_vsperf_run_ok(self, mock_ssh, mock_subprocess):
88 p = vsperf.Vsperf(self.args, self.ctx)
90 # setup() specific mocks
91 mock_ssh.SSH().execute.return_value = (0, '', '')
92 mock_subprocess.call().execute.return_value = None
94 # run() specific mocks
95 mock_ssh.SSH().execute.return_value = (0, '', '')
96 mock_ssh.SSH().execute.return_value = (
97 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
102 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
104 def test_vsperf_run_falied_vsperf_execution(self, mock_ssh,
106 p = vsperf.Vsperf(self.args, self.ctx)
108 # setup() specific mocks
109 mock_ssh.SSH().execute.return_value = (0, '', '')
110 mock_subprocess.call().execute.return_value = None
112 # run() specific mocks
113 mock_ssh.SSH().execute.return_value = (1, '', '')
116 self.assertRaises(RuntimeError, p.run, result)
118 def test_vsperf_run_falied_csv_report(self, mock_ssh, mock_subprocess):
119 p = vsperf.Vsperf(self.args, self.ctx)
121 # setup() specific mocks
122 mock_ssh.SSH().execute.return_value = (0, '', '')
123 mock_subprocess.call().execute.return_value = None
125 # run() specific mocks
126 mock_ssh.SSH().execute.return_value = (0, '', '')
127 mock_ssh.SSH().execute.return_value = (1, '', '')
130 self.assertRaises(RuntimeError, p.run, result)
137 if __name__ == '__main__':