1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from yardstick.benchmark.runners import base as runner_base
16 from yardstick.benchmark.runners import iteration
17 from yardstick.tests.unit import base as ut_base
20 class ActionTestCase(ut_base.BaseUnitTestCase):
23 self._mock_log = mock.patch.object(runner_base.log, 'error')
24 self.mock_log = self._mock_log.start()
25 self.addCleanup(self._stop_mocks)
27 def _stop_mocks(self):
30 @mock.patch.object(subprocess, 'check_output')
31 def test__execute_shell_command(self, mock_subprocess):
32 mock_subprocess.side_effect = subprocess.CalledProcessError(-1, '')
33 self.assertEqual(runner_base._execute_shell_command("")[0], -1)
35 @mock.patch.object(subprocess, 'check_output')
36 def test__single_action(self, mock_subprocess):
37 mock_subprocess.side_effect = subprocess.CalledProcessError(-1, '')
38 runner_base._single_action(0, 'echo', mock.Mock())
40 @mock.patch.object(subprocess, 'check_output')
41 def test__periodic_action(self, mock_subprocess):
42 mock_subprocess.side_effect = subprocess.CalledProcessError(-1, '')
43 runner_base._periodic_action(0, 'echo', mock.Mock())
46 class RunnerTestCase(ut_base.BaseUnitTestCase):
56 self.runner = iteration.IterationRunner(config)
58 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
59 def test_get_output(self, *args):
60 self.runner.output_queue.put({'case': 'opnfv_yardstick_tc002'})
61 self.runner.output_queue.put({'criteria': 'PASS'})
64 'case': 'opnfv_yardstick_tc002',
70 if not self.runner.output_queue.empty():
72 actual_result = self.runner.get_output()
73 self.assertEqual(idle_result, actual_result)
75 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
76 def test_get_result(self, *args):
77 self.runner.result_queue.put({'case': 'opnfv_yardstick_tc002'})
78 self.runner.result_queue.put({'criteria': 'PASS'})
81 {'case': 'opnfv_yardstick_tc002'},
87 if not self.runner.result_queue.empty():
89 actual_result = self.runner.get_result()
90 self.assertEqual(idle_result, actual_result)
92 def test__run_benchmark(self):
93 runner = runner_base.Runner(mock.Mock())
95 with self.assertRaises(NotImplementedError):
96 runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())