Merge "DRAFT: remove apexlake"
[yardstick.git] / tests / unit / benchmark / scenarios / compute / test_spec_cpu.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 #
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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.compute.spec_cpu.SpecCPU
13
14 from __future__ import absolute_import
15
16 import unittest
17
18 import mock
19
20 from yardstick.common import utils
21 from yardstick.benchmark.scenarios.compute import spec_cpu
22
23
24 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu.ssh')
25 class SpecCPUTestCase(unittest.TestCase):
26
27     def setUp(self):
28         self.ctx = {
29             'host': {
30                 'ip': '172.16.0.137',
31                 'user': 'root',
32                 'key_filename': "mykey.key"
33             }
34         }
35
36         self.result = {}
37
38     def test_spec_cpu_successful_setup(self, mock_ssh):
39
40         options = {
41             "SPECint_benchmark": "perlbench",
42             "runspec_tune": "all",
43             "output_format": "all",
44             "runspec_iterations": "1",
45             "runspec_tune": "base",
46             "runspec_size": "test"
47         }
48         args = {"options": options}
49         s = spec_cpu.SpecCPU(args, self.ctx)
50         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
51
52         s.setup()
53         self.assertIsNotNone(s.client)
54         self.assertTrue(s.setup_done, True)
55
56     def test_spec_cpu_successful__run_no_sla(self, mock_ssh):
57
58         options = {
59             "SPECint_benchmark": "perlbench",
60             "runspec_tune": "all",
61             "output_format": "all"
62         }
63         args = {"options": options}
64         s = spec_cpu.SpecCPU(args, self.ctx)
65
66         sample_output = ''
67         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
68         s.run(self.result)
69         expected_result = {}
70         self.assertEqual(self.result, expected_result)
71
72     def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
73         options = {
74             "benchmark_subset": "int"
75         }
76         args = {"options": options}
77         s = spec_cpu.SpecCPU(args, self.ctx)
78
79         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
80         self.assertRaises(RuntimeError, s.run, self.result)
81
82 def main():
83     unittest.main()
84
85 if __name__ == '__main__':
86     main()