3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
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 # Unittest for yardstick.benchmark.scenarios.compute.unixbench.Unixbench
18 from yardstick.benchmark.scenarios.compute import unixbench
21 @mock.patch('yardstick.benchmark.scenarios.compute.unixbench.ssh')
22 class UnixbenchTestCase(unittest.TestCase):
27 "ip": "192.168.50.28",
29 "key_filename": "mykey.key"
33 def test_unixbench_successful_setup(self, mock_ssh):
35 u = unixbench.Unixbench({}, self.ctx)
38 mock_ssh.SSH().execute.return_value = (0, '', '')
39 self.assertIsNotNone(u.client)
40 self.assertEqual(u.setup_done, True)
42 def test_unixbench_successful_no_sla(self, mock_ssh):
45 "test_type": 'dhry2reg',
51 u = unixbench.Unixbench(args, self.ctx)
54 u.server = mock_ssh.SSH()
56 sample_output = '{"Score":"4425.4"}'
57 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
60 expected_result = json.loads(sample_output)
61 self.assertEqual(result, expected_result)
63 def test_unixbench_successful_in_quiet_mode(self, mock_ssh):
66 "test_type": 'dhry2reg',
73 u = unixbench.Unixbench(args, self.ctx)
76 u.server = mock_ssh.SSH()
78 sample_output = '{"Score":"4425.4"}'
79 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
82 expected_result = json.loads(sample_output)
83 self.assertEqual(result, expected_result)
86 def test_unixbench_successful_sla(self, mock_ssh):
89 "test_type": 'dhry2reg',
93 "single_score": '100',
94 "parallel_score": '500'
100 u = unixbench.Unixbench(args, self.ctx)
103 u.server = mock_ssh.SSH()
105 sample_output = '{"signle_score":"2251.7","parallel_score":"4395.9"}'
106 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
109 expected_result = json.loads(sample_output)
110 self.assertEqual(result, expected_result)
112 def test_unixbench_unsuccessful_sla_single_score(self, mock_ssh):
116 "sla": {"single_score": "500"}
118 u = unixbench.Unixbench(args, self.ctx)
121 u.server = mock_ssh.SSH()
122 sample_output = '{"single_score":"200.7","parallel_score":"4395.9"}'
124 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
125 self.assertRaises(AssertionError, u.run, result)
127 def test_unixbench_unsuccessful_sla_parallel_score(self, mock_ssh):
131 "sla": {"parallel_score": "4000"}
133 u = unixbench.Unixbench(args, self.ctx)
136 u.server = mock_ssh.SSH()
137 sample_output = '{"signle_score":"2251.7","parallel_score":"3395.9"}'
139 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
140 self.assertRaises(AssertionError, u.run, result)
142 def test_unixbench_unsuccessful_script_error(self, mock_ssh):
145 "test_type": 'dhry2reg',
146 "run_mode": 'verbose'
149 "single_score": '100',
150 "parallel_score": '500'
156 u = unixbench.Unixbench(args, self.ctx)
159 u.server = mock_ssh.SSH()
161 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
162 self.assertRaises(RuntimeError, u.run, result)
168 if __name__ == '__main__':