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 ##############################################################################
14 from subprocess import CalledProcessError
17 from yardstick.benchmark.runners import base
18 from yardstick.benchmark.runners import iteration
21 class ActionTestCase(unittest.TestCase):
23 @mock.patch("yardstick.benchmark.runners.base.subprocess")
24 def test__execute_shell_command(self, mock_subprocess):
25 mock_subprocess.check_output.side_effect = CalledProcessError(-1, '')
27 self.assertEqual(base._execute_shell_command("")[0], -1)
29 @mock.patch("yardstick.benchmark.runners.base.subprocess")
30 def test__single_action(self, mock_subprocess):
31 mock_subprocess.check_output.side_effect = CalledProcessError(-1, '')
33 base._single_action(0, "echo", mock.MagicMock())
35 @mock.patch("yardstick.benchmark.runners.base.subprocess")
36 def test__periodic_action(self, mock_subprocess):
37 mock_subprocess.check_output.side_effect = CalledProcessError(-1, '')
39 base._periodic_action(0, "echo", mock.MagicMock())
42 class RunnerTestCase(unittest.TestCase):
52 self.runner = iteration.IterationRunner(config)
54 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
55 def test_get_output(self, *args):
56 self.runner.output_queue.put({'case': 'opnfv_yardstick_tc002'})
57 self.runner.output_queue.put({'criteria': 'PASS'})
60 'case': 'opnfv_yardstick_tc002',
66 if not self.runner.output_queue.empty():
68 actual_result = self.runner.get_output()
69 self.assertEqual(idle_result, actual_result)
71 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
72 def test_get_result(self, *args):
73 self.runner.result_queue.put({'case': 'opnfv_yardstick_tc002'})
74 self.runner.result_queue.put({'criteria': 'PASS'})
77 {'case': 'opnfv_yardstick_tc002'},
83 if not self.runner.result_queue.empty():
85 actual_result = self.runner.get_result()
86 self.assertEqual(idle_result, actual_result)
88 def test__run_benchmark(self):
89 runner = base.Runner(mock.Mock())
91 with self.assertRaises(NotImplementedError):
92 runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())