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 utils
24 from yardstick.common import constants
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)
130 class TestMacAddressToHex(unittest.TestCase):
132 def test_mac_address_to_hex_list(self):
133 self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
134 ['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
137 class TranslateToStrTestCase(unittest.TestCase):
139 def test_translate_to_str_unicode(self):
141 output_str = utils.translate_to_str(input_str)
144 self.assertEqual(result, output_str)
146 def test_translate_to_str_dict_list_unicode(self):
148 u'hello': {u'hello': [u'world']}
150 output_str = utils.translate_to_str(input_str)
153 'hello': {'hello': ['world']}
155 self.assertEqual(result, output_str)
157 def test_translate_to_str_non_string(self):
158 input_value = object()
159 result = utils.translate_to_str(input_value)
160 self.assertIs(input_value, result)
163 class TestParseCpuInfo(unittest.TestCase):
165 def test_single_socket_no_hyperthread(self):
168 vendor_id : GenuineIntel
171 model name : Intel Core Processor (Haswell, no TSX)
186 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
191 address sizes : 46 bits physical, 48 bits virtual
195 vendor_id : GenuineIntel
198 model name : Intel Core Processor (Haswell, no TSX)
213 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
218 address sizes : 46 bits physical, 48 bits virtual
222 vendor_id : GenuineIntel
225 model name : Intel Core Processor (Haswell, no TSX)
240 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
245 address sizes : 46 bits physical, 48 bits virtual
249 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
250 assert sorted(socket_map.keys()) == [0]
251 assert sorted(socket_map[0].keys()) == [2, 3, 4]
253 def test_single_socket_hyperthread(self):
256 vendor_id : GenuineIntel
259 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
274 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
279 address sizes : 39 bits physical, 48 bits virtual
283 vendor_id : GenuineIntel
286 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
301 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
306 address sizes : 39 bits physical, 48 bits virtual
310 vendor_id : GenuineIntel
313 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
328 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
333 address sizes : 39 bits physical, 48 bits virtual
337 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
338 assert sorted(socket_map.keys()) == [0]
339 assert sorted(socket_map[0].keys()) == [1, 2, 3]
340 assert sorted(socket_map[0][1]) == [5]
341 assert sorted(socket_map[0][2]) == [6]
342 assert sorted(socket_map[0][3]) == [7]
344 def test_dual_socket_hyperthread(self):
347 vendor_id : GenuineIntel
350 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
352 microcode : 0xb00001f
354 cache size : 56320 KB
365 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
370 address sizes : 46 bits physical, 48 bits virtual
374 vendor_id : GenuineIntel
377 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
379 microcode : 0xb00001f
381 cache size : 56320 KB
392 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
397 address sizes : 46 bits physical, 48 bits virtual
401 vendor_id : GenuineIntel
404 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
406 microcode : 0xb00001f
408 cache size : 56320 KB
419 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
424 address sizes : 46 bits physical, 48 bits virtual
428 vendor_id : GenuineIntel
431 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
433 microcode : 0xb00001f
435 cache size : 56320 KB
446 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
451 address sizes : 46 bits physical, 48 bits virtual
455 vendor_id : GenuineIntel
458 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
460 microcode : 0xb00001f
462 cache size : 56320 KB
473 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
478 address sizes : 46 bits physical, 48 bits virtual
482 vendor_id : GenuineIntel
485 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
487 microcode : 0xb00001f
489 cache size : 56320 KB
500 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
505 address sizes : 46 bits physical, 48 bits virtual
509 vendor_id : GenuineIntel
512 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
514 microcode : 0xb00001f
516 cache size : 56320 KB
527 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
532 address sizes : 46 bits physical, 48 bits virtual
536 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
537 assert sorted(socket_map.keys()) == [0, 1]
538 assert sorted(socket_map[0].keys()) == [0, 1, 2]
539 assert sorted(socket_map[1].keys()) == [26, 27, 28]
540 assert sorted(socket_map[0][0]) == [44]
541 assert sorted(socket_map[0][1]) == [1]
542 assert sorted(socket_map[0][2]) == [2]
543 assert sorted(socket_map[1][26]) == [85]
544 assert sorted(socket_map[1][27]) == [86]
545 assert sorted(socket_map[1][28]) == [43, 87]
547 def test_dual_socket_no_hyperthread(self):
550 vendor_id : GenuineIntel
553 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
555 microcode : 0xb00001f
557 cache size : 56320 KB
568 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
573 address sizes : 46 bits physical, 48 bits virtual
577 vendor_id : GenuineIntel
580 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
582 microcode : 0xb00001f
584 cache size : 56320 KB
595 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
600 address sizes : 46 bits physical, 48 bits virtual
604 vendor_id : GenuineIntel
607 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
609 microcode : 0xb00001f
611 cache size : 56320 KB
622 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
627 address sizes : 46 bits physical, 48 bits virtual
631 vendor_id : GenuineIntel
634 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
636 microcode : 0xb00001f
638 cache size : 56320 KB
649 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
654 address sizes : 46 bits physical, 48 bits virtual
658 vendor_id : GenuineIntel
661 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
663 microcode : 0xb00001f
665 cache size : 56320 KB
676 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
681 address sizes : 46 bits physical, 48 bits virtual
685 vendor_id : GenuineIntel
688 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
690 microcode : 0xb00001f
692 cache size : 56320 KB
703 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
708 address sizes : 46 bits physical, 48 bits virtual
712 vendor_id : GenuineIntel
715 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
717 microcode : 0xb00001f
719 cache size : 56320 KB
730 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
735 address sizes : 46 bits physical, 48 bits virtual
739 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
740 processors = socket_map.processors()
741 assert processors == [1, 2, 43, 44, 85, 86, 87]
742 cores = socket_map.cores()
743 assert cores == [0, 1, 2, 26, 27, 28]
744 sockets = socket_map.sockets()
745 assert sockets == [0, 1]
748 class ChangeObjToDictTestCase(unittest.TestCase):
750 def test_change_obj_to_dict(self):
753 self.name = 'yardstick'
756 obj_r = utils.change_obj_to_dict(obj)
757 obj_s = {'name': 'yardstick'}
758 self.assertEqual(obj_r, obj_s)
761 class SetDictValueTestCase(unittest.TestCase):
763 def test_set_dict_value(self):
767 output_dic = utils.set_dict_value(input_dic, 'welcome.to', 'yardstick')
768 self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick')
771 class RemoveFileTestCase(unittest.TestCase):
773 def test_remove_file(self):
775 utils.remove_file('notexistfile.txt')
776 except Exception as e: # pylint: disable=broad-except
777 # NOTE(ralonsoh): to narrow the scope of this exception.
778 self.assertTrue(isinstance(e, OSError))
781 class TestUtils(unittest.TestCase):
783 @mock.patch('yardstick.common.utils.os.makedirs')
784 def test_makedirs(self, *_):
785 self.assertIsNone(utils.makedirs('a/b/c/d'))
787 @mock.patch('yardstick.common.utils.os.makedirs')
788 def test_makedirs_exists(self, mock_os_makedirs):
789 mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
790 self.assertIsNone(utils.makedirs('a/b/c/d'))
792 @mock.patch('yardstick.common.utils.os.makedirs')
793 def test_makedirs_busy(self, mock_os_makedirs):
794 mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
795 with self.assertRaises(OSError):
796 utils.makedirs('a/b/c/d')
798 @mock.patch('yardstick.common.utils.jsonify')
799 def test_result_handler(self, mock_jsonify):
800 mock_jsonify.return_value = 432
802 self.assertEqual(utils.result_handler('x', 234), 432)
803 mock_jsonify.assert_called_once_with({'status': 'x', 'result': 234})
805 @mock.patch('random.randint')
806 @mock.patch('socket.socket')
807 def test_get_free_port(self, mock_socket, mock_randint):
808 mock_randint.return_value = 7777
809 s = mock_socket('x', 'y')
810 s.connect_ex.side_effect = iter([0, 1])
811 result = utils.get_free_port('10.20.30.40')
812 self.assertEqual(result, 7777)
813 self.assertEqual(s.connect_ex.call_count, 2)
815 @mock.patch('subprocess.check_output')
816 def test_execute_command(self, mock_check_output):
817 expected = ['hello world', '1234']
818 mock_check_output.return_value = os.linesep.join(expected)
819 result = utils.execute_command('my_command arg1 arg2')
820 self.assertEqual(result, expected)
822 @mock.patch('subprocess.Popen')
823 def test_source_env(self, mock_popen):
824 base_env = deepcopy(os.environ)
825 mock_process = mock_popen()
827 'garbage line before',
829 'garbage line after',
831 mock_process.communicate.return_value = os.linesep.join(output_list), '', 0
832 expected = {'NEW_ENV_VALUE': '234'}
833 result = utils.source_env('my_file')
834 self.assertDictEqual(result, expected)
836 os.environ.update(base_env)
838 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
839 def test_parse_ini_file(self, mock_config_parser_type):
841 'default1': 'value1',
842 'default2': 'value2',
853 mock_config_parser = mock_config_parser_type()
854 mock_config_parser.read.return_value = True
855 mock_config_parser.sections.return_value = ['s1', 's2']
856 mock_config_parser.items.side_effect = iter([
867 result = utils.parse_ini_file('my_path')
868 self.assertDictEqual(result, expected)
870 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
871 def test_parse_ini_file_missing_section_header(self, mock_config_parser_type):
872 mock_config_parser = mock_config_parser_type()
873 mock_config_parser.read.side_effect = \
874 configparser.MissingSectionHeaderError(mock.Mock(), 321, mock.Mock())
876 with self.assertRaises(configparser.MissingSectionHeaderError):
877 utils.parse_ini_file('my_path')
879 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
880 def test_parse_ini_file_no_file(self, mock_config_parser_type):
881 mock_config_parser = mock_config_parser_type()
882 mock_config_parser.read.return_value = False
883 with self.assertRaises(RuntimeError):
884 utils.parse_ini_file('my_path')
886 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
887 def test_parse_ini_file_no_default_section_header(self, mock_config_parser_type):
897 mock_config_parser = mock_config_parser_type()
898 mock_config_parser.read.return_value = True
899 mock_config_parser.sections.return_value = ['s1', 's2']
900 mock_config_parser.items.side_effect = iter([
901 configparser.NoSectionError(mock.Mock()),
911 result = utils.parse_ini_file('my_path')
912 self.assertDictEqual(result, expected)
914 def test_join_non_strings(self):
915 self.assertEqual(utils.join_non_strings(':'), '')
916 self.assertEqual(utils.join_non_strings(':', 'a'), 'a')
917 self.assertEqual(utils.join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
918 self.assertEqual(utils.join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
919 self.assertEqual(utils.join_non_strings(':', 'abc'), 'abc')
921 def test_validate_non_string_sequence(self):
922 self.assertEqual(utils.validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
923 self.assertIsNone(utils.validate_non_string_sequence('123'))
924 self.assertIsNone(utils.validate_non_string_sequence(1))
926 self.assertEqual(utils.validate_non_string_sequence(1, 2), 2)
927 self.assertEqual(utils.validate_non_string_sequence(1, default=2), 2)
929 with self.assertRaises(RuntimeError):
930 utils.validate_non_string_sequence(1, raise_exc=RuntimeError)
932 def test_error_class(self):
933 with self.assertRaises(RuntimeError):
936 error_instance = utils.ErrorClass(test='')
937 with self.assertRaises(AttributeError):
938 error_instance.get_name()
941 class TestUtilsIpAddrMethods(unittest.TestCase):
943 GOOD_IP_V4_ADDRESS_STR_LIST = [
953 GOOD_IP_V4_MASK_STR_LIST = [
962 GOOD_IP_V6_ADDRESS_STR_LIST = [
964 u'fe80::250:56ff:fe89:91ff',
965 u'123:4567:89ab:cdef:123:4567:89ab:cdef',
968 GOOD_IP_V6_MASK_STR_LIST = [
977 INVALID_IP_ADDRESS_STR_LIST = [
981 u'123:4567:89ab:cdef:123:4567:89ab:cdef/129',
984 def test_safe_ip_address(self):
985 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
986 for addr in addr_list:
988 expected = ipaddress.ip_address(addr)
989 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
991 def test_safe_ip_address_v6_ip(self):
992 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
993 for addr in addr_list:
995 expected = ipaddress.ip_address(addr)
996 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
998 @mock.patch("yardstick.common.utils.logging")
999 def test_safe_ip_address_negative(self, *args):
1000 # NOTE(ralonsoh): check the calls to mocked functions.
1001 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1002 self.assertIsNone(utils.safe_ip_address(value), value)
1004 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1005 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1006 for addr_mask_pair in product(addr_list, mask_list):
1007 value = ''.join(addr_mask_pair)
1008 self.assertIsNone(utils.safe_ip_address(value), value)
1010 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1011 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1012 for addr_mask_pair in product(addr_list, mask_list):
1013 value = ''.join(addr_mask_pair)
1014 self.assertIsNone(utils.safe_ip_address(value), value)
1016 def test_get_ip_version(self):
1017 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1018 for addr in addr_list:
1020 self.assertEqual(utils.get_ip_version(addr), 4, addr)
1022 def test_get_ip_version_v6_ip(self):
1023 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1024 for addr in addr_list:
1026 self.assertEqual(utils.get_ip_version(addr), 6, addr)
1028 @mock.patch("yardstick.common.utils.logging")
1029 def test_get_ip_version_negative(self, *args):
1030 # NOTE(ralonsoh): check the calls to mocked functions.
1031 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1032 self.assertIsNone(utils.get_ip_version(value), value)
1034 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1035 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1036 for addr_mask_pair in product(addr_list, mask_list):
1037 value = ''.join(addr_mask_pair)
1038 self.assertIsNone(utils.get_ip_version(value), value)
1040 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1041 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1042 for addr_mask_pair in product(addr_list, mask_list):
1043 value = ''.join(addr_mask_pair)
1044 self.assertIsNone(utils.get_ip_version(value), value)
1046 def test_ip_to_hex(self):
1047 self.assertEqual(utils.ip_to_hex('0.0.0.0'), '00000000')
1048 self.assertEqual(utils.ip_to_hex('10.20.30.40'), '0a141e28')
1049 self.assertEqual(utils.ip_to_hex('127.0.0.1'), '7f000001')
1050 self.assertEqual(utils.ip_to_hex('172.31.90.100'), 'ac1f5a64')
1051 self.assertEqual(utils.ip_to_hex('192.168.254.253'), 'c0a8fefd')
1052 self.assertEqual(utils.ip_to_hex('255.255.255.255'), 'ffffffff')
1054 def test_ip_to_hex_v6_ip(self):
1055 for value in self.GOOD_IP_V6_ADDRESS_STR_LIST:
1056 self.assertEqual(utils.ip_to_hex(value), value)
1058 @mock.patch("yardstick.common.utils.logging")
1059 def test_ip_to_hex_negative(self, *args):
1060 # NOTE(ralonsoh): check the calls to mocked functions.
1061 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1062 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1063 value_iter = (''.join(pair) for pair in product(addr_list, mask_list))
1064 for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST):
1065 self.assertEqual(utils.ip_to_hex(value), value)
1068 class SafeDecodeUtf8TestCase(unittest.TestCase):
1070 @unittest.skipIf(six.PY2,
1071 'This test should only be launched with Python 3.x')
1072 def test_safe_decode_utf8(self):
1073 _bytes = b'this is a byte array'
1074 out = utils.safe_decode_utf8(_bytes)
1075 self.assertIs(type(out), str)
1076 self.assertEqual('this is a byte array', out)
1079 class ReadMeminfoTestCase(unittest.TestCase):
1081 MEMINFO = (b'MemTotal: 65860500 kB\n'
1082 b'MemFree: 28690900 kB\n'
1083 b'MemAvailable: 52873764 kB\n'
1084 b'Active(anon): 3015676 kB\n'
1085 b'HugePages_Total: 8\n'
1086 b'Hugepagesize: 1048576 kB')
1087 MEMINFO_DICT = {'MemTotal': '65860500',
1088 'MemFree': '28690900',
1089 'MemAvailable': '52873764',
1090 'Active(anon)': '3015676',
1091 'HugePages_Total': '8',
1092 'Hugepagesize': '1048576'}
1094 def test_read_meminfo(self):
1095 ssh_client = ssh.SSH('user', 'host')
1096 with mock.patch.object(ssh_client, 'get_file_obj') as \
1098 mock.patch.object(six, 'BytesIO',
1099 return_value=six.BytesIO(self.MEMINFO)):
1100 output = utils.read_meminfo(ssh_client)
1101 mock_get_client.assert_called_once_with('/proc/meminfo', mock.ANY)
1102 self.assertEqual(self.MEMINFO_DICT, output)