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.common import utils
23 from yardstick.common import constants
26 class IterSubclassesTestCase(unittest.TestCase):
27 # Disclaimer: this class is a modified copy from
28 # rally/tests/unit/common/plugin/test_discover.py
29 # Copyright 2015: Mirantis Inc.
31 def test_itersubclasses(self):
44 self.assertEqual([B, C, D], list(utils.itersubclasses(A)))
47 class ImportModulesFromPackageTestCase(unittest.TestCase):
49 @mock.patch('yardstick.common.utils.os.walk')
50 def test_import_modules_from_package_no_mod(self, mock_walk):
51 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
52 mock_walk.return_value = ([
53 (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']),
54 (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst'])
57 utils.import_modules_from_package('foo.bar')
59 @mock.patch('yardstick.common.utils.os.walk')
60 @mock.patch.object(importlib, 'import_module')
61 def test_import_modules_from_package(self, mock_import_module, mock_walk):
63 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
64 mock_walk.return_value = ([
65 (os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py'])
68 utils.import_modules_from_package('foo.bar')
69 mock_import_module.assert_called_once_with('bar.baz')
72 class GetParaFromYaml(unittest.TestCase):
74 @mock.patch('yardstick.common.utils.os.environ.get')
75 def test_get_param_para_not_found(self, get_env):
76 file_path = 'config_sample.yaml'
77 get_env.return_value = self._get_file_abspath(file_path)
80 self.assertTrue(constants.get_param(args, default), default)
82 @mock.patch('yardstick.common.utils.os.environ.get')
83 def test_get_param_para_exists(self, get_env):
84 file_path = 'config_sample.yaml'
85 get_env.return_value = self._get_file_abspath(file_path)
87 para = '/home/opnfv/repos/releng'
88 self.assertEqual(para, constants.get_param(args))
90 def _get_file_abspath(self, filename):
91 curr_path = os.path.dirname(os.path.abspath(__file__))
92 file_path = os.path.join(curr_path, filename)
96 class CommonUtilTestCase(unittest.TestCase):
117 def test__dict_key_flatten(self):
118 line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \
119 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
120 # need to sort for assert to work
121 line = ",".join(sorted(line.split(',')))
122 flattened_data = utils.flatten_dict_key(
123 self.data['benchmark']['data'])
125 ("=".join(item) for item in sorted(flattened_data.items())))
126 self.assertEqual(result, line)
129 class TestMacAddressToHex(unittest.TestCase):
131 def test_mac_address_to_hex_list(self):
132 self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
133 ['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
136 class TranslateToStrTestCase(unittest.TestCase):
138 def test_translate_to_str_unicode(self):
140 output_str = utils.translate_to_str(input_str)
143 self.assertEqual(result, output_str)
145 def test_translate_to_str_dict_list_unicode(self):
147 u'hello': {u'hello': [u'world']}
149 output_str = utils.translate_to_str(input_str)
152 'hello': {'hello': ['world']}
154 self.assertEqual(result, output_str)
156 def test_translate_to_str_non_string(self):
157 input_value = object()
158 result = utils.translate_to_str(input_value)
159 self.assertIs(input_value, result)
162 class TestParseCpuInfo(unittest.TestCase):
164 def test_single_socket_no_hyperthread(self):
167 vendor_id : GenuineIntel
170 model name : Intel Core Processor (Haswell, no TSX)
185 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
190 address sizes : 46 bits physical, 48 bits virtual
194 vendor_id : GenuineIntel
197 model name : Intel Core Processor (Haswell, no TSX)
212 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
217 address sizes : 46 bits physical, 48 bits virtual
221 vendor_id : GenuineIntel
224 model name : Intel Core Processor (Haswell, no TSX)
239 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
244 address sizes : 46 bits physical, 48 bits virtual
248 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
249 assert sorted(socket_map.keys()) == [0]
250 assert sorted(socket_map[0].keys()) == [2, 3, 4]
252 def test_single_socket_hyperthread(self):
255 vendor_id : GenuineIntel
258 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
273 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
278 address sizes : 39 bits physical, 48 bits virtual
282 vendor_id : GenuineIntel
285 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
300 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
305 address sizes : 39 bits physical, 48 bits virtual
309 vendor_id : GenuineIntel
312 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
327 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
332 address sizes : 39 bits physical, 48 bits virtual
336 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
337 assert sorted(socket_map.keys()) == [0]
338 assert sorted(socket_map[0].keys()) == [1, 2, 3]
339 assert sorted(socket_map[0][1]) == [5]
340 assert sorted(socket_map[0][2]) == [6]
341 assert sorted(socket_map[0][3]) == [7]
343 def test_dual_socket_hyperthread(self):
346 vendor_id : GenuineIntel
349 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
351 microcode : 0xb00001f
353 cache size : 56320 KB
364 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
369 address sizes : 46 bits physical, 48 bits virtual
373 vendor_id : GenuineIntel
376 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
378 microcode : 0xb00001f
380 cache size : 56320 KB
391 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
396 address sizes : 46 bits physical, 48 bits virtual
400 vendor_id : GenuineIntel
403 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
405 microcode : 0xb00001f
407 cache size : 56320 KB
418 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
423 address sizes : 46 bits physical, 48 bits virtual
427 vendor_id : GenuineIntel
430 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
432 microcode : 0xb00001f
434 cache size : 56320 KB
445 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
450 address sizes : 46 bits physical, 48 bits virtual
454 vendor_id : GenuineIntel
457 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
459 microcode : 0xb00001f
461 cache size : 56320 KB
472 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
477 address sizes : 46 bits physical, 48 bits virtual
481 vendor_id : GenuineIntel
484 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
486 microcode : 0xb00001f
488 cache size : 56320 KB
499 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
504 address sizes : 46 bits physical, 48 bits virtual
508 vendor_id : GenuineIntel
511 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
513 microcode : 0xb00001f
515 cache size : 56320 KB
526 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
531 address sizes : 46 bits physical, 48 bits virtual
535 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
536 assert sorted(socket_map.keys()) == [0, 1]
537 assert sorted(socket_map[0].keys()) == [0, 1, 2]
538 assert sorted(socket_map[1].keys()) == [26, 27, 28]
539 assert sorted(socket_map[0][0]) == [44]
540 assert sorted(socket_map[0][1]) == [1]
541 assert sorted(socket_map[0][2]) == [2]
542 assert sorted(socket_map[1][26]) == [85]
543 assert sorted(socket_map[1][27]) == [86]
544 assert sorted(socket_map[1][28]) == [43, 87]
546 def test_dual_socket_no_hyperthread(self):
549 vendor_id : GenuineIntel
552 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
554 microcode : 0xb00001f
556 cache size : 56320 KB
567 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
572 address sizes : 46 bits physical, 48 bits virtual
576 vendor_id : GenuineIntel
579 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
581 microcode : 0xb00001f
583 cache size : 56320 KB
594 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
599 address sizes : 46 bits physical, 48 bits virtual
603 vendor_id : GenuineIntel
606 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
608 microcode : 0xb00001f
610 cache size : 56320 KB
621 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
626 address sizes : 46 bits physical, 48 bits virtual
630 vendor_id : GenuineIntel
633 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
635 microcode : 0xb00001f
637 cache size : 56320 KB
648 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
653 address sizes : 46 bits physical, 48 bits virtual
657 vendor_id : GenuineIntel
660 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
662 microcode : 0xb00001f
664 cache size : 56320 KB
675 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
680 address sizes : 46 bits physical, 48 bits virtual
684 vendor_id : GenuineIntel
687 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
689 microcode : 0xb00001f
691 cache size : 56320 KB
702 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
707 address sizes : 46 bits physical, 48 bits virtual
711 vendor_id : GenuineIntel
714 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
716 microcode : 0xb00001f
718 cache size : 56320 KB
729 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
734 address sizes : 46 bits physical, 48 bits virtual
738 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
739 processors = socket_map.processors()
740 assert processors == [1, 2, 43, 44, 85, 86, 87]
741 cores = socket_map.cores()
742 assert cores == [0, 1, 2, 26, 27, 28]
743 sockets = socket_map.sockets()
744 assert sockets == [0, 1]
747 class ChangeObjToDictTestCase(unittest.TestCase):
749 def test_change_obj_to_dict(self):
752 self.name = 'yardstick'
755 obj_r = utils.change_obj_to_dict(obj)
756 obj_s = {'name': 'yardstick'}
757 self.assertEqual(obj_r, obj_s)
760 class SetDictValueTestCase(unittest.TestCase):
762 def test_set_dict_value(self):
766 output_dic = utils.set_dict_value(input_dic, 'welcome.to', 'yardstick')
767 self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick')
770 class RemoveFileTestCase(unittest.TestCase):
772 def test_remove_file(self):
774 utils.remove_file('notexistfile.txt')
775 except Exception as e: # pylint: disable=broad-except
776 # NOTE(ralonsoh): to narrow the scope of this exception.
777 self.assertTrue(isinstance(e, OSError))
780 class TestUtils(unittest.TestCase):
782 @mock.patch('yardstick.common.utils.os.makedirs')
783 def test_makedirs(self, *_):
784 self.assertIsNone(utils.makedirs('a/b/c/d'))
786 @mock.patch('yardstick.common.utils.os.makedirs')
787 def test_makedirs_exists(self, mock_os_makedirs):
788 mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
789 self.assertIsNone(utils.makedirs('a/b/c/d'))
791 @mock.patch('yardstick.common.utils.os.makedirs')
792 def test_makedirs_busy(self, mock_os_makedirs):
793 mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
794 with self.assertRaises(OSError):
795 utils.makedirs('a/b/c/d')
797 @mock.patch('yardstick.common.utils.jsonify')
798 def test_result_handler(self, mock_jsonify):
799 mock_jsonify.return_value = 432
801 self.assertEqual(utils.result_handler('x', 234), 432)
802 mock_jsonify.assert_called_once_with({'status': 'x', 'result': 234})
804 @mock.patch('random.randint')
805 @mock.patch('socket.socket')
806 def test_get_free_port(self, mock_socket, mock_randint):
807 mock_randint.return_value = 7777
808 s = mock_socket('x', 'y')
809 s.connect_ex.side_effect = iter([0, 1])
810 result = utils.get_free_port('10.20.30.40')
811 self.assertEqual(result, 7777)
812 self.assertEqual(s.connect_ex.call_count, 2)
814 @mock.patch('subprocess.check_output')
815 def test_execute_command(self, mock_check_output):
816 expected = ['hello world', '1234']
817 mock_check_output.return_value = os.linesep.join(expected)
818 result = utils.execute_command('my_command arg1 arg2')
819 self.assertEqual(result, expected)
821 @mock.patch('subprocess.Popen')
822 def test_source_env(self, mock_popen):
823 base_env = deepcopy(os.environ)
824 mock_process = mock_popen()
826 'garbage line before',
828 'garbage line after',
830 mock_process.communicate.return_value = os.linesep.join(output_list), '', 0
831 expected = {'NEW_ENV_VALUE': '234'}
832 result = utils.source_env('my_file')
833 self.assertDictEqual(result, expected)
835 os.environ.update(base_env)
837 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
838 def test_parse_ini_file(self, mock_config_parser_type):
840 'default1': 'value1',
841 'default2': 'value2',
852 mock_config_parser = mock_config_parser_type()
853 mock_config_parser.read.return_value = True
854 mock_config_parser.sections.return_value = ['s1', 's2']
855 mock_config_parser.items.side_effect = iter([
866 result = utils.parse_ini_file('my_path')
867 self.assertDictEqual(result, expected)
869 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
870 def test_parse_ini_file_missing_section_header(self, mock_config_parser_type):
871 mock_config_parser = mock_config_parser_type()
872 mock_config_parser.read.side_effect = \
873 configparser.MissingSectionHeaderError(mock.Mock(), 321, mock.Mock())
875 with self.assertRaises(configparser.MissingSectionHeaderError):
876 utils.parse_ini_file('my_path')
878 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
879 def test_parse_ini_file_no_file(self, mock_config_parser_type):
880 mock_config_parser = mock_config_parser_type()
881 mock_config_parser.read.return_value = False
882 with self.assertRaises(RuntimeError):
883 utils.parse_ini_file('my_path')
885 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
886 def test_parse_ini_file_no_default_section_header(self, mock_config_parser_type):
896 mock_config_parser = mock_config_parser_type()
897 mock_config_parser.read.return_value = True
898 mock_config_parser.sections.return_value = ['s1', 's2']
899 mock_config_parser.items.side_effect = iter([
900 configparser.NoSectionError(mock.Mock()),
910 result = utils.parse_ini_file('my_path')
911 self.assertDictEqual(result, expected)
913 def test_join_non_strings(self):
914 self.assertEqual(utils.join_non_strings(':'), '')
915 self.assertEqual(utils.join_non_strings(':', 'a'), 'a')
916 self.assertEqual(utils.join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
917 self.assertEqual(utils.join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
918 self.assertEqual(utils.join_non_strings(':', 'abc'), 'abc')
920 def test_validate_non_string_sequence(self):
921 self.assertEqual(utils.validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
922 self.assertIsNone(utils.validate_non_string_sequence('123'))
923 self.assertIsNone(utils.validate_non_string_sequence(1))
925 self.assertEqual(utils.validate_non_string_sequence(1, 2), 2)
926 self.assertEqual(utils.validate_non_string_sequence(1, default=2), 2)
928 with self.assertRaises(RuntimeError):
929 utils.validate_non_string_sequence(1, raise_exc=RuntimeError)
931 def test_error_class(self):
932 with self.assertRaises(RuntimeError):
935 error_instance = utils.ErrorClass(test='')
936 with self.assertRaises(AttributeError):
937 error_instance.get_name()
940 class TestUtilsIpAddrMethods(unittest.TestCase):
942 GOOD_IP_V4_ADDRESS_STR_LIST = [
952 GOOD_IP_V4_MASK_STR_LIST = [
961 GOOD_IP_V6_ADDRESS_STR_LIST = [
963 u'fe80::250:56ff:fe89:91ff',
964 u'123:4567:89ab:cdef:123:4567:89ab:cdef',
967 GOOD_IP_V6_MASK_STR_LIST = [
976 INVALID_IP_ADDRESS_STR_LIST = [
980 u'123:4567:89ab:cdef:123:4567:89ab:cdef/129',
983 def test_safe_ip_address(self):
984 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
985 for addr in addr_list:
987 expected = ipaddress.ip_address(addr)
988 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
990 def test_safe_ip_address_v6_ip(self):
991 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
992 for addr in addr_list:
994 expected = ipaddress.ip_address(addr)
995 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
997 @mock.patch("yardstick.common.utils.logging")
998 def test_safe_ip_address_negative(self, *args):
999 # NOTE(ralonsoh): check the calls to mocked functions.
1000 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1001 self.assertIsNone(utils.safe_ip_address(value), value)
1003 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1004 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1005 for addr_mask_pair in product(addr_list, mask_list):
1006 value = ''.join(addr_mask_pair)
1007 self.assertIsNone(utils.safe_ip_address(value), value)
1009 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1010 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1011 for addr_mask_pair in product(addr_list, mask_list):
1012 value = ''.join(addr_mask_pair)
1013 self.assertIsNone(utils.safe_ip_address(value), value)
1015 def test_get_ip_version(self):
1016 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1017 for addr in addr_list:
1019 self.assertEqual(utils.get_ip_version(addr), 4, addr)
1021 def test_get_ip_version_v6_ip(self):
1022 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1023 for addr in addr_list:
1025 self.assertEqual(utils.get_ip_version(addr), 6, addr)
1027 @mock.patch("yardstick.common.utils.logging")
1028 def test_get_ip_version_negative(self, *args):
1029 # NOTE(ralonsoh): check the calls to mocked functions.
1030 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1031 self.assertIsNone(utils.get_ip_version(value), value)
1033 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1034 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1035 for addr_mask_pair in product(addr_list, mask_list):
1036 value = ''.join(addr_mask_pair)
1037 self.assertIsNone(utils.get_ip_version(value), value)
1039 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1040 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1041 for addr_mask_pair in product(addr_list, mask_list):
1042 value = ''.join(addr_mask_pair)
1043 self.assertIsNone(utils.get_ip_version(value), value)
1045 def test_ip_to_hex(self):
1046 self.assertEqual(utils.ip_to_hex('0.0.0.0'), '00000000')
1047 self.assertEqual(utils.ip_to_hex('10.20.30.40'), '0a141e28')
1048 self.assertEqual(utils.ip_to_hex('127.0.0.1'), '7f000001')
1049 self.assertEqual(utils.ip_to_hex('172.31.90.100'), 'ac1f5a64')
1050 self.assertEqual(utils.ip_to_hex('192.168.254.253'), 'c0a8fefd')
1051 self.assertEqual(utils.ip_to_hex('255.255.255.255'), 'ffffffff')
1053 def test_ip_to_hex_v6_ip(self):
1054 for value in self.GOOD_IP_V6_ADDRESS_STR_LIST:
1055 self.assertEqual(utils.ip_to_hex(value), value)
1057 @mock.patch("yardstick.common.utils.logging")
1058 def test_ip_to_hex_negative(self, *args):
1059 # NOTE(ralonsoh): check the calls to mocked functions.
1060 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1061 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1062 value_iter = (''.join(pair) for pair in product(addr_list, mask_list))
1063 for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST):
1064 self.assertEqual(utils.ip_to_hex(value), value)
1067 class SafeDecodeUtf8TestCase(unittest.TestCase):
1069 @unittest.skipIf(six.PY2,
1070 'This test should only be launched with Python 3.x')
1071 def test_safe_decode_utf8(self):
1072 _bytes = b'this is a byte array'
1073 out = utils.safe_decode_utf8(_bytes)
1074 self.assertIs(type(out), str)
1075 self.assertEqual('this is a byte array', out)
1081 if __name__ == '__main__':