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
14 from __future__ import absolute_import
19 from oslo_serialization import jsonutils
21 from yardstick.benchmark.scenarios.compute import lmbench
24 @mock.patch('yardstick.benchmark.scenarios.compute.lmbench.ssh')
25 class LmbenchTestCase(unittest.TestCase):
32 'key_filename': "mykey.key"
38 def test_successful_setup(self, mock_ssh):
40 l = lmbench.Lmbench({}, self.ctx)
41 mock_ssh.SSH().execute.return_value = (0, '', '')
44 self.assertIsNotNone(l.client)
45 self.assertTrue(l.setup_done)
47 def test_unsuccessful_unknown_type_run(self, mock_ssh):
52 args = {'options': options}
54 l = lmbench.Lmbench(args, self.ctx)
56 self.assertRaises(RuntimeError, l.run, self.result)
58 def test_successful_latency_run_no_sla(self, mock_ssh):
61 "test_type": "latency",
65 args = {'options': options}
66 l = lmbench.Lmbench(args, self.ctx)
68 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
69 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
71 expected_result = jsonutils.loads(
72 '{"latencies": ' + sample_output + "}")
73 self.assertEqual(self.result, expected_result)
75 def test_successful_bandwidth_run_no_sla(self, mock_ssh):
78 "test_type": "bandwidth",
83 args = {"options": options}
84 l = lmbench.Lmbench(args, self.ctx)
86 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
87 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
89 expected_result = jsonutils.loads(sample_output)
90 self.assertEqual(self.result, expected_result)
92 def test_successful_latency_run_sla(self, mock_ssh):
95 "test_type": "latency",
101 "sla": {"max_latency": 35}
103 l = lmbench.Lmbench(args, self.ctx)
105 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
106 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
108 expected_result = jsonutils.loads(
109 '{"latencies": ' + sample_output + "}")
110 self.assertEqual(self.result, expected_result)
112 def test_successful_bandwidth_run_sla(self, mock_ssh):
115 "test_type": "bandwidth",
122 "sla": {"min_bandwidth": 10000}
124 l = lmbench.Lmbench(args, self.ctx)
126 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
127 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
129 expected_result = jsonutils.loads(sample_output)
130 self.assertEqual(self.result, expected_result)
132 def test_unsuccessful_latency_run_sla(self, mock_ssh):
135 "test_type": "latency",
141 "sla": {"max_latency": 35}
143 l = lmbench.Lmbench(args, self.ctx)
145 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
146 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
147 self.assertRaises(AssertionError, l.run, self.result)
149 def test_unsuccessful_bandwidth_run_sla(self, mock_ssh):
152 "test_type": "bandwidth",
159 "sla": {"min_bandwidth": 10000}
161 l = lmbench.Lmbench(args, self.ctx)
163 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
164 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
165 self.assertRaises(AssertionError, l.run, self.result)
167 def test_successful_latency_for_cache_run_sla(self, mock_ssh):
170 "test_type": "latency_for_cache",
176 "sla": {"max_latency": 35}
178 l = lmbench.Lmbench(args, self.ctx)
180 sample_output = "{\"L1cache\": 1.6}"
181 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
183 expected_result = jsonutils.loads(sample_output)
184 self.assertEqual(self.result, expected_result)
186 def test_unsuccessful_script_error(self, mock_ssh):
188 options = {"test_type": "bandwidth"}
189 args = {"options": options}
190 l = lmbench.Lmbench(args, self.ctx)
192 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
193 self.assertRaises(RuntimeError, l.run, self.result)