74612d7b642423218cfa62690836608b0e46b6d1
[yardstick.git] / yardstick / 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.benchmark.scenarios.compute import spec_cpu
21
22
23 @mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu.ssh')
24 class SpecCPUTestCase(unittest.TestCase):
25
26     def setUp(self):
27         self.ctx = {
28             'host': {
29                 'ip': '172.16.0.137',
30                 'user': 'root',
31                 'key_filename': "mykey.key"
32             }
33         }
34
35         self.result = {}
36
37     def test_spec_cpu_successful_setup(self, mock_ssh):
38
39         options = {
40             "SPECint_benchmark": "perlbench",
41             "output_format": "all",
42             "runspec_iterations": "1",
43             "runspec_tune": "base",
44             "runspec_size": "test"
45         }
46         args = {"options": options}
47         s = spec_cpu.SpecCPU(args, self.ctx)
48         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
49
50         s.setup()
51         self.assertIsNotNone(s.client)
52         self.assertTrue(s.setup_done, True)
53
54     def test_spec_cpu_successful__run_no_sla(self, mock_ssh):
55
56         options = {
57             "SPECint_benchmark": "perlbench",
58             "runspec_tune": "all",
59             "output_format": "all"
60         }
61         args = {"options": options}
62         s = spec_cpu.SpecCPU(args, self.ctx)
63
64         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
65         s.run(self.result)
66         expected_result = {}
67         self.assertEqual(self.result, expected_result)
68
69     def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
70         options = {
71             "benchmark_subset": "int"
72         }
73         args = {"options": options}
74         s = spec_cpu.SpecCPU(args, self.ctx)
75
76         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
77         self.assertRaises(RuntimeError, s.run, self.result)
78
79
80 def main():
81     unittest.main()
82
83
84 if __name__ == '__main__':
85     main()