3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
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.lmbench.Lmbench
18 from yardstick.benchmark.scenarios.compute import lmbench
21 @mock.patch('yardstick.benchmark.scenarios.compute.lmbench.ssh')
22 class LmbenchTestCase(unittest.TestCase):
29 'key_filename': "mykey.key"
35 def test_successful_setup(self, mock_ssh):
37 l = lmbench.Lmbench({}, self.ctx)
38 mock_ssh.SSH().execute.return_value = (0, '', '')
41 self.assertIsNotNone(l.client)
42 self.assertTrue(l.setup_done)
44 def test_unsuccessful_unknown_type_run(self, mock_ssh):
49 args = {'options': options}
51 l = lmbench.Lmbench(args, self.ctx)
53 self.assertRaises(RuntimeError, l.run, self.result)
55 def test_successful_latency_run_no_sla(self, mock_ssh):
58 "test_type": "latency",
62 args = {'options': options}
63 l = lmbench.Lmbench(args, self.ctx)
65 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
66 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
68 expected_result = json.loads('{"latencies": ' + sample_output + "}")
69 self.assertEqual(self.result, expected_result)
71 def test_successful_bandwidth_run_no_sla(self, mock_ssh):
74 "test_type": "bandwidth",
79 args = {"options": options}
80 l = lmbench.Lmbench(args, self.ctx)
82 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
83 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
85 expected_result = json.loads(sample_output)
86 self.assertEqual(self.result, expected_result)
88 def test_successful_latency_run_sla(self, mock_ssh):
91 "test_type": "latency",
97 "sla": {"max_latency": 35}
99 l = lmbench.Lmbench(args, self.ctx)
101 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
102 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
104 expected_result = json.loads('{"latencies": ' + sample_output + "}")
105 self.assertEqual(self.result, expected_result)
107 def test_successful_bandwidth_run_sla(self, mock_ssh):
110 "test_type": "bandwidth",
117 "sla": {"min_bandwidth": 10000}
119 l = lmbench.Lmbench(args, self.ctx)
121 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
122 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
124 expected_result = json.loads(sample_output)
125 self.assertEqual(self.result, expected_result)
127 def test_unsuccessful_latency_run_sla(self, mock_ssh):
130 "test_type": "latency",
136 "sla": {"max_latency": 35}
138 l = lmbench.Lmbench(args, self.ctx)
140 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
141 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
142 self.assertRaises(AssertionError, l.run, self.result)
144 def test_unsuccessful_bandwidth_run_sla(self, mock_ssh):
147 "test_type": "bandwidth",
154 "sla": {"min_bandwidth": 10000}
156 l = lmbench.Lmbench(args, self.ctx)
158 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
159 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
160 self.assertRaises(AssertionError, l.run, self.result)
162 def test_successful_latency_for_cache_run_sla(self, mock_ssh):
165 "test_type": "latency_for_cache",
171 "sla": {"max_latency": 35}
173 l = lmbench.Lmbench(args, self.ctx)
175 sample_output = "{\"L1cache\": 1.6}"
176 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
178 expected_result = json.loads(sample_output)
179 self.assertEqual(self.result, expected_result)
181 def test_unsuccessful_script_error(self, mock_ssh):
183 options = {"test_type": "bandwidth"}
184 args = {"options": options}
185 l = lmbench.Lmbench(args, self.ctx)
187 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
188 self.assertRaises(RuntimeError, l.run, self.result)