3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd 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.ramspeed.Ramspeed
18 from yardstick.benchmark.scenarios.compute import ramspeed
21 @mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
22 class RamspeedTestCase(unittest.TestCase):
29 'key_filename': "mykey.key"
35 def test_ramspeed_successful_setup(self, mock_ssh):
37 r = ramspeed.Ramspeed({}, self.ctx)
38 mock_ssh.SSH().execute.return_value = (0, '', '')
41 self.assertIsNotNone(r.client)
42 self.assertTrue(r.setup_done, True)
44 def test_ramspeed_successful__run_no_sla(self, mock_ssh):
51 args = {"options": options}
52 r = ramspeed.Ramspeed(args, self.ctx)
54 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
55 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
56 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
57 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
58 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
59 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
60 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
61 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
62 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
63 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
64 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
65 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
66 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
67 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
68 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
69 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
70 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
71 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
72 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
73 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
74 "Bandwidth(MBps)": 8340.85}]}'
75 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
77 expected_result = json.loads(sample_output)
78 self.assertEqual(self.result, expected_result)
80 def test_ramspeed_successful_run_sla(self, mock_ssh):
87 args = {"options": options, "sla": {"min_bandwidth": 6000}}
88 r = ramspeed.Ramspeed(args, self.ctx)
90 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
91 "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
92 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
93 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
94 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
95 "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
96 "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
97 "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
98 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
99 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
100 "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
101 "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
102 "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
103 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
104 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
105 "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
106 "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
107 "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
108 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
109 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
110 "Bandwidth(MBps)": 8340.85}]}'
111 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
113 expected_result = json.loads(sample_output)
114 self.assertEqual(self.result, expected_result)
116 def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
122 args = {"options": options, "sla": {"min_bandwidth": 100000}}
123 r = ramspeed.Ramspeed(args, self.ctx)
125 sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
126 "Block_size(kb)": 1, "Bandwidth(MBps)": 5000.18}, {"Test_type":\
127 "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 5000.89},\
128 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4,\
129 "Bandwidth(MBps)": 5000.56}, {"Test_type": "INTEGER & WRITING",\
130 "Block_size(kb)": 8, "Bandwidth(MBps)": 19906.94}, {"Test_type":\
131 "INTEGER & WRITING", "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74},\
132 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32,\
133 "Bandwidth(MBps)": 19395.65}, {"Test_type": "INTEGER & WRITING",\
134 "Block_size(kb)": 64, "Bandwidth(MBps)": 17623.14}, {"Test_type":\
135 "INTEGER & WRITING", "Block_size(kb)": 128, "Bandwidth(MBps)": 17677.36},\
136 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 256, "Bandwidth(MBps)":\
137 16113.49}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 512,\
138 "Bandwidth(MBps)": 14659.19}, {"Test_type": "INTEGER & WRITING",\
139 "Block_size(kb)": 1024, "Bandwidth(MBps)": 14680.75}, {"Test_type":\
140 "INTEGER & WRITING", "Block_size(kb)": 2048, "Bandwidth(MBps)": 14756.45},\
141 {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4096, "Bandwidth(MBps)":\
142 14604.44}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8192,\
143 "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\
144 "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\
145 "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
146 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
147 self.assertRaises(AssertionError, r.run, self.result)
149 def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
155 args = {"options": options}
156 r = ramspeed.Ramspeed(args, self.ctx)
158 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
159 self.assertRaises(RuntimeError, r.run, self.result)
161 def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
168 args = {"options": options}
169 r = ramspeed.Ramspeed(args, self.ctx)
171 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
172 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
173 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
174 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
175 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
176 "Bandwidth(MBps)": 9401.58}]}'
177 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
179 expected_result = json.loads(sample_output)
180 self.assertEqual(self.result, expected_result)
182 def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
189 args = {"options": options, "sla": {"min_bandwidth": 6000}}
190 r = ramspeed.Ramspeed(args, self.ctx)
192 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
193 "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
194 "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
195 "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
196 "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
197 "Bandwidth(MBps)": 9401.58}]}'
198 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
200 expected_result = json.loads(sample_output)
201 self.assertEqual(self.result, expected_result)
203 def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
210 args = {"options": options, "sla": {"min_bandwidth": 86000}}
211 r = ramspeed.Ramspeed(args, self.ctx)
213 sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
214 "Bandwidth(MBps)": 4000.97}, {"Test_type": "INTEGER Scale:",\
215 "Bandwidth(MBps)": 4400.59}, {"Test_type": "INTEGER Add:",\
216 "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\
217 "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\
218 "Bandwidth(MBps)": 2401.58}]}'
219 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
220 self.assertRaises(AssertionError, r.run, self.result)
222 def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
228 args = {'options': options}
229 r = ramspeed.Ramspeed(args, self.ctx)
231 mock_ssh.SSH().execute.return_value = (1, '', 'No such type_id: 30 for \
233 self.assertRaises(RuntimeError, r.run, self.result)
239 if __name__ == '__main__':