1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from copy import deepcopy
14 from itertools import product, chain
18 from six.moves import configparser
23 from yardstick import ssh
24 from yardstick.common import constants
25 from yardstick.common import utils
26 from yardstick.common import exceptions
29 class IterSubclassesTestCase(unittest.TestCase):
30 # Disclaimer: this class is a modified copy from
31 # rally/tests/unit/common/plugin/test_discover.py
32 # Copyright 2015: Mirantis Inc.
34 def test_itersubclasses(self):
47 self.assertEqual([B, C, D], list(utils.itersubclasses(A)))
50 class ImportModulesFromPackageTestCase(unittest.TestCase):
52 @mock.patch('yardstick.common.utils.os.walk')
53 def test_import_modules_from_package_no_mod(self, mock_walk):
54 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
55 mock_walk.return_value = ([
56 (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']),
57 (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst'])
60 utils.import_modules_from_package('foo.bar')
62 @mock.patch('yardstick.common.utils.os.walk')
63 @mock.patch.object(importlib, 'import_module')
64 def test_import_modules_from_package(self, mock_import_module, mock_walk):
66 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
67 mock_walk.return_value = ([
68 (os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py'])
71 utils.import_modules_from_package('foo.bar')
72 mock_import_module.assert_called_once_with('bar.baz')
75 class GetParaFromYaml(unittest.TestCase):
77 @mock.patch('yardstick.common.utils.os.environ.get')
78 def test_get_param_para_not_found(self, get_env):
79 file_path = 'config_sample.yaml'
80 get_env.return_value = self._get_file_abspath(file_path)
83 self.assertTrue(constants.get_param(args, default), default)
85 @mock.patch('yardstick.common.utils.os.environ.get')
86 def test_get_param_para_exists(self, get_env):
87 file_path = 'config_sample.yaml'
88 get_env.return_value = self._get_file_abspath(file_path)
90 para = '/home/opnfv/repos/releng'
91 self.assertEqual(para, constants.get_param(args))
93 def _get_file_abspath(self, filename):
94 curr_path = os.path.dirname(os.path.abspath(__file__))
95 file_path = os.path.join(curr_path, filename)
99 class CommonUtilTestCase(unittest.TestCase):
120 def test__dict_key_flatten(self):
121 line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \
122 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
123 # need to sort for assert to work
124 line = ",".join(sorted(line.split(',')))
125 flattened_data = utils.flatten_dict_key(
126 self.data['benchmark']['data'])
128 ("=".join(item) for item in sorted(flattened_data.items())))
129 self.assertEqual(result, line)
131 def test_get_key_with_default_negative(self):
132 with self.assertRaises(KeyError):
133 utils.get_key_with_default({}, 'key1')
135 @mock.patch('yardstick.common.utils.open', create=True)
136 def test_(self, mock_open):
137 mock_open.side_effect = IOError
139 with self.assertRaises(IOError):
140 utils.find_relative_file('my/path', 'task/path')
142 self.assertEqual(mock_open.call_count, 2)
144 @mock.patch('yardstick.common.utils.open', create=True)
145 def test_open_relative_path(self, mock_open):
146 mock_open_result = mock_open()
147 mock_open_call_count = 1 # initial call to get result
149 self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
151 mock_open_call_count += 1 # one more call expected
152 self.assertEqual(mock_open.call_count, mock_open_call_count)
153 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
154 self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])
156 def open_effect(*args, **kwargs):
157 if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
158 return mock_open_result
159 raise IOError(errno.ENOENT, 'not found')
161 mock_open.side_effect = open_effect
162 self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
164 mock_open_call_count += 2 # two more calls expected
165 self.assertEqual(mock_open.call_count, mock_open_call_count)
166 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
167 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
169 # test an IOError of type ENOENT
170 mock_open.side_effect = IOError(errno.ENOENT, 'not found')
171 with self.assertRaises(IOError):
172 # the second call still raises
173 utils.open_relative_file('foo', 'bar')
175 mock_open_call_count += 2 # two more calls expected
176 self.assertEqual(mock_open.call_count, mock_open_call_count)
177 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
178 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
180 # test an IOError other than ENOENT
181 mock_open.side_effect = IOError(errno.EBUSY, 'busy')
182 with self.assertRaises(IOError):
183 utils.open_relative_file('foo', 'bar')
185 mock_open_call_count += 1 # one more call expected
186 self.assertEqual(mock_open.call_count, mock_open_call_count)
189 class TestMacAddressToHex(unittest.TestCase):
191 def test_mac_address_to_hex_list(self):
192 self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
193 ['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
196 class TranslateToStrTestCase(unittest.TestCase):
198 def test_translate_to_str_unicode(self):
200 output_str = utils.translate_to_str(input_str)
203 self.assertEqual(result, output_str)
205 def test_translate_to_str_dict_list_unicode(self):
207 u'hello': {u'hello': [u'world']}
209 output_str = utils.translate_to_str(input_str)
212 'hello': {'hello': ['world']}
214 self.assertEqual(result, output_str)
216 def test_translate_to_str_non_string(self):
217 input_value = object()
218 result = utils.translate_to_str(input_value)
219 self.assertIs(input_value, result)
222 class TestParseCpuInfo(unittest.TestCase):
224 def test_single_socket_no_hyperthread(self):
227 vendor_id : GenuineIntel
230 model name : Intel Core Processor (Haswell, no TSX)
245 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat
250 address sizes : 46 bits physical, 48 bits virtual
254 vendor_id : GenuineIntel
257 model name : Intel Core Processor (Haswell, no TSX)
272 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat
277 address sizes : 46 bits physical, 48 bits virtual
281 vendor_id : GenuineIntel
284 model name : Intel Core Processor (Haswell, no TSX)
299 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat
304 address sizes : 46 bits physical, 48 bits virtual
308 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
309 self.assertEqual(sorted(socket_map.keys()), [0])
310 self.assertEqual(sorted(socket_map[0].keys()), [2, 3, 4])
312 def test_single_socket_hyperthread(self):
315 vendor_id : GenuineIntel
318 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
333 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
338 address sizes : 39 bits physical, 48 bits virtual
342 vendor_id : GenuineIntel
345 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
360 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
365 address sizes : 39 bits physical, 48 bits virtual
369 vendor_id : GenuineIntel
372 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
387 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts
392 address sizes : 39 bits physical, 48 bits virtual
396 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
397 self.assertEqual(sorted(socket_map.keys()), [0])
398 self.assertEqual(sorted(socket_map[0].keys()), [1, 2, 3])
399 self.assertEqual(sorted(socket_map[0][1]), [5])
400 self.assertEqual(sorted(socket_map[0][2]), [6])
401 self.assertEqual(sorted(socket_map[0][3]), [7])
403 def test_dual_socket_hyperthread(self):
406 vendor_id : GenuineIntel
409 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
411 microcode : 0xb00001f
413 cache size : 56320 KB
424 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
429 address sizes : 46 bits physical, 48 bits virtual
433 vendor_id : GenuineIntel
436 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
438 microcode : 0xb00001f
440 cache size : 56320 KB
451 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
456 address sizes : 46 bits physical, 48 bits virtual
460 vendor_id : GenuineIntel
463 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
465 microcode : 0xb00001f
467 cache size : 56320 KB
478 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
483 address sizes : 46 bits physical, 48 bits virtual
487 vendor_id : GenuineIntel
490 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
492 microcode : 0xb00001f
494 cache size : 56320 KB
505 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
510 address sizes : 46 bits physical, 48 bits virtual
514 vendor_id : GenuineIntel
517 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
519 microcode : 0xb00001f
521 cache size : 56320 KB
532 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
537 address sizes : 46 bits physical, 48 bits virtual
541 vendor_id : GenuineIntel
544 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
546 microcode : 0xb00001f
548 cache size : 56320 KB
559 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
564 address sizes : 46 bits physical, 48 bits virtual
568 vendor_id : GenuineIntel
571 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
573 microcode : 0xb00001f
575 cache size : 56320 KB
586 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
591 address sizes : 46 bits physical, 48 bits virtual
595 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
596 self.assertEqual(sorted(socket_map.keys()), [0, 1])
597 self.assertEqual(sorted(socket_map[0].keys()), [0, 1, 2])
598 self.assertEqual(sorted(socket_map[1].keys()), [26, 27, 28])
599 self.assertEqual(sorted(socket_map[0][0]), [44])
600 self.assertEqual(sorted(socket_map[0][1]), [1])
601 self.assertEqual(sorted(socket_map[0][2]), [2])
602 self.assertEqual(sorted(socket_map[1][26]), [85])
603 self.assertEqual(sorted(socket_map[1][27]), [86])
604 self.assertEqual(sorted(socket_map[1][28]), [43, 87])
606 def test_dual_socket_no_hyperthread(self):
609 vendor_id : GenuineIntel
612 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
614 microcode : 0xb00001f
616 cache size : 56320 KB
627 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
632 address sizes : 46 bits physical, 48 bits virtual
636 vendor_id : GenuineIntel
639 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
641 microcode : 0xb00001f
643 cache size : 56320 KB
654 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
659 address sizes : 46 bits physical, 48 bits virtual
663 vendor_id : GenuineIntel
666 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
668 microcode : 0xb00001f
670 cache size : 56320 KB
681 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
686 address sizes : 46 bits physical, 48 bits virtual
690 vendor_id : GenuineIntel
693 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
695 microcode : 0xb00001f
697 cache size : 56320 KB
708 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
713 address sizes : 46 bits physical, 48 bits virtual
717 vendor_id : GenuineIntel
720 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
722 microcode : 0xb00001f
724 cache size : 56320 KB
735 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
740 address sizes : 46 bits physical, 48 bits virtual
744 vendor_id : GenuineIntel
747 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
749 microcode : 0xb00001f
751 cache size : 56320 KB
762 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
767 address sizes : 46 bits physical, 48 bits virtual
771 vendor_id : GenuineIntel
774 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
776 microcode : 0xb00001f
778 cache size : 56320 KB
789 flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
794 address sizes : 46 bits physical, 48 bits virtual
798 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
799 processors = socket_map.processors()
800 self.assertEqual(processors, [1, 2, 43, 44, 85, 86, 87])
801 cores = socket_map.cores()
802 self.assertEqual(cores, [0, 1, 2, 26, 27, 28])
803 sockets = socket_map.sockets()
804 self.assertEqual(sockets, [0, 1])
807 class ChangeObjToDictTestCase(unittest.TestCase):
809 def test_change_obj_to_dict(self):
812 self.name = 'yardstick'
815 obj_r = utils.change_obj_to_dict(obj)
816 obj_s = {'name': 'yardstick'}
817 self.assertEqual(obj_r, obj_s)
820 class SetDictValueTestCase(unittest.TestCase):
822 def test_set_dict_value(self):
826 output_dic = utils.set_dict_value(input_dic, 'welcome.to', 'yardstick')
827 self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick')
830 class RemoveFileTestCase(unittest.TestCase):
832 def test_remove_file(self):
834 utils.remove_file('notexistfile.txt')
835 except Exception as e: # pylint: disable=broad-except
836 # NOTE(ralonsoh): to narrow the scope of this exception.
837 self.assertTrue(isinstance(e, OSError))
840 class TestUtils(unittest.TestCase):
842 @mock.patch('yardstick.common.utils.os.makedirs')
843 def test_makedirs(self, *_):
844 self.assertIsNone(utils.makedirs('a/b/c/d'))
846 @mock.patch('yardstick.common.utils.os.makedirs')
847 def test_makedirs_exists(self, mock_os_makedirs):
848 mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
849 self.assertIsNone(utils.makedirs('a/b/c/d'))
851 @mock.patch('yardstick.common.utils.os.makedirs')
852 def test_makedirs_busy(self, mock_os_makedirs):
853 mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
854 with self.assertRaises(OSError):
855 utils.makedirs('a/b/c/d')
857 @mock.patch('yardstick.common.utils.jsonify')
858 def test_result_handler(self, mock_jsonify):
859 mock_jsonify.return_value = 432
861 self.assertEqual(utils.result_handler('x', 234), 432)
862 mock_jsonify.assert_called_once_with({'status': 'x', 'result': 234})
864 @mock.patch('random.randint')
865 @mock.patch('socket.socket')
866 def test_get_free_port(self, mock_socket, mock_randint):
867 mock_randint.return_value = 7777
868 s = mock_socket('x', 'y')
869 s.connect_ex.side_effect = iter([0, 1])
870 result = utils.get_free_port('10.20.30.40')
871 self.assertEqual(result, 7777)
872 self.assertEqual(s.connect_ex.call_count, 2)
874 @mock.patch('subprocess.check_output')
875 def test_execute_command(self, mock_check_output):
876 expected = ['hello world', '1234']
877 mock_check_output.return_value = os.linesep.join(expected)
878 result = utils.execute_command('my_command arg1 arg2')
879 self.assertEqual(result, expected)
881 @mock.patch('subprocess.Popen')
882 def test_source_env(self, mock_popen):
883 base_env = deepcopy(os.environ)
884 mock_process = mock_popen()
886 'garbage line before',
888 'garbage line after',
890 mock_process.communicate.return_value = os.linesep.join(output_list), '', 0
891 expected = {'NEW_ENV_VALUE': '234'}
892 result = utils.source_env('my_file')
893 self.assertDictEqual(result, expected)
895 os.environ.update(base_env)
897 @mock.patch.object(configparser, 'ConfigParser')
898 def test_parse_ini_file(self, mock_config_parser_type):
900 'default1': 'value1',
901 'default2': 'value2',
912 mock_config_parser = mock_config_parser_type()
913 mock_config_parser.read.return_value = True
914 mock_config_parser.sections.return_value = ['s1', 's2']
915 mock_config_parser.items.side_effect = iter([
926 result = utils.parse_ini_file('my_path')
927 self.assertDictEqual(result, expected)
929 @mock.patch.object(utils, 'logger')
930 @mock.patch.object(configparser, 'ConfigParser')
931 def test_parse_ini_file_missing_section_header(
932 self, mock_config_parser_type, *args):
933 mock_config_parser = mock_config_parser_type()
934 mock_config_parser.read.side_effect = (
935 configparser.MissingSectionHeaderError(mock.Mock(), 321,
938 with self.assertRaises(configparser.MissingSectionHeaderError):
939 utils.parse_ini_file('my_path')
941 @mock.patch.object(configparser, 'ConfigParser')
942 def test_parse_ini_file_no_file(self, mock_config_parser_type):
943 mock_config_parser = mock_config_parser_type()
944 mock_config_parser.read.return_value = False
945 with self.assertRaises(RuntimeError):
946 utils.parse_ini_file('my_path')
948 @mock.patch.object(configparser, 'ConfigParser')
949 def test_parse_ini_file_no_default_section_header(self, mock_config_parser_type):
959 mock_config_parser = mock_config_parser_type()
960 mock_config_parser.read.return_value = True
961 mock_config_parser.sections.return_value = ['s1', 's2']
962 mock_config_parser.items.side_effect = iter([
963 configparser.NoSectionError(mock.Mock()),
973 result = utils.parse_ini_file('my_path')
974 self.assertDictEqual(result, expected)
976 def test_join_non_strings(self):
977 self.assertEqual(utils.join_non_strings(':'), '')
978 self.assertEqual(utils.join_non_strings(':', 'a'), 'a')
979 self.assertEqual(utils.join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
980 self.assertEqual(utils.join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
981 self.assertEqual(utils.join_non_strings(':', 'abc'), 'abc')
983 def test_validate_non_string_sequence(self):
984 self.assertEqual(utils.validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
985 self.assertIsNone(utils.validate_non_string_sequence('123'))
986 self.assertIsNone(utils.validate_non_string_sequence(1))
988 self.assertEqual(utils.validate_non_string_sequence(1, 2), 2)
989 self.assertEqual(utils.validate_non_string_sequence(1, default=2), 2)
991 with self.assertRaises(RuntimeError):
992 utils.validate_non_string_sequence(1, raise_exc=RuntimeError)
995 class TestUtilsIpAddrMethods(unittest.TestCase):
997 GOOD_IP_V4_ADDRESS_STR_LIST = [
1007 GOOD_IP_V4_MASK_STR_LIST = [
1016 GOOD_IP_V6_ADDRESS_STR_LIST = [
1018 u'fe80::250:56ff:fe89:91ff',
1019 u'123:4567:89ab:cdef:123:4567:89ab:cdef',
1022 GOOD_IP_V6_MASK_STR_LIST = [
1031 INVALID_IP_ADDRESS_STR_LIST = [
1035 u'123:4567:89ab:cdef:123:4567:89ab:cdef/129',
1038 def test_safe_ip_address(self):
1039 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1040 for addr in addr_list:
1042 expected = ipaddress.ip_address(addr)
1043 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
1045 def test_safe_ip_address_v6_ip(self):
1046 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1047 for addr in addr_list:
1049 expected = ipaddress.ip_address(addr)
1050 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
1052 @mock.patch("yardstick.common.utils.logging")
1053 def test_safe_ip_address_negative(self, *args):
1054 # NOTE(ralonsoh): check the calls to mocked functions.
1055 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1056 self.assertIsNone(utils.safe_ip_address(value), value)
1058 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1059 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1060 for addr_mask_pair in product(addr_list, mask_list):
1061 value = ''.join(addr_mask_pair)
1062 self.assertIsNone(utils.safe_ip_address(value), value)
1064 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1065 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1066 for addr_mask_pair in product(addr_list, mask_list):
1067 value = ''.join(addr_mask_pair)
1068 self.assertIsNone(utils.safe_ip_address(value), value)
1070 def test_get_ip_version(self):
1071 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1072 for addr in addr_list:
1074 self.assertEqual(utils.get_ip_version(addr), 4, addr)
1076 def test_get_ip_version_v6_ip(self):
1077 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1078 for addr in addr_list:
1080 self.assertEqual(utils.get_ip_version(addr), 6, addr)
1082 @mock.patch("yardstick.common.utils.logging")
1083 def test_get_ip_version_negative(self, *args):
1084 # NOTE(ralonsoh): check the calls to mocked functions.
1085 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1086 self.assertIsNone(utils.get_ip_version(value), value)
1088 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1089 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1090 for addr_mask_pair in product(addr_list, mask_list):
1091 value = ''.join(addr_mask_pair)
1092 self.assertIsNone(utils.get_ip_version(value), value)
1094 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1095 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1096 for addr_mask_pair in product(addr_list, mask_list):
1097 value = ''.join(addr_mask_pair)
1098 self.assertIsNone(utils.get_ip_version(value), value)
1100 def test_ip_to_hex(self):
1101 self.assertEqual(utils.ip_to_hex('0.0.0.0'), '00000000')
1102 self.assertEqual(utils.ip_to_hex('10.20.30.40'), '0a141e28')
1103 self.assertEqual(utils.ip_to_hex('127.0.0.1'), '7f000001')
1104 self.assertEqual(utils.ip_to_hex('172.31.90.100'), 'ac1f5a64')
1105 self.assertEqual(utils.ip_to_hex('192.168.254.253'), 'c0a8fefd')
1106 self.assertEqual(utils.ip_to_hex('255.255.255.255'), 'ffffffff')
1108 def test_ip_to_hex_v6_ip(self):
1109 for value in self.GOOD_IP_V6_ADDRESS_STR_LIST:
1110 self.assertEqual(utils.ip_to_hex(value), value)
1112 @mock.patch("yardstick.common.utils.logging")
1113 def test_ip_to_hex_negative(self, *args):
1114 # NOTE(ralonsoh): check the calls to mocked functions.
1115 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1116 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1117 value_iter = (''.join(pair) for pair in product(addr_list, mask_list))
1118 for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST):
1119 self.assertEqual(utils.ip_to_hex(value), value)
1122 class SafeDecodeUtf8TestCase(unittest.TestCase):
1124 @unittest.skipIf(six.PY2,
1125 'This test should only be launched with Python 3.x')
1126 def test_safe_decode_utf8(self):
1127 _bytes = b'this is a byte array'
1128 out = utils.safe_decode_utf8(_bytes)
1129 self.assertIs(type(out), str)
1130 self.assertEqual('this is a byte array', out)
1133 class ReadMeminfoTestCase(unittest.TestCase):
1135 MEMINFO = (b'MemTotal: 65860500 kB\n'
1136 b'MemFree: 28690900 kB\n'
1137 b'MemAvailable: 52873764 kB\n'
1138 b'Active(anon): 3015676 kB\n'
1139 b'HugePages_Total: 8\n'
1140 b'Hugepagesize: 1048576 kB')
1141 MEMINFO_DICT = {'MemTotal': '65860500',
1142 'MemFree': '28690900',
1143 'MemAvailable': '52873764',
1144 'Active(anon)': '3015676',
1145 'HugePages_Total': '8',
1146 'Hugepagesize': '1048576'}
1148 def test_read_meminfo(self):
1149 ssh_client = ssh.SSH('user', 'host')
1150 with mock.patch.object(ssh_client, 'get_file_obj') as \
1152 mock.patch.object(six, 'BytesIO',
1153 return_value=six.BytesIO(self.MEMINFO)):
1154 output = utils.read_meminfo(ssh_client)
1155 mock_get_client.assert_called_once_with('/proc/meminfo', mock.ANY)
1156 self.assertEqual(self.MEMINFO_DICT, output)
1159 class TimerTestCase(unittest.TestCase):
1161 def test__getattr(self):
1162 with utils.Timer() as timer:
1164 self.assertEqual(1, round(timer.total_seconds(), 0))
1165 self.assertEqual(1, timer.delta.seconds)
1167 def test__enter_with_timeout(self):
1168 with utils.Timer(timeout=10) as timer:
1170 self.assertEqual(1, round(timer.total_seconds(), 0))
1172 def test__enter_with_timeout_exception(self):
1173 with self.assertRaises(exceptions.TimerTimeout):
1174 with utils.Timer(timeout=1):
1178 class WaitUntilTrueTestCase(unittest.TestCase):
1180 def test_no_timeout(self):
1181 self.assertIsNone(utils.wait_until_true(lambda: True,
1182 timeout=1, sleep=1))
1184 def test_timeout_generic_exception(self):
1185 with self.assertRaises(exceptions.WaitTimeout):
1186 self.assertIsNone(utils.wait_until_true(lambda: False,
1187 timeout=1, sleep=1))
1189 def test_timeout_given_exception(self):
1190 class MyTimeoutException(exceptions.YardstickException):
1191 message = 'My timeout exception'
1193 with self.assertRaises(MyTimeoutException):
1195 utils.wait_until_true(lambda: False, timeout=1, sleep=1,
1196 exception=MyTimeoutException))