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 # pylint: disable=unused-argument
25 # disable this for now because I keep forgetting mock patch arg ordering
28 @mock.patch('yardstick.benchmark.scenarios.compute.lmbench.ssh')
29 class LmbenchTestCase(unittest.TestCase):
36 'key_filename': "mykey.key"
42 def test_successful_setup(self, mock_ssh):
44 l = lmbench.Lmbench({}, self.ctx)
45 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
48 self.assertIsNotNone(l.client)
49 self.assertTrue(l.setup_done)
51 def test_unsuccessful_unknown_type_run(self, mock_ssh):
56 args = {'options': options}
58 l = lmbench.Lmbench(args, self.ctx)
60 self.assertRaises(RuntimeError, l.run, self.result)
62 def test_successful_latency_run_no_sla(self, mock_ssh):
65 "test_type": "latency",
69 args = {'options': options}
70 l = lmbench.Lmbench(args, self.ctx)
72 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
73 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
75 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
76 self.assertEqual(self.result, expected_result)
78 def test_successful_bandwidth_run_no_sla(self, mock_ssh):
81 "test_type": "bandwidth",
86 args = {"options": options}
87 l = lmbench.Lmbench(args, self.ctx)
89 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
90 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
92 expected_result = jsonutils.loads(sample_output)
93 self.assertEqual(self.result, expected_result)
95 def test_successful_latency_run_sla(self, mock_ssh):
98 "test_type": "latency",
104 "sla": {"max_latency": 35}
106 l = lmbench.Lmbench(args, self.ctx)
108 sample_output = '[{"latency": 4.944, "size": 0.00049}]'
109 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
111 expected_result = {"latencies0.latency": 4.944, "latencies0.size": 0.00049}
112 self.assertEqual(self.result, expected_result)
114 def test_successful_bandwidth_run_sla(self, mock_ssh):
117 "test_type": "bandwidth",
124 "sla": {"min_bandwidth": 10000}
126 l = lmbench.Lmbench(args, self.ctx)
128 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
129 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
131 expected_result = jsonutils.loads(sample_output)
132 self.assertEqual(self.result, expected_result)
134 def test_unsuccessful_latency_run_sla(self, mock_ssh):
137 "test_type": "latency",
143 "sla": {"max_latency": 35}
145 l = lmbench.Lmbench(args, self.ctx)
147 sample_output = '[{"latency": 37.5, "size": 0.00049}]'
148 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
149 self.assertRaises(AssertionError, l.run, self.result)
151 def test_unsuccessful_bandwidth_run_sla(self, mock_ssh):
154 "test_type": "bandwidth",
161 "sla": {"min_bandwidth": 10000}
163 l = lmbench.Lmbench(args, self.ctx)
165 sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 9925.5}'
166 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
167 self.assertRaises(AssertionError, l.run, self.result)
169 def test_successful_latency_for_cache_run_sla(self, mock_ssh):
172 "test_type": "latency_for_cache",
178 "sla": {"max_latency": 35}
180 l = lmbench.Lmbench(args, self.ctx)
182 sample_output = "{\"L1cache\": 1.6}"
183 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
185 expected_result = jsonutils.loads(sample_output)
186 self.assertEqual(self.result, expected_result)
188 def test_unsuccessful_script_error(self, mock_ssh):
190 options = {"test_type": "bandwidth"}
191 args = {"options": options}
192 l = lmbench.Lmbench(args, self.ctx)
194 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
195 self.assertRaises(RuntimeError, l.run, self.result)
201 if __name__ == '__main__':