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 import yardstick.error
24 from yardstick.common import utils
25 from yardstick.common import constants
28 class IterSubclassesTestCase(unittest.TestCase):
29 # Disclaimer: this class is a modified copy from
30 # rally/tests/unit/common/plugin/test_discover.py
31 # Copyright 2015: Mirantis Inc.
33 def test_itersubclasses(self):
46 self.assertEqual([B, C, D], list(utils.itersubclasses(A)))
49 class ImportModulesFromPackageTestCase(unittest.TestCase):
51 @mock.patch('yardstick.common.utils.os.walk')
52 def test_import_modules_from_package_no_mod(self, mock_walk):
53 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
54 mock_walk.return_value = ([
55 (os.path.join(yardstick_root, 'foo'), ['bar'], ['__init__.py']),
56 (os.path.join(yardstick_root, 'foo', 'bar'), [], ['baz.txt', 'qux.rst'])
59 utils.import_modules_from_package('foo.bar')
61 @mock.patch('yardstick.common.utils.os.walk')
62 @mock.patch.object(importlib, 'import_module')
63 def test_import_modules_from_package(self, mock_import_module, mock_walk):
65 yardstick_root = os.path.dirname(os.path.dirname(yardstick.__file__))
66 mock_walk.return_value = ([
67 (os.path.join(yardstick_root, 'foo', os.pardir, 'bar'), [], ['baz.py'])
70 utils.import_modules_from_package('foo.bar')
71 mock_import_module.assert_called_once_with('bar.baz')
74 class GetParaFromYaml(unittest.TestCase):
76 @mock.patch('yardstick.common.utils.os.environ.get')
77 def test_get_param_para_not_found(self, get_env):
78 file_path = 'config_sample.yaml'
79 get_env.return_value = self._get_file_abspath(file_path)
82 self.assertTrue(constants.get_param(args, default), default)
84 @mock.patch('yardstick.common.utils.os.environ.get')
85 def test_get_param_para_exists(self, get_env):
86 file_path = 'config_sample.yaml'
87 get_env.return_value = self._get_file_abspath(file_path)
89 para = '/home/opnfv/repos/releng'
90 self.assertEqual(para, constants.get_param(args))
92 def _get_file_abspath(self, filename):
93 curr_path = os.path.dirname(os.path.abspath(__file__))
94 file_path = os.path.join(curr_path, filename)
98 class CommonUtilTestCase(unittest.TestCase):
119 def test__dict_key_flatten(self):
120 line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \
121 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
122 # need to sort for assert to work
123 line = ",".join(sorted(line.split(',')))
124 flattened_data = utils.flatten_dict_key(
125 self.data['benchmark']['data'])
127 ("=".join(item) for item in sorted(flattened_data.items())))
128 self.assertEqual(result, line)
130 def test_get_key_with_default_negative(self):
131 with self.assertRaises(KeyError):
132 utils.get_key_with_default({}, 'key1')
134 @mock.patch('yardstick.common.utils.open', create=True)
135 def test_(self, mock_open):
136 mock_open.side_effect = IOError
138 with self.assertRaises(IOError):
139 utils.find_relative_file('my/path', 'task/path')
141 self.assertEqual(mock_open.call_count, 2)
143 @mock.patch('yardstick.common.utils.open', create=True)
144 def test_open_relative_path(self, mock_open):
145 mock_open_result = mock_open()
146 mock_open_call_count = 1 # initial call to get result
148 self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
150 mock_open_call_count += 1 # one more call expected
151 self.assertEqual(mock_open.call_count, mock_open_call_count)
152 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
153 self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])
155 def open_effect(*args, **kwargs):
156 if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
157 return mock_open_result
158 raise IOError(errno.ENOENT, 'not found')
160 mock_open.side_effect = open_effect
161 self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
163 mock_open_call_count += 2 # two more calls expected
164 self.assertEqual(mock_open.call_count, mock_open_call_count)
165 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
166 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
168 # test an IOError of type ENOENT
169 mock_open.side_effect = IOError(errno.ENOENT, 'not found')
170 with self.assertRaises(IOError):
171 # the second call still raises
172 utils.open_relative_file('foo', 'bar')
174 mock_open_call_count += 2 # two more calls expected
175 self.assertEqual(mock_open.call_count, mock_open_call_count)
176 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
177 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
179 # test an IOError other than ENOENT
180 mock_open.side_effect = IOError(errno.EBUSY, 'busy')
181 with self.assertRaises(IOError):
182 utils.open_relative_file('foo', 'bar')
184 mock_open_call_count += 1 # one more call expected
185 self.assertEqual(mock_open.call_count, mock_open_call_count)
188 class TestMacAddressToHex(unittest.TestCase):
190 def test_mac_address_to_hex_list(self):
191 self.assertEqual(utils.mac_address_to_hex_list("ea:3e:e1:9a:99:e8"),
192 ['0xea', '0x3e', '0xe1', '0x9a', '0x99', '0xe8'])
195 class TranslateToStrTestCase(unittest.TestCase):
197 def test_translate_to_str_unicode(self):
199 output_str = utils.translate_to_str(input_str)
202 self.assertEqual(result, output_str)
204 def test_translate_to_str_dict_list_unicode(self):
206 u'hello': {u'hello': [u'world']}
208 output_str = utils.translate_to_str(input_str)
211 'hello': {'hello': ['world']}
213 self.assertEqual(result, output_str)
215 def test_translate_to_str_non_string(self):
216 input_value = object()
217 result = utils.translate_to_str(input_value)
218 self.assertIs(input_value, result)
221 class TestParseCpuInfo(unittest.TestCase):
223 def test_single_socket_no_hyperthread(self):
226 vendor_id : GenuineIntel
229 model name : Intel Core Processor (Haswell, no TSX)
244 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
249 address sizes : 46 bits physical, 48 bits virtual
253 vendor_id : GenuineIntel
256 model name : Intel Core Processor (Haswell, no TSX)
271 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
276 address sizes : 46 bits physical, 48 bits virtual
280 vendor_id : GenuineIntel
283 model name : Intel Core Processor (Haswell, no TSX)
298 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
303 address sizes : 46 bits physical, 48 bits virtual
307 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
308 self.assertEqual(sorted(socket_map.keys()), [0])
309 self.assertEqual(sorted(socket_map[0].keys()), [2, 3, 4])
311 def test_single_socket_hyperthread(self):
314 vendor_id : GenuineIntel
317 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
332 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
337 address sizes : 39 bits physical, 48 bits virtual
341 vendor_id : GenuineIntel
344 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
359 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
364 address sizes : 39 bits physical, 48 bits virtual
368 vendor_id : GenuineIntel
371 model name : Intel(R) Xeon(R) CPU E3-1275 v3 @ 3.50GHz
386 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
391 address sizes : 39 bits physical, 48 bits virtual
395 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
396 self.assertEqual(sorted(socket_map.keys()), [0])
397 self.assertEqual(sorted(socket_map[0].keys()), [1, 2, 3])
398 self.assertEqual(sorted(socket_map[0][1]), [5])
399 self.assertEqual(sorted(socket_map[0][2]), [6])
400 self.assertEqual(sorted(socket_map[0][3]), [7])
402 def test_dual_socket_hyperthread(self):
405 vendor_id : GenuineIntel
408 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
410 microcode : 0xb00001f
412 cache size : 56320 KB
423 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
428 address sizes : 46 bits physical, 48 bits virtual
432 vendor_id : GenuineIntel
435 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
437 microcode : 0xb00001f
439 cache size : 56320 KB
450 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
455 address sizes : 46 bits physical, 48 bits virtual
459 vendor_id : GenuineIntel
462 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
464 microcode : 0xb00001f
466 cache size : 56320 KB
477 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
482 address sizes : 46 bits physical, 48 bits virtual
486 vendor_id : GenuineIntel
489 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
491 microcode : 0xb00001f
493 cache size : 56320 KB
504 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
509 address sizes : 46 bits physical, 48 bits virtual
513 vendor_id : GenuineIntel
516 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
518 microcode : 0xb00001f
520 cache size : 56320 KB
531 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
536 address sizes : 46 bits physical, 48 bits virtual
540 vendor_id : GenuineIntel
543 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
545 microcode : 0xb00001f
547 cache size : 56320 KB
558 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
563 address sizes : 46 bits physical, 48 bits virtual
567 vendor_id : GenuineIntel
570 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
572 microcode : 0xb00001f
574 cache size : 56320 KB
585 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
590 address sizes : 46 bits physical, 48 bits virtual
594 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
595 self.assertEqual(sorted(socket_map.keys()), [0, 1])
596 self.assertEqual(sorted(socket_map[0].keys()), [0, 1, 2])
597 self.assertEqual(sorted(socket_map[1].keys()), [26, 27, 28])
598 self.assertEqual(sorted(socket_map[0][0]), [44])
599 self.assertEqual(sorted(socket_map[0][1]), [1])
600 self.assertEqual(sorted(socket_map[0][2]), [2])
601 self.assertEqual(sorted(socket_map[1][26]), [85])
602 self.assertEqual(sorted(socket_map[1][27]), [86])
603 self.assertEqual(sorted(socket_map[1][28]), [43, 87])
605 def test_dual_socket_no_hyperthread(self):
608 vendor_id : GenuineIntel
611 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
613 microcode : 0xb00001f
615 cache size : 56320 KB
626 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
631 address sizes : 46 bits physical, 48 bits virtual
635 vendor_id : GenuineIntel
638 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
640 microcode : 0xb00001f
642 cache size : 56320 KB
653 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
658 address sizes : 46 bits physical, 48 bits virtual
662 vendor_id : GenuineIntel
665 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
667 microcode : 0xb00001f
669 cache size : 56320 KB
680 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
685 address sizes : 46 bits physical, 48 bits virtual
689 vendor_id : GenuineIntel
692 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
694 microcode : 0xb00001f
696 cache size : 56320 KB
707 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
712 address sizes : 46 bits physical, 48 bits virtual
716 vendor_id : GenuineIntel
719 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
721 microcode : 0xb00001f
723 cache size : 56320 KB
734 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
739 address sizes : 46 bits physical, 48 bits virtual
743 vendor_id : GenuineIntel
746 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
748 microcode : 0xb00001f
750 cache size : 56320 KB
761 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
766 address sizes : 46 bits physical, 48 bits virtual
770 vendor_id : GenuineIntel
773 model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
775 microcode : 0xb00001f
777 cache size : 56320 KB
788 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
793 address sizes : 46 bits physical, 48 bits virtual
797 socket_map = utils.SocketTopology.parse_cpuinfo(cpuinfo)
798 processors = socket_map.processors()
799 self.assertEqual(processors, [1, 2, 43, 44, 85, 86, 87])
800 cores = socket_map.cores()
801 self.assertEqual(cores, [0, 1, 2, 26, 27, 28])
802 sockets = socket_map.sockets()
803 self.assertEqual(sockets, [0, 1])
806 class ChangeObjToDictTestCase(unittest.TestCase):
808 def test_change_obj_to_dict(self):
811 self.name = 'yardstick'
814 obj_r = utils.change_obj_to_dict(obj)
815 obj_s = {'name': 'yardstick'}
816 self.assertEqual(obj_r, obj_s)
819 class SetDictValueTestCase(unittest.TestCase):
821 def test_set_dict_value(self):
825 output_dic = utils.set_dict_value(input_dic, 'welcome.to', 'yardstick')
826 self.assertEqual(output_dic.get('welcome', {}).get('to'), 'yardstick')
829 class RemoveFileTestCase(unittest.TestCase):
831 def test_remove_file(self):
833 utils.remove_file('notexistfile.txt')
834 except Exception as e: # pylint: disable=broad-except
835 # NOTE(ralonsoh): to narrow the scope of this exception.
836 self.assertTrue(isinstance(e, OSError))
839 class TestUtils(unittest.TestCase):
841 @mock.patch('yardstick.common.utils.os.makedirs')
842 def test_makedirs(self, *_):
843 self.assertIsNone(utils.makedirs('a/b/c/d'))
845 @mock.patch('yardstick.common.utils.os.makedirs')
846 def test_makedirs_exists(self, mock_os_makedirs):
847 mock_os_makedirs.side_effect = OSError(errno.EEXIST, 'exists')
848 self.assertIsNone(utils.makedirs('a/b/c/d'))
850 @mock.patch('yardstick.common.utils.os.makedirs')
851 def test_makedirs_busy(self, mock_os_makedirs):
852 mock_os_makedirs.side_effect = OSError(errno.EBUSY, 'busy')
853 with self.assertRaises(OSError):
854 utils.makedirs('a/b/c/d')
856 @mock.patch('yardstick.common.utils.jsonify')
857 def test_result_handler(self, mock_jsonify):
858 mock_jsonify.return_value = 432
860 self.assertEqual(utils.result_handler('x', 234), 432)
861 mock_jsonify.assert_called_once_with({'status': 'x', 'result': 234})
863 @mock.patch('random.randint')
864 @mock.patch('socket.socket')
865 def test_get_free_port(self, mock_socket, mock_randint):
866 mock_randint.return_value = 7777
867 s = mock_socket('x', 'y')
868 s.connect_ex.side_effect = iter([0, 1])
869 result = utils.get_free_port('10.20.30.40')
870 self.assertEqual(result, 7777)
871 self.assertEqual(s.connect_ex.call_count, 2)
873 @mock.patch('subprocess.check_output')
874 def test_execute_command(self, mock_check_output):
875 expected = ['hello world', '1234']
876 mock_check_output.return_value = os.linesep.join(expected)
877 result = utils.execute_command('my_command arg1 arg2')
878 self.assertEqual(result, expected)
880 @mock.patch('subprocess.Popen')
881 def test_source_env(self, mock_popen):
882 base_env = deepcopy(os.environ)
883 mock_process = mock_popen()
885 'garbage line before',
887 'garbage line after',
889 mock_process.communicate.return_value = os.linesep.join(output_list), '', 0
890 expected = {'NEW_ENV_VALUE': '234'}
891 result = utils.source_env('my_file')
892 self.assertDictEqual(result, expected)
894 os.environ.update(base_env)
896 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
897 def test_parse_ini_file(self, mock_config_parser_type):
899 'default1': 'value1',
900 'default2': 'value2',
911 mock_config_parser = mock_config_parser_type()
912 mock_config_parser.read.return_value = True
913 mock_config_parser.sections.return_value = ['s1', 's2']
914 mock_config_parser.items.side_effect = iter([
925 result = utils.parse_ini_file('my_path')
926 self.assertDictEqual(result, expected)
928 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
929 def test_parse_ini_file_missing_section_header(self, mock_config_parser_type):
930 mock_config_parser = mock_config_parser_type()
931 mock_config_parser.read.side_effect = \
932 configparser.MissingSectionHeaderError(mock.Mock(), 321, mock.Mock())
934 with self.assertRaises(configparser.MissingSectionHeaderError):
935 utils.parse_ini_file('my_path')
937 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
938 def test_parse_ini_file_no_file(self, mock_config_parser_type):
939 mock_config_parser = mock_config_parser_type()
940 mock_config_parser.read.return_value = False
941 with self.assertRaises(RuntimeError):
942 utils.parse_ini_file('my_path')
944 @mock.patch('yardstick.common.utils.configparser.ConfigParser')
945 def test_parse_ini_file_no_default_section_header(self, mock_config_parser_type):
955 mock_config_parser = mock_config_parser_type()
956 mock_config_parser.read.return_value = True
957 mock_config_parser.sections.return_value = ['s1', 's2']
958 mock_config_parser.items.side_effect = iter([
959 configparser.NoSectionError(mock.Mock()),
969 result = utils.parse_ini_file('my_path')
970 self.assertDictEqual(result, expected)
972 def test_join_non_strings(self):
973 self.assertEqual(utils.join_non_strings(':'), '')
974 self.assertEqual(utils.join_non_strings(':', 'a'), 'a')
975 self.assertEqual(utils.join_non_strings(':', 'a', 2, 'c'), 'a:2:c')
976 self.assertEqual(utils.join_non_strings(':', ['a', 2, 'c']), 'a:2:c')
977 self.assertEqual(utils.join_non_strings(':', 'abc'), 'abc')
979 def test_validate_non_string_sequence(self):
980 self.assertEqual(utils.validate_non_string_sequence([1, 2, 3]), [1, 2, 3])
981 self.assertIsNone(utils.validate_non_string_sequence('123'))
982 self.assertIsNone(utils.validate_non_string_sequence(1))
984 self.assertEqual(utils.validate_non_string_sequence(1, 2), 2)
985 self.assertEqual(utils.validate_non_string_sequence(1, default=2), 2)
987 with self.assertRaises(RuntimeError):
988 utils.validate_non_string_sequence(1, raise_exc=RuntimeError)
991 class TestUtilsIpAddrMethods(unittest.TestCase):
993 GOOD_IP_V4_ADDRESS_STR_LIST = [
1003 GOOD_IP_V4_MASK_STR_LIST = [
1012 GOOD_IP_V6_ADDRESS_STR_LIST = [
1014 u'fe80::250:56ff:fe89:91ff',
1015 u'123:4567:89ab:cdef:123:4567:89ab:cdef',
1018 GOOD_IP_V6_MASK_STR_LIST = [
1027 INVALID_IP_ADDRESS_STR_LIST = [
1031 u'123:4567:89ab:cdef:123:4567:89ab:cdef/129',
1034 def test_safe_ip_address(self):
1035 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1036 for addr in addr_list:
1038 expected = ipaddress.ip_address(addr)
1039 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
1041 def test_safe_ip_address_v6_ip(self):
1042 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1043 for addr in addr_list:
1045 expected = ipaddress.ip_address(addr)
1046 self.assertEqual(utils.safe_ip_address(addr), expected, addr)
1048 @mock.patch("yardstick.common.utils.logging")
1049 def test_safe_ip_address_negative(self, *args):
1050 # NOTE(ralonsoh): check the calls to mocked functions.
1051 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1052 self.assertIsNone(utils.safe_ip_address(value), value)
1054 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1055 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1056 for addr_mask_pair in product(addr_list, mask_list):
1057 value = ''.join(addr_mask_pair)
1058 self.assertIsNone(utils.safe_ip_address(value), value)
1060 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1061 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1062 for addr_mask_pair in product(addr_list, mask_list):
1063 value = ''.join(addr_mask_pair)
1064 self.assertIsNone(utils.safe_ip_address(value), value)
1066 def test_get_ip_version(self):
1067 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1068 for addr in addr_list:
1070 self.assertEqual(utils.get_ip_version(addr), 4, addr)
1072 def test_get_ip_version_v6_ip(self):
1073 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1074 for addr in addr_list:
1076 self.assertEqual(utils.get_ip_version(addr), 6, addr)
1078 @mock.patch("yardstick.common.utils.logging")
1079 def test_get_ip_version_negative(self, *args):
1080 # NOTE(ralonsoh): check the calls to mocked functions.
1081 for value in self.INVALID_IP_ADDRESS_STR_LIST:
1082 self.assertIsNone(utils.get_ip_version(value), value)
1084 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1085 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1086 for addr_mask_pair in product(addr_list, mask_list):
1087 value = ''.join(addr_mask_pair)
1088 self.assertIsNone(utils.get_ip_version(value), value)
1090 addr_list = self.GOOD_IP_V6_ADDRESS_STR_LIST
1091 mask_list = self.GOOD_IP_V6_MASK_STR_LIST
1092 for addr_mask_pair in product(addr_list, mask_list):
1093 value = ''.join(addr_mask_pair)
1094 self.assertIsNone(utils.get_ip_version(value), value)
1096 def test_ip_to_hex(self):
1097 self.assertEqual(utils.ip_to_hex('0.0.0.0'), '00000000')
1098 self.assertEqual(utils.ip_to_hex('10.20.30.40'), '0a141e28')
1099 self.assertEqual(utils.ip_to_hex('127.0.0.1'), '7f000001')
1100 self.assertEqual(utils.ip_to_hex('172.31.90.100'), 'ac1f5a64')
1101 self.assertEqual(utils.ip_to_hex('192.168.254.253'), 'c0a8fefd')
1102 self.assertEqual(utils.ip_to_hex('255.255.255.255'), 'ffffffff')
1104 def test_ip_to_hex_v6_ip(self):
1105 for value in self.GOOD_IP_V6_ADDRESS_STR_LIST:
1106 self.assertEqual(utils.ip_to_hex(value), value)
1108 @mock.patch("yardstick.common.utils.logging")
1109 def test_ip_to_hex_negative(self, *args):
1110 # NOTE(ralonsoh): check the calls to mocked functions.
1111 addr_list = self.GOOD_IP_V4_ADDRESS_STR_LIST
1112 mask_list = self.GOOD_IP_V4_MASK_STR_LIST
1113 value_iter = (''.join(pair) for pair in product(addr_list, mask_list))
1114 for value in chain(value_iter, self.INVALID_IP_ADDRESS_STR_LIST):
1115 self.assertEqual(utils.ip_to_hex(value), value)
1118 class SafeDecodeUtf8TestCase(unittest.TestCase):
1120 @unittest.skipIf(six.PY2,
1121 'This test should only be launched with Python 3.x')
1122 def test_safe_decode_utf8(self):
1123 _bytes = b'this is a byte array'
1124 out = utils.safe_decode_utf8(_bytes)
1125 self.assertIs(type(out), str)
1126 self.assertEqual('this is a byte array', out)
1129 class ReadMeminfoTestCase(unittest.TestCase):
1131 MEMINFO = (b'MemTotal: 65860500 kB\n'
1132 b'MemFree: 28690900 kB\n'
1133 b'MemAvailable: 52873764 kB\n'
1134 b'Active(anon): 3015676 kB\n'
1135 b'HugePages_Total: 8\n'
1136 b'Hugepagesize: 1048576 kB')
1137 MEMINFO_DICT = {'MemTotal': '65860500',
1138 'MemFree': '28690900',
1139 'MemAvailable': '52873764',
1140 'Active(anon)': '3015676',
1141 'HugePages_Total': '8',
1142 'Hugepagesize': '1048576'}
1144 def test_read_meminfo(self):
1145 ssh_client = ssh.SSH('user', 'host')
1146 with mock.patch.object(ssh_client, 'get_file_obj') as \
1148 mock.patch.object(six, 'BytesIO',
1149 return_value=six.BytesIO(self.MEMINFO)):
1150 output = utils.read_meminfo(ssh_client)
1151 mock_get_client.assert_called_once_with('/proc/meminfo', mock.ANY)
1152 self.assertEqual(self.MEMINFO_DICT, output)