1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from yardstick.common import process
21 class ProcessTestcase(unittest.TestCase):
22 def test_check_if_procces_failed_None(self):
23 p = mock.MagicMock(**{"exitcode": None, "name": "debug"})
24 process.check_if_process_failed(p)
26 def test_check_if_procces_failed_0(self):
27 p = mock.MagicMock(**{"exitcode": 0, "name": "debug"})
28 process.check_if_process_failed(p)
30 def test_check_if_procces_failed_1(self):
31 p = mock.MagicMock(**{"exitcode": 1, "name": "debug"})
32 with self.assertRaises(RuntimeError):
33 process.check_if_process_failed(p)
36 @mock.patch("yardstick.common.process.multiprocessing")
37 class TerminateChildrenTestcase(unittest.TestCase):
38 def test_some_children(self, mock_multiprocessing):
41 mock_multiprocessing.active_children.return_value = [p1, p2]
42 process.terminate_children()
44 def test_no_children(self, mock_multiprocessing):
45 mock_multiprocessing.active_children.return_value = []
46 process.terminate_children()