3 ##############################################################################
4 # Copyright (c) 2017 Huawei Technologies Co.,Ltd 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 from __future__ import print_function
13 from __future__ import absolute_import
20 from yardstick.benchmark.runners import base
21 from yardstick.benchmark.runners.iteration import IterationRunner
24 class ActionTestCase(unittest.TestCase):
26 @mock.patch("yardstick.benchmark.runners.base.subprocess")
27 def test__execute_shell_command(self, mock_subprocess):
28 mock_subprocess.check_output.side_effect = Exception()
30 self.assertEqual(base._execute_shell_command("")[0], -1)
32 @mock.patch("yardstick.benchmark.runners.base.subprocess")
33 def test__single_action(self, mock_subprocess):
34 mock_subprocess.check_output.side_effect = Exception()
36 base._single_action(0, "echo", mock.MagicMock())
38 @mock.patch("yardstick.benchmark.runners.base.subprocess")
39 def test__periodic_action(self, mock_subprocess):
40 mock_subprocess.check_output.side_effect = Exception()
42 base._periodic_action(0, "echo", mock.MagicMock())
45 class RunnerTestCase(unittest.TestCase):
47 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
48 def test_get_output(self, mock_process):
49 runner = IterationRunner({})
50 runner.output_queue.put({'case': 'opnfv_yardstick_tc002'})
51 runner.output_queue.put({'criteria': 'PASS'})
54 'case': 'opnfv_yardstick_tc002',
58 for retries in range(1000):
60 if not runner.output_queue.empty():
62 actual_result = runner.get_output()
63 self.assertEqual(idle_result, actual_result)
65 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
66 def test_get_result(self, mock_process):
67 runner = IterationRunner({})
68 runner.result_queue.put({'case': 'opnfv_yardstick_tc002'})
69 runner.result_queue.put({'criteria': 'PASS'})
72 {'case': 'opnfv_yardstick_tc002'},
76 for retries in range(1000):
78 if not runner.result_queue.empty():
80 actual_result = runner.get_result()
81 self.assertEqual(idle_result, actual_result)
83 def test__run_benchmark(self):
84 runner = base.Runner(mock.Mock())
86 with self.assertRaises(NotImplementedError):
87 runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())
94 if __name__ == '__main__':