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
22 from yardstick import ssh
23 from yardstick.common import constants
24 from yardstick.common import utils
27 class IterSubclassesTestCase(unittest.TestCase):
28 # Disclaimer: this class is a modified copy from
29 # rally/tests/unit/common/plugin/test_discover.py
30 # Copyright 2015: Mirantis Inc.
32 def test_itersubclasses(self):
45 self.assertEqual([B, C, D], list(utils.itersubclasses(A)))
48 class ImportModulesFromPackageTestCase(unittest.TestCase):
50 @mock.patch('yardstick.common.utils.os.walk')
51 def test_import_modules_from_package_no_mod(self, mock_walk):
52 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
53 mock_walk.return_value = ([
54 (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']),
55 (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst'])
58 utils.import_modules_from_package('foo.bar')
60 @mock.patch('yardstick.common.utils.os.walk')
61 @mock.patch.object(importlib, 'import_module')
62 def test_import_modules_from_package(self, mock_import_module, mock_walk):
64 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
65 mock_walk.return_value = ([
66 (os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py'])
69 utils.import_modules_from_package('foo.bar')
70 mock_import_module.assert_called_once_with('bar.baz')
73 class GetParaFromYaml(unittest.TestCase):
75 @mock.patch('yardstick.common.utils.os.environ.get')
76 def test_get_param_para_not_found(self, get_env):
77 file_path = 'config_sample.yaml'
78 get_env.return_value = self._get_file_abspath(file_path)
81 self.assertTrue(constants.get_param(args, default), default)
83 @mock.patch('yardstick.common.utils.os.environ.get')
84 def test_get_param_para_exists(self, get_env):
85 file_path = 'config_sample.yaml'
86 get_env.return_value = self._get_file_abspath(file_path)
88 para = '/home/opnfv/repos/releng'
89 self.assertEqual(para, constants.get_param(args))
91 def _get_file_abspath(self, filename):
92 curr_path = os.path.dirname(os.path.abspath(__file__))
93 file_path = os.path.join(curr_path, filename)
97 class CommonUtilTestCase(unittest.TestCase):
118 def test__dict_key_flatten(self):
119 line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \
120 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
121 # need to sort for assert to work
122 line = ",".join(sorted(line.split(',')))
123 flattened_data = utils.flatten_dict_key(
124 self.data['benchmark']['data'])
126 ("=".join(item) for item in sorted(flattened_data.items())))
127 self.assertEqual(result, line)
129 def test_get_key_with_default_negative(self):
130 with self.assertRaises(KeyError):
131 utils.get_key_with_default({}, 'key1')
133 @mock.patch('yardstick.common.utils.open', create=True)
134 def test_(self, mock_open):
135 mock_open.side_effect = IOError
137 with self.assertRaises(IOError):
138 utils.find_relative_file('my/path', 'task/path')
140 self.assertEqual(mock_open.call_count, 2)
142 @mock.patch('yardstick.common.utils.open', create=True)
143 def test_open_relative_path(self, mock_open):
144 mock_open_result = mock_open()
145 mock_open_call_count = 1 # initial call to get result
147 self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
149 mock_open_call_count += 1 # one more call expected
150 self.assertEqual(mock_open.call_count, mock_open_call_count)
151 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
152 self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])
154 def open_effect(*args, **kwargs):
155 if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
156 return mock_open_result
157 raise IOError(errno.ENOENT, 'not found')
159 mock_open.side_effect = open_effect
160 self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
162 mock_open_call_count += 2 # two more calls expected
163 self.assertEqual(mock_open.call_count, mock_open_call_count)
164 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
165 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
167 # test an IOError of type ENOENT
168 mock_open.side_effect = IOError(errno.ENOENT, 'not found')
169 with self.assertRaises(IOError):
170 # the second call still raises
171 utils.open_relative_file('foo', 'bar')
173 mock_open_call_count += 2 # two more calls expected
174 self.assertEqual(mock_open.call_count, mock_open_call_count)
175 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
176 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
178 # test an IOError other than ENOENT
179 mock_open.side_effect = IOError(errno.EBUSY, 'busy')
180 with self.assertRaises(IOError):
181 utils.open_relative_file('foo', 'bar')
183 mock_open_call_count += 1 # one more call expected
184 self.assertEqual(mock_open.call_count, mock_open_call_count)
187 class TestMacAddressToHex(unittest.TestCase):
189 def test_mac_address_to_hex_list(self):
190 self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
191 ['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
194 class TranslateToStrTestCase(unittest.TestCase):
196 def test_translate_to_str_unicode(self):
198 output_str = utils.translate_to_str(input_str)
201 self.assertEqual(result, output_str)
203 def test_translate_to_str_dict_list_unicode(self):
205 u'hello': {u'hello': [u'world']}
207 output_str = utils.translate_to_str(input_str)
210 'hello': {'hello': ['world']}
212 self.assertEqual(result, output_str)
214 def test_translate_to_str_non_string(self):
215 input_value = object()
216 result = utils.translate_to_str(input_value)
217 self.assertIs(input_value, result)
220 class TestParseCpuInfo(unittest.TestCase):
222 def test_single_socket_no_hyperthread(self):
225 vendor_id : GenuineIntel
228 model name : Intel Core Processor (Haswell, no TSX)
243 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
248 address sizes : 46 bits physical, 48 bits virtual
252 vendor_id : GenuineIntel
255 model name : Intel Core Processor (Haswell, no TSX)
270 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
275 address sizes : 46 bits physical, 48 bits virtual
279 vendor_id : GenuineIntel
282 model name : Intel Core Processor (Haswell, no TSX)
297 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
302 address sizes : 46 bits physical, 48 bits virtual
306 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
307 self.assertEqual(sorted(socket_map.keys()), [0])
308 self.assertEqual(sorted(socket_map[0].keys()), [2, 3, 4])
310 def test_single_socket_hyperthread(self):
313 vendor_id : GenuineIntel
316 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
331 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
336 address sizes : 39 bits physical, 48 bits virtual
340 vendor_id : GenuineIntel
343 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
358 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
363 address sizes : 39 bits physical, 48 bits virtual
367 vendor_id : GenuineIntel
370 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
385 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
390 address sizes : 39 bits physical, 48 bits virtual
394 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
395 self.assertEqual(sorted(socket_map.keys()), [0])
396 self.assertEqual(sorted(socket_map[0].keys()), [1, 2, 3])
397 self.assertEqual(sorted(socket_map[0][1]), [5])
398 self.assertEqual(sorted(socket_map[0][2]), [6])
399 self.assertEqual(sorted(socket_map[0][3]), [7])
401 def test_dual_socket_hyperthread(self):
404 vendor_id : GenuineIntel
407 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
409 microcode : 0xb00001f
411 cache size : 56320 KB
422 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
427 address sizes : 46 bits physical, 48 bits virtual
431 vendor_id : GenuineIntel
434 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
436 microcode : 0xb00001f
438 cache size : 56320 KB
449 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
454 address sizes : 46 bits physical, 48 bits virtual
458 vendor_id : GenuineIntel
461 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
463 microcode : 0xb00001f
465 cache size : 56320 KB
476 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
481 address sizes : 46 bits physical, 48 bits virtual
485 vendor_id : GenuineIntel
488 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
490 microcode : 0xb00001f
492 cache size : 56320 KB
503 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
508 address sizes : 46 bits physical, 48 bits virtual
512 vendor_id : GenuineIntel
515 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
517 microcode : 0xb00001f
519 cache size : 56320 KB
530 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
535 address sizes : 46 bits physical, 48 bits virtual
539 vendor_id : GenuineIntel
542 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
544 microcode : 0xb00001f
546 cache size : 56320 KB
557 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
562 address sizes : 46 bits physical, 48 bits virtual
566 vendor_id : GenuineIntel
569 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
571 microcode : 0xb00001f
573 cache size : 56320 KB
584 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
589 address sizes : 46 bits physical, 48 bits virtual
593 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
594 self.assertEqual(sorted(socket_map.keys()), [0, 1])
595 self.assertEqual(sorted(socket_map[0].keys()), [0, 1, 2])
596 self.assertEqual(sorted(socket_map[1].keys()), [26, 27, 28])
597 self.assertEqual(sorted(socket_map[0][0]), [44])
598 self.assertEqual(sorted(socket_map[0][1]), [1])
599 self.assertEqual(sorted(socket_map[0][2]), [2])
600 self.assertEqual(sorted(socket_map[1][26]), [85])
601 self.assertEqual(sorted(socket_map[1][27]), [86])
602 self.assertEqual(sorted(socket_map[1][28]), [43, 87])
604 def test_dual_socket_no_hyperthread(self):
607 vendor_id : GenuineIntel
610 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
612 microcode : 0xb00001f
614 cache size : 56320 KB
625 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
630 address sizes : 46 bits physical, 48 bits virtual
634 vendor_id : GenuineIntel
637 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
639 microcode : 0xb00001f
641 cache size : 56320 KB
652 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
657 address sizes : 46 bits physical, 48 bits virtual
661 vendor_id : GenuineIntel
664 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
666 microcode : 0xb00001f
668 cache size : 56320 KB
679 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
684 address sizes : 46 bits physical, 48 bits virtual
688 vendor_id : GenuineIntel
691 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
693 microcode : 0xb00001f
695 cache size : 56320 KB
706 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
711 address sizes : 46 bits physical, 48 bits virtual
715 vendor_id : GenuineIntel
718 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
720 microcode : 0xb00001f
722 cache size : 56320 KB
733 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
738 address sizes : 46 bits physical, 48 bits virtual
742 vendor_id : GenuineIntel
745 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
747 microcode : 0xb00001f
749 cache size : 56320 KB
760 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
765 address sizes : 46 bits physical, 48 bits virtual
769 vendor_id : GenuineIntel
772 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
774 microcode : 0xb00001f
776 cache size : 56320 KB
787 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
792 address sizes : 46 bits physical, 48 bits virtual
796 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
797 processors = socket_map.processors()
798 self.assertEqual(processors, [1, 2, 43, 44, 85, 86, 87])
799 cores = socket_map.cores()
800 self.assertEqual(cores, [0, 1, 2, 26, 27, 28])
801 sockets = socket_map.sockets()
802 self.assertEqual(sockets, [0, 1])
805 class ChangeObjToDictTestCase(unittest.TestCase):
807 def test_change_obj_to_dict(self):
810 self.name = 'yardstick'
813 obj_r = utils.change_obj_to_dict(obj)
814 obj_s = {'name': 'yardstick'}
815 self.assertEqual(obj_r, obj_s)
818 class SetDictValueTestCase(unittest.TestCase):
820 def test_set_dict_value(self):
824 output_dic = utils.set_dict_value(input_dic, 'welcome.to', 'yardstick')
825 self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick')
828 class RemoveFileTestCase(unittest.TestCase):
830 def test_remove_file(self):
832 utils.remove_file('notexistfile.txt')
833 except Exception as e: # pylint: disable=broad-except
834 # NOTE(ralonsoh): to narrow the scope of this exception.
835 self.assertTrue(isinstance(e, OSError))
838 class TestUtils(unittest.TestCase):
840 @mock.patch('yardstick.common.utils.os.makedirs')
841 def test_makedirs(self, *_):
842 self.assertIsNone(utils.makedirs('a/b/c/d'))
844 @mock.patch('yardstick.common.utils.os.makedirs')
845 def test_makedirs_exists(self, mock_os_makedirs):
846 mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
847 self.assertIsNone(utils.makedirs('a/b/c/d'))
849 @mock.patch('yardstick.common.utils.os.makedirs')
850 def test_makedirs_busy(self, mock_os_makedirs):
851 mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
852 with self.assertRaises(OSError):
853 utils.makedirs('a/b/c/d')
855 @mock.patch('yardstick.common.utils.jsonify')
856 def test_result_handler(self, mock_jsonify):
857 mock_jsonify.return_value = 432
859 self.assertEqual(utils.result_handler('x', 234), 432)
860 mock_jsonify.assert_called_once_with({'status': 'x', 'result': 234})
862 @mock.patch('random.randint')
863 @mock.patch('socket.socket')
864 def test_get_free_port(self, mock_socket, mock_randint):
865 mock_randint.return_value = 7777
866 s = mock_socket('x', 'y')
867 s.connect_ex.side_effect = iter([0, 1])
868 result = utils.get_free_port('10.20.30.40')
869 self.assertEqual(result, 7777)
870 self.assertEqual(s.connect_ex.call_count, 2)
872 @mock.patch('subprocess.check_output')
873 def test_execute_command(self, mock_check_output):
874 expected = ['hello world', '1234']
875 mock_check_output.return_value = os.linesep.join(expected)
876 result = utils.execute_command('my_command arg1 arg2')
877 self.assertEqual(result, expected)
879 @mock.patch('subprocess.Popen')
880 def test_source_env(self, mock_popen):
881 base_env = deepcopy(os.environ)
882 mock_process = mock_popen()
884 'garbage line before',
886 'garbage line after',
888 mock_process.communicate.return_value = os.linesep.join(output_list), '', 0
889 expected = {'NEW_ENV_VALUE': '234'}
890 result = utils.source_env('my_file')
891 self.assertDictEqual(result, expected)
893 os.environ.update(base_env)
895 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
896 def test_parse_ini_file(self, mock_config_parser_type):
898 'default1': 'value1',
899 'default2': 'value2',
910 mock_config_parser = mock_config_parser_type()
911 mock_config_parser.read.return_value = True
912 mock_config_parser.sections.return_value = ['s1', 's2']
913 mock_config_parser.items.side_effect = iter([
924 result = utils.parse_ini_file('my_path')
925 self.assertDictEqual(result, expected)
927 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
928 def test_parse_ini_file_missing_section_header(self, mock_config_parser_type):
929 mock_config_parser = mock_config_parser_type()
930 mock_config_parser.read.side_effect = \
931 configparser.MissingSectionHeaderError(mock.Mock(), 321, mock.Mock())
933 with self.assertRaises(configparser.MissingSectionHeaderError):
934 utils.parse_ini_file('my_path')
936 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
937 def test_parse_ini_file_no_file(self, mock_config_parser_type):
938 mock_config_parser = mock_config_parser_type()
939 mock_config_parser.read.return_value = False
940 with self.assertRaises(RuntimeError):
941 utils.parse_ini_file('my_path')
943 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
944 def test_parse_ini_file_no_default_section_header(self, mock_config_parser_type):
954 mock_config_parser = mock_config_parser_type()
955 mock_config_parser.read.return_value = True
956 mock_config_parser.sections.return_value = ['s1', 's2']
957 mock_config_parser.items.side_effect = iter([
958 configparser.NoSectionError(mock.Mock()),
968 result = utils.parse_ini_file('my_path')
969 self.assertDictEqual(result, expected)
971 def test_join_non_strings(self):
972 self.assertEqual(utils.join_non_strings(':'), '')
973 self.assertEqual(utils.join_non_strings(':', 'a'), 'a')
974 self.assertEqual(utils.join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
975 self.assertEqual(utils.join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
976 self.assertEqual(utils.join_non_strings(':', 'abc'), 'abc')
978 def test_validate_non_string_sequence(self):
979 self.assertEqual(utils.validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
980 self.assertIsNone(utils.validate_non_string_sequence('123'))
981 self.assertIsNone(utils.validate_non_string_sequence(1))
983 self.assertEqual(utils.validate_non_string_sequence(1, 2), 2)
984 self.assertEqual(utils.validate_non_string_sequence(1, default=2), 2)
986 with self.assertRaises(RuntimeError):
987 utils.validate_non_string_sequence(1, raise_exc=RuntimeError)
990 class TestUtilsIpAddrMethods(unittest.TestCase):
992 GOOD_IP_V4_ADDRESS_STR_LIST = [
1002 GOOD_IP_V4_MASK_STR_LIST = [
1011 GOOD_IP_V6_ADDRESS_STR_LIST = [
1013 u'fe80::250:56ff:fe89:91ff',
1014 u'123:4567:89ab:cdef:123:4567:89ab:cdef',
1017 GOOD_IP_V6_MASK_STR_LIST = [
1026 INVALID_IP_ADDRESS_STR_LIST = [
1030 u'123:4567:89ab:cdef:123:4567:89ab:cdef/129',
1033 def test_safe_ip_address(self):
1034 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1035 for addr in addr_list:
1037 expected = ipaddress.ip_address(addr)
1038 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
1040 def test_safe_ip_address_v6_ip(self):
1041 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1042 for addr in addr_list:
1044 expected = ipaddress.ip_address(addr)
1045 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
1047 @mock.patch("yardstick.common.utils.logging")
1048 def test_safe_ip_address_negative(self, *args):
1049 # NOTE(ralonsoh): check the calls to mocked functions.
1050 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1051 self.assertIsNone(utils.safe_ip_address(value), value)
1053 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1054 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1055 for addr_mask_pair in product(addr_list, mask_list):
1056 value = ''.join(addr_mask_pair)
1057 self.assertIsNone(utils.safe_ip_address(value), value)
1059 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1060 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1061 for addr_mask_pair in product(addr_list, mask_list):
1062 value = ''.join(addr_mask_pair)
1063 self.assertIsNone(utils.safe_ip_address(value), value)
1065 def test_get_ip_version(self):
1066 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1067 for addr in addr_list:
1069 self.assertEqual(utils.get_ip_version(addr), 4, addr)
1071 def test_get_ip_version_v6_ip(self):
1072 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1073 for addr in addr_list:
1075 self.assertEqual(utils.get_ip_version(addr), 6, addr)
1077 @mock.patch("yardstick.common.utils.logging")
1078 def test_get_ip_version_negative(self, *args):
1079 # NOTE(ralonsoh): check the calls to mocked functions.
1080 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1081 self.assertIsNone(utils.get_ip_version(value), value)
1083 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1084 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1085 for addr_mask_pair in product(addr_list, mask_list):
1086 value = ''.join(addr_mask_pair)
1087 self.assertIsNone(utils.get_ip_version(value), value)
1089 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1090 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1091 for addr_mask_pair in product(addr_list, mask_list):
1092 value = ''.join(addr_mask_pair)
1093 self.assertIsNone(utils.get_ip_version(value), value)
1095 def test_ip_to_hex(self):
1096 self.assertEqual(utils.ip_to_hex('0.0.0.0'), '00000000')
1097 self.assertEqual(utils.ip_to_hex('10.20.30.40'), '0a141e28')
1098 self.assertEqual(utils.ip_to_hex('127.0.0.1'), '7f000001')
1099 self.assertEqual(utils.ip_to_hex('172.31.90.100'), 'ac1f5a64')
1100 self.assertEqual(utils.ip_to_hex('192.168.254.253'), 'c0a8fefd')
1101 self.assertEqual(utils.ip_to_hex('255.255.255.255'), 'ffffffff')
1103 def test_ip_to_hex_v6_ip(self):
1104 for value in self.GOOD_IP_V6_ADDRESS_STR_LIST:
1105 self.assertEqual(utils.ip_to_hex(value), value)
1107 @mock.patch("yardstick.common.utils.logging")
1108 def test_ip_to_hex_negative(self, *args):
1109 # NOTE(ralonsoh): check the calls to mocked functions.
1110 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1111 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1112 value_iter = (''.join(pair) for pair in product(addr_list, mask_list))
1113 for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST):
1114 self.assertEqual(utils.ip_to_hex(value), value)
1117 class SafeDecodeUtf8TestCase(unittest.TestCase):
1119 @unittest.skipIf(six.PY2,
1120 'This test should only be launched with Python 3.x')
1121 def test_safe_decode_utf8(self):
1122 _bytes = b'this is a byte array'
1123 out = utils.safe_decode_utf8(_bytes)
1124 self.assertIs(type(out), str)
1125 self.assertEqual('this is a byte array', out)
1128 class ReadMeminfoTestCase(unittest.TestCase):
1130 MEMINFO = (b'MemTotal: 65860500 kB\n'
1131 b'MemFree: 28690900 kB\n'
1132 b'MemAvailable: 52873764 kB\n'
1133 b'Active(anon): 3015676 kB\n'
1134 b'HugePages_Total: 8\n'
1135 b'Hugepagesize: 1048576 kB')
1136 MEMINFO_DICT = {'MemTotal': '65860500',
1137 'MemFree': '28690900',
1138 'MemAvailable': '52873764',
1139 'Active(anon)': '3015676',
1140 'HugePages_Total': '8',
1141 'Hugepagesize': '1048576'}
1143 def test_read_meminfo(self):
1144 ssh_client = ssh.SSH('user', 'host')
1145 with mock.patch.object(ssh_client, 'get_file_obj') as \
1147 mock.patch.object(six, 'BytesIO',
1148 return_value=six.BytesIO(self.MEMINFO)):
1149 output = utils.read_meminfo(ssh_client)
1150 mock_get_client.assert_called_once_with('/proc/meminfo', mock.ANY)
1151 self.assertEqual(self.MEMINFO_DICT, output)