Import upstream version 7.0.0, md5 1c20faea9100e7c938e03cec92172393
Debian Janitor
3 years ago
0 | 07/05/2020 Release 7.0.0 | |
1 | * Fixed Bug #133: CPU flags vary between runs on Mac OS X | |
2 | * Fixed Bug #150: Change 'byte code' to 'machine code' | |
3 | * Fixed Bug #128: Overhead from generating machine code throws off CPUID HZ | |
4 | * Fixed Bug #136: On non BeOS systems, calling sysinfo may open GUI program | |
5 | * Fixed Bug #138: Invalid escape sequences warn when building in Python 3.8 | |
6 | * Fixed Bug #147: Remove extended_model and extended_family fields | |
7 | * Fixed Bug #146: CPUID family and model is wrong | |
8 | * Fixed Bug #144: Cache fields should be full ints instead of kb strings | |
9 | ||
10 | 06/11/2020 Release 6.0.0 | |
11 | * Fixed Bug #140: The get_cache function has swapped fields | |
12 | * Fixed Bug #142: Remove empty and zeroed fields | |
13 | * Fixed Bug #115: Missing data on Ryzen CPUs | |
14 | * Fixed Bug #122: Rename fields to be more clear | |
15 | * Fixed Bug #125: Add option to return --version | |
16 | * Fixed Bug #126: Make test suite also check SELinux | |
17 | * Fixed Bug #120: Make unit tests also test CPUID | |
18 | * Fixed Bug #69: Add s390x support | |
19 | ||
0 | 20 | 03/20/2019 Release 5.0.0 |
1 | 21 | * Fixed Bug #117: Remove PyInstaller hacks |
2 | 22 | * Fixed Bug #108: Client script runs multiple times without __main__ |
0 | 0 | The MIT License (MIT) |
1 | 1 | |
2 | Copyright (c) 2014-2019 Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
2 | Copyright (c) 2014-2020 Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
3 | 3 | |
4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
5 | 5 | this software and associated documentation files (the "Software"), to deal in |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: py-cpuinfo |
2 | Version: 5.0.0 | |
2 | Version: 7.0.0 | |
3 | 3 | Summary: Get CPU info with pure Python 2 & 3 |
4 | 4 | Home-page: https://github.com/workhorsy/py-cpuinfo |
5 | 5 | Author: Matthew Brennan Jones |
0 | 0 | #!/usr/bin/env python |
1 | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | |
3 | # Copyright (c) 2014-2019, Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
3 | # Copyright (c) 2014-2020 Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
4 | 4 | # Py-cpuinfo gets CPU info with pure Python 2 & 3 |
5 | 5 | # It uses the MIT License |
6 | 6 | # It is hosted at: https://github.com/workhorsy/py-cpuinfo |
24 | 24 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
25 | 25 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
26 | 26 | |
27 | CPUINFO_VERSION = (5, 0, 0) | |
27 | CPUINFO_VERSION = (7, 0, 0) | |
28 | CPUINFO_VERSION_STRING = '.'.join([str(n) for n in CPUINFO_VERSION]) | |
28 | 29 | |
29 | 30 | import os, sys |
30 | 31 | import platform |
31 | 32 | import multiprocessing |
32 | 33 | import ctypes |
33 | 34 | |
34 | try: | |
35 | import _winreg as winreg | |
36 | except ImportError as err: | |
37 | try: | |
38 | import winreg | |
39 | except ImportError as err: | |
40 | pass | |
41 | 35 | |
42 | 36 | IS_PY2 = sys.version_info[0] == 2 |
37 | CAN_CALL_CPUID_IN_SUBPROCESS = True | |
43 | 38 | |
44 | 39 | |
45 | 40 | class DataSource(object): |
46 | 41 | bits = platform.architecture()[0] |
47 | 42 | cpu_count = multiprocessing.cpu_count() |
48 | 43 | is_windows = platform.system().lower() == 'windows' |
49 | raw_arch_string = platform.machine() | |
44 | arch_string_raw = platform.machine() | |
45 | uname_string_raw = platform.uname()[5] | |
50 | 46 | can_cpuid = True |
51 | 47 | |
52 | 48 | @staticmethod |
84 | 80 | |
85 | 81 | @staticmethod |
86 | 82 | def has_sysinfo(): |
87 | return len(_program_paths('sysinfo')) > 0 | |
83 | uname = platform.system().strip().strip('"').strip("'").strip().lower() | |
84 | is_beos = 'beos' in uname or 'haiku' in uname | |
85 | return is_beos and len(_program_paths('sysinfo')) > 0 | |
88 | 86 | |
89 | 87 | @staticmethod |
90 | 88 | def has_lscpu(): |
108 | 106 | return _run_and_get_stdout(['cpufreq-info']) |
109 | 107 | |
110 | 108 | @staticmethod |
111 | def sestatus_allow_execheap(): | |
112 | return _run_and_get_stdout(['sestatus', '-b'], ['grep', '-i', '"allow_execheap"'])[1].strip().lower().endswith('on') | |
113 | ||
114 | @staticmethod | |
115 | def sestatus_allow_execmem(): | |
116 | return _run_and_get_stdout(['sestatus', '-b'], ['grep', '-i', '"allow_execmem"'])[1].strip().lower().endswith('on') | |
109 | def sestatus_b(): | |
110 | return _run_and_get_stdout(['sestatus', '-b']) | |
117 | 111 | |
118 | 112 | @staticmethod |
119 | 113 | def dmesg_a(): |
157 | 151 | |
158 | 152 | @staticmethod |
159 | 153 | def winreg_processor_brand(): |
160 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") | |
161 | processor_brand = winreg.QueryValueEx(key, "ProcessorNameString")[0] | |
162 | winreg.CloseKey(key) | |
163 | return processor_brand | |
164 | ||
165 | @staticmethod | |
166 | def winreg_vendor_id(): | |
167 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") | |
168 | vendor_id = winreg.QueryValueEx(key, "VendorIdentifier")[0] | |
169 | winreg.CloseKey(key) | |
170 | return vendor_id | |
171 | ||
172 | @staticmethod | |
173 | def winreg_raw_arch_string(): | |
174 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment") | |
175 | raw_arch_string = winreg.QueryValueEx(key, "PROCESSOR_ARCHITECTURE")[0] | |
176 | winreg.CloseKey(key) | |
177 | return raw_arch_string | |
154 | processor_brand = _read_windows_registry_key(r"Hardware\Description\System\CentralProcessor\0", "ProcessorNameString") | |
155 | return processor_brand.strip() | |
156 | ||
157 | @staticmethod | |
158 | def winreg_vendor_id_raw(): | |
159 | vendor_id_raw = _read_windows_registry_key(r"Hardware\Description\System\CentralProcessor\0", "VendorIdentifier") | |
160 | return vendor_id_raw | |
161 | ||
162 | @staticmethod | |
163 | def winreg_arch_string_raw(): | |
164 | arch_string_raw = _read_windows_registry_key(r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "PROCESSOR_ARCHITECTURE") | |
165 | return arch_string_raw | |
178 | 166 | |
179 | 167 | @staticmethod |
180 | 168 | def winreg_hz_actual(): |
181 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") | |
182 | hz_actual = winreg.QueryValueEx(key, "~Mhz")[0] | |
183 | winreg.CloseKey(key) | |
184 | hz_actual = _to_hz_string(hz_actual) | |
169 | hz_actual = _read_windows_registry_key(r"Hardware\Description\System\CentralProcessor\0", "~Mhz") | |
170 | hz_actual = _to_decimal_string(hz_actual) | |
185 | 171 | return hz_actual |
186 | 172 | |
187 | 173 | @staticmethod |
188 | 174 | def winreg_feature_bits(): |
189 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") | |
190 | feature_bits = winreg.QueryValueEx(key, "FeatureSet")[0] | |
191 | winreg.CloseKey(key) | |
175 | feature_bits = _read_windows_registry_key(r"Hardware\Description\System\CentralProcessor\0", "FeatureSet") | |
192 | 176 | return feature_bits |
193 | 177 | |
194 | 178 | |
224 | 208 | output = output.decode(encoding='UTF-8') |
225 | 209 | return p2.returncode, output |
226 | 210 | |
211 | def _read_windows_registry_key(key_name, field_name): | |
212 | try: | |
213 | import _winreg as winreg | |
214 | except ImportError as err: | |
215 | try: | |
216 | import winreg | |
217 | except ImportError as err: | |
218 | pass | |
219 | ||
220 | key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_name) | |
221 | value = winreg.QueryValueEx(key, field_name)[0] | |
222 | winreg.CloseKey(key) | |
223 | return value | |
224 | ||
227 | 225 | # Make sure we are running on a supported system |
228 | 226 | def _check_arch(): |
229 | arch, bits = _parse_arch(DataSource.raw_arch_string) | |
230 | if not arch in ['X86_32', 'X86_64', 'ARM_7', 'ARM_8', 'PPC_64']: | |
231 | raise Exception("py-cpuinfo currently only works on X86 and some PPC and ARM CPUs.") | |
227 | arch, bits = _parse_arch(DataSource.arch_string_raw) | |
228 | if not arch in ['X86_32', 'X86_64', 'ARM_7', 'ARM_8', 'PPC_64', 'S390X']: | |
229 | raise Exception("py-cpuinfo currently only works on X86 and some ARM/PPC/S390X CPUs.") | |
232 | 230 | |
233 | 231 | def _obj_to_b64(thing): |
234 | 232 | import pickle |
264 | 262 | |
265 | 263 | def _copy_new_fields(info, new_info): |
266 | 264 | keys = [ |
267 | 'vendor_id', 'hardware', 'brand', 'hz_advertised', 'hz_actual', | |
268 | 'hz_advertised_raw', 'hz_actual_raw', 'arch', 'bits', 'count', | |
269 | 'raw_arch_string', 'l2_cache_size', 'l2_cache_line_size', | |
270 | 'l2_cache_associativity', 'stepping', 'model', 'family', | |
271 | 'processor_type', 'extended_model', 'extended_family', 'flags', | |
265 | 'vendor_id_raw', 'hardware_raw', 'brand_raw', 'hz_advertised_friendly', 'hz_actual_friendly', | |
266 | 'hz_advertised', 'hz_actual', 'arch', 'bits', 'count', | |
267 | 'arch_string_raw', 'uname_string_raw', | |
268 | 'l2_cache_size', 'l2_cache_line_size', 'l2_cache_associativity', | |
269 | 'stepping', 'model', 'family', | |
270 | 'processor_type', 'flags', | |
272 | 271 | 'l3_cache_size', 'l1_data_cache_size', 'l1_instruction_cache_size' |
273 | 272 | ] |
274 | 273 | |
313 | 312 | |
314 | 313 | return retval |
315 | 314 | |
316 | def _get_hz_string_from_brand(processor_brand): | |
317 | # Just return 0 if the processor brand does not have the Hz | |
318 | if not 'hz' in processor_brand.lower(): | |
319 | return (1, '0.0') | |
320 | ||
321 | hz_brand = processor_brand.lower() | |
322 | scale = 1 | |
323 | ||
324 | if hz_brand.endswith('mhz'): | |
325 | scale = 6 | |
326 | elif hz_brand.endswith('ghz'): | |
327 | scale = 9 | |
328 | if '@' in hz_brand: | |
329 | hz_brand = hz_brand.split('@')[1] | |
330 | else: | |
331 | hz_brand = hz_brand.rsplit(None, 1)[1] | |
332 | ||
333 | hz_brand = hz_brand.rstrip('mhz').rstrip('ghz').strip() | |
334 | hz_brand = _to_hz_string(hz_brand) | |
335 | ||
336 | return (scale, hz_brand) | |
337 | ||
338 | def _to_friendly_hz(ticks, scale): | |
339 | # Get the raw Hz as a string | |
340 | left, right = _to_raw_hz(ticks, scale) | |
341 | ticks = '{0}.{1}'.format(left, right) | |
342 | ||
343 | # Get the location of the dot, and remove said dot | |
344 | dot_index = ticks.index('.') | |
345 | ticks = ticks.replace('.', '') | |
346 | ||
347 | # Get the Hz symbol and scale | |
348 | symbol = "Hz" | |
349 | scale = 0 | |
350 | if dot_index > 9: | |
351 | symbol = "GHz" | |
352 | scale = 9 | |
353 | elif dot_index > 6: | |
354 | symbol = "MHz" | |
355 | scale = 6 | |
356 | elif dot_index > 3: | |
357 | symbol = "KHz" | |
358 | scale = 3 | |
359 | ||
360 | # Get the Hz with the dot at the new scaled point | |
361 | ticks = '{0}.{1}'.format(ticks[:-scale-1], ticks[-scale-1:]) | |
362 | ||
363 | # Format the ticks to have 4 numbers after the decimal | |
364 | # and remove any superfluous zeroes. | |
365 | ticks = '{0:.4f} {1}'.format(float(ticks), symbol) | |
366 | ticks = ticks.rstrip('0') | |
367 | ||
368 | return ticks | |
369 | ||
370 | def _to_raw_hz(ticks, scale): | |
371 | # Scale the numbers | |
372 | ticks = ticks.lstrip('0') | |
373 | old_index = ticks.index('.') | |
374 | ticks = ticks.replace('.', '') | |
375 | ticks = ticks.ljust(scale + old_index+1, '0') | |
376 | new_index = old_index + scale | |
377 | ticks = '{0}.{1}'.format(ticks[:new_index], ticks[new_index:]) | |
378 | left, right = ticks.split('.') | |
379 | left, right = int(left), int(right) | |
380 | return (left, right) | |
381 | ||
382 | def _to_hz_string(ticks): | |
383 | # Convert to string | |
384 | ticks = '{0}'.format(ticks) | |
385 | ||
386 | # Add decimal if missing | |
387 | if '.' not in ticks: | |
388 | ticks = '{0}.0'.format(ticks) | |
389 | ||
390 | # Remove trailing zeros | |
391 | ticks = ticks.rstrip('0') | |
392 | ||
393 | # Add one trailing zero for empty right side | |
394 | if ticks.endswith('.'): | |
395 | ticks = '{0}0'.format(ticks) | |
396 | ||
397 | return ticks | |
315 | def _to_decimal_string(ticks): | |
316 | try: | |
317 | # Convert to string | |
318 | ticks = '{0}'.format(ticks) | |
319 | ||
320 | # Strip off non numbers and decimal places | |
321 | ticks = "".join(n for n in ticks if n.isdigit() or n=='.').strip() | |
322 | if ticks == '': | |
323 | ticks = '0' | |
324 | ||
325 | # Add decimal if missing | |
326 | if '.' not in ticks: | |
327 | ticks = '{0}.0'.format(ticks) | |
328 | ||
329 | # Remove trailing zeros | |
330 | ticks = ticks.rstrip('0') | |
331 | ||
332 | # Add one trailing zero for empty right side | |
333 | if ticks.endswith('.'): | |
334 | ticks = '{0}0'.format(ticks) | |
335 | ||
336 | # Make sure the number can be converted to a float | |
337 | ticks = float(ticks) | |
338 | ticks = '{0}'.format(ticks) | |
339 | return ticks | |
340 | except: | |
341 | return '0.0' | |
342 | ||
343 | def _hz_short_to_full(ticks, scale): | |
344 | try: | |
345 | # Make sure the number can be converted to a float | |
346 | ticks = float(ticks) | |
347 | ticks = '{0}'.format(ticks) | |
348 | ||
349 | # Scale the numbers | |
350 | hz = ticks.lstrip('0') | |
351 | old_index = hz.index('.') | |
352 | hz = hz.replace('.', '') | |
353 | hz = hz.ljust(scale + old_index+1, '0') | |
354 | new_index = old_index + scale | |
355 | hz = '{0}.{1}'.format(hz[:new_index], hz[new_index:]) | |
356 | left, right = hz.split('.') | |
357 | left, right = int(left), int(right) | |
358 | return (left, right) | |
359 | except: | |
360 | return (0, 0) | |
361 | ||
362 | def _hz_friendly_to_full(hz_string): | |
363 | try: | |
364 | hz_string = hz_string.strip().lower() | |
365 | hz, scale = (None, None) | |
366 | ||
367 | if hz_string.endswith('ghz'): | |
368 | scale = 9 | |
369 | elif hz_string.endswith('mhz'): | |
370 | scale = 6 | |
371 | elif hz_string.endswith('hz'): | |
372 | scale = 0 | |
373 | ||
374 | hz = "".join(n for n in hz_string if n.isdigit() or n=='.').strip() | |
375 | if not '.' in hz: | |
376 | hz += '.0' | |
377 | ||
378 | hz, scale = _hz_short_to_full(hz, scale) | |
379 | ||
380 | return (hz, scale) | |
381 | except: | |
382 | return (0, 0) | |
383 | ||
384 | def _hz_short_to_friendly(ticks, scale): | |
385 | try: | |
386 | # Get the raw Hz as a string | |
387 | left, right = _hz_short_to_full(ticks, scale) | |
388 | result = '{0}.{1}'.format(left, right) | |
389 | ||
390 | # Get the location of the dot, and remove said dot | |
391 | dot_index = result.index('.') | |
392 | result = result.replace('.', '') | |
393 | ||
394 | # Get the Hz symbol and scale | |
395 | symbol = "Hz" | |
396 | scale = 0 | |
397 | if dot_index > 9: | |
398 | symbol = "GHz" | |
399 | scale = 9 | |
400 | elif dot_index > 6: | |
401 | symbol = "MHz" | |
402 | scale = 6 | |
403 | elif dot_index > 3: | |
404 | symbol = "KHz" | |
405 | scale = 3 | |
406 | ||
407 | # Get the Hz with the dot at the new scaled point | |
408 | result = '{0}.{1}'.format(result[:-scale-1], result[-scale-1:]) | |
409 | ||
410 | # Format the ticks to have 4 numbers after the decimal | |
411 | # and remove any superfluous zeroes. | |
412 | result = '{0:.4f} {1}'.format(float(result), symbol) | |
413 | result = result.rstrip('0') | |
414 | return result | |
415 | except: | |
416 | return '0.0000 Hz' | |
398 | 417 | |
399 | 418 | def _to_friendly_bytes(input): |
400 | 419 | import re |
416 | 435 | |
417 | 436 | return input |
418 | 437 | |
419 | def _parse_cpu_string(cpu_string): | |
420 | # Get location of fields at end of string | |
421 | fields_index = cpu_string.find('(', cpu_string.find('@')) | |
422 | #print(fields_index) | |
423 | ||
424 | # Processor Brand | |
425 | processor_brand = cpu_string | |
426 | if fields_index != -1: | |
427 | processor_brand = cpu_string[0 : fields_index].strip() | |
428 | #print('processor_brand: ', processor_brand) | |
429 | ||
430 | fields = None | |
431 | if fields_index != -1: | |
432 | fields = cpu_string[fields_index : ] | |
433 | #print('fields: ', fields) | |
434 | ||
435 | # Hz | |
436 | scale, hz_brand = _get_hz_string_from_brand(processor_brand) | |
437 | ||
438 | # Various fields | |
438 | def _friendly_bytes_to_int(friendly_bytes): | |
439 | input = friendly_bytes.lower() | |
440 | ||
441 | formats = { | |
442 | 'gb' : 1024 * 1024 * 1024, | |
443 | 'mb' : 1024 * 1024, | |
444 | 'kb' : 1024, | |
445 | ||
446 | 'g' : 1024 * 1024 * 1024, | |
447 | 'm' : 1024 * 1024, | |
448 | 'k' : 1024, | |
449 | 'b' : 1, | |
450 | } | |
451 | ||
452 | try: | |
453 | for pattern, multiplier in formats.items(): | |
454 | if input.endswith(pattern): | |
455 | return int(input.split(pattern)[0].strip()) * multiplier | |
456 | ||
457 | except Exception as err: | |
458 | pass | |
459 | ||
460 | return friendly_bytes | |
461 | ||
462 | def _parse_cpu_brand_string(cpu_string): | |
463 | # Just return 0 if the processor brand does not have the Hz | |
464 | if not 'hz' in cpu_string.lower(): | |
465 | return ('0.0', 0) | |
466 | ||
467 | hz = cpu_string.lower() | |
468 | scale = 0 | |
469 | ||
470 | if hz.endswith('mhz'): | |
471 | scale = 6 | |
472 | elif hz.endswith('ghz'): | |
473 | scale = 9 | |
474 | if '@' in hz: | |
475 | hz = hz.split('@')[1] | |
476 | else: | |
477 | hz = hz.rsplit(None, 1)[1] | |
478 | ||
479 | hz = hz.rstrip('mhz').rstrip('ghz').strip() | |
480 | hz = _to_decimal_string(hz) | |
481 | ||
482 | return (hz, scale) | |
483 | ||
484 | def _parse_cpu_brand_string_dx(cpu_string): | |
485 | import re | |
486 | ||
487 | # Find all the strings inside brackets () | |
488 | starts = [m.start() for m in re.finditer(r"\(", cpu_string)] | |
489 | ends = [m.start() for m in re.finditer(r"\)", cpu_string)] | |
490 | insides = {k: v for k, v in zip(starts, ends)} | |
491 | insides = [cpu_string[start+1 : end] for start, end in insides.items()] | |
492 | ||
493 | # Find all the fields | |
439 | 494 | vendor_id, stepping, model, family = (None, None, None, None) |
440 | if fields: | |
441 | try: | |
442 | fields = fields.rsplit('(', 1)[1].split(')')[0].split(',') | |
443 | fields = [f.strip().lower() for f in fields] | |
444 | fields = [f.split(':') for f in fields] | |
445 | fields = [{f[0].strip() : f[1].strip()} for f in fields] | |
446 | #print('fields: ', fields) | |
447 | for field in fields: | |
448 | name = list(field.keys())[0] | |
449 | value = list(field.values())[0] | |
450 | #print('name:{0}, value:{1}'.format(name, value)) | |
495 | for inside in insides: | |
496 | for pair in inside.split(','): | |
497 | pair = [n.strip() for n in pair.split(':')] | |
498 | if len(pair) > 1: | |
499 | name, value = pair[0], pair[1] | |
451 | 500 | if name == 'origin': |
452 | 501 | vendor_id = value.strip('"') |
453 | 502 | elif name == 'stepping': |
456 | 505 | model = int(value.lstrip('0x'), 16) |
457 | 506 | elif name in ['fam', 'family']: |
458 | 507 | family = int(value.lstrip('0x'), 16) |
459 | except: | |
460 | #raise | |
461 | pass | |
462 | ||
463 | return (processor_brand, hz_brand, scale, vendor_id, stepping, model, family) | |
508 | ||
509 | # Find the Processor Brand | |
510 | # Strip off extra strings in brackets at end | |
511 | brand = cpu_string.strip() | |
512 | is_working = True | |
513 | while is_working: | |
514 | is_working = False | |
515 | for inside in insides: | |
516 | full = "({0})".format(inside) | |
517 | if brand.endswith(full): | |
518 | brand = brand[ :-len(full)].strip() | |
519 | is_working = True | |
520 | ||
521 | # Find the Hz in the brand string | |
522 | hz_brand, scale = _parse_cpu_brand_string(brand) | |
523 | ||
524 | # Find Hz inside brackets () after the brand string | |
525 | if hz_brand == '0.0': | |
526 | for inside in insides: | |
527 | hz = inside | |
528 | for entry in ['GHz', 'MHz', 'Hz']: | |
529 | if entry in hz: | |
530 | hz = "CPU @ " + hz[ : hz.find(entry) + len(entry)] | |
531 | hz_brand, scale = _parse_cpu_brand_string(hz) | |
532 | break | |
533 | ||
534 | return (hz_brand, scale, brand, vendor_id, stepping, model, family) | |
464 | 535 | |
465 | 536 | def _parse_dmesg_output(output): |
466 | 537 | try: |
474 | 545 | lines = [l.split('\n')[0].strip() for l in lines] |
475 | 546 | |
476 | 547 | # Convert the lines to CPU strings |
477 | cpu_strings = [_parse_cpu_string(l) for l in lines] | |
548 | cpu_strings = [_parse_cpu_brand_string_dx(l) for l in lines] | |
478 | 549 | |
479 | 550 | # Find the CPU string that has the most fields |
480 | 551 | best_string = None |
489 | 560 | if not best_string: |
490 | 561 | return {} |
491 | 562 | |
492 | processor_brand, hz_actual, scale, vendor_id, stepping, model, family = best_string | |
563 | hz_actual, scale, processor_brand, vendor_id, stepping, model, family = best_string | |
493 | 564 | |
494 | 565 | # Origin |
495 | 566 | if ' Origin=' in output: |
497 | 568 | fields = fields.strip().split() |
498 | 569 | fields = [n.strip().split('=') for n in fields] |
499 | 570 | fields = [{n[0].strip().lower() : n[1].strip()} for n in fields] |
500 | #print('fields: ', fields) | |
571 | ||
501 | 572 | for field in fields: |
502 | 573 | name = list(field.keys())[0] |
503 | 574 | value = list(field.values())[0] |
504 | #print('name:{0}, value:{1}'.format(name, value)) | |
575 | ||
505 | 576 | if name == 'origin': |
506 | 577 | vendor_id = value.strip('"') |
507 | 578 | elif name == 'stepping': |
510 | 581 | model = int(value.lstrip('0x'), 16) |
511 | 582 | elif name in ['fam', 'family']: |
512 | 583 | family = int(value.lstrip('0x'), 16) |
513 | #print('FIELDS: ', (vendor_id, stepping, model, family)) | |
514 | 584 | |
515 | 585 | # Features |
516 | 586 | flag_lines = [] |
526 | 596 | flags.sort() |
527 | 597 | |
528 | 598 | # Convert from GHz/MHz string to Hz |
529 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
599 | hz_advertised, scale = _parse_cpu_brand_string(processor_brand) | |
600 | ||
601 | # If advertised hz not found, use the actual hz | |
602 | if hz_advertised == '0.0': | |
603 | scale = 6 | |
604 | hz_advertised = _to_decimal_string(hz_actual) | |
530 | 605 | |
531 | 606 | info = { |
532 | 'vendor_id' : vendor_id, | |
533 | 'brand' : processor_brand, | |
607 | 'vendor_id_raw' : vendor_id, | |
608 | 'brand_raw' : processor_brand, | |
534 | 609 | |
535 | 610 | 'stepping' : stepping, |
536 | 611 | 'model' : model, |
539 | 614 | } |
540 | 615 | |
541 | 616 | if hz_advertised and hz_advertised != '0.0': |
542 | info['hz_advertised'] = _to_friendly_hz(hz_advertised, scale) | |
543 | info['hz_actual'] = _to_friendly_hz(hz_actual, scale) | |
617 | info['hz_advertised_friendly'] = _hz_short_to_friendly(hz_advertised, scale) | |
618 | info['hz_actual_friendly'] = _hz_short_to_friendly(hz_actual, scale) | |
544 | 619 | |
545 | 620 | if hz_advertised and hz_advertised != '0.0': |
546 | info['hz_advertised_raw'] = _to_raw_hz(hz_advertised, scale) | |
547 | info['hz_actual_raw'] = _to_raw_hz(hz_actual, scale) | |
621 | info['hz_advertised'] = _hz_short_to_full(hz_advertised, scale) | |
622 | info['hz_actual'] = _hz_short_to_full(hz_actual, scale) | |
548 | 623 | |
549 | 624 | return {k: v for k, v in info.items() if v} |
550 | 625 | except: |
553 | 628 | |
554 | 629 | return {} |
555 | 630 | |
556 | def _parse_arch(raw_arch_string): | |
631 | def _parse_arch(arch_string_raw): | |
557 | 632 | import re |
558 | 633 | |
559 | 634 | arch, bits = None, None |
560 | raw_arch_string = raw_arch_string.lower() | |
635 | arch_string_raw = arch_string_raw.lower() | |
561 | 636 | |
562 | 637 | # X86 |
563 | if re.match('^i\d86$|^x86$|^x86_32$|^i86pc$|^ia32$|^ia-32$|^bepc$', raw_arch_string): | |
638 | if re.match(r'^i\d86$|^x86$|^x86_32$|^i86pc$|^ia32$|^ia-32$|^bepc$', arch_string_raw): | |
564 | 639 | arch = 'X86_32' |
565 | 640 | bits = 32 |
566 | elif re.match('^x64$|^x86_64$|^x86_64t$|^i686-64$|^amd64$|^ia64$|^ia-64$', raw_arch_string): | |
641 | elif re.match(r'^x64$|^x86_64$|^x86_64t$|^i686-64$|^amd64$|^ia64$|^ia-64$', arch_string_raw): | |
567 | 642 | arch = 'X86_64' |
568 | 643 | bits = 64 |
569 | 644 | # ARM |
570 | elif re.match('^armv8-a|aarch64$', raw_arch_string): | |
645 | elif re.match(r'^armv8-a|aarch64$', arch_string_raw): | |
571 | 646 | arch = 'ARM_8' |
572 | 647 | bits = 64 |
573 | elif re.match('^armv7$|^armv7[a-z]$|^armv7-[a-z]$|^armv6[a-z]$', raw_arch_string): | |
648 | elif re.match(r'^armv7$|^armv7[a-z]$|^armv7-[a-z]$|^armv6[a-z]$', arch_string_raw): | |
574 | 649 | arch = 'ARM_7' |
575 | 650 | bits = 32 |
576 | elif re.match('^armv8$|^armv8[a-z]$|^armv8-[a-z]$', raw_arch_string): | |
651 | elif re.match(r'^armv8$|^armv8[a-z]$|^armv8-[a-z]$', arch_string_raw): | |
577 | 652 | arch = 'ARM_8' |
578 | 653 | bits = 32 |
579 | 654 | # PPC |
580 | elif re.match('^ppc32$|^prep$|^pmac$|^powermac$', raw_arch_string): | |
655 | elif re.match(r'^ppc32$|^prep$|^pmac$|^powermac$', arch_string_raw): | |
581 | 656 | arch = 'PPC_32' |
582 | 657 | bits = 32 |
583 | elif re.match('^powerpc$|^ppc64$|^ppc64le$', raw_arch_string): | |
658 | elif re.match(r'^powerpc$|^ppc64$|^ppc64le$', arch_string_raw): | |
584 | 659 | arch = 'PPC_64' |
585 | 660 | bits = 64 |
586 | 661 | # SPARC |
587 | elif re.match('^sparc32$|^sparc$', raw_arch_string): | |
662 | elif re.match(r'^sparc32$|^sparc$', arch_string_raw): | |
588 | 663 | arch = 'SPARC_32' |
589 | 664 | bits = 32 |
590 | elif re.match('^sparc64$|^sun4u$|^sun4v$', raw_arch_string): | |
665 | elif re.match(r'^sparc64$|^sun4u$|^sun4v$', arch_string_raw): | |
591 | 666 | arch = 'SPARC_64' |
667 | bits = 64 | |
668 | # S390X | |
669 | elif re.match(r'^s390x$', arch_string_raw): | |
670 | arch = 'S390X' | |
592 | 671 | bits = 64 |
593 | 672 | |
594 | 673 | return (arch, bits) |
599 | 678 | return is_set |
600 | 679 | |
601 | 680 | |
602 | class CPUID(object): | |
603 | def __init__(self): | |
681 | def _is_selinux_enforcing(): | |
682 | # Just return if the SE Linux Status Tool is not installed | |
683 | if not DataSource.has_sestatus(): | |
684 | return False | |
685 | ||
686 | # Run the sestatus, and just return if it failed to run | |
687 | returncode, output = DataSource.sestatus_b() | |
688 | if returncode != 0: | |
689 | return False | |
690 | ||
691 | # Figure out if explicitly in enforcing mode | |
692 | for line in output.splitlines(): | |
693 | line = line.strip().lower() | |
694 | if line.startswith("current mode:"): | |
695 | if line.endswith("enforcing"): | |
696 | return True | |
697 | else: | |
698 | return False | |
699 | ||
700 | # Figure out if we can execute heap and execute memory | |
701 | can_selinux_exec_heap = False | |
702 | can_selinux_exec_memory = False | |
703 | for line in output.splitlines(): | |
704 | line = line.strip().lower() | |
705 | if line.startswith("allow_execheap") and line.endswith("on"): | |
706 | can_selinux_exec_heap = True | |
707 | elif line.startswith("allow_execmem") and line.endswith("on"): | |
708 | can_selinux_exec_memory = True | |
709 | ||
710 | return (not can_selinux_exec_heap or not can_selinux_exec_memory) | |
711 | ||
712 | def _filter_dict_keys_with_empty_values(info): | |
713 | # Filter out None, 0, "", (), {}, [] | |
714 | info = {k: v for k, v in info.items() if v} | |
715 | ||
716 | # Filter out (0, 0) | |
717 | info = {k: v for k, v in info.items() if v != (0, 0)} | |
718 | ||
719 | # Filter out strings that start with "0.0" | |
720 | info = {k: v for k, v in info.items() if not (type(v) == str and v.startswith('0.0'))} | |
721 | ||
722 | return info | |
723 | ||
724 | ||
725 | class ASM(object): | |
726 | def __init__(self, restype=None, argtypes=(), machine_code=[]): | |
727 | self.restype = restype | |
728 | self.argtypes = argtypes | |
729 | self.machine_code = machine_code | |
604 | 730 | self.prochandle = None |
605 | ||
606 | # Figure out if SE Linux is on and in enforcing mode | |
607 | self.is_selinux_enforcing = False | |
608 | ||
609 | # Just return if the SE Linux Status Tool is not installed | |
610 | if not DataSource.has_sestatus(): | |
611 | return | |
612 | ||
613 | # Figure out if we can execute heap and execute memory | |
614 | can_selinux_exec_heap = DataSource.sestatus_allow_execheap() | |
615 | can_selinux_exec_memory = DataSource.sestatus_allow_execmem() | |
616 | self.is_selinux_enforcing = (not can_selinux_exec_heap or not can_selinux_exec_memory) | |
617 | ||
618 | def _asm_func(self, restype=None, argtypes=(), byte_code=[]): | |
619 | byte_code = bytes.join(b'', byte_code) | |
620 | address = None | |
731 | self.mm = None | |
732 | self.func = None | |
733 | self.address = None | |
734 | self.size = 0 | |
735 | self.is_selinux_enforcing = _is_selinux_enforcing() | |
736 | ||
737 | def compile(self): | |
738 | machine_code = bytes.join(b'', self.machine_code) | |
739 | self.size = ctypes.c_size_t(len(machine_code)) | |
621 | 740 | |
622 | 741 | if DataSource.is_windows: |
623 | # Allocate a memory segment the size of the byte code, and make it executable | |
624 | size = len(byte_code) | |
742 | # Allocate a memory segment the size of the machine code, and make it executable | |
743 | size = len(machine_code) | |
625 | 744 | # Alloc at least 1 page to ensure we own all pages that we want to change protection on |
626 | 745 | if size < 0x1000: size = 0x1000 |
627 | 746 | MEM_COMMIT = ctypes.c_ulong(0x1000) |
628 | 747 | PAGE_READWRITE = ctypes.c_ulong(0x4) |
629 | 748 | pfnVirtualAlloc = ctypes.windll.kernel32.VirtualAlloc |
630 | 749 | pfnVirtualAlloc.restype = ctypes.c_void_p |
631 | address = pfnVirtualAlloc(None, ctypes.c_size_t(size), MEM_COMMIT, PAGE_READWRITE) | |
632 | if not address: | |
750 | self.address = pfnVirtualAlloc(None, ctypes.c_size_t(size), MEM_COMMIT, PAGE_READWRITE) | |
751 | if not self.address: | |
633 | 752 | raise Exception("Failed to VirtualAlloc") |
634 | 753 | |
635 | # Copy the byte code into the memory segment | |
754 | # Copy the machine code into the memory segment | |
636 | 755 | memmove = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t)(ctypes._memmove_addr) |
637 | if memmove(address, byte_code, size) < 0: | |
756 | if memmove(self.address, machine_code, size) < 0: | |
638 | 757 | raise Exception("Failed to memmove") |
639 | 758 | |
640 | 759 | # Enable execute permissions |
641 | 760 | PAGE_EXECUTE = ctypes.c_ulong(0x10) |
642 | 761 | old_protect = ctypes.c_ulong(0) |
643 | 762 | pfnVirtualProtect = ctypes.windll.kernel32.VirtualProtect |
644 | res = pfnVirtualProtect(ctypes.c_void_p(address), ctypes.c_size_t(size), PAGE_EXECUTE, ctypes.byref(old_protect)) | |
763 | res = pfnVirtualProtect(ctypes.c_void_p(self.address), ctypes.c_size_t(size), PAGE_EXECUTE, ctypes.byref(old_protect)) | |
645 | 764 | if not res: |
646 | 765 | raise Exception("Failed VirtualProtect") |
647 | 766 | |
652 | 771 | pfnGetCurrentProcess.restype = ctypes.c_void_p |
653 | 772 | self.prochandle = ctypes.c_void_p(pfnGetCurrentProcess()) |
654 | 773 | # Actually flush cache |
655 | res = ctypes.windll.kernel32.FlushInstructionCache(self.prochandle, ctypes.c_void_p(address), ctypes.c_size_t(size)) | |
774 | res = ctypes.windll.kernel32.FlushInstructionCache(self.prochandle, ctypes.c_void_p(self.address), ctypes.c_size_t(size)) | |
656 | 775 | if not res: |
657 | 776 | raise Exception("Failed FlushInstructionCache") |
658 | 777 | else: |
659 | # Allocate a memory segment the size of the byte code | |
660 | size = len(byte_code) | |
661 | pfnvalloc = ctypes.pythonapi.valloc | |
662 | pfnvalloc.restype = ctypes.c_void_p | |
663 | address = pfnvalloc(ctypes.c_size_t(size)) | |
664 | if not address: | |
665 | raise Exception("Failed to valloc") | |
666 | ||
667 | # Mark the memory segment as writeable only | |
668 | if not self.is_selinux_enforcing: | |
669 | WRITE = 0x2 | |
670 | if ctypes.pythonapi.mprotect(ctypes.c_void_p(address), size, WRITE) < 0: | |
671 | raise Exception("Failed to mprotect") | |
672 | ||
673 | # Copy the byte code into the memory segment | |
674 | if ctypes.pythonapi.memmove(ctypes.c_void_p(address), byte_code, ctypes.c_size_t(size)) < 0: | |
675 | raise Exception("Failed to memmove") | |
676 | ||
677 | # Mark the memory segment as writeable and executable only | |
678 | if not self.is_selinux_enforcing: | |
679 | WRITE_EXECUTE = 0x2 | 0x4 | |
680 | if ctypes.pythonapi.mprotect(ctypes.c_void_p(address), size, WRITE_EXECUTE) < 0: | |
681 | raise Exception("Failed to mprotect") | |
778 | from mmap import mmap, MAP_PRIVATE, MAP_ANONYMOUS, PROT_WRITE, PROT_READ, PROT_EXEC | |
779 | ||
780 | # Allocate a private and executable memory segment the size of the machine code | |
781 | machine_code = bytes.join(b'', self.machine_code) | |
782 | self.size = len(machine_code) | |
783 | self.mm = mmap(-1, self.size, flags=MAP_PRIVATE | MAP_ANONYMOUS, prot=PROT_WRITE | PROT_READ | PROT_EXEC) | |
784 | ||
785 | # Copy the machine code into the memory segment | |
786 | self.mm.write(machine_code) | |
787 | self.address = ctypes.addressof(ctypes.c_int.from_buffer(self.mm)) | |
682 | 788 | |
683 | 789 | # Cast the memory segment into a function |
684 | functype = ctypes.CFUNCTYPE(restype, *argtypes) | |
685 | fun = functype(address) | |
686 | return fun, address | |
687 | ||
688 | def _run_asm(self, *byte_code): | |
689 | # Convert the byte code into a function that returns an int | |
690 | restype = ctypes.c_uint32 | |
691 | argtypes = () | |
692 | func, address = self._asm_func(restype, argtypes, byte_code) | |
693 | ||
694 | # Call the byte code like a function | |
695 | retval = func() | |
696 | ||
697 | byte_code = bytes.join(b'', byte_code) | |
698 | size = ctypes.c_size_t(len(byte_code)) | |
699 | ||
790 | functype = ctypes.CFUNCTYPE(self.restype, *self.argtypes) | |
791 | self.func = functype(self.address) | |
792 | ||
793 | def run(self): | |
794 | # Call the machine code like a function | |
795 | retval = self.func() | |
796 | ||
797 | return retval | |
798 | ||
799 | def free(self): | |
700 | 800 | # Free the function memory segment |
701 | 801 | if DataSource.is_windows: |
702 | 802 | MEM_RELEASE = ctypes.c_ulong(0x8000) |
703 | ctypes.windll.kernel32.VirtualFree(ctypes.c_void_p(address), ctypes.c_size_t(0), MEM_RELEASE) | |
803 | ctypes.windll.kernel32.VirtualFree(ctypes.c_void_p(self.address), ctypes.c_size_t(0), MEM_RELEASE) | |
704 | 804 | else: |
705 | # Remove the executable tag on the memory | |
706 | READ_WRITE = 0x1 | 0x2 | |
707 | if ctypes.pythonapi.mprotect(ctypes.c_void_p(address), size, READ_WRITE) < 0: | |
708 | raise Exception("Failed to mprotect") | |
709 | ||
710 | ctypes.pythonapi.free(ctypes.c_void_p(address)) | |
711 | ||
805 | self.mm.close() | |
806 | ||
807 | self.prochandle = None | |
808 | self.mm = None | |
809 | self.func = None | |
810 | self.address = None | |
811 | self.size = 0 | |
812 | ||
813 | ||
814 | class CPUID(object): | |
815 | def __init__(self): | |
816 | # Figure out if SE Linux is on and in enforcing mode | |
817 | self.is_selinux_enforcing = _is_selinux_enforcing() | |
818 | ||
819 | def _asm_func(self, restype=None, argtypes=(), machine_code=[]): | |
820 | asm = ASM(restype, argtypes, machine_code) | |
821 | asm.compile() | |
822 | return asm | |
823 | ||
824 | def _run_asm(self, *machine_code): | |
825 | asm = ASM(ctypes.c_uint32, (), machine_code) | |
826 | asm.compile() | |
827 | retval = asm.run() | |
828 | asm.free() | |
712 | 829 | return retval |
713 | ||
714 | # FIXME: We should not have to use different instructions to | |
715 | # set eax to 0 or 1, on 32bit and 64bit machines. | |
716 | def _zero_eax(self): | |
717 | return ( | |
718 | b"\x31\xC0" # xor eax,eax | |
719 | ) | |
720 | ||
721 | def _zero_ecx(self): | |
722 | return ( | |
723 | b"\x31\xC9" # xor ecx,ecx | |
724 | ) | |
725 | def _one_eax(self): | |
726 | return ( | |
727 | b"\xB8\x01\x00\x00\x00" # mov eax,0x1" | |
728 | ) | |
729 | 830 | |
730 | 831 | # http://en.wikipedia.org/wiki/CPUID#EAX.3D0:_Get_vendor_ID |
731 | 832 | def get_vendor_id(self): |
732 | 833 | # EBX |
733 | 834 | ebx = self._run_asm( |
734 | self._zero_eax(), | |
835 | b"\x31\xC0", # xor eax,eax | |
735 | 836 | b"\x0F\xA2" # cpuid |
736 | 837 | b"\x89\xD8" # mov ax,bx |
737 | 838 | b"\xC3" # ret |
739 | 840 | |
740 | 841 | # ECX |
741 | 842 | ecx = self._run_asm( |
742 | self._zero_eax(), | |
843 | b"\x31\xC0", # xor eax,eax | |
743 | 844 | b"\x0f\xa2" # cpuid |
744 | 845 | b"\x89\xC8" # mov ax,cx |
745 | 846 | b"\xC3" # ret |
747 | 848 | |
748 | 849 | # EDX |
749 | 850 | edx = self._run_asm( |
750 | self._zero_eax(), | |
851 | b"\x31\xC0", # xor eax,eax | |
751 | 852 | b"\x0f\xa2" # cpuid |
752 | 853 | b"\x89\xD0" # mov ax,dx |
753 | 854 | b"\xC3" # ret |
766 | 867 | def get_info(self): |
767 | 868 | # EAX |
768 | 869 | eax = self._run_asm( |
769 | self._one_eax(), | |
770 | b"\x0f\xa2" # cpuid | |
771 | b"\xC3" # ret | |
870 | b"\xB8\x01\x00\x00\x00", # mov eax,0x1" | |
871 | b"\x0f\xa2" # cpuid | |
872 | b"\xC3" # ret | |
772 | 873 | ) |
773 | 874 | |
774 | 875 | # Get the CPU info |
775 | stepping = (eax >> 0) & 0xF # 4 bits | |
876 | stepping_id = (eax >> 0) & 0xF # 4 bits | |
776 | 877 | model = (eax >> 4) & 0xF # 4 bits |
777 | family = (eax >> 8) & 0xF # 4 bits | |
878 | family_id = (eax >> 8) & 0xF # 4 bits | |
778 | 879 | processor_type = (eax >> 12) & 0x3 # 2 bits |
779 | extended_model = (eax >> 16) & 0xF # 4 bits | |
780 | extended_family = (eax >> 20) & 0xFF # 8 bits | |
880 | extended_model_id = (eax >> 16) & 0xF # 4 bits | |
881 | extended_family_id = (eax >> 20) & 0xFF # 8 bits | |
882 | family = 0 | |
883 | ||
884 | if family_id in [15]: | |
885 | family = extended_family_id + family_id | |
886 | else: | |
887 | family = family_id | |
888 | ||
889 | if family_id in [6, 15]: | |
890 | model = (extended_model_id << 4) + model | |
781 | 891 | |
782 | 892 | return { |
783 | 'stepping' : stepping, | |
893 | 'stepping' : stepping_id, | |
784 | 894 | 'model' : model, |
785 | 895 | 'family' : family, |
786 | 'processor_type' : processor_type, | |
787 | 'extended_model' : extended_model, | |
788 | 'extended_family' : extended_family | |
896 | 'processor_type' : processor_type | |
789 | 897 | } |
790 | 898 | |
791 | 899 | # http://en.wikipedia.org/wiki/CPUID#EAX.3D80000000h:_Get_Highest_Extended_Function_Supported |
803 | 911 | def get_flags(self, max_extension_support): |
804 | 912 | # EDX |
805 | 913 | edx = self._run_asm( |
806 | self._one_eax(), | |
807 | b"\x0f\xa2" # cpuid | |
808 | b"\x89\xD0" # mov ax,dx | |
809 | b"\xC3" # ret | |
914 | b"\xB8\x01\x00\x00\x00", # mov eax,0x1" | |
915 | b"\x0f\xa2" # cpuid | |
916 | b"\x89\xD0" # mov ax,dx | |
917 | b"\xC3" # ret | |
810 | 918 | ) |
811 | 919 | |
812 | 920 | # ECX |
813 | 921 | ecx = self._run_asm( |
814 | self._one_eax(), | |
815 | b"\x0f\xa2" # cpuid | |
816 | b"\x89\xC8" # mov ax,cx | |
817 | b"\xC3" # ret | |
922 | b"\xB8\x01\x00\x00\x00", # mov eax,0x1" | |
923 | b"\x0f\xa2" # cpuid | |
924 | b"\x89\xC8" # mov ax,cx | |
925 | b"\xC3" # ret | |
818 | 926 | ) |
819 | 927 | |
820 | 928 | # Get the CPU flags |
893 | 1001 | if max_extension_support >= 7: |
894 | 1002 | # EBX |
895 | 1003 | ebx = self._run_asm( |
896 | self._zero_ecx(), | |
1004 | b"\x31\xC9", # xor ecx,ecx | |
897 | 1005 | b"\xB8\x07\x00\x00\x00" # mov eax,7 |
898 | 1006 | b"\x0f\xa2" # cpuid |
899 | 1007 | b"\x89\xD8" # mov ax,bx |
902 | 1010 | |
903 | 1011 | # ECX |
904 | 1012 | ecx = self._run_asm( |
905 | self._zero_ecx(), | |
1013 | b"\x31\xC9", # xor ecx,ecx | |
906 | 1014 | b"\xB8\x07\x00\x00\x00" # mov eax,7 |
907 | 1015 | b"\x0f\xa2" # cpuid |
908 | 1016 | b"\x89\xC8" # mov ax,cx |
1147 | 1255 | ) |
1148 | 1256 | |
1149 | 1257 | cache_info = { |
1150 | 'size_kb' : ecx & 0xFF, | |
1151 | 'line_size_b' : (ecx >> 12) & 0xF, | |
1152 | 'associativity' : (ecx >> 16) & 0xFFFF | |
1258 | 'size_b' : (ecx & 0xFF) * 1024, | |
1259 | 'associativity' : (ecx >> 12) & 0xF, | |
1260 | 'line_size_b' : (ecx >> 16) & 0xFFFF | |
1153 | 1261 | } |
1154 | 1262 | |
1155 | 1263 | return cache_info |
1156 | 1264 | |
1157 | def get_ticks(self): | |
1265 | def get_ticks_func(self): | |
1158 | 1266 | retval = None |
1159 | 1267 | |
1160 | 1268 | if DataSource.bits == '32bit': |
1161 | 1269 | # Works on x86_32 |
1162 | 1270 | restype = None |
1163 | 1271 | argtypes = (ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint)) |
1164 | get_ticks_x86_32, address = self._asm_func(restype, argtypes, | |
1272 | get_ticks_x86_32 = self._asm_func(restype, argtypes, | |
1165 | 1273 | [ |
1166 | 1274 | b"\x55", # push bp |
1167 | 1275 | b"\x89\xE5", # mov bp,sp |
1177 | 1285 | ] |
1178 | 1286 | ) |
1179 | 1287 | |
1180 | high = ctypes.c_uint32(0) | |
1181 | low = ctypes.c_uint32(0) | |
1182 | ||
1183 | get_ticks_x86_32(ctypes.byref(high), ctypes.byref(low)) | |
1184 | retval = ((high.value << 32) & 0xFFFFFFFF00000000) | low.value | |
1288 | # Monkey patch func to combine high and low args into one return | |
1289 | old_func = get_ticks_x86_32.func | |
1290 | def new_func(): | |
1291 | # Pass two uint32s into function | |
1292 | high = ctypes.c_uint32(0) | |
1293 | low = ctypes.c_uint32(0) | |
1294 | old_func(ctypes.byref(high), ctypes.byref(low)) | |
1295 | ||
1296 | # Shift the two uint32s into one uint64 | |
1297 | retval = ((high.value << 32) & 0xFFFFFFFF00000000) | low.value | |
1298 | return retval | |
1299 | get_ticks_x86_32.func = new_func | |
1300 | ||
1301 | retval = get_ticks_x86_32 | |
1185 | 1302 | elif DataSource.bits == '64bit': |
1186 | 1303 | # Works on x86_64 |
1187 | 1304 | restype = ctypes.c_uint64 |
1188 | 1305 | argtypes = () |
1189 | get_ticks_x86_64, address = self._asm_func(restype, argtypes, | |
1306 | get_ticks_x86_64 = self._asm_func(restype, argtypes, | |
1190 | 1307 | [ |
1191 | 1308 | b"\x48", # dec ax |
1192 | 1309 | b"\x31\xC0", # xor ax,ax |
1199 | 1316 | b"\xC3", # ret |
1200 | 1317 | ] |
1201 | 1318 | ) |
1202 | retval = get_ticks_x86_64() | |
1203 | ||
1319 | ||
1320 | retval = get_ticks_x86_64 | |
1204 | 1321 | return retval |
1205 | 1322 | |
1206 | 1323 | def get_raw_hz(self): |
1207 | import time | |
1208 | ||
1209 | start = self.get_ticks() | |
1210 | ||
1211 | time.sleep(1) | |
1212 | ||
1213 | end = self.get_ticks() | |
1324 | from time import sleep | |
1325 | ||
1326 | ticks_fn = self.get_ticks_func() | |
1327 | ||
1328 | start = ticks_fn.func() | |
1329 | sleep(1) | |
1330 | end = ticks_fn.func() | |
1214 | 1331 | |
1215 | 1332 | ticks = (end - start) |
1333 | ticks_fn.free() | |
1216 | 1334 | |
1217 | 1335 | return ticks |
1218 | 1336 | |
1219 | def _actual_get_cpu_info_from_cpuid(queue): | |
1337 | def _get_cpu_info_from_cpuid_actual(): | |
1220 | 1338 | ''' |
1221 | 1339 | Warning! This function has the potential to crash the Python runtime. |
1222 | 1340 | Do not call it directly. Use the _get_cpu_info_from_cpuid function instead. |
1223 | 1341 | It will safely call this function in another process. |
1224 | 1342 | ''' |
1225 | 1343 | |
1226 | # Pipe all output to nothing | |
1227 | sys.stdout = open(os.devnull, 'w') | |
1228 | sys.stderr = open(os.devnull, 'w') | |
1229 | ||
1230 | 1344 | # Get the CPU arch and bits |
1231 | arch, bits = _parse_arch(DataSource.raw_arch_string) | |
1345 | arch, bits = _parse_arch(DataSource.arch_string_raw) | |
1232 | 1346 | |
1233 | 1347 | # Return none if this is not an X86 CPU |
1234 | 1348 | if not arch in ['X86_32', 'X86_64']: |
1235 | queue.put(_obj_to_b64({})) | |
1236 | return | |
1349 | return {} | |
1237 | 1350 | |
1238 | 1351 | # Return none if SE Linux is in enforcing mode |
1239 | 1352 | cpuid = CPUID() |
1240 | 1353 | if cpuid.is_selinux_enforcing: |
1241 | queue.put(_obj_to_b64({})) | |
1242 | return | |
1354 | return {} | |
1243 | 1355 | |
1244 | 1356 | # Get the cpu info from the CPUID register |
1245 | 1357 | max_extension_support = cpuid.get_max_extension_support() |
1250 | 1362 | |
1251 | 1363 | # Get the Hz and scale |
1252 | 1364 | hz_actual = cpuid.get_raw_hz() |
1253 | hz_actual = _to_hz_string(hz_actual) | |
1365 | hz_actual = _to_decimal_string(hz_actual) | |
1254 | 1366 | |
1255 | 1367 | # Get the Hz and scale |
1256 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
1368 | hz_advertised, scale = _parse_cpu_brand_string(processor_brand) | |
1257 | 1369 | info = { |
1258 | 'vendor_id' : cpuid.get_vendor_id(), | |
1259 | 'hardware' : '', | |
1260 | 'brand' : processor_brand, | |
1261 | ||
1262 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale), | |
1263 | 'hz_actual' : _to_friendly_hz(hz_actual, 0), | |
1264 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale), | |
1265 | 'hz_actual_raw' : _to_raw_hz(hz_actual, 0), | |
1266 | ||
1267 | 'l2_cache_size' : _to_friendly_bytes(cache_info['size_kb']), | |
1370 | 'vendor_id_raw' : cpuid.get_vendor_id(), | |
1371 | 'hardware_raw' : '', | |
1372 | 'brand_raw' : processor_brand, | |
1373 | ||
1374 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale), | |
1375 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, 0), | |
1376 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale), | |
1377 | 'hz_actual' : _hz_short_to_full(hz_actual, 0), | |
1378 | ||
1379 | 'l2_cache_size' : cache_info['size_b'], | |
1268 | 1380 | 'l2_cache_line_size' : cache_info['line_size_b'], |
1269 | 'l2_cache_associativity' : hex(cache_info['associativity']), | |
1381 | 'l2_cache_associativity' : cache_info['associativity'], | |
1270 | 1382 | |
1271 | 1383 | 'stepping' : info['stepping'], |
1272 | 1384 | 'model' : info['model'], |
1273 | 1385 | 'family' : info['family'], |
1274 | 1386 | 'processor_type' : info['processor_type'], |
1275 | 'extended_model' : info['extended_model'], | |
1276 | 'extended_family' : info['extended_family'], | |
1277 | 1387 | 'flags' : cpuid.get_flags(max_extension_support) |
1278 | 1388 | } |
1279 | 1389 | |
1280 | info = {k: v for k, v in info.items() if v} | |
1390 | return _filter_dict_keys_with_empty_values(info) | |
1391 | ||
1392 | def _get_cpu_info_from_cpuid_subprocess_wrapper(queue): | |
1393 | # Pipe all output to nothing | |
1394 | sys.stdout = open(os.devnull, 'w') | |
1395 | sys.stderr = open(os.devnull, 'w') | |
1396 | ||
1397 | info = _get_cpu_info_from_cpuid_actual() | |
1398 | ||
1281 | 1399 | queue.put(_obj_to_b64(info)) |
1282 | 1400 | |
1283 | 1401 | def _get_cpu_info_from_cpuid(): |
1293 | 1411 | return {} |
1294 | 1412 | |
1295 | 1413 | # Get the CPU arch and bits |
1296 | arch, bits = _parse_arch(DataSource.raw_arch_string) | |
1414 | arch, bits = _parse_arch(DataSource.arch_string_raw) | |
1297 | 1415 | |
1298 | 1416 | # Return {} if this is not an X86 CPU |
1299 | 1417 | if not arch in ['X86_32', 'X86_64']: |
1300 | 1418 | return {} |
1301 | 1419 | |
1302 | 1420 | try: |
1303 | # Start running the function in a subprocess | |
1304 | queue = Queue() | |
1305 | p = Process(target=_actual_get_cpu_info_from_cpuid, args=(queue,)) | |
1306 | p.start() | |
1307 | ||
1308 | # Wait for the process to end, while it is still alive | |
1309 | while p.is_alive(): | |
1310 | p.join(0) | |
1311 | ||
1312 | # Return {} if it failed | |
1313 | if p.exitcode != 0: | |
1314 | return {} | |
1315 | ||
1316 | # Return the result, only if there is something to read | |
1317 | if not queue.empty(): | |
1318 | output = queue.get() | |
1319 | return _b64_to_obj(output) | |
1421 | if CAN_CALL_CPUID_IN_SUBPROCESS: | |
1422 | # Start running the function in a subprocess | |
1423 | queue = Queue() | |
1424 | p = Process(target=_get_cpu_info_from_cpuid_subprocess_wrapper, args=(queue,)) | |
1425 | p.start() | |
1426 | ||
1427 | # Wait for the process to end, while it is still alive | |
1428 | while p.is_alive(): | |
1429 | p.join(0) | |
1430 | ||
1431 | # Return {} if it failed | |
1432 | if p.exitcode != 0: | |
1433 | return {} | |
1434 | ||
1435 | # Return the result, only if there is something to read | |
1436 | if not queue.empty(): | |
1437 | output = queue.get() | |
1438 | return _b64_to_obj(output) | |
1439 | else: | |
1440 | info = _get_cpu_info_from_cpuid_actual() | |
1441 | return info | |
1320 | 1442 | except: |
1321 | 1443 | pass |
1322 | 1444 | |
1345 | 1467 | model = _get_field(False, output, int, 0, 'model') |
1346 | 1468 | family = _get_field(False, output, int, 0, 'cpu family') |
1347 | 1469 | hardware = _get_field(False, output, None, '', 'Hardware') |
1470 | ||
1348 | 1471 | # Flags |
1349 | 1472 | flags = _get_field(False, output, None, None, 'flags', 'Features') |
1350 | 1473 | if flags: |
1351 | 1474 | flags = flags.split() |
1352 | 1475 | flags.sort() |
1353 | 1476 | |
1477 | # Check for other cache format | |
1478 | if not cache_size: | |
1479 | try: | |
1480 | for i in range(0, 10): | |
1481 | name = "cache{0}".format(i) | |
1482 | value = _get_field(False, output, None, None, name) | |
1483 | if value: | |
1484 | value = [entry.split('=') for entry in value.split(' ')] | |
1485 | value = dict(value) | |
1486 | if 'level' in value and value['level'] == '3' and 'size' in value: | |
1487 | cache_size = value['size'] | |
1488 | break | |
1489 | except Exception: | |
1490 | pass | |
1491 | ||
1354 | 1492 | # Convert from MHz string to Hz |
1355 | hz_actual = _get_field(False, output, None, '', 'cpu MHz', 'cpu speed', 'clock') | |
1493 | hz_actual = _get_field(False, output, None, '', 'cpu MHz', 'cpu speed', 'clock', 'cpu MHz dynamic', 'cpu MHz static') | |
1356 | 1494 | hz_actual = hz_actual.lower().rstrip('mhz').strip() |
1357 | hz_actual = _to_hz_string(hz_actual) | |
1495 | hz_actual = _to_decimal_string(hz_actual) | |
1358 | 1496 | |
1359 | 1497 | # Convert from GHz/MHz string to Hz |
1360 | scale, hz_advertised = (0, None) | |
1498 | hz_advertised, scale = (None, 0) | |
1361 | 1499 | try: |
1362 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
1500 | hz_advertised, scale = _parse_cpu_brand_string(processor_brand) | |
1363 | 1501 | except Exception: |
1364 | 1502 | pass |
1365 | 1503 | |
1366 | 1504 | info = { |
1367 | 'hardware' : hardware, | |
1368 | 'brand' : processor_brand, | |
1369 | ||
1370 | 'l3_cache_size' : _to_friendly_bytes(cache_size), | |
1505 | 'hardware_raw' : hardware, | |
1506 | 'brand_raw' : processor_brand, | |
1507 | ||
1508 | 'l3_cache_size' : _friendly_bytes_to_int(cache_size), | |
1371 | 1509 | 'flags' : flags, |
1372 | 'vendor_id' : vendor_id, | |
1510 | 'vendor_id_raw' : vendor_id, | |
1373 | 1511 | 'stepping' : stepping, |
1374 | 1512 | 'model' : model, |
1375 | 1513 | 'family' : family, |
1383 | 1521 | hz_actual = hz_advertised |
1384 | 1522 | |
1385 | 1523 | # Add the Hz if there is one |
1386 | if _to_raw_hz(hz_advertised, scale) > (0, 0): | |
1387 | info['hz_advertised'] = _to_friendly_hz(hz_advertised, scale) | |
1388 | info['hz_advertised_raw'] = _to_raw_hz(hz_advertised, scale) | |
1389 | if _to_raw_hz(hz_actual, scale) > (0, 0): | |
1390 | info['hz_actual'] = _to_friendly_hz(hz_actual, 6) | |
1391 | info['hz_actual_raw'] = _to_raw_hz(hz_actual, 6) | |
1392 | ||
1393 | info = {k: v for k, v in info.items() if v} | |
1394 | return info | |
1524 | if _hz_short_to_full(hz_advertised, scale) > (0, 0): | |
1525 | info['hz_advertised_friendly'] = _hz_short_to_friendly(hz_advertised, scale) | |
1526 | info['hz_advertised'] = _hz_short_to_full(hz_advertised, scale) | |
1527 | if _hz_short_to_full(hz_actual, scale) > (0, 0): | |
1528 | info['hz_actual_friendly'] = _hz_short_to_friendly(hz_actual, 6) | |
1529 | info['hz_actual'] = _hz_short_to_full(hz_actual, 6) | |
1530 | ||
1531 | return _filter_dict_keys_with_empty_values(info) | |
1395 | 1532 | except: |
1396 | 1533 | #raise # NOTE: To have this throw on error, uncomment this line |
1397 | 1534 | return {} |
1402 | 1539 | Returns {} if cpufreq-info is not found. |
1403 | 1540 | ''' |
1404 | 1541 | try: |
1405 | scale, hz_brand = 1, '0.0' | |
1542 | hz_brand, scale = '0.0', 0 | |
1406 | 1543 | |
1407 | 1544 | if not DataSource.has_cpufreq_info(): |
1408 | 1545 | return {} |
1421 | 1558 | elif hz_brand.endswith('ghz'): |
1422 | 1559 | scale = 9 |
1423 | 1560 | hz_brand = hz_brand.rstrip('mhz').rstrip('ghz').strip() |
1424 | hz_brand = _to_hz_string(hz_brand) | |
1561 | hz_brand = _to_decimal_string(hz_brand) | |
1425 | 1562 | |
1426 | 1563 | info = { |
1427 | 'hz_advertised' : _to_friendly_hz(hz_brand, scale), | |
1428 | 'hz_actual' : _to_friendly_hz(hz_brand, scale), | |
1429 | 'hz_advertised_raw' : _to_raw_hz(hz_brand, scale), | |
1430 | 'hz_actual_raw' : _to_raw_hz(hz_brand, scale), | |
1564 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_brand, scale), | |
1565 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_brand, scale), | |
1566 | 'hz_advertised' : _hz_short_to_full(hz_brand, scale), | |
1567 | 'hz_actual' : _hz_short_to_full(hz_brand, scale), | |
1431 | 1568 | } |
1432 | 1569 | |
1433 | info = {k: v for k, v in info.items() if v} | |
1434 | return info | |
1570 | return _filter_dict_keys_with_empty_values(info) | |
1435 | 1571 | except: |
1436 | 1572 | #raise # NOTE: To have this throw on error, uncomment this line |
1437 | 1573 | return {} |
1453 | 1589 | |
1454 | 1590 | new_hz = _get_field(False, output, None, None, 'CPU max MHz', 'CPU MHz') |
1455 | 1591 | if new_hz: |
1456 | new_hz = _to_hz_string(new_hz) | |
1592 | new_hz = _to_decimal_string(new_hz) | |
1457 | 1593 | scale = 6 |
1458 | info['hz_advertised'] = _to_friendly_hz(new_hz, scale) | |
1459 | info['hz_actual'] = _to_friendly_hz(new_hz, scale) | |
1460 | info['hz_advertised_raw'] = _to_raw_hz(new_hz, scale) | |
1461 | info['hz_actual_raw'] = _to_raw_hz(new_hz, scale) | |
1594 | info['hz_advertised_friendly'] = _hz_short_to_friendly(new_hz, scale) | |
1595 | info['hz_actual_friendly'] = _hz_short_to_friendly(new_hz, scale) | |
1596 | info['hz_advertised'] = _hz_short_to_full(new_hz, scale) | |
1597 | info['hz_actual'] = _hz_short_to_full(new_hz, scale) | |
1598 | ||
1599 | new_hz = _get_field(False, output, None, None, 'CPU dynamic MHz', 'CPU static MHz') | |
1600 | if new_hz: | |
1601 | new_hz = _to_decimal_string(new_hz) | |
1602 | scale = 6 | |
1603 | info['hz_advertised_friendly'] = _hz_short_to_friendly(new_hz, scale) | |
1604 | info['hz_actual_friendly'] = _hz_short_to_friendly(new_hz, scale) | |
1605 | info['hz_advertised'] = _hz_short_to_full(new_hz, scale) | |
1606 | info['hz_actual'] = _hz_short_to_full(new_hz, scale) | |
1462 | 1607 | |
1463 | 1608 | vendor_id = _get_field(False, output, None, None, 'Vendor ID') |
1464 | 1609 | if vendor_id: |
1465 | info['vendor_id'] = vendor_id | |
1610 | info['vendor_id_raw'] = vendor_id | |
1466 | 1611 | |
1467 | 1612 | brand = _get_field(False, output, None, None, 'Model name') |
1468 | 1613 | if brand: |
1469 | info['brand'] = brand | |
1614 | info['brand_raw'] = brand | |
1470 | 1615 | |
1471 | 1616 | family = _get_field(False, output, None, None, 'CPU family') |
1472 | 1617 | if family and family.isdigit(): |
1482 | 1627 | |
1483 | 1628 | l1_data_cache_size = _get_field(False, output, None, None, 'L1d cache') |
1484 | 1629 | if l1_data_cache_size: |
1485 | info['l1_data_cache_size'] = _to_friendly_bytes(l1_data_cache_size) | |
1630 | info['l1_data_cache_size'] = _friendly_bytes_to_int(l1_data_cache_size) | |
1486 | 1631 | |
1487 | 1632 | l1_instruction_cache_size = _get_field(False, output, None, None, 'L1i cache') |
1488 | 1633 | if l1_instruction_cache_size: |
1489 | info['l1_instruction_cache_size'] = _to_friendly_bytes(l1_instruction_cache_size) | |
1490 | ||
1491 | l2_cache_size = _get_field(False, output, None, None, 'L2 cache') | |
1634 | info['l1_instruction_cache_size'] = _friendly_bytes_to_int(l1_instruction_cache_size) | |
1635 | ||
1636 | l2_cache_size = _get_field(False, output, None, None, 'L2 cache', 'L2d cache') | |
1492 | 1637 | if l2_cache_size: |
1493 | info['l2_cache_size'] = _to_friendly_bytes(l2_cache_size) | |
1638 | info['l2_cache_size'] = _friendly_bytes_to_int(l2_cache_size) | |
1494 | 1639 | |
1495 | 1640 | l3_cache_size = _get_field(False, output, None, None, 'L3 cache') |
1496 | 1641 | if l3_cache_size: |
1497 | info['l3_cache_size'] = _to_friendly_bytes(l3_cache_size) | |
1642 | info['l3_cache_size'] = _friendly_bytes_to_int(l3_cache_size) | |
1498 | 1643 | |
1499 | 1644 | # Flags |
1500 | 1645 | flags = _get_field(False, output, None, None, 'flags', 'Features') |
1503 | 1648 | flags.sort() |
1504 | 1649 | info['flags'] = flags |
1505 | 1650 | |
1506 | info = {k: v for k, v in info.items() if v} | |
1507 | return info | |
1651 | return _filter_dict_keys_with_empty_values(info) | |
1508 | 1652 | except: |
1509 | 1653 | #raise # NOTE: To have this throw on error, uncomment this line |
1510 | 1654 | return {} |
1514 | 1658 | Returns the CPU info gathered from dmesg. |
1515 | 1659 | Returns {} if dmesg is not found or does not have the desired info. |
1516 | 1660 | ''' |
1661 | ||
1662 | # Just return {} if this arch has an unreliable dmesg log | |
1663 | arch, bits = _parse_arch(DataSource.arch_string_raw) | |
1664 | if arch in ['S390X']: | |
1665 | return {} | |
1666 | ||
1517 | 1667 | # Just return {} if there is no dmesg |
1518 | 1668 | if not DataSource.has_dmesg(): |
1519 | 1669 | return {} |
1642 | 1792 | info = { |
1643 | 1793 | 'flags' : flags |
1644 | 1794 | } |
1645 | info = {k: v for k, v in info.items() if v} | |
1646 | ||
1647 | return info | |
1795 | return _filter_dict_keys_with_empty_values(info) | |
1648 | 1796 | except: |
1649 | 1797 | return {} |
1650 | 1798 | |
1696 | 1844 | flags.sort() |
1697 | 1845 | |
1698 | 1846 | # Convert from GHz/MHz string to Hz |
1699 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
1847 | hz_advertised, scale = _parse_cpu_brand_string(processor_brand) | |
1700 | 1848 | hz_actual = _get_field(False, output, None, None, 'hw.cpufrequency') |
1701 | hz_actual = _to_hz_string(hz_actual) | |
1849 | hz_actual = _to_decimal_string(hz_actual) | |
1702 | 1850 | |
1703 | 1851 | info = { |
1704 | 'vendor_id' : vendor_id, | |
1705 | 'brand' : processor_brand, | |
1706 | ||
1707 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale), | |
1708 | 'hz_actual' : _to_friendly_hz(hz_actual, 0), | |
1709 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale), | |
1710 | 'hz_actual_raw' : _to_raw_hz(hz_actual, 0), | |
1711 | ||
1712 | 'l2_cache_size' : _to_friendly_bytes(cache_size), | |
1852 | 'vendor_id_raw' : vendor_id, | |
1853 | 'brand_raw' : processor_brand, | |
1854 | ||
1855 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale), | |
1856 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, 0), | |
1857 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale), | |
1858 | 'hz_actual' : _hz_short_to_full(hz_actual, 0), | |
1859 | ||
1860 | 'l2_cache_size' : int(cache_size) * 1024, | |
1713 | 1861 | |
1714 | 1862 | 'stepping' : stepping, |
1715 | 1863 | 'model' : model, |
1717 | 1865 | 'flags' : flags |
1718 | 1866 | } |
1719 | 1867 | |
1720 | info = {k: v for k, v in info.items() if v} | |
1721 | return info | |
1868 | return _filter_dict_keys_with_empty_values(info) | |
1722 | 1869 | except: |
1723 | 1870 | return {} |
1724 | 1871 | |
1749 | 1896 | |
1750 | 1897 | # Various fields |
1751 | 1898 | vendor_id = '' #_get_field(False, output, None, None, 'CPU #0: ') |
1752 | processor_brand = output.split('CPU #0: "')[1].split('"\n')[0] | |
1899 | processor_brand = output.split('CPU #0: "')[1].split('"\n')[0].strip() | |
1753 | 1900 | cache_size = '' #_get_field(False, output, None, None, 'machdep.cpu.cache.size') |
1754 | 1901 | stepping = int(output.split(', stepping ')[1].split(',')[0].strip()) |
1755 | 1902 | model = int(output.split(', model ')[1].split(',')[0].strip()) |
1764 | 1911 | flags.sort() |
1765 | 1912 | |
1766 | 1913 | # Convert from GHz/MHz string to Hz |
1767 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
1914 | hz_advertised, scale = _parse_cpu_brand_string(processor_brand) | |
1768 | 1915 | hz_actual = hz_advertised |
1769 | 1916 | |
1770 | 1917 | info = { |
1771 | 'vendor_id' : vendor_id, | |
1772 | 'brand' : processor_brand, | |
1773 | ||
1774 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale), | |
1775 | 'hz_actual' : _to_friendly_hz(hz_actual, scale), | |
1776 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale), | |
1777 | 'hz_actual_raw' : _to_raw_hz(hz_actual, scale), | |
1918 | 'vendor_id_raw' : vendor_id, | |
1919 | 'brand_raw' : processor_brand, | |
1920 | ||
1921 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale), | |
1922 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, scale), | |
1923 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale), | |
1924 | 'hz_actual' : _hz_short_to_full(hz_actual, scale), | |
1778 | 1925 | |
1779 | 1926 | 'l2_cache_size' : _to_friendly_bytes(cache_size), |
1780 | 1927 | |
1784 | 1931 | 'flags' : flags |
1785 | 1932 | } |
1786 | 1933 | |
1787 | info = {k: v for k, v in info.items() if v} | |
1788 | return info | |
1934 | return _filter_dict_keys_with_empty_values(info) | |
1789 | 1935 | except: |
1936 | #raise # NOTE: To have this throw on error, uncomment this line | |
1790 | 1937 | return {} |
1791 | 1938 | |
1792 | 1939 | def _get_cpu_info_from_sysinfo_v2(): |
1806 | 1953 | |
1807 | 1954 | # Various fields |
1808 | 1955 | vendor_id = '' #_get_field(False, output, None, None, 'CPU #0: ') |
1809 | processor_brand = output.split('CPU #0: "')[1].split('"\n')[0] | |
1956 | processor_brand = output.split('CPU #0: "')[1].split('"\n')[0].strip() | |
1810 | 1957 | cache_size = '' #_get_field(False, output, None, None, 'machdep.cpu.cache.size') |
1811 | 1958 | signature = output.split('Signature:')[1].split('\n')[0].strip() |
1812 | 1959 | # |
1818 | 1965 | def get_subsection_flags(output): |
1819 | 1966 | retval = [] |
1820 | 1967 | for line in output.split('\n')[1:]: |
1821 | if not line.startswith(' '): break | |
1968 | if not line.startswith(' ') and not line.startswith(' '): break | |
1822 | 1969 | for entry in line.strip().lower().split(' '): |
1823 | 1970 | retval.append(entry) |
1824 | 1971 | return retval |
1829 | 1976 | flags.sort() |
1830 | 1977 | |
1831 | 1978 | # Convert from GHz/MHz string to Hz |
1832 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
1979 | lines = [n for n in output.split('\n') if n] | |
1980 | raw_hz = lines[0].split('running at ')[1].strip().lower() | |
1981 | hz_advertised = raw_hz.rstrip('mhz').rstrip('ghz').strip() | |
1982 | hz_advertised = _to_decimal_string(hz_advertised) | |
1833 | 1983 | hz_actual = hz_advertised |
1834 | 1984 | |
1985 | scale = 0 | |
1986 | if raw_hz.endswith('mhz'): | |
1987 | scale = 6 | |
1988 | elif raw_hz.endswith('ghz'): | |
1989 | scale = 9 | |
1990 | ||
1835 | 1991 | info = { |
1836 | 'vendor_id' : vendor_id, | |
1837 | 'brand' : processor_brand, | |
1838 | ||
1839 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale), | |
1840 | 'hz_actual' : _to_friendly_hz(hz_actual, scale), | |
1841 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale), | |
1842 | 'hz_actual_raw' : _to_raw_hz(hz_actual, scale), | |
1992 | 'vendor_id_raw' : vendor_id, | |
1993 | 'brand_raw' : processor_brand, | |
1994 | ||
1995 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale), | |
1996 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, scale), | |
1997 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale), | |
1998 | 'hz_actual' : _hz_short_to_full(hz_actual, scale), | |
1843 | 1999 | |
1844 | 2000 | 'l2_cache_size' : _to_friendly_bytes(cache_size), |
1845 | 2001 | |
1849 | 2005 | 'flags' : flags |
1850 | 2006 | } |
1851 | 2007 | |
1852 | info = {k: v for k, v in info.items() if v} | |
1853 | return info | |
2008 | return _filter_dict_keys_with_empty_values(info) | |
1854 | 2009 | except: |
2010 | #raise # NOTE: To have this throw on error, uncomment this line | |
1855 | 2011 | return {} |
1856 | 2012 | |
1857 | 2013 | def _get_cpu_info_from_wmic(): |
1876 | 2032 | |
1877 | 2033 | # Get the advertised MHz |
1878 | 2034 | processor_brand = value.get('Name') |
1879 | scale_advertised, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
2035 | hz_advertised, scale_advertised = _parse_cpu_brand_string(processor_brand) | |
1880 | 2036 | |
1881 | 2037 | # Get the actual MHz |
1882 | 2038 | hz_actual = value.get('CurrentClockSpeed') |
1883 | 2039 | scale_actual = 6 |
1884 | 2040 | if hz_actual: |
1885 | hz_actual = _to_hz_string(hz_actual) | |
2041 | hz_actual = _to_decimal_string(hz_actual) | |
1886 | 2042 | |
1887 | 2043 | # Get cache sizes |
1888 | l2_cache_size = value.get('L2CacheSize') | |
2044 | l2_cache_size = value.get('L2CacheSize') # NOTE: L2CacheSize is in kilobytes | |
1889 | 2045 | if l2_cache_size: |
1890 | l2_cache_size = l2_cache_size + ' KB' | |
1891 | ||
1892 | l3_cache_size = value.get('L3CacheSize') | |
2046 | l2_cache_size = int(l2_cache_size) * 1024 | |
2047 | ||
2048 | l3_cache_size = value.get('L3CacheSize') # NOTE: L3CacheSize is in kilobytes | |
1893 | 2049 | if l3_cache_size: |
1894 | l3_cache_size = l3_cache_size + ' KB' | |
2050 | l3_cache_size = int(l3_cache_size) * 1024 | |
1895 | 2051 | |
1896 | 2052 | # Get family, model, and stepping |
1897 | 2053 | family, model, stepping = '', '', '' |
1911 | 2067 | stepping = int(entries[i + 1]) |
1912 | 2068 | |
1913 | 2069 | info = { |
1914 | 'vendor_id' : value.get('Manufacturer'), | |
1915 | 'brand' : processor_brand, | |
1916 | ||
1917 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale_advertised), | |
1918 | 'hz_actual' : _to_friendly_hz(hz_actual, scale_actual), | |
1919 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale_advertised), | |
1920 | 'hz_actual_raw' : _to_raw_hz(hz_actual, scale_actual), | |
2070 | 'vendor_id_raw' : value.get('Manufacturer'), | |
2071 | 'brand_raw' : processor_brand, | |
2072 | ||
2073 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale_advertised), | |
2074 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, scale_actual), | |
2075 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale_advertised), | |
2076 | 'hz_actual' : _hz_short_to_full(hz_actual, scale_actual), | |
1921 | 2077 | |
1922 | 2078 | 'l2_cache_size' : l2_cache_size, |
1923 | 2079 | 'l3_cache_size' : l3_cache_size, |
1927 | 2083 | 'family' : family, |
1928 | 2084 | } |
1929 | 2085 | |
1930 | info = {k: v for k, v in info.items() if v} | |
1931 | return info | |
2086 | return _filter_dict_keys_with_empty_values(info) | |
1932 | 2087 | except: |
1933 | 2088 | #raise # NOTE: To have this throw on error, uncomment this line |
1934 | 2089 | return {} |
1935 | 2090 | |
1936 | 2091 | def _get_cpu_info_from_registry(): |
1937 | 2092 | ''' |
1938 | FIXME: Is missing many of the newer CPU flags like sse3 | |
1939 | 2093 | Returns the CPU info gathered from the Windows Registry. |
1940 | 2094 | Returns {} if not on Windows. |
1941 | 2095 | ''' |
1945 | 2099 | return {} |
1946 | 2100 | |
1947 | 2101 | # Get the CPU name |
1948 | processor_brand = DataSource.winreg_processor_brand() | |
2102 | processor_brand = DataSource.winreg_processor_brand().strip() | |
1949 | 2103 | |
1950 | 2104 | # Get the CPU vendor id |
1951 | vendor_id = DataSource.winreg_vendor_id() | |
2105 | vendor_id = DataSource.winreg_vendor_id_raw() | |
1952 | 2106 | |
1953 | 2107 | # Get the CPU arch and bits |
1954 | raw_arch_string = DataSource.winreg_raw_arch_string() | |
1955 | arch, bits = _parse_arch(raw_arch_string) | |
2108 | arch_string_raw = DataSource.winreg_arch_string_raw() | |
2109 | arch, bits = _parse_arch(arch_string_raw) | |
1956 | 2110 | |
1957 | 2111 | # Get the actual CPU Hz |
1958 | 2112 | hz_actual = DataSource.winreg_hz_actual() |
1959 | hz_actual = _to_hz_string(hz_actual) | |
2113 | hz_actual = _to_decimal_string(hz_actual) | |
1960 | 2114 | |
1961 | 2115 | # Get the advertised CPU Hz |
1962 | scale, hz_advertised = _get_hz_string_from_brand(processor_brand) | |
2116 | hz_advertised, scale = _parse_cpu_brand_string(processor_brand) | |
2117 | ||
2118 | # If advertised hz not found, use the actual hz | |
2119 | if hz_advertised == '0.0': | |
2120 | scale = 6 | |
2121 | hz_advertised = _to_decimal_string(hz_actual) | |
1963 | 2122 | |
1964 | 2123 | # Get the CPU features |
1965 | 2124 | feature_bits = DataSource.winreg_feature_bits() |
2012 | 2171 | flags.sort() |
2013 | 2172 | |
2014 | 2173 | info = { |
2015 | 'vendor_id' : vendor_id, | |
2016 | 'brand' : processor_brand, | |
2017 | ||
2018 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale), | |
2019 | 'hz_actual' : _to_friendly_hz(hz_actual, 6), | |
2020 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale), | |
2021 | 'hz_actual_raw' : _to_raw_hz(hz_actual, 6), | |
2174 | 'vendor_id_raw' : vendor_id, | |
2175 | 'brand_raw' : processor_brand, | |
2176 | ||
2177 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale), | |
2178 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, 6), | |
2179 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale), | |
2180 | 'hz_actual' : _hz_short_to_full(hz_actual, 6), | |
2022 | 2181 | |
2023 | 2182 | 'flags' : flags |
2024 | 2183 | } |
2025 | 2184 | |
2026 | info = {k: v for k, v in info.items() if v} | |
2027 | return info | |
2185 | return _filter_dict_keys_with_empty_values(info) | |
2028 | 2186 | except: |
2029 | 2187 | return {} |
2030 | 2188 | |
2062 | 2220 | # Convert from GHz/MHz string to Hz |
2063 | 2221 | scale = 6 |
2064 | 2222 | hz_advertised = kstat.split('\tclock_MHz ')[1].split('\n')[0].strip() |
2065 | hz_advertised = _to_hz_string(hz_advertised) | |
2223 | hz_advertised = _to_decimal_string(hz_advertised) | |
2066 | 2224 | |
2067 | 2225 | # Convert from GHz/MHz string to Hz |
2068 | 2226 | hz_actual = kstat.split('\tcurrent_clock_Hz ')[1].split('\n')[0].strip() |
2069 | hz_actual = _to_hz_string(hz_actual) | |
2227 | hz_actual = _to_decimal_string(hz_actual) | |
2070 | 2228 | |
2071 | 2229 | info = { |
2072 | 'vendor_id' : vendor_id, | |
2073 | 'brand' : processor_brand, | |
2074 | ||
2075 | 'hz_advertised' : _to_friendly_hz(hz_advertised, scale), | |
2076 | 'hz_actual' : _to_friendly_hz(hz_actual, 0), | |
2077 | 'hz_advertised_raw' : _to_raw_hz(hz_advertised, scale), | |
2078 | 'hz_actual_raw' : _to_raw_hz(hz_actual, 0), | |
2230 | 'vendor_id_raw' : vendor_id, | |
2231 | 'brand_raw' : processor_brand, | |
2232 | ||
2233 | 'hz_advertised_friendly' : _hz_short_to_friendly(hz_advertised, scale), | |
2234 | 'hz_actual_friendly' : _hz_short_to_friendly(hz_actual, 0), | |
2235 | 'hz_advertised' : _hz_short_to_full(hz_advertised, scale), | |
2236 | 'hz_actual' : _hz_short_to_full(hz_actual, 0), | |
2079 | 2237 | |
2080 | 2238 | 'stepping' : stepping, |
2081 | 2239 | 'model' : model, |
2083 | 2241 | 'flags' : flags |
2084 | 2242 | } |
2085 | 2243 | |
2086 | info = {k: v for k, v in info.items() if v} | |
2087 | return info | |
2244 | return _filter_dict_keys_with_empty_values(info) | |
2088 | 2245 | except: |
2089 | 2246 | return {} |
2090 | 2247 | |
2248 | def _get_cpu_info_from_platform_uname(): | |
2249 | try: | |
2250 | uname = DataSource.uname_string_raw.split(',')[0] | |
2251 | ||
2252 | family, model, stepping = (None, None, None) | |
2253 | entries = uname.split(' ') | |
2254 | ||
2255 | if 'Family' in entries and entries.index('Family') < len(entries)-1: | |
2256 | i = entries.index('Family') | |
2257 | family = int(entries[i + 1]) | |
2258 | ||
2259 | if 'Model' in entries and entries.index('Model') < len(entries)-1: | |
2260 | i = entries.index('Model') | |
2261 | model = int(entries[i + 1]) | |
2262 | ||
2263 | if 'Stepping' in entries and entries.index('Stepping') < len(entries)-1: | |
2264 | i = entries.index('Stepping') | |
2265 | stepping = int(entries[i + 1]) | |
2266 | ||
2267 | info = { | |
2268 | 'family' : family, | |
2269 | 'model' : model, | |
2270 | 'stepping' : stepping | |
2271 | } | |
2272 | return _filter_dict_keys_with_empty_values(info) | |
2273 | except: | |
2274 | return {} | |
2275 | ||
2091 | 2276 | def _get_cpu_info_internal(): |
2092 | 2277 | ''' |
2093 | 2278 | Returns the CPU info by using the best sources of information for your OS. |
2095 | 2280 | ''' |
2096 | 2281 | |
2097 | 2282 | # Get the CPU arch and bits |
2098 | arch, bits = _parse_arch(DataSource.raw_arch_string) | |
2283 | arch, bits = _parse_arch(DataSource.arch_string_raw) | |
2099 | 2284 | |
2100 | 2285 | friendly_maxsize = { 2**31-1: '32 bit', 2**63-1: '64 bit' }.get(sys.maxsize) or 'unknown bits' |
2101 | 2286 | friendly_version = "{0}.{1}.{2}.{3}.{4}".format(*sys.version_info) |
2104 | 2289 | info = { |
2105 | 2290 | 'python_version' : PYTHON_VERSION, |
2106 | 2291 | 'cpuinfo_version' : CPUINFO_VERSION, |
2292 | 'cpuinfo_version_string' : CPUINFO_VERSION_STRING, | |
2107 | 2293 | 'arch' : arch, |
2108 | 2294 | 'bits' : bits, |
2109 | 2295 | 'count' : DataSource.cpu_count, |
2110 | 'raw_arch_string' : DataSource.raw_arch_string, | |
2296 | 'arch_string_raw' : DataSource.arch_string_raw, | |
2111 | 2297 | } |
2112 | 2298 | |
2113 | 2299 | # Try the Windows wmic |
2145 | 2331 | |
2146 | 2332 | # Try querying the CPU cpuid register |
2147 | 2333 | _copy_new_fields(info, _get_cpu_info_from_cpuid()) |
2334 | ||
2335 | # Try platform.uname | |
2336 | _copy_new_fields(info, _get_cpu_info_from_platform_uname()) | |
2148 | 2337 | |
2149 | 2338 | return info |
2150 | 2339 | |
2203 | 2392 | # Parse args |
2204 | 2393 | parser = ArgumentParser(description='Gets CPU info with pure Python 2 & 3') |
2205 | 2394 | parser.add_argument('--json', action='store_true', help='Return the info in JSON format') |
2395 | parser.add_argument('--version', action='store_true', help='Return the version of py-cpuinfo') | |
2206 | 2396 | args = parser.parse_args() |
2207 | 2397 | |
2208 | 2398 | try: |
2219 | 2409 | |
2220 | 2410 | if args.json: |
2221 | 2411 | print(json.dumps(info)) |
2412 | elif args.version: | |
2413 | print(CPUINFO_VERSION_STRING) | |
2222 | 2414 | else: |
2223 | 2415 | print('Python Version: {0}'.format(info.get('python_version', ''))) |
2224 | print('Cpuinfo Version: {0}'.format(info.get('cpuinfo_version', ''))) | |
2225 | print('Vendor ID: {0}'.format(info.get('vendor_id', ''))) | |
2226 | print('Hardware Raw: {0}'.format(info.get('hardware', ''))) | |
2227 | print('Brand: {0}'.format(info.get('brand', ''))) | |
2416 | print('Cpuinfo Version: {0}'.format(info.get('cpuinfo_version_string', ''))) | |
2417 | print('Vendor ID Raw: {0}'.format(info.get('vendor_id_raw', ''))) | |
2418 | print('Hardware Raw: {0}'.format(info.get('hardware_raw', ''))) | |
2419 | print('Brand Raw: {0}'.format(info.get('brand_raw', ''))) | |
2420 | print('Hz Advertised Friendly: {0}'.format(info.get('hz_advertised_friendly', ''))) | |
2421 | print('Hz Actual Friendly: {0}'.format(info.get('hz_actual_friendly', ''))) | |
2228 | 2422 | print('Hz Advertised: {0}'.format(info.get('hz_advertised', ''))) |
2229 | 2423 | print('Hz Actual: {0}'.format(info.get('hz_actual', ''))) |
2230 | print('Hz Advertised Raw: {0}'.format(info.get('hz_advertised_raw', ''))) | |
2231 | print('Hz Actual Raw: {0}'.format(info.get('hz_actual_raw', ''))) | |
2232 | 2424 | print('Arch: {0}'.format(info.get('arch', ''))) |
2233 | 2425 | print('Bits: {0}'.format(info.get('bits', ''))) |
2234 | 2426 | print('Count: {0}'.format(info.get('count', ''))) |
2235 | ||
2236 | print('Raw Arch String: {0}'.format(info.get('raw_arch_string', ''))) | |
2237 | ||
2427 | print('Arch String Raw: {0}'.format(info.get('arch_string_raw', ''))) | |
2238 | 2428 | print('L1 Data Cache Size: {0}'.format(info.get('l1_data_cache_size', ''))) |
2239 | 2429 | print('L1 Instruction Cache Size: {0}'.format(info.get('l1_instruction_cache_size', ''))) |
2240 | 2430 | print('L2 Cache Size: {0}'.format(info.get('l2_cache_size', ''))) |
2245 | 2435 | print('Model: {0}'.format(info.get('model', ''))) |
2246 | 2436 | print('Family: {0}'.format(info.get('family', ''))) |
2247 | 2437 | print('Processor Type: {0}'.format(info.get('processor_type', ''))) |
2248 | print('Extended Model: {0}'.format(info.get('extended_model', ''))) | |
2249 | print('Extended Family: {0}'.format(info.get('extended_family', ''))) | |
2250 | 2438 | print('Flags: {0}'.format(', '.join(info.get('flags', '')))) |
2251 | 2439 | |
2252 | 2440 |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: py-cpuinfo |
2 | Version: 5.0.0 | |
2 | Version: 7.0.0 | |
3 | 3 | Summary: Get CPU info with pure Python 2 & 3 |
4 | 4 | Home-page: https://github.com/workhorsy/py-cpuinfo |
5 | 5 | Author: Matthew Brennan Jones |
14 | 14 | tests/helpers.py |
15 | 15 | tests/test_actual.py |
16 | 16 | tests/test_cli.py |
17 | tests/test_compile_errors.py | |
17 | 18 | tests/test_cpuid.py |
18 | 19 | tests/test_example.py |
19 | 20 | tests/test_free_bsd_11_x86_64.py |
20 | 21 | tests/test_haiku_x86_32.py |
21 | 22 | tests/test_haiku_x86_64.py |
23 | tests/test_haiku_x86_64_beta_1_ryzen_7.py | |
22 | 24 | tests/test_invalid_cpu.py |
23 | 25 | tests/test_linux_aarch64_64.py |
24 | 26 | tests/test_linux_beagle_bone_arm.py |
27 | 29 | tests/test_linux_debian_8_x86_64.py |
28 | 30 | tests/test_linux_fedora_24_ppc64le.py |
29 | 31 | tests/test_linux_fedora_24_x86_64.py |
32 | tests/test_linux_fedora_29_x86_64_ryzen_7.py | |
33 | tests/test_linux_fedora_5_s390x.py | |
30 | 34 | tests/test_linux_gentoo_2_2_x86_64.py |
31 | 35 | tests/test_linux_odroid_c2_aarch64.py |
32 | 36 | tests/test_linux_odroid_xu3_arm_32.py |
33 | 37 | tests/test_linux_raspberry_pi_model_b_arm.py |
34 | 38 | tests/test_linux_rhel_7_3_ppc64le.py |
35 | 39 | tests/test_linux_ubuntu_16_04_x86_64.py |
40 | tests/test_open_indiana_5_11_x86_64_ryzen_7.py | |
36 | 41 | tests/test_osx_10_12_x86_64.py |
37 | 42 | tests/test_osx_10_9_x86_64.py |
38 | 43 | tests/test_parse_cpu_string.py |
39 | 44 | tests/test_parse_errors.py |
40 | 45 | tests/test_pcbsd_10_x86_64.py |
46 | tests/test_selinux.py | |
41 | 47 | tests/test_solaris_11_x86_32.py |
48 | tests/test_true_os_18_x86_64_ryzen_7.py | |
42 | 49 | tests/test_windows_10_x86_64.py |
50 | tests/test_windows_10_x86_64_ryzen_7.py | |
43 | 51 | tests/test_windows_8_x86_64.py⏎ |
0 | # Copyright (c) 2014-2019, Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
0 | # Copyright (c) 2014-2020 Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
1 | 1 | # Py-cpuinfo gets CPU info with pure Python 2 & 3 |
2 | 2 | # It uses the MIT License |
3 | 3 | # It is hosted at: https://github.com/workhorsy/py-cpuinfo |
10 | 10 | |
11 | 11 | setup( |
12 | 12 | name = "py-cpuinfo", |
13 | version = "5.0.0", | |
13 | version = "7.0.0", | |
14 | 14 | author = "Matthew Brennan Jones", |
15 | 15 | author_email = "matthew.brennan.jones@gmail.com", |
16 | 16 | description = "Get CPU info with pure Python 2 & 3", |
0 | 0 | #!/usr/bin/env python |
1 | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | |
3 | # Copyright (c) 2014-2019, Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
3 | # Copyright (c) 2014-2020 Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
4 | 4 | # Py-cpuinfo gets CPU info with pure Python 2 & 3 |
5 | 5 | # It uses the MIT License |
6 | 6 | # It is hosted at: https://github.com/workhorsy/py-cpuinfo |
34 | 34 | |
35 | 35 | |
36 | 36 | # Import all the test files |
37 | from test_compile_errors import TestCompileErrors | |
37 | 38 | from test_example import TestExample |
38 | 39 | from test_parse_errors import TestParseErrors |
39 | 40 | from test_parse_cpu_string import TestParseCPUString |
40 | 41 | from test_invalid_cpu import TestInvalidCPU |
42 | from test_selinux import TestSELinux | |
41 | 43 | from test_linux_debian_8_x86_64 import TestLinuxDebian_8_X86_64 |
42 | 44 | from test_linux_debian_8_5_x86_64 import TestLinuxDebian_8_5_X86_64 |
43 | 45 | from test_linux_debian_8_7_1_ppc64le import TestLinuxDebian_8_7_1_ppc64le |
44 | 46 | from test_linux_ubuntu_16_04_x86_64 import TestLinuxUbuntu_16_04_X86_64 |
45 | 47 | from test_linux_fedora_24_x86_64 import TestLinuxFedora_24_X86_64 |
46 | 48 | from test_linux_fedora_24_ppc64le import TestLinuxFedora_24_ppc64le |
49 | from test_linux_fedora_29_x86_64_ryzen_7 import Test_Linux_Fedora_29_X86_64_Ryzen_7 | |
50 | from test_linux_fedora_5_s390x import TestLinuxFedora_5_s390x | |
47 | 51 | from test_linux_aarch64_64 import TestLinux_Aarch_64 |
48 | 52 | from test_linux_gentoo_2_2_x86_64 import TestLinuxGentoo_2_2_X86_64 |
49 | 53 | from test_linux_rhel_7_3_ppc64le import TestLinuxRHEL_7_3_ppc64le |
55 | 59 | from test_free_bsd_11_x86_64 import TestFreeBSD_11_X86_64 |
56 | 60 | from test_osx_10_9_x86_64 import TestOSX_10_9 |
57 | 61 | from test_osx_10_12_x86_64 import TestOSX_10_12 |
58 | from test_solaris_11_x86_32 import TestSolaris | |
62 | from test_solaris_11_x86_32 import TestSolaris_11 | |
63 | from test_open_indiana_5_11_x86_64_ryzen_7 import TestOpenIndiana_5_11_Ryzen_7 | |
59 | 64 | from test_haiku_x86_32 import TestHaiku_x86_32 |
60 | 65 | from test_haiku_x86_64 import TestHaiku_x86_64 |
66 | from test_haiku_x86_64_beta_1_ryzen_7 import TestHaiku_x86_64_Beta_1_Ryzen7 | |
67 | from test_true_os_18_x86_64_ryzen_7 import TestTrueOS_18_X86_64_Ryzen7 | |
61 | 68 | from test_windows_8_x86_64 import TestWindows_8_X86_64 |
62 | 69 | from test_windows_10_x86_64 import TestWindows_10_X86_64 |
70 | from test_windows_10_x86_64_ryzen_7 import TestWindows_10_X86_64_Ryzen7 | |
63 | 71 | from test_cpuid import TestCPUID |
64 | 72 | from test_actual import TestActual |
65 | 73 | from test_cli import TestCLI |
72 | 80 | |
73 | 81 | # Get all the tests |
74 | 82 | tests = [ |
83 | TestCompileErrors, | |
75 | 84 | TestParseCPUString, |
76 | 85 | TestExample, |
77 | 86 | TestParseErrors, |
78 | 87 | TestInvalidCPU, |
88 | TestSELinux, | |
79 | 89 | TestLinuxDebian_8_X86_64, |
80 | 90 | TestLinuxDebian_8_5_X86_64, |
81 | 91 | TestLinuxDebian_8_7_1_ppc64le, |
82 | 92 | TestLinuxUbuntu_16_04_X86_64, |
83 | 93 | TestLinuxFedora_24_X86_64, |
84 | 94 | TestLinuxFedora_24_ppc64le, |
95 | Test_Linux_Fedora_29_X86_64_Ryzen_7, | |
96 | TestLinuxFedora_5_s390x, | |
85 | 97 | TestLinux_Aarch_64, |
86 | 98 | TestLinuxGentoo_2_2_X86_64, |
87 | 99 | TestLinuxRHEL_7_3_ppc64le, |
93 | 105 | TestPCBSD, |
94 | 106 | TestOSX_10_9, |
95 | 107 | TestOSX_10_12, |
96 | TestSolaris, | |
108 | TestSolaris_11, | |
109 | TestOpenIndiana_5_11_Ryzen_7, | |
97 | 110 | TestHaiku_x86_32, |
98 | 111 | TestHaiku_x86_64, |
112 | TestHaiku_x86_64_Beta_1_Ryzen7, | |
113 | TestTrueOS_18_X86_64_Ryzen7, | |
99 | 114 | TestWindows_8_X86_64, |
100 | 115 | TestWindows_10_X86_64, |
116 | TestWindows_10_X86_64_Ryzen7, | |
101 | 117 | TestCPUID, |
102 | 118 | TestActual, |
103 | 119 | TestCLI |
0 | 0 | #!/usr/bin/env python |
1 | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | |
3 | # Copyright (c) 2014-2019, Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
3 | # Copyright (c) 2014-2020 Matthew Brennan Jones <matthew.brennan.jones@gmail.com> | |
4 | 4 | # Py-cpuinfo gets CPU info with pure Python 2 & 3 |
5 | 5 | # It uses the MIT License |
6 | 6 | # It is hosted at: https://github.com/workhorsy/py-cpuinfo |
114 | 114 | cpuinfo.DataSource.cpu_count = NewDataSource.cpu_count |
115 | 115 | if hasattr(NewDataSource, 'is_windows'): |
116 | 116 | cpuinfo.DataSource.is_windows = NewDataSource.is_windows |
117 | if hasattr(NewDataSource, 'raw_arch_string'): | |
118 | cpuinfo.DataSource.raw_arch_string = NewDataSource.raw_arch_string | |
117 | if hasattr(NewDataSource, 'arch_string_raw'): | |
118 | cpuinfo.DataSource.arch_string_raw = NewDataSource.arch_string_raw | |
119 | if hasattr(NewDataSource, 'uname_string_raw'): | |
120 | cpuinfo.DataSource.uname_string_raw = NewDataSource.uname_string_raw | |
119 | 121 | if hasattr(NewDataSource, 'can_cpuid'): |
120 | 122 | cpuinfo.DataSource.can_cpuid = NewDataSource.can_cpuid |
121 | 123 | |
147 | 149 | cpuinfo.DataSource.cat_proc_cpuinfo = staticmethod(NewDataSource.cat_proc_cpuinfo) |
148 | 150 | if hasattr(NewDataSource, 'cpufreq_info'): |
149 | 151 | cpuinfo.DataSource.cpufreq_info = staticmethod(NewDataSource.cpufreq_info) |
150 | if hasattr(NewDataSource, 'sestatus_allow_execheap'): | |
151 | cpuinfo.DataSource.sestatus_allow_execheap = staticmethod(NewDataSource.sestatus_allow_execheap) | |
152 | if hasattr(NewDataSource, 'sestatus_allow_execmem'): | |
153 | cpuinfo.DataSource.sestatus_allow_execmem = staticmethod(NewDataSource.sestatus_allow_execmem) | |
152 | if hasattr(NewDataSource, 'sestatus_b'): | |
153 | cpuinfo.DataSource.sestatus_b = staticmethod(NewDataSource.sestatus_b) | |
154 | 154 | if hasattr(NewDataSource, 'dmesg_a'): |
155 | 155 | cpuinfo.DataSource.dmesg_a = staticmethod(NewDataSource.dmesg_a) |
156 | 156 | if hasattr(NewDataSource, 'cat_var_run_dmesg_boot'): |
171 | 171 | cpuinfo.DataSource.sysinfo_cpu = staticmethod(NewDataSource.sysinfo_cpu) |
172 | 172 | if hasattr(NewDataSource, 'winreg_processor_brand'): |
173 | 173 | cpuinfo.DataSource.winreg_processor_brand = staticmethod(NewDataSource.winreg_processor_brand) |
174 | if hasattr(NewDataSource, 'winreg_vendor_id'): | |
175 | cpuinfo.DataSource.winreg_vendor_id = staticmethod(NewDataSource.winreg_vendor_id) | |
176 | if hasattr(NewDataSource, 'winreg_raw_arch_string'): | |
177 | cpuinfo.DataSource.winreg_raw_arch_string = staticmethod(NewDataSource.winreg_raw_arch_string) | |
174 | if hasattr(NewDataSource, 'winreg_vendor_id_raw'): | |
175 | cpuinfo.DataSource.winreg_vendor_id_raw = staticmethod(NewDataSource.winreg_vendor_id_raw) | |
176 | if hasattr(NewDataSource, 'winreg_arch_string_raw'): | |
177 | cpuinfo.DataSource.winreg_arch_string_raw = staticmethod(NewDataSource.winreg_arch_string_raw) | |
178 | 178 | if hasattr(NewDataSource, 'winreg_hz_actual'): |
179 | 179 | cpuinfo.DataSource.winreg_hz_actual = staticmethod(NewDataSource.winreg_hz_actual) |
180 | 180 | if hasattr(NewDataSource, 'winreg_feature_bits'): |
186 | 186 | cpuinfo.BackupDataSource.bits = cpuinfo.DataSource.bits |
187 | 187 | cpuinfo.BackupDataSource.cpu_count = cpuinfo.DataSource.cpu_count |
188 | 188 | cpuinfo.BackupDataSource.is_windows = cpuinfo.DataSource.is_windows |
189 | cpuinfo.BackupDataSource.raw_arch_string = cpuinfo.DataSource.raw_arch_string | |
189 | cpuinfo.BackupDataSource.arch_string_raw = cpuinfo.DataSource.arch_string_raw | |
190 | cpuinfo.BackupDataSource.uname_string_raw = cpuinfo.DataSource.uname_string_raw | |
190 | 191 | cpuinfo.BackupDataSource.can_cpuid = cpuinfo.DataSource.can_cpuid |
191 | 192 | |
192 | 193 | cpuinfo.BackupDataSource.has_proc_cpuinfo = staticmethod(cpuinfo.DataSource.has_proc_cpuinfo) |
203 | 204 | cpuinfo.BackupDataSource.has_wmic = staticmethod(cpuinfo.DataSource.has_wmic) |
204 | 205 | cpuinfo.BackupDataSource.cat_proc_cpuinfo = staticmethod(cpuinfo.DataSource.cat_proc_cpuinfo) |
205 | 206 | cpuinfo.BackupDataSource.cpufreq_info = staticmethod(cpuinfo.DataSource.cpufreq_info) |
206 | cpuinfo.BackupDataSource.sestatus_allow_execheap = staticmethod(cpuinfo.DataSource.sestatus_allow_execheap) | |
207 | cpuinfo.BackupDataSource.sestatus_allow_execmem = staticmethod(cpuinfo.DataSource.sestatus_allow_execmem) | |
207 | cpuinfo.BackupDataSource.sestatus_b = staticmethod(cpuinfo.DataSource.sestatus_b) | |
208 | 208 | cpuinfo.BackupDataSource.dmesg_a = staticmethod(cpuinfo.DataSource.dmesg_a) |
209 | 209 | cpuinfo.BackupDataSource.cat_var_run_dmesg_boot = staticmethod(cpuinfo.DataSource.cat_var_run_dmesg_boot) |
210 | 210 | cpuinfo.BackupDataSource.sysctl_machdep_cpu_hw_cpufrequency = staticmethod(cpuinfo.DataSource.sysctl_machdep_cpu_hw_cpufrequency) |
215 | 215 | cpuinfo.BackupDataSource.wmic_cpu = staticmethod(cpuinfo.DataSource.wmic_cpu) |
216 | 216 | cpuinfo.BackupDataSource.sysinfo_cpu = staticmethod(cpuinfo.DataSource.sysinfo_cpu) |
217 | 217 | cpuinfo.BackupDataSource.winreg_processor_brand = staticmethod(cpuinfo.DataSource.winreg_processor_brand) |
218 | cpuinfo.BackupDataSource.winreg_vendor_id = staticmethod(cpuinfo.DataSource.winreg_vendor_id) | |
219 | cpuinfo.BackupDataSource.winreg_raw_arch_string = staticmethod(cpuinfo.DataSource.winreg_raw_arch_string) | |
218 | cpuinfo.BackupDataSource.winreg_vendor_id_raw = staticmethod(cpuinfo.DataSource.winreg_vendor_id_raw) | |
219 | cpuinfo.BackupDataSource.winreg_arch_string_raw = staticmethod(cpuinfo.DataSource.winreg_arch_string_raw) | |
220 | 220 | cpuinfo.BackupDataSource.winreg_hz_actual = staticmethod(cpuinfo.DataSource.winreg_hz_actual) |
221 | 221 | cpuinfo.BackupDataSource.winreg_feature_bits = staticmethod(cpuinfo.DataSource.winreg_feature_bits) |
222 | 222 | |
224 | 224 | cpuinfo.DataSource.bits = cpuinfo.BackupDataSource.bits |
225 | 225 | cpuinfo.DataSource.cpu_count = cpuinfo.BackupDataSource.cpu_count |
226 | 226 | cpuinfo.DataSource.is_windows = cpuinfo.BackupDataSource.is_windows |
227 | cpuinfo.DataSource.raw_arch_string = cpuinfo.BackupDataSource.raw_arch_string | |
227 | cpuinfo.DataSource.arch_string_raw = cpuinfo.BackupDataSource.arch_string_raw | |
228 | cpuinfo.DataSource.uname_string_raw = cpuinfo.BackupDataSource.uname_string_raw | |
228 | 229 | cpuinfo.DataSource.can_cpuid = cpuinfo.BackupDataSource.can_cpuid |
229 | 230 | |
230 | 231 | cpuinfo.DataSource.has_proc_cpuinfo = cpuinfo.BackupDataSource.has_proc_cpuinfo |
241 | 242 | cpuinfo.DataSource.has_wmic = cpuinfo.BackupDataSource.has_wmic |
242 | 243 | cpuinfo.DataSource.cat_proc_cpuinfo = cpuinfo.BackupDataSource.cat_proc_cpuinfo |
243 | 244 | cpuinfo.DataSource.cpufreq_info = cpuinfo.BackupDataSource.cpufreq_info |
244 | cpuinfo.DataSource.sestatus_allow_execheap = cpuinfo.BackupDataSource.sestatus_allow_execheap | |
245 | cpuinfo.DataSource.sestatus_allow_execmem = cpuinfo.BackupDataSource.sestatus_allow_execmem | |
245 | cpuinfo.DataSource.sestatus_b = cpuinfo.BackupDataSource.sestatus_b | |
246 | 246 | cpuinfo.DataSource.dmesg_a = cpuinfo.BackupDataSource.dmesg_a |
247 | 247 | cpuinfo.DataSource.cat_var_run_dmesg_boot = cpuinfo.BackupDataSource.cat_var_run_dmesg_boot |
248 | 248 | cpuinfo.DataSource.sysctl_machdep_cpu_hw_cpufrequency = cpuinfo.BackupDataSource.sysctl_machdep_cpu_hw_cpufrequency |
253 | 253 | cpuinfo.DataSource.wmic_cpu = cpuinfo.BackupDataSource.wmic_cpu |
254 | 254 | cpuinfo.DataSource.sysinfo_cpu = cpuinfo.BackupDataSource.sysinfo_cpu |
255 | 255 | cpuinfo.DataSource.winreg_processor_brand = cpuinfo.BackupDataSource.winreg_processor_brand |
256 | cpuinfo.DataSource.winreg_vendor_id = cpuinfo.BackupDataSource.winreg_vendor_id | |
257 | cpuinfo.DataSource.winreg_raw_arch_string = cpuinfo.BackupDataSource.winreg_raw_arch_string | |
256 | cpuinfo.DataSource.winreg_vendor_id_raw = cpuinfo.BackupDataSource.winreg_vendor_id_raw | |
257 | cpuinfo.DataSource.winreg_arch_string_raw = cpuinfo.BackupDataSource.winreg_arch_string_raw | |
258 | 258 | cpuinfo.DataSource.winreg_hz_actual = cpuinfo.BackupDataSource.winreg_hz_actual |
259 | 259 | cpuinfo.DataSource.winreg_feature_bits = cpuinfo.BackupDataSource.winreg_feature_bits |
260 | ||
261 | def backup_cpuid(cpuinfo): | |
262 | BackupCPUID = type('BackupCPUID', (object,), {}) | |
263 | cpuinfo.BackupCPUID = BackupCPUID() | |
264 | cpuinfo.BackupCPUID._run_asm = cpuinfo.CPUID._run_asm | |
265 | cpuinfo.BackupCPUID._asm_func = cpuinfo.CPUID._asm_func | |
266 | ||
267 | def monkey_patch_cpuid(cpuinfo, return_hz, return_values): | |
268 | class MockCPUID(object): | |
269 | _counter = 0 | |
270 | _is_first = False | |
271 | ||
272 | def _asm_func(self, restype=None, argtypes=(), machine_code=[]): | |
273 | class CPUIDGetTicks(object): | |
274 | # NOTE: This assumes that the function returned is a get_ticks function | |
275 | def func(self): | |
276 | MockCPUID._is_first = not MockCPUID._is_first | |
277 | ||
278 | if MockCPUID._is_first: | |
279 | return return_hz | |
280 | else: | |
281 | return 0 | |
282 | ||
283 | def free(self): | |
284 | pass | |
285 | ||
286 | return CPUIDGetTicks() | |
287 | ||
288 | def _run_asm(self, *machine_code): | |
289 | result = return_values[MockCPUID._counter] | |
290 | MockCPUID._counter += 1 | |
291 | if MockCPUID._counter == len(return_values): | |
292 | MockCPUID._counter = 0 | |
293 | return result | |
294 | ||
295 | cpuinfo.CPUID._run_asm = MockCPUID.__dict__['_run_asm'] | |
296 | cpuinfo.CPUID._asm_func = MockCPUID.__dict__['_asm_func'] | |
297 | ||
298 | def restore_cpuid(cpuinfo): | |
299 | cpuinfo.CPUID._run_asm = cpuinfo.BackupCPUID._run_asm | |
300 | cpuinfo.CPUID._asm_func = cpuinfo.BackupCPUID._asm_func | |
301 | ||
302 | ||
303 | def backup_asm(cpuinfo): | |
304 | BackupASM = type('BackupASM', (object,), {}) | |
305 | cpuinfo.BackupASM = BackupASM() | |
306 | cpuinfo.BackupASM.compile = cpuinfo.ASM.compile | |
307 | cpuinfo.BackupASM.run = cpuinfo.ASM.run | |
308 | cpuinfo.BackupASM.free = cpuinfo.ASM.free | |
309 | ||
310 | def monkey_patch_asm(cpuinfo, NewASM): | |
311 | cpuinfo.ASM.compile = NewASM.__dict__['compile'] | |
312 | cpuinfo.ASM.run = NewASM.__dict__['run'] | |
313 | cpuinfo.ASM.free = NewASM.__dict__['free'] | |
314 | ||
315 | def restore_asm(cpuinfo): | |
316 | cpuinfo.ASM.compile = cpuinfo.BackupASM.compile | |
317 | cpuinfo.ASM.run = cpuinfo.BackupASM.run | |
318 | cpuinfo.ASM.free = cpuinfo.BackupASM.free |
28 | 28 | info = json.loads(output, object_hook = cpuinfo._utf_to_str) |
29 | 29 | |
30 | 30 | self.assertEqual(list(cpuinfo.CPUINFO_VERSION), info['cpuinfo_version']) |
31 | self.assertEqual(cpuinfo.CPUINFO_VERSION_STRING, info['cpuinfo_version_string']) | |
32 | ||
33 | def test_version(self): | |
34 | from subprocess import Popen, PIPE | |
35 | ||
36 | command = [sys.executable, 'cpuinfo/cpuinfo.py', '--version'] | |
37 | p1 = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE) | |
38 | output = p1.communicate()[0] | |
39 | ||
40 | self.assertEqual(0, p1.returncode) | |
41 | ||
42 | if not IS_PY2: | |
43 | output = output.decode(encoding='UTF-8') | |
44 | output = output.strip() | |
45 | ||
46 | self.assertEqual(cpuinfo.CPUINFO_VERSION_STRING, output) | |
31 | 47 | |
32 | 48 | def test_default(self): |
33 | 49 | from subprocess import Popen, PIPE |
43 | 59 | |
44 | 60 | version = output.split('Cpuinfo Version: ')[1].split('\n')[0].strip() |
45 | 61 | |
46 | self.assertEqual(str(cpuinfo.CPUINFO_VERSION), version) | |
62 | self.assertEqual(cpuinfo.CPUINFO_VERSION_STRING, version) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class TestCompileErrors(unittest.TestCase): | |
8 | def test_all(self): | |
9 | self.maxDiff = None | |
10 | ||
11 | import os | |
12 | from subprocess import Popen, PIPE | |
13 | ||
14 | # Find all the python files | |
15 | py_files = [] | |
16 | for root, dirs, files in os.walk("."): | |
17 | for file in files: | |
18 | if file.lower().endswith(".py"): | |
19 | py_files.append(os.path.join(root, file).lstrip(".\\").lstrip('/')) | |
20 | ||
21 | ||
22 | # Compile the files and check for errors | |
23 | command = sys.executable + " -Wall -m py_compile " + ' '.join(py_files) | |
24 | p1 = Popen(command.split(' '), stdout=PIPE, stderr=PIPE, stdin=PIPE) | |
25 | p1_stdout, p1_stderr = p1.communicate() | |
26 | ||
27 | if not cpuinfo.IS_PY2: | |
28 | p1_stdout = p1_stdout.decode(encoding='UTF-8') | |
29 | ||
30 | if not cpuinfo.IS_PY2: | |
31 | p1_stderr = p1_stderr.decode(encoding='UTF-8') | |
32 | ||
33 | # Check for no errors | |
34 | self.assertEqual("", p1_stderr) | |
35 | self.assertEqual("", p1_stdout) | |
36 | self.assertEqual(0, p1.returncode) |
4 | 4 | import helpers |
5 | 5 | |
6 | 6 | |
7 | class MockASM(ASM): | |
8 | is_first = False | |
9 | ||
10 | def __init__(self, restype=None, argtypes=(), machine_code=[]): | |
11 | super(MockASM, self).__init__(restype, argtypes, machine_code) | |
12 | ||
13 | def compile(self): | |
14 | self.func = self.run | |
15 | ||
16 | def run(self): | |
17 | machine_code = tuple(self.machine_code) | |
18 | ||
19 | # get_max_extension_support | |
20 | if machine_code == \ | |
21 | (b"\xB8\x00\x00\x00\x80" # mov ax,0x80000000 | |
22 | b"\x0f\xa2" # cpuid | |
23 | b"\xC3",): # ret | |
24 | return 0x8000001f | |
25 | ||
26 | # get_cache | |
27 | if machine_code == \ | |
28 | (b"\xB8\x06\x00\x00\x80" # mov ax,0x80000006 | |
29 | b"\x0f\xa2" # cpuid | |
30 | b"\x89\xC8" # mov ax,cx | |
31 | b"\xC3",): # ret)) | |
32 | return 0x2006140 | |
33 | ||
34 | # get_info | |
35 | if machine_code == \ | |
36 | (b"\xB8\x01\x00\x00\x00", # mov eax,0x1" | |
37 | b"\x0f\xa2" # cpuid | |
38 | b"\xC3",): # ret | |
39 | return 0x800f82 | |
40 | ||
41 | # get_processor_brand | |
42 | if machine_code == \ | |
43 | (b"\xB8\x02\x00\x00\x80", # mov ax,0x80000002 | |
44 | b"\x0f\xa2" # cpuid | |
45 | b"\x89\xC0" # mov ax,ax | |
46 | b"\xC3",): # ret | |
47 | return 0x20444d41 | |
48 | elif machine_code == \ | |
49 | (b"\xB8\x02\x00\x00\x80", # mov ax,0x80000002 | |
50 | b"\x0f\xa2" # cpuid | |
51 | b"\x89\xD8" # mov ax,bx | |
52 | b"\xC3",): # ret | |
53 | return 0x657a7952 | |
54 | elif machine_code == \ | |
55 | (b"\xB8\x02\x00\x00\x80", # mov ax,0x80000002 | |
56 | b"\x0f\xa2" # cpuid | |
57 | b"\x89\xC8" # mov ax,cx | |
58 | b"\xC3",): # ret | |
59 | return 0x2037206e | |
60 | elif machine_code == \ | |
61 | (b"\xB8\x02\x00\x00\x80", # mov ax,0x80000002 | |
62 | b"\x0f\xa2" # cpuid | |
63 | b"\x89\xD0" # mov ax,dx | |
64 | b"\xC3",): # ret | |
65 | return 0x30303732 | |
66 | elif machine_code == \ | |
67 | (b"\xB8\x03\x00\x00\x80", # mov ax,0x80000003 | |
68 | b"\x0f\xa2" # cpuid | |
69 | b"\x89\xC0" # mov ax,ax | |
70 | b"\xC3",): # ret | |
71 | return 0x69452058 | |
72 | elif machine_code == \ | |
73 | (b"\xB8\x03\x00\x00\x80", # mov ax,0x80000003 | |
74 | b"\x0f\xa2" # cpuid | |
75 | b"\x89\xD8" # mov ax,bx | |
76 | b"\xC3",): # ret | |
77 | return 0x2d746867 | |
78 | elif machine_code == \ | |
79 | (b"\xB8\x03\x00\x00\x80", # mov ax,0x80000003 | |
80 | b"\x0f\xa2" # cpuid | |
81 | b"\x89\xC8" # mov ax,cx | |
82 | b"\xC3",): # ret | |
83 | return 0x65726f43 | |
84 | elif machine_code == \ | |
85 | (b"\xB8\x03\x00\x00\x80", # mov ax,0x80000003 | |
86 | b"\x0f\xa2" # cpuid | |
87 | b"\x89\xD0" # mov ax,dx | |
88 | b"\xC3",): # ret | |
89 | return 0x6f725020 | |
90 | elif machine_code == \ | |
91 | (b"\xB8\x04\x00\x00\x80", # mov ax,0x80000004 | |
92 | b"\x0f\xa2" # cpuid | |
93 | b"\x89\xC0" # mov ax,ax | |
94 | b"\xC3",): # ret | |
95 | return 0x73736563 | |
96 | elif machine_code == \ | |
97 | (b"\xB8\x04\x00\x00\x80", # mov ax,0x80000004 | |
98 | b"\x0f\xa2" # cpuid | |
99 | b"\x89\xD8" # mov ax,bx | |
100 | b"\xC3",): # ret | |
101 | return 0x2020726f | |
102 | elif machine_code == \ | |
103 | (b"\xB8\x04\x00\x00\x80", # mov ax,0x80000004 | |
104 | b"\x0f\xa2" # cpuid | |
105 | b"\x89\xC8" # mov ax,cx | |
106 | b"\xC3",): # ret | |
107 | return 0x20202020 | |
108 | elif machine_code == \ | |
109 | (b"\xB8\x04\x00\x00\x80", # mov ax,0x80000004 | |
110 | b"\x0f\xa2" # cpuid | |
111 | b"\x89\xD0" # mov ax,dx | |
112 | b"\xC3",): # ret | |
113 | return 0x202020 | |
114 | ||
115 | # get_vendor_id | |
116 | if machine_code == \ | |
117 | (b"\x31\xC0", # xor eax,eax | |
118 | b"\x0F\xA2" # cpuid | |
119 | b"\x89\xD8" # mov ax,bx | |
120 | b"\xC3",): # ret | |
121 | return 0x68747541 | |
122 | elif machine_code == \ | |
123 | (b"\x31\xC0", # xor eax,eax | |
124 | b"\x0f\xa2" # cpuid | |
125 | b"\x89\xC8" # mov ax,cx | |
126 | b"\xC3",): # ret | |
127 | return 0x444d4163 | |
128 | elif machine_code == \ | |
129 | (b"\x31\xC0", # xor eax,eax | |
130 | b"\x0f\xa2" # cpuid | |
131 | b"\x89\xD0" # mov ax,dx | |
132 | b"\xC3",): # ret | |
133 | return 0x69746e65 | |
134 | ||
135 | # get_flags | |
136 | if machine_code == \ | |
137 | (b"\xB8\x01\x00\x00\x00", # mov eax,0x1" | |
138 | b"\x0f\xa2" # cpuid | |
139 | b"\x89\xD0" # mov ax,dx | |
140 | b"\xC3",): # ret | |
141 | return 0x178bfbff | |
142 | elif machine_code == \ | |
143 | (b"\xB8\x01\x00\x00\x00", # mov eax,0x1" | |
144 | b"\x0f\xa2" # cpuid | |
145 | b"\x89\xC8" # mov ax,cx | |
146 | b"\xC3",): # ret | |
147 | return 0x7ed8320b | |
148 | elif machine_code == \ | |
149 | (b"\x31\xC9", # xor ecx,ecx | |
150 | b"\xB8\x07\x00\x00\x00" # mov eax,7 | |
151 | b"\x0f\xa2" # cpuid | |
152 | b"\x89\xD8" # mov ax,bx | |
153 | b"\xC3",): # ret | |
154 | return 0x209c01a9 | |
155 | elif machine_code == \ | |
156 | (b"\x31\xC9", # xor ecx,ecx | |
157 | b"\xB8\x07\x00\x00\x00" # mov eax,7 | |
158 | b"\x0f\xa2" # cpuid | |
159 | b"\x89\xC8" # mov ax,cx | |
160 | b"\xC3",): # ret | |
161 | return 0x0 | |
162 | elif machine_code == \ | |
163 | (b"\xB8\x01\x00\x00\x80" # mov ax,0x80000001 | |
164 | b"\x0f\xa2" # cpuid | |
165 | b"\x89\xD8" # mov ax,bx | |
166 | b"\xC3",): # ret | |
167 | return 0x20000000 | |
168 | elif machine_code == \ | |
169 | (b"\xB8\x01\x00\x00\x80" # mov ax,0x80000001 | |
170 | b"\x0f\xa2" # cpuid | |
171 | b"\x89\xC8" # mov ax,cx | |
172 | b"\xC3",): # ret | |
173 | return 0x35c233ff | |
174 | ||
175 | # get_ticks | |
176 | # 32 bit | |
177 | if machine_code == \ | |
178 | (b"\x55", # push bp | |
179 | b"\x89\xE5", # mov bp,sp | |
180 | b"\x31\xC0", # xor ax,ax | |
181 | b"\x0F\xA2", # cpuid | |
182 | b"\x0F\x31", # rdtsc | |
183 | b"\x8B\x5D\x08", # mov bx,[di+0x8] | |
184 | b"\x8B\x4D\x0C", # mov cx,[di+0xc] | |
185 | b"\x89\x13", # mov [bp+di],dx | |
186 | b"\x89\x01", # mov [bx+di],ax | |
187 | b"\x5D", # pop bp | |
188 | b"\xC3",): # ret | |
189 | raise Exception("FIXME: Add ticks for 32bit get_ticks") | |
190 | # 64 bit | |
191 | elif machine_code == \ | |
192 | (b"\x48", # dec ax | |
193 | b"\x31\xC0", # xor ax,ax | |
194 | b"\x0F\xA2", # cpuid | |
195 | b"\x0F\x31", # rdtsc | |
196 | b"\x48", # dec ax | |
197 | b"\xC1\xE2\x20", # shl dx,byte 0x20 | |
198 | b"\x48", # dec ax | |
199 | b"\x09\xD0", # or ax,dx | |
200 | b"\xC3",): # ret | |
201 | MockASM.is_first = not MockASM.is_first | |
202 | if MockASM.is_first: | |
203 | return 19233706151817 | |
204 | else: | |
205 | return 19237434253761 | |
206 | ||
207 | raise Exception("Unexpected machine code") | |
208 | ||
209 | def free(self): | |
210 | self.func = None | |
211 | ||
7 | 212 | |
8 | 213 | class MockDataSource(object): |
9 | 214 | bits = '64bit' |
10 | 215 | cpu_count = 1 |
11 | is_windows = False | |
12 | raw_arch_string = 'INVALID' | |
216 | is_windows = platform.system().lower() == 'windows' | |
217 | arch_string_raw = 'INVALID' | |
218 | uname_string_raw = 'INVALID' | |
13 | 219 | can_cpuid = True |
14 | 220 | |
15 | 221 | |
18 | 224 | helpers.backup_data_source(cpuinfo) |
19 | 225 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
20 | 226 | |
227 | helpers.backup_asm(cpuinfo) | |
228 | helpers.monkey_patch_asm(cpuinfo, MockASM) | |
229 | ||
21 | 230 | def tearDown(self): |
22 | 231 | helpers.restore_data_source(cpuinfo) |
232 | ||
233 | helpers.restore_asm(cpuinfo) | |
23 | 234 | |
24 | 235 | # Make sure this returns {} on an invalid arch |
25 | 236 | def test_return_empty(self): |
26 | 237 | self.assertEqual({}, cpuinfo._get_cpu_info_from_cpuid()) |
238 | ||
239 | def test_normal(self): | |
240 | cpuid = CPUID() | |
241 | self.assertIsNotNone(cpuid) | |
242 | ||
243 | self.assertFalse(cpuid.is_selinux_enforcing) | |
244 | ||
245 | max_extension_support = cpuid.get_max_extension_support() | |
246 | self.assertEqual(0x8000001f, max_extension_support) | |
247 | ||
248 | cache_info = cpuid.get_cache(max_extension_support) | |
249 | self.assertEqual({'size_b': 64 * 1024, 'line_size_b': 512, 'associativity': 6}, cache_info) | |
250 | ||
251 | info = cpuid.get_info() | |
252 | self.assertEqual({'stepping': 2, 'model': 8, 'family': 23, 'processor_type': 0}, info) | |
253 | ||
254 | processor_brand = cpuid.get_processor_brand(max_extension_support) | |
255 | self.assertEqual("AMD Ryzen 7 2700X Eight-Core Processor", processor_brand) | |
256 | ||
257 | hz_actual = cpuid.get_raw_hz() | |
258 | self.assertEqual(3728101944, hz_actual) | |
259 | ||
260 | vendor_id = cpuid.get_vendor_id() | |
261 | self.assertEqual('AuthenticAMD', vendor_id) | |
262 | ||
263 | flags = cpuid.get_flags(max_extension_support) | |
264 | self.assertEqual( | |
265 | ['3dnowprefetch', 'abm', 'adx', 'aes', 'apic', 'avx', 'avx2', 'bmi1', | |
266 | 'bmi2', 'clflush', 'clflushopt', 'cmov', 'cmp_legacy', 'cr8_legacy', | |
267 | 'cx16', 'cx8', 'dbx', 'de', 'extapic', 'f16c', 'fma', 'fpu', 'fxsr', | |
268 | 'ht', 'lahf_lm', 'lm', 'mca', 'mce', 'misalignsse', 'mmx', 'monitor', | |
269 | 'movbe', 'msr', 'mtrr', 'osvw', 'osxsave', 'pae', 'pat', 'pci_l2i', | |
270 | 'pclmulqdq', 'perfctr_core', 'perfctr_nb', 'pge', 'pni', 'popcnt', | |
271 | 'pse', 'pse36', 'rdrnd', 'rdseed', 'sep', 'sha', 'skinit', 'smap', | |
272 | 'smep', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'sse4a', 'ssse3', 'svm', | |
273 | 'tce', 'topoext', 'tsc', 'vme', 'wdt', 'xsave' | |
274 | ], flags) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | |
13 | 14 | @staticmethod |
14 | 15 | def has_proc_cpuinfo(): |
59 | 60 | return 1, None |
60 | 61 | |
61 | 62 | @staticmethod |
62 | def sestatus_allow_execheap(): | |
63 | return False | |
64 | ||
65 | @staticmethod | |
66 | def sestatus_allow_execmem(): | |
67 | return False | |
63 | def sestatus_b(): | |
64 | return 1, None | |
68 | 65 | |
69 | 66 | @staticmethod |
70 | 67 | def dmesg_a(): |
99 | 96 | return None |
100 | 97 | |
101 | 98 | @staticmethod |
102 | def winreg_vendor_id(): | |
99 | def winreg_vendor_id_raw(): | |
103 | 100 | return None |
104 | 101 | |
105 | 102 | @staticmethod |
106 | def winreg_raw_arch_string(): | |
103 | def winreg_arch_string_raw(): | |
107 | 104 | return None |
108 | 105 | |
109 | 106 | @staticmethod |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'amd64' | |
11 | arch_string_raw = 'amd64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
22 | 23 | @staticmethod |
23 | 24 | def dmesg_a(): |
24 | 25 | retcode = 0 |
25 | output = '''Copyright (c) 1992-2014 The FreeBSD Project. | |
26 | output = r'''Copyright (c) 1992-2014 The FreeBSD Project. | |
26 | 27 | Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 |
27 | 28 | The Regents of the University of California. All rights reserved. |
28 | 29 | FreeBSD is a registered trademark of The FreeBSD Foundation. |
43 | 44 | @staticmethod |
44 | 45 | def cat_var_run_dmesg_boot(): |
45 | 46 | retcode = 0 |
46 | output = ''' | |
47 | output = r''' | |
47 | 48 | VT(vga): text 80x25 |
48 | 49 | CPU: Intel(R) Pentium(R) CPU G640 @ 2.80GHz (2793.73-MHz K8-class CPU) |
49 | 50 | Origin="GenuineIntel" Id=0x206a7 Family=0x6 Model=02a Stepping=7 |
80 | 81 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
81 | 82 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
82 | 83 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
83 | self.assertEqual(16, len(cpuinfo._get_cpu_info_internal())) | |
84 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
84 | 85 | |
85 | 86 | def test_get_cpu_info_from_dmesg(self): |
86 | 87 | info = cpuinfo._get_cpu_info_from_dmesg() |
87 | 88 | |
88 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
89 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
90 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
91 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
92 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
93 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
89 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
90 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
91 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
92 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
93 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
94 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
94 | 95 | |
95 | 96 | self.assertEqual(7, info['stepping']) |
96 | 97 | self.assertEqual(42, info['model']) |
108 | 109 | def test_get_cpu_info_from_cat_var_run_dmesg_boot(self): |
109 | 110 | info = cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot() |
110 | 111 | |
111 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
112 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
113 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
114 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
115 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
116 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
112 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
113 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
114 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
115 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
116 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
117 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
117 | 118 | |
118 | 119 | self.assertEqual(7, info['stepping']) |
119 | 120 | self.assertEqual(42, info['model']) |
131 | 132 | def test_all(self): |
132 | 133 | info = cpuinfo._get_cpu_info_internal() |
133 | 134 | |
134 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
135 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
136 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
137 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
138 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
139 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
135 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
136 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
137 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
138 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
139 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
140 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
140 | 141 | self.assertEqual('X86_64', info['arch']) |
141 | 142 | self.assertEqual(64, info['bits']) |
142 | 143 | self.assertEqual(1, info['count']) |
143 | 144 | |
144 | self.assertEqual('amd64', info['raw_arch_string']) | |
145 | self.assertEqual('amd64', info['arch_string_raw']) | |
145 | 146 | |
146 | 147 | self.assertEqual(7, info['stepping']) |
147 | 148 | self.assertEqual(42, info['model']) |
8 | 8 | bits = '32bit' |
9 | 9 | cpu_count = 4 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'BePC' | |
11 | arch_string_raw = 'BePC' | |
12 | uname_string_raw = 'x86_32' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
18 | 19 | @staticmethod |
19 | 20 | def sysinfo_cpu(): |
20 | 21 | returncode = 0 |
21 | output = ''' | |
22 | output = r''' | |
22 | 23 | 4 Intel Core i7, revision 46e5 running at 2928MHz (ID: 0x00000000 0x00000000) |
23 | 24 | |
24 | 25 | CPU #0: "Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz" |
73 | 74 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
74 | 75 | self.assertEqual(9, len(cpuinfo._get_cpu_info_from_sysinfo())) |
75 | 76 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
76 | self.assertEqual(15, len(cpuinfo._get_cpu_info_internal())) | |
77 | self.assertEqual(16, len(cpuinfo._get_cpu_info_internal())) | |
77 | 78 | |
78 | 79 | def test_get_cpu_info_from_sysinfo(self): |
79 | 80 | info = cpuinfo._get_cpu_info_from_sysinfo() |
80 | 81 | |
81 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
82 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
83 | self.assertEqual('2.9300 GHz', info['hz_actual']) | |
84 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
85 | self.assertEqual((2930000000, 0), info['hz_actual_raw']) | |
82 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
83 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
84 | self.assertEqual('2.9300 GHz', info['hz_actual_friendly']) | |
85 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
86 | self.assertEqual((2930000000, 0), info['hz_actual']) | |
86 | 87 | |
87 | 88 | self.assertEqual(5, info['stepping']) |
88 | 89 | self.assertEqual(30, info['model']) |
98 | 99 | def test_all(self): |
99 | 100 | info = cpuinfo._get_cpu_info_internal() |
100 | 101 | |
101 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
102 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
103 | self.assertEqual('2.9300 GHz', info['hz_actual']) | |
104 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
105 | self.assertEqual((2930000000, 0), info['hz_actual_raw']) | |
102 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
103 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
104 | self.assertEqual('2.9300 GHz', info['hz_actual_friendly']) | |
105 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
106 | self.assertEqual((2930000000, 0), info['hz_actual']) | |
106 | 107 | self.assertEqual('X86_32', info['arch']) |
107 | 108 | self.assertEqual(32, info['bits']) |
108 | 109 | self.assertEqual(4, info['count']) |
109 | 110 | |
110 | self.assertEqual('BePC', info['raw_arch_string']) | |
111 | self.assertEqual('BePC', info['arch_string_raw']) | |
111 | 112 | |
112 | 113 | self.assertEqual(5, info['stepping']) |
113 | 114 | self.assertEqual(30, info['model']) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 4 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'BePC' | |
11 | arch_string_raw = 'BePC' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
18 | 19 | @staticmethod |
19 | 20 | def sysinfo_cpu(): |
20 | 21 | returncode = 0 |
21 | output = ''' | |
22 | output = r''' | |
22 | 23 | 1 Intel Core i7, revision 106e5 running at 2933MHz |
23 | 24 | |
24 | 25 | CPU #0: "Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz" |
73 | 74 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
74 | 75 | self.assertEqual(9, len(cpuinfo._get_cpu_info_from_sysinfo())) |
75 | 76 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
76 | self.assertEqual(15, len(cpuinfo._get_cpu_info_internal())) | |
77 | self.assertEqual(16, len(cpuinfo._get_cpu_info_internal())) | |
77 | 78 | |
78 | 79 | def test_get_cpu_info_from_sysinfo(self): |
79 | 80 | info = cpuinfo._get_cpu_info_from_sysinfo() |
80 | 81 | |
81 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
82 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
83 | self.assertEqual('2.9300 GHz', info['hz_actual']) | |
84 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
85 | self.assertEqual((2930000000, 0), info['hz_actual_raw']) | |
82 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
83 | self.assertEqual('2.9330 GHz', info['hz_advertised_friendly']) | |
84 | self.assertEqual('2.9330 GHz', info['hz_actual_friendly']) | |
85 | self.assertEqual((2933000000, 0), info['hz_advertised']) | |
86 | self.assertEqual((2933000000, 0), info['hz_actual']) | |
86 | 87 | |
87 | 88 | self.assertEqual(5, info['stepping']) |
88 | 89 | self.assertEqual(30, info['model']) |
99 | 100 | def test_all(self): |
100 | 101 | info = cpuinfo._get_cpu_info_internal() |
101 | 102 | |
102 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
103 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
104 | self.assertEqual('2.9300 GHz', info['hz_actual']) | |
105 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
106 | self.assertEqual((2930000000, 0), info['hz_actual_raw']) | |
103 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
104 | self.assertEqual('2.9330 GHz', info['hz_advertised_friendly']) | |
105 | self.assertEqual('2.9330 GHz', info['hz_actual_friendly']) | |
106 | self.assertEqual((2933000000, 0), info['hz_advertised']) | |
107 | self.assertEqual((2933000000, 0), info['hz_actual']) | |
107 | 108 | self.assertEqual('X86_32', info['arch']) |
108 | 109 | self.assertEqual(32, info['bits']) |
109 | 110 | self.assertEqual(4, info['count']) |
110 | 111 | |
111 | self.assertEqual('BePC', info['raw_arch_string']) | |
112 | self.assertEqual('BePC', info['arch_string_raw']) | |
112 | 113 | |
113 | 114 | self.assertEqual(5, info['stepping']) |
114 | 115 | self.assertEqual(30, info['model']) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource(object): | |
8 | bits = '32bit' | |
9 | cpu_count = 2 | |
10 | is_windows = False | |
11 | arch_string_raw = 'BePC' | |
12 | uname_string_raw = 'x86_32' | |
13 | can_cpuid = False | |
14 | ||
15 | @staticmethod | |
16 | def has_sysinfo(): | |
17 | return True | |
18 | ||
19 | @staticmethod | |
20 | def sysinfo_cpu(): | |
21 | returncode = 0 | |
22 | output = r''' | |
23 | 2 AMD Ryzen 7, revision 800f82 running at 3693MHz | |
24 | ||
25 | CPU #0: "AMD Ryzen 7 2700X Eight-Core Processor " | |
26 | Signature: 0x800f82; Type 0, family 23, model 8, stepping 2 | |
27 | Features: 0x178bfbff | |
28 | FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT | |
29 | PSE36 CFLUSH MMX FXSTR SSE SSE2 HTT | |
30 | Extended Features (0x00000001): 0x56d82203 | |
31 | SSE3 PCLMULDQ SSSE3 CX16 SSE4.1 SSE4.2 MOVEB POPCNT AES XSAVE AVX RDRND | |
32 | Extended Features (0x80000001): 0x2bd3fb7f | |
33 | SCE NX AMD-MMX FXSR FFXSR RDTSCP 64 | |
34 | Extended Features (0x80000007): 0x00000100 | |
35 | ITSC | |
36 | Extended Features (0x80000008): 0x00000000 | |
37 | ||
38 | Inst TLB: 2M/4M-byte pages, 64 entries, fully associative | |
39 | Data TLB: 2M/4M-byte pages, 64 entries, fully associative | |
40 | Inst TLB: 4K-byte pages, 64 entries, fully associative | |
41 | Data TLB: 4K-byte pages, 64 entries, fully associative | |
42 | L1 inst cache: 32 KB, 8-way set associative, 1 lines/tag, 64 bytes/line | |
43 | L1 data cache: 64 KB, 4-way set associative, 1 lines/tag, 64 bytes/line | |
44 | L2 cache: 512 KB, 8-way set associative, 1 lines/tag, 64 bytes/line | |
45 | ||
46 | ''' | |
47 | return returncode, output | |
48 | ||
49 | ||
50 | ||
51 | ||
52 | class TestHaiku_x86_64_Beta_1_Ryzen7(unittest.TestCase): | |
53 | def setUp(self): | |
54 | helpers.backup_data_source(cpuinfo) | |
55 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) | |
56 | ||
57 | def tearDown(self): | |
58 | helpers.restore_data_source(cpuinfo) | |
59 | ||
60 | ''' | |
61 | Make sure calls return the expected number of fields. | |
62 | ''' | |
63 | def test_returns(self): | |
64 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_registry())) | |
65 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpufreq_info())) | |
66 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_lscpu())) | |
67 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) | |
68 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) | |
69 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_kstat())) | |
70 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_dmesg())) | |
71 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) | |
72 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) | |
73 | self.assertEqual(9, len(cpuinfo._get_cpu_info_from_sysinfo())) | |
74 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
75 | self.assertEqual(16, len(cpuinfo._get_cpu_info_internal())) | |
76 | ||
77 | def test_get_cpu_info_from_sysinfo(self): | |
78 | info = cpuinfo._get_cpu_info_from_sysinfo() | |
79 | ||
80 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
81 | self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
82 | self.assertEqual('3.6930 GHz', info['hz_actual_friendly']) | |
83 | self.assertEqual((3693000000, 0), info['hz_advertised']) | |
84 | self.assertEqual((3693000000, 0), info['hz_actual']) | |
85 | ||
86 | self.assertEqual(2, info['stepping']) | |
87 | self.assertEqual(8, info['model']) | |
88 | self.assertEqual(23, info['family']) | |
89 | self.assertEqual( | |
90 | ['64', 'aes', 'amd-mmx', 'apic', 'avx', 'cflush', 'cmov', 'cx16', | |
91 | 'cx8', 'de', 'ffxsr', 'fpu', 'fxsr', 'fxstr', 'htt', 'mca', 'mce', | |
92 | 'mmx', 'moveb', 'msr', 'mtrr', 'nx', 'pae', 'pat', 'pclmuldq', | |
93 | 'pge', 'popcnt', 'pse', 'pse36', 'rdrnd', 'rdtscp', 'sce', 'sep', | |
94 | 'sse', 'sse2', 'sse3', 'sse4.1', 'sse4.2', 'ssse3', 'tsc', 'vme', | |
95 | 'xsave'] | |
96 | , | |
97 | info['flags'] | |
98 | ) | |
99 | ||
100 | def test_all(self): | |
101 | info = cpuinfo._get_cpu_info_internal() | |
102 | ||
103 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
104 | self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
105 | self.assertEqual('3.6930 GHz', info['hz_actual_friendly']) | |
106 | self.assertEqual((3693000000, 0), info['hz_advertised']) | |
107 | self.assertEqual((3693000000, 0), info['hz_actual']) | |
108 | self.assertEqual('X86_32', info['arch']) | |
109 | self.assertEqual(32, info['bits']) | |
110 | self.assertEqual(2, info['count']) | |
111 | ||
112 | self.assertEqual('BePC', info['arch_string_raw']) | |
113 | ||
114 | self.assertEqual(2, info['stepping']) | |
115 | self.assertEqual(8, info['model']) | |
116 | self.assertEqual(23, info['family']) | |
117 | self.assertEqual( | |
118 | ['64', 'aes', 'amd-mmx', 'apic', 'avx', 'cflush', 'cmov', 'cx16', | |
119 | 'cx8', 'de', 'ffxsr', 'fpu', 'fxsr', 'fxstr', 'htt', 'mca', 'mce', | |
120 | 'mmx', 'moveb', 'msr', 'mtrr', 'nx', 'pae', 'pat', 'pclmuldq', | |
121 | 'pge', 'popcnt', 'pse', 'pse36', 'rdrnd', 'rdtscp', 'sce', 'sep', | |
122 | 'sse', 'sse2', 'sse3', 'sse4.1', 'sse4.2', 'ssse3', 'tsc', 'vme', | |
123 | 'xsave'] | |
124 | , | |
125 | info['flags'] | |
126 | ) |
8 | 8 | bits = '32bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'unknown_cpu' | |
11 | arch_string_raw = 'unknown_cpu' | |
12 | uname_string_raw = 'unknown_cpu' | |
12 | 13 | |
13 | 14 | |
14 | 15 | class TestInvalidCPU(unittest.TestCase): |
21 | 22 | |
22 | 23 | def test_arch_parse_unknown(self): |
23 | 24 | # If the arch is unknown, the result should be null |
24 | arch, bits = cpuinfo._parse_arch(DataSource.raw_arch_string) | |
25 | arch, bits = cpuinfo._parse_arch(DataSource.arch_string_raw) | |
25 | 26 | self.assertIsNone(arch) |
26 | 27 | self.assertIsNone(bits) |
27 | 28 | |
31 | 32 | cpuinfo._check_arch() |
32 | 33 | self.fail('Failed to raise Exception') |
33 | 34 | except Exception as err: |
34 | self.assertEqual('py-cpuinfo currently only works on X86 and some PPC and ARM CPUs.', err.args[0]) | |
35 | self.assertEqual('py-cpuinfo currently only works on X86 and some ARM/PPC/S390X CPUs.', err.args[0]) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 6 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'aarch64' | |
11 | arch_string_raw = 'aarch64' | |
12 | uname_string_raw = '' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
22 | 23 | @staticmethod |
23 | 24 | def cat_proc_cpuinfo(): |
24 | 25 | returncode = 0 |
25 | output = ''' | |
26 | output = r''' | |
26 | 27 | processor : 90 |
27 | 28 | BogoMIPS : 200.00 |
28 | 29 | Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics |
84 | 85 | @staticmethod |
85 | 86 | def lscpu(): |
86 | 87 | returncode = 0 |
87 | output = ''' | |
88 | output = r''' | |
88 | 89 | Architecture: aarch64 |
89 | 90 | Byte Order: Little Endian |
90 | 91 | CPU(s): 96 |
125 | 126 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
126 | 127 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
127 | 128 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
128 | self.assertEqual(10, len(cpuinfo._get_cpu_info_internal())) | |
129 | self.assertEqual(11, len(cpuinfo._get_cpu_info_internal())) | |
129 | 130 | |
130 | 131 | def test_get_cpu_info_from_lscpu(self): |
131 | 132 | info = cpuinfo._get_cpu_info_from_lscpu() |
132 | 133 | |
133 | self.assertEqual('78 KB', info['l1_instruction_cache_size']) | |
134 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
134 | self.assertEqual(78 * 1024, info['l1_instruction_cache_size']) | |
135 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
135 | 136 | |
136 | self.assertEqual('16384 KB', info['l2_cache_size']) | |
137 | self.assertEqual(16384 * 1024, info['l2_cache_size']) | |
137 | 138 | |
138 | 139 | self.assertEqual(3, len(info)) |
139 | 140 | |
151 | 152 | def test_all(self): |
152 | 153 | info = cpuinfo._get_cpu_info_internal() |
153 | 154 | |
154 | self.assertEqual('', info['vendor_id']) | |
155 | self.assertEqual('FIXME', info['hardware']) | |
156 | self.assertEqual('FIXME', info['brand']) | |
157 | self.assertEqual('FIXME', info['hz_advertised']) | |
158 | self.assertEqual('FIXME', info['hz_actual']) | |
159 | self.assertEqual((1000000000, 0), info['hz_advertised_raw']) | |
160 | self.assertEqual((1000000000, 0), info['hz_actual_raw']) | |
155 | self.assertEqual('', info['vendor_id_raw']) | |
156 | self.assertEqual('FIXME', info['hardware_raw']) | |
157 | self.assertEqual('FIXME', info['brand_raw']) | |
158 | self.assertEqual('FIXME', info['hz_advertised_friendly']) | |
159 | self.assertEqual('FIXME', info['hz_actual_friendly']) | |
160 | self.assertEqual((1000000000, 0), info['hz_advertised']) | |
161 | self.assertEqual((1000000000, 0), info['hz_actual']) | |
161 | 162 | self.assertEqual('ARM_8', info['arch']) |
162 | 163 | self.assertEqual(64, info['bits']) |
163 | 164 | self.assertEqual(6, info['count']) |
164 | 165 | |
165 | self.assertEqual('aarch64', info['raw_arch_string']) | |
166 | self.assertEqual('aarch64', info['arch_string_raw']) | |
166 | 167 | |
167 | self.assertEqual('78K', info['l1_instruction_cache_size']) | |
168 | self.assertEqual('32K', info['l1_data_cache_size']) | |
168 | self.assertEqual(78 * 1024, info['l1_instruction_cache_size']) | |
169 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
169 | 170 | |
170 | self.assertEqual('16384K', info['l2_cache_size']) | |
171 | self.assertEqual(16384 * 1024, info['l2_cache_size']) | |
171 | 172 | self.assertEqual(0, info['l2_cache_line_size']) |
172 | 173 | self.assertEqual(0, info['l2_cache_associativity']) |
173 | 174 | |
174 | self.assertEqual('', info['l3_cache_size']) | |
175 | self.assertEqual(0, info['l3_cache_size']) | |
175 | 176 | |
176 | 177 | self.assertEqual(0, info['stepping']) |
177 | 178 | self.assertEqual(0, info['model']) |
178 | 179 | self.assertEqual(0, info['family']) |
179 | 180 | self.assertEqual(0, info['processor_type']) |
180 | self.assertEqual(0, info['extended_model']) | |
181 | self.assertEqual(0, info['extended_family']) | |
182 | 181 | self.assertEqual( |
183 | 182 | ['aes', 'asimd', 'atomics', 'crc32', 'evtstrm', |
184 | 183 | 'fp', 'pmull', 'sha1', 'sha2'] |
8 | 8 | bits = '32bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'armv7l' | |
11 | arch_string_raw = 'armv7l' | |
12 | uname_string_raw = '' | |
12 | 13 | |
13 | 14 | @staticmethod |
14 | 15 | def has_proc_cpuinfo(): |
21 | 22 | @staticmethod |
22 | 23 | def cat_proc_cpuinfo(): |
23 | 24 | returncode = 0 |
24 | output = ''' | |
25 | output = r''' | |
25 | 26 | processor : 0 |
26 | 27 | model name : ARMv6-compatible processor rev 7 (v6l) |
27 | 28 | Features : swp half thumb fastmult vfp edsp java tls |
43 | 44 | @staticmethod |
44 | 45 | def cpufreq_info(): |
45 | 46 | returncode = 0 |
46 | output = ''' | |
47 | output = r''' | |
47 | 48 | cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 |
48 | 49 | Report errors and bugs to cpufreq@vger.kernel.org, please. |
49 | 50 | analyzing CPU 0: |
86 | 87 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
87 | 88 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
88 | 89 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
89 | self.assertEqual(13, len(cpuinfo._get_cpu_info_internal())) | |
90 | self.assertEqual(14, len(cpuinfo._get_cpu_info_internal())) | |
90 | 91 | |
91 | 92 | def test_get_cpu_info_from_cpufreq_info(self): |
92 | 93 | info = cpuinfo._get_cpu_info_from_cpufreq_info() |
93 | 94 | |
94 | self.assertEqual('1.0000 GHz', info['hz_advertised']) | |
95 | self.assertEqual('1.0000 GHz', info['hz_actual']) | |
96 | self.assertEqual((1000000000, 0), info['hz_advertised_raw']) | |
97 | self.assertEqual((1000000000, 0), info['hz_actual_raw']) | |
95 | self.assertEqual('1.0000 GHz', info['hz_advertised_friendly']) | |
96 | self.assertEqual('1.0000 GHz', info['hz_actual_friendly']) | |
97 | self.assertEqual((1000000000, 0), info['hz_advertised']) | |
98 | self.assertEqual((1000000000, 0), info['hz_actual']) | |
98 | 99 | |
99 | 100 | def test_get_cpu_info_from_proc_cpuinfo(self): |
100 | 101 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
101 | 102 | |
102 | self.assertEqual('BCM2708', info['hardware']) | |
103 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand']) | |
103 | self.assertEqual('BCM2708', info['hardware_raw']) | |
104 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand_raw']) | |
104 | 105 | |
105 | 106 | self.assertEqual( |
106 | 107 | ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp'] |
111 | 112 | def test_all(self): |
112 | 113 | info = cpuinfo._get_cpu_info_internal() |
113 | 114 | |
114 | self.assertEqual('BCM2708', info['hardware']) | |
115 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand']) | |
116 | self.assertEqual('1.0000 GHz', info['hz_advertised']) | |
117 | self.assertEqual('1.0000 GHz', info['hz_actual']) | |
118 | self.assertEqual((1000000000, 0), info['hz_advertised_raw']) | |
119 | self.assertEqual((1000000000, 0), info['hz_actual_raw']) | |
115 | self.assertEqual('BCM2708', info['hardware_raw']) | |
116 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand_raw']) | |
117 | self.assertEqual('1.0000 GHz', info['hz_advertised_friendly']) | |
118 | self.assertEqual('1.0000 GHz', info['hz_actual_friendly']) | |
119 | self.assertEqual((1000000000, 0), info['hz_advertised']) | |
120 | self.assertEqual((1000000000, 0), info['hz_actual']) | |
120 | 121 | self.assertEqual('ARM_7', info['arch']) |
121 | 122 | self.assertEqual(32, info['bits']) |
122 | 123 | self.assertEqual(1, info['count']) |
123 | 124 | |
124 | self.assertEqual('armv7l', info['raw_arch_string']) | |
125 | self.assertEqual('armv7l', info['arch_string_raw']) | |
125 | 126 | |
126 | 127 | self.assertEqual( |
127 | 128 | ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp'] |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 2 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
26 | 27 | @staticmethod |
27 | 28 | def cat_proc_cpuinfo(): |
28 | 29 | returncode = 0 |
29 | output = ''' | |
30 | output = r''' | |
30 | 31 | processor : 0 |
31 | 32 | vendor_id : GenuineIntel |
32 | 33 | cpu family : 6 |
84 | 85 | @staticmethod |
85 | 86 | def dmesg_a(): |
86 | 87 | returncode = 0 |
87 | output = ''' | |
88 | output = r''' | |
88 | 89 | [ 0.000000] Initializing cgroup subsys cpuset |
89 | 90 | [ 0.000000] Initializing cgroup subsys cpu |
90 | 91 | [ 0.000000] Initializing cgroup subsys cpuacct |
408 | 409 | @staticmethod |
409 | 410 | def lscpu(): |
410 | 411 | returncode = 0 |
411 | output = ''' | |
412 | output = r''' | |
412 | 413 | Architecture: x86_64 |
413 | 414 | CPU op-mode(s): 32-bit, 64-bit |
414 | 415 | Byte Order: Little Endian |
460 | 461 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
461 | 462 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
462 | 463 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
463 | self.assertEqual(20, len(cpuinfo._get_cpu_info_internal())) | |
464 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
464 | 465 | |
465 | 466 | def test_get_cpu_info_from_lscpu(self): |
466 | 467 | info = cpuinfo._get_cpu_info_from_lscpu() |
467 | 468 | |
468 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
469 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
470 | self.assertEqual('2.7937 GHz', info['hz_advertised']) | |
471 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
472 | self.assertEqual((2793652000, 0), info['hz_advertised_raw']) | |
473 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
469 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
470 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
471 | self.assertEqual('2.7937 GHz', info['hz_advertised_friendly']) | |
472 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
473 | self.assertEqual((2793652000, 0), info['hz_advertised']) | |
474 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
474 | 475 | |
475 | 476 | self.assertEqual(7, info['stepping']) |
476 | 477 | self.assertEqual(42, info['model']) |
477 | 478 | self.assertEqual(6, info['family']) |
478 | 479 | |
479 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
480 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
481 | ||
482 | self.assertEqual('256 KB', info['l2_cache_size']) | |
483 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
480 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
481 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
482 | ||
483 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
484 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
484 | 485 | |
485 | 486 | def test_get_cpu_info_from_dmesg(self): |
486 | 487 | info = cpuinfo._get_cpu_info_from_dmesg() |
487 | 488 | |
488 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
489 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
490 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
491 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
492 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
489 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
490 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
491 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
492 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
493 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
493 | 494 | |
494 | 495 | self.assertEqual(7, info['stepping']) |
495 | 496 | self.assertEqual(42, info['model']) |
498 | 499 | def test_get_cpu_info_from_proc_cpuinfo(self): |
499 | 500 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
500 | 501 | |
501 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
502 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
503 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
504 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
505 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
506 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
507 | ||
508 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
502 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
503 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
504 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
505 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
506 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
507 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
508 | ||
509 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
509 | 510 | |
510 | 511 | self.assertEqual(7, info['stepping']) |
511 | 512 | self.assertEqual(42, info['model']) |
524 | 525 | def test_all(self): |
525 | 526 | info = cpuinfo._get_cpu_info_internal() |
526 | 527 | |
527 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
528 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
529 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
530 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
531 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
532 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
528 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
529 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
530 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
531 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
532 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
533 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
533 | 534 | self.assertEqual('X86_64', info['arch']) |
534 | 535 | self.assertEqual(64, info['bits']) |
535 | 536 | self.assertEqual(2, info['count']) |
536 | 537 | |
537 | self.assertEqual('x86_64', info['raw_arch_string']) | |
538 | ||
539 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
540 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
541 | ||
542 | self.assertEqual('256 KB', info['l2_cache_size']) | |
543 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
538 | self.assertEqual('x86_64', info['arch_string_raw']) | |
539 | ||
540 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
541 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
542 | ||
543 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
544 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
544 | 545 | |
545 | 546 | self.assertEqual(7, info['stepping']) |
546 | 547 | self.assertEqual(42, info['model']) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 2 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'ppc64le' | |
11 | arch_string_raw = 'ppc64le' | |
12 | uname_string_raw = '' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
30 | 31 | @staticmethod |
31 | 32 | def ibm_pa_features(): |
32 | 33 | returncode = 0 |
33 | output = ''' | |
34 | output = r''' | |
34 | 35 | /proc/device-tree/cpus/PowerPC,POWER8@0/ibm,pa-features |
35 | 36 | 18 00 f6 3f c7 c0 80 f0 80 00 00 00 00 00 00 00...?............ |
36 | 37 | 00 00 80 00 80 00 80 00 80 00 .......... |
41 | 42 | @staticmethod |
42 | 43 | def cat_proc_cpuinfo(): |
43 | 44 | returncode = 0 |
44 | output = ''' | |
45 | output = r''' | |
45 | 46 | processor : 0 |
46 | 47 | cpu : POWER7 (raw), altivec supported |
47 | 48 | clock : 1000.000000MHz |
63 | 64 | @staticmethod |
64 | 65 | def dmesg_a(): |
65 | 66 | returncode = 0 |
66 | output = ''' | |
67 | output = r''' | |
67 | 68 | [ 0.000000] Allocated 4718592 bytes for 2048 pacas at c00000000fb80000 |
68 | 69 | [ 0.000000] Using pSeries machine description |
69 | 70 | [ 0.000000] Page sizes from device-tree: |
388 | 389 | @staticmethod |
389 | 390 | def lscpu(): |
390 | 391 | returncode = 0 |
391 | output = ''' | |
392 | output = r''' | |
392 | 393 | Architecture: ppc64le |
393 | 394 | Byte Order: Little Endian |
394 | 395 | CPU(s): 2 |
430 | 431 | self.assertEqual(1, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
431 | 432 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
432 | 433 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
433 | self.assertEqual(14, len(cpuinfo._get_cpu_info_internal())) | |
434 | self.assertEqual(15, len(cpuinfo._get_cpu_info_internal())) | |
434 | 435 | |
435 | 436 | def test_get_cpu_info_from_lscpu(self): |
436 | 437 | info = cpuinfo._get_cpu_info_from_lscpu() |
437 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
438 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
438 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
439 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
439 | 440 | self.assertEqual(2, len(info)) |
440 | 441 | |
441 | 442 | def test_get_cpu_info_from_ibm_pa_features(self): |
448 | 449 | def test_get_cpu_info_from_proc_cpuinfo(self): |
449 | 450 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
450 | 451 | |
451 | self.assertEqual('POWER7 (raw), altivec supported', info['brand']) | |
452 | self.assertEqual('1.0000 GHz', info['hz_advertised']) | |
453 | self.assertEqual('1.0000 GHz', info['hz_actual']) | |
454 | self.assertEqual((1000000000, 0), info['hz_advertised_raw']) | |
455 | self.assertEqual((1000000000, 0), info['hz_actual_raw']) | |
452 | self.assertEqual('POWER7 (raw), altivec supported', info['brand_raw']) | |
453 | self.assertEqual('1.0000 GHz', info['hz_advertised_friendly']) | |
454 | self.assertEqual('1.0000 GHz', info['hz_actual_friendly']) | |
455 | self.assertEqual((1000000000, 0), info['hz_advertised']) | |
456 | self.assertEqual((1000000000, 0), info['hz_actual']) | |
456 | 457 | |
457 | 458 | def test_all(self): |
458 | 459 | info = cpuinfo._get_cpu_info_internal() |
459 | 460 | |
460 | self.assertEqual('POWER7 (raw), altivec supported', info['brand']) | |
461 | self.assertEqual('1.0000 GHz', info['hz_advertised']) | |
462 | self.assertEqual('1.0000 GHz', info['hz_actual']) | |
463 | self.assertEqual((1000000000, 0), info['hz_advertised_raw']) | |
464 | self.assertEqual((1000000000, 0), info['hz_actual_raw']) | |
461 | self.assertEqual('POWER7 (raw), altivec supported', info['brand_raw']) | |
462 | self.assertEqual('1.0000 GHz', info['hz_advertised_friendly']) | |
463 | self.assertEqual('1.0000 GHz', info['hz_actual_friendly']) | |
464 | self.assertEqual((1000000000, 0), info['hz_advertised']) | |
465 | self.assertEqual((1000000000, 0), info['hz_actual']) | |
465 | 466 | self.assertEqual('PPC_64', info['arch']) |
466 | 467 | self.assertEqual(64, info['bits']) |
467 | 468 | self.assertEqual(2, info['count']) |
468 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
469 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
470 | self.assertEqual('ppc64le', info['raw_arch_string']) | |
469 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
470 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
471 | self.assertEqual('ppc64le', info['arch_string_raw']) | |
471 | 472 | self.assertEqual( |
472 | 473 | ['dabr', 'dabrx', 'dsisr', 'fpu', 'lp', 'mmu', 'pp', 'rislb', 'run', 'slb', 'sprg3'], |
473 | 474 | info['flags'] |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
18 | 19 | @staticmethod |
19 | 20 | def cat_proc_cpuinfo(): |
20 | 21 | returncode = 0 |
21 | output = ''' | |
22 | output = r''' | |
22 | 23 | processor : 0 |
23 | 24 | vendor_id : GenuineIntel |
24 | 25 | cpu family : 6 |
74 | 75 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
75 | 76 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
76 | 77 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
77 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
78 | self.assertEqual(18, len(cpuinfo._get_cpu_info_internal())) | |
78 | 79 | |
79 | 80 | def test_get_cpu_info_from_proc_cpuinfo(self): |
80 | 81 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
81 | 82 | |
82 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
83 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
84 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
85 | self.assertEqual('2.9283 GHz', info['hz_actual']) | |
86 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
87 | self.assertEqual((2928283000, 0), info['hz_actual_raw']) | |
83 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
84 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
85 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
86 | self.assertEqual('2.9283 GHz', info['hz_actual_friendly']) | |
87 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
88 | self.assertEqual((2928283000, 0), info['hz_actual']) | |
88 | 89 | |
89 | self.assertEqual('6144 KB', info['l3_cache_size']) | |
90 | self.assertEqual(6144 * 1024, info['l3_cache_size']) | |
90 | 91 | |
91 | 92 | self.assertEqual(5, info['stepping']) |
92 | 93 | self.assertEqual(30, info['model']) |
103 | 104 | def test_all(self): |
104 | 105 | info = cpuinfo._get_cpu_info_internal() |
105 | 106 | |
106 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
107 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
108 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
109 | self.assertEqual('2.9283 GHz', info['hz_actual']) | |
110 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
111 | self.assertEqual((2928283000, 0), info['hz_actual_raw']) | |
107 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
108 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
109 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
110 | self.assertEqual('2.9283 GHz', info['hz_actual_friendly']) | |
111 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
112 | self.assertEqual((2928283000, 0), info['hz_actual']) | |
112 | 113 | self.assertEqual('X86_64', info['arch']) |
113 | 114 | self.assertEqual(64, info['bits']) |
114 | 115 | self.assertEqual(1, info['count']) |
115 | 116 | |
116 | self.assertEqual('x86_64', info['raw_arch_string']) | |
117 | self.assertEqual('x86_64', info['arch_string_raw']) | |
117 | 118 | |
118 | self.assertEqual('6144 KB', info['l3_cache_size']) | |
119 | self.assertEqual(6144 * 1024, info['l3_cache_size']) | |
119 | 120 | |
120 | 121 | self.assertEqual(5, info['stepping']) |
121 | 122 | self.assertEqual(30, info['model']) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 2 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'ppc64le' | |
11 | arch_string_raw = 'ppc64le' | |
12 | uname_string_raw = '' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
30 | 31 | @staticmethod |
31 | 32 | def ibm_pa_features(): |
32 | 33 | returncode = 0 |
33 | output = ''' | |
34 | output = r''' | |
34 | 35 | /proc/device-tree/cpus/PowerPC,POWER7@1/ibm,pa-features 3ff60006 c08000c7 |
35 | 36 | |
36 | 37 | ''' |
39 | 40 | @staticmethod |
40 | 41 | def cat_proc_cpuinfo(): |
41 | 42 | returncode = 0 |
42 | output = ''' | |
43 | output = r''' | |
43 | 44 | processor : 0 |
44 | 45 | cpu : POWER8E (raw), altivec supported |
45 | 46 | clock : 3425.000000MHz |
59 | 60 | @staticmethod |
60 | 61 | def dmesg_a(): |
61 | 62 | returncode = 0 |
62 | output = ''' | |
63 | output = r''' | |
63 | 64 | [ 0.000000] Allocated 2359296 bytes for 1024 pacas at c00000000fdc0000 |
64 | 65 | [ 0.000000] Using pSeries machine description |
65 | 66 | [ 0.000000] Page sizes from device-tree: |
319 | 320 | @staticmethod |
320 | 321 | def lscpu(): |
321 | 322 | returncode = 0 |
322 | output = ''' | |
323 | output = r''' | |
323 | 324 | Architecture: ppc64le |
324 | 325 | Byte Order: Little Endian |
325 | 326 | CPU(s): 2 |
363 | 364 | self.assertEqual(1, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
364 | 365 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
365 | 366 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
366 | self.assertEqual(14, len(cpuinfo._get_cpu_info_internal())) | |
367 | self.assertEqual(15, len(cpuinfo._get_cpu_info_internal())) | |
367 | 368 | |
368 | 369 | def test_get_cpu_info_from_lscpu(self): |
369 | 370 | info = cpuinfo._get_cpu_info_from_lscpu() |
370 | 371 | |
371 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
372 | self.assertEqual('64 KB', info['l1_data_cache_size']) | |
373 | ||
374 | self.assertEqual('POWER8E (raw), altivec supported', info['brand']) | |
372 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
373 | self.assertEqual(64 * 1024, info['l1_data_cache_size']) | |
374 | ||
375 | self.assertEqual('POWER8E (raw), altivec supported', info['brand_raw']) | |
375 | 376 | |
376 | 377 | def test_get_cpu_info_from_ibm_pa_features(self): |
377 | 378 | info = cpuinfo._get_cpu_info_from_ibm_pa_features() |
383 | 384 | def test_get_cpu_info_from_proc_cpuinfo(self): |
384 | 385 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
385 | 386 | |
386 | self.assertEqual('POWER8E (raw), altivec supported', info['brand']) | |
387 | self.assertEqual('3.4250 GHz', info['hz_advertised']) | |
388 | self.assertEqual('3.4250 GHz', info['hz_actual']) | |
389 | self.assertEqual((3425000000, 0), info['hz_advertised_raw']) | |
390 | self.assertEqual((3425000000, 0), info['hz_actual_raw']) | |
387 | self.assertEqual('POWER8E (raw), altivec supported', info['brand_raw']) | |
388 | self.assertEqual('3.4250 GHz', info['hz_advertised_friendly']) | |
389 | self.assertEqual('3.4250 GHz', info['hz_actual_friendly']) | |
390 | self.assertEqual((3425000000, 0), info['hz_advertised']) | |
391 | self.assertEqual((3425000000, 0), info['hz_actual']) | |
391 | 392 | |
392 | 393 | def test_all(self): |
393 | 394 | info = cpuinfo._get_cpu_info_internal() |
394 | 395 | |
395 | self.assertEqual('POWER8E (raw), altivec supported', info['brand']) | |
396 | self.assertEqual('3.4250 GHz', info['hz_advertised']) | |
397 | self.assertEqual('3.4250 GHz', info['hz_actual']) | |
398 | self.assertEqual((3425000000, 0), info['hz_advertised_raw']) | |
399 | self.assertEqual((3425000000, 0), info['hz_actual_raw']) | |
396 | self.assertEqual('POWER8E (raw), altivec supported', info['brand_raw']) | |
397 | self.assertEqual('3.4250 GHz', info['hz_advertised_friendly']) | |
398 | self.assertEqual('3.4250 GHz', info['hz_actual_friendly']) | |
399 | self.assertEqual((3425000000, 0), info['hz_advertised']) | |
400 | self.assertEqual((3425000000, 0), info['hz_actual']) | |
400 | 401 | self.assertEqual('PPC_64', info['arch']) |
401 | 402 | self.assertEqual(64, info['bits']) |
402 | 403 | self.assertEqual(2, info['count']) |
403 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
404 | self.assertEqual('64 KB', info['l1_data_cache_size']) | |
405 | self.assertEqual('ppc64le', info['raw_arch_string']) | |
404 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
405 | self.assertEqual(64 * 1024, info['l1_data_cache_size']) | |
406 | self.assertEqual('ppc64le', info['arch_string_raw']) | |
406 | 407 | self.assertEqual( |
407 | 408 | ['dss_2.02', 'dss_2.05', 'dss_2.06', 'fpu', 'lsd_in_dscr', 'ppr', 'slb', 'sso_2.06', 'ugr_in_dscr'], |
408 | 409 | info['flags'] |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 2 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
26 | 27 | @staticmethod |
27 | 28 | def cat_proc_cpuinfo(): |
28 | 29 | returncode = 0 |
29 | output = ''' | |
30 | output = r''' | |
30 | 31 | processor : 0 |
31 | 32 | vendor_id : GenuineIntel |
32 | 33 | cpu family : 6 |
84 | 85 | @staticmethod |
85 | 86 | def dmesg_a(): |
86 | 87 | returncode = 0 |
87 | output = ''' | |
88 | output = r''' | |
88 | 89 | [ 0.000000] Initializing cgroup subsys cpuset |
89 | 90 | [ 0.000000] Initializing cgroup subsys cpu |
90 | 91 | [ 0.000000] Initializing cgroup subsys cpuacct |
408 | 409 | @staticmethod |
409 | 410 | def lscpu(): |
410 | 411 | returncode = 0 |
411 | output = ''' | |
412 | output = r''' | |
412 | 413 | Architecture: x86_64 |
413 | 414 | CPU op-mode(s): 32-bit, 64-bit |
414 | 415 | Byte Order: Little Endian |
460 | 461 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
461 | 462 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
462 | 463 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
463 | self.assertEqual(20, len(cpuinfo._get_cpu_info_internal())) | |
464 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
464 | 465 | |
465 | 466 | def test_get_cpu_info_from_lscpu(self): |
466 | 467 | info = cpuinfo._get_cpu_info_from_lscpu() |
467 | 468 | |
468 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
469 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
470 | self.assertEqual('2.7937 GHz', info['hz_advertised']) | |
471 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
472 | self.assertEqual((2793652000, 0), info['hz_advertised_raw']) | |
473 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
469 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
470 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
471 | self.assertEqual('2.7937 GHz', info['hz_advertised_friendly']) | |
472 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
473 | self.assertEqual((2793652000, 0), info['hz_advertised']) | |
474 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
474 | 475 | |
475 | 476 | self.assertEqual(7, info['stepping']) |
476 | 477 | self.assertEqual(42, info['model']) |
477 | 478 | self.assertEqual(6, info['family']) |
478 | 479 | |
479 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
480 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
481 | ||
482 | self.assertEqual('256 KB', info['l2_cache_size']) | |
483 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
480 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
481 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
482 | ||
483 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
484 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
484 | 485 | |
485 | 486 | def test_get_cpu_info_from_dmesg(self): |
486 | 487 | info = cpuinfo._get_cpu_info_from_dmesg() |
487 | 488 | |
488 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
489 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
490 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
491 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
492 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
489 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
490 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
491 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
492 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
493 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
493 | 494 | |
494 | 495 | self.assertEqual(7, info['stepping']) |
495 | 496 | self.assertEqual(42, info['model']) |
499 | 500 | def test_get_cpu_info_from_proc_cpuinfo(self): |
500 | 501 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
501 | 502 | |
502 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
503 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
504 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
505 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
506 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
507 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
508 | ||
509 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
503 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
504 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
505 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
506 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
507 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
508 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
509 | ||
510 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
510 | 511 | |
511 | 512 | self.assertEqual(7, info['stepping']) |
512 | 513 | self.assertEqual(42, info['model']) |
525 | 526 | def test_all(self): |
526 | 527 | info = cpuinfo._get_cpu_info_internal() |
527 | 528 | |
528 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
529 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
530 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
531 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
532 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
533 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
529 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
530 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
531 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
532 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
533 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
534 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
534 | 535 | self.assertEqual('X86_64', info['arch']) |
535 | 536 | self.assertEqual(64, info['bits']) |
536 | 537 | self.assertEqual(2, info['count']) |
537 | 538 | |
538 | self.assertEqual('x86_64', info['raw_arch_string']) | |
539 | ||
540 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
541 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
542 | ||
543 | self.assertEqual('256 KB', info['l2_cache_size']) | |
544 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
539 | self.assertEqual('x86_64', info['arch_string_raw']) | |
540 | ||
541 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
542 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
543 | ||
544 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
545 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
545 | 546 | |
546 | 547 | self.assertEqual(7, info['stepping']) |
547 | 548 | self.assertEqual(42, info['model']) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource(object): | |
8 | bits = '64bit' | |
9 | cpu_count = 8 | |
10 | is_windows = False | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
13 | can_cpuid = False | |
14 | ||
15 | @staticmethod | |
16 | def has_proc_cpuinfo(): | |
17 | return True | |
18 | ||
19 | @staticmethod | |
20 | def has_lscpu(): | |
21 | return True | |
22 | ||
23 | @staticmethod | |
24 | def has_sestatus(): | |
25 | return True | |
26 | ||
27 | @staticmethod | |
28 | def cat_proc_cpuinfo(): | |
29 | returncode = 0 | |
30 | output = r''' | |
31 | processor : 0 | |
32 | vendor_id : AuthenticAMD | |
33 | cpu family : 23 | |
34 | model : 8 | |
35 | model name : AMD Ryzen 7 2700X Eight-Core Processor | |
36 | stepping : 2 | |
37 | microcode : 0x6000626 | |
38 | cpu MHz : 3693.060 | |
39 | cache size : 512 KB | |
40 | physical id : 0 | |
41 | siblings : 8 | |
42 | core id : 0 | |
43 | cpu cores : 8 | |
44 | apicid : 0 | |
45 | initial apicid : 0 | |
46 | fpu : yes | |
47 | fpu_exception : yes | |
48 | cpuid level : 13 | |
49 | wp : yes | |
50 | flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch cpb ssbd vmmcall fsgsbase avx2 rdseed clflushopt arat | |
51 | bugs : fxsave_leak sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass | |
52 | bogomips : 7386.12 | |
53 | TLB size : 2560 4K pages | |
54 | clflush size : 64 | |
55 | cache_alignment : 64 | |
56 | address sizes : 48 bits physical, 48 bits virtual | |
57 | power management: | |
58 | ||
59 | ||
60 | ''' | |
61 | return returncode, output | |
62 | ||
63 | @staticmethod | |
64 | def lscpu(): | |
65 | returncode = 0 | |
66 | output = r''' | |
67 | Architecture: x86_64 | |
68 | CPU op-mode(s): 32-bit, 64-bit | |
69 | Byte Order: Little Endian | |
70 | CPU(s): 8 | |
71 | On-line CPU(s) list: 0-7 | |
72 | Thread(s) per core: 1 | |
73 | Core(s) per socket: 8 | |
74 | Socket(s): 1 | |
75 | NUMA node(s): 1 | |
76 | Vendor ID: AuthenticAMD | |
77 | CPU family: 23 | |
78 | Model: 8 | |
79 | Model name: AMD Ryzen 7 2700X Eight-Core Processor | |
80 | Stepping: 2 | |
81 | CPU MHz: 3693.060 | |
82 | BogoMIPS: 7386.12 | |
83 | Hypervisor vendor: KVM | |
84 | Virtualization type: full | |
85 | L1d cache: 32K | |
86 | L1i cache: 64K | |
87 | L2 cache: 512K | |
88 | L3 cache: 16384K | |
89 | NUMA node0 CPU(s): 0-7 | |
90 | Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch cpb ssbd vmmcall fsgsbase avx2 rdseed clflushopt arat | |
91 | ||
92 | ||
93 | ''' | |
94 | return returncode, output | |
95 | ||
96 | @staticmethod | |
97 | def sestatus_b(): | |
98 | returncode = 0 | |
99 | output = r''' | |
100 | SELinux status: enabled | |
101 | SELinuxfs mount: /sys/fs/selinux | |
102 | SELinux root directory: /etc/selinux | |
103 | Loaded policy name: targeted | |
104 | Current mode: enforcing | |
105 | Mode from config file: enforcing | |
106 | Policy MLS status: enabled | |
107 | Policy deny_unknown status: allowed | |
108 | Memory protection checking: actual (secure) | |
109 | Max kernel policy version: 31 | |
110 | ||
111 | Policy booleans: | |
112 | abrt_anon_write off | |
113 | abrt_handle_event off | |
114 | abrt_upload_watch_anon_write on | |
115 | antivirus_can_scan_system off | |
116 | antivirus_use_jit off | |
117 | auditadm_exec_content on | |
118 | authlogin_nsswitch_use_ldap off | |
119 | authlogin_radius off | |
120 | authlogin_yubikey off | |
121 | awstats_purge_apache_log_files off | |
122 | boinc_execmem on | |
123 | cdrecord_read_content off | |
124 | cluster_can_network_connect off | |
125 | cluster_manage_all_files off | |
126 | cluster_use_execmem off | |
127 | cobbler_anon_write off | |
128 | cobbler_can_network_connect off | |
129 | cobbler_use_cifs off | |
130 | cobbler_use_nfs off | |
131 | collectd_tcp_network_connect off | |
132 | colord_use_nfs off | |
133 | condor_tcp_network_connect off | |
134 | conman_can_network off | |
135 | conman_use_nfs off | |
136 | cron_can_relabel off | |
137 | cron_system_cronjob_use_shares off | |
138 | cron_userdomain_transition on | |
139 | cups_execmem off | |
140 | cvs_read_shadow off | |
141 | daemons_dump_core off | |
142 | daemons_enable_cluster_mode off | |
143 | daemons_use_tcp_wrapper off | |
144 | daemons_use_tty off | |
145 | dbadm_exec_content on | |
146 | dbadm_manage_user_files off | |
147 | dbadm_read_user_files off | |
148 | deny_execmem off | |
149 | deny_ptrace off | |
150 | dhcpc_exec_iptables off | |
151 | dhcpd_use_ldap off | |
152 | domain_can_mmap_files off | |
153 | domain_can_write_kmsg off | |
154 | domain_fd_use on | |
155 | domain_kernel_load_modules off | |
156 | entropyd_use_audio on | |
157 | exim_can_connect_db off | |
158 | exim_manage_user_files off | |
159 | exim_read_user_files off | |
160 | fcron_crond off | |
161 | fenced_can_network_connect off | |
162 | fenced_can_ssh off | |
163 | fips_mode on | |
164 | ftpd_anon_write off | |
165 | ftpd_connect_all_unreserved off | |
166 | ftpd_connect_db off | |
167 | ftpd_full_access off | |
168 | ftpd_use_cifs off | |
169 | ftpd_use_fusefs off | |
170 | ftpd_use_nfs off | |
171 | ftpd_use_passive_mode off | |
172 | git_cgi_enable_homedirs off | |
173 | git_cgi_use_cifs off | |
174 | git_cgi_use_nfs off | |
175 | git_session_bind_all_unreserved_ports off | |
176 | git_session_users off | |
177 | git_system_enable_homedirs off | |
178 | git_system_use_cifs off | |
179 | git_system_use_nfs off | |
180 | gitosis_can_sendmail off | |
181 | glance_api_can_network off | |
182 | glance_use_execmem off | |
183 | glance_use_fusefs off | |
184 | global_ssp off | |
185 | gluster_anon_write off | |
186 | gluster_export_all_ro off | |
187 | gluster_export_all_rw on | |
188 | gluster_use_execmem off | |
189 | gpg_web_anon_write off | |
190 | gssd_read_tmp on | |
191 | guest_exec_content on | |
192 | haproxy_connect_any off | |
193 | httpd_anon_write off | |
194 | httpd_builtin_scripting on | |
195 | httpd_can_check_spam off | |
196 | httpd_can_connect_ftp off | |
197 | httpd_can_connect_ldap off | |
198 | httpd_can_connect_mythtv off | |
199 | httpd_can_connect_zabbix off | |
200 | httpd_can_network_connect off | |
201 | httpd_can_network_connect_cobbler off | |
202 | httpd_can_network_connect_db off | |
203 | httpd_can_network_memcache off | |
204 | httpd_can_network_relay off | |
205 | httpd_can_sendmail off | |
206 | httpd_dbus_avahi off | |
207 | httpd_dbus_sssd off | |
208 | httpd_dontaudit_search_dirs off | |
209 | httpd_enable_cgi on | |
210 | httpd_enable_ftp_server off | |
211 | httpd_enable_homedirs off | |
212 | httpd_execmem off | |
213 | httpd_graceful_shutdown off | |
214 | httpd_manage_ipa off | |
215 | httpd_mod_auth_ntlm_winbind off | |
216 | httpd_mod_auth_pam off | |
217 | httpd_read_user_content off | |
218 | httpd_run_ipa off | |
219 | httpd_run_preupgrade off | |
220 | httpd_run_stickshift off | |
221 | httpd_serve_cobbler_files off | |
222 | httpd_setrlimit off | |
223 | httpd_ssi_exec off | |
224 | httpd_sys_script_anon_write off | |
225 | httpd_tmp_exec off | |
226 | httpd_tty_comm off | |
227 | httpd_unified off | |
228 | httpd_use_cifs off | |
229 | httpd_use_fusefs off | |
230 | httpd_use_gpg off | |
231 | httpd_use_nfs off | |
232 | httpd_use_openstack off | |
233 | httpd_use_sasl off | |
234 | httpd_verify_dns off | |
235 | icecast_use_any_tcp_ports off | |
236 | irc_use_any_tcp_ports off | |
237 | irssi_use_full_network off | |
238 | kdumpgui_run_bootloader off | |
239 | keepalived_connect_any off | |
240 | kerberos_enabled on | |
241 | ksmtuned_use_cifs off | |
242 | ksmtuned_use_nfs off | |
243 | logadm_exec_content on | |
244 | logging_syslogd_can_sendmail off | |
245 | logging_syslogd_run_nagios_plugins off | |
246 | logging_syslogd_use_tty on | |
247 | login_console_enabled on | |
248 | logrotate_read_inside_containers off | |
249 | logrotate_use_nfs off | |
250 | logwatch_can_network_connect_mail off | |
251 | lsmd_plugin_connect_any off | |
252 | mailman_use_fusefs off | |
253 | mcelog_client off | |
254 | mcelog_exec_scripts on | |
255 | mcelog_foreground off | |
256 | mcelog_server off | |
257 | minidlna_read_generic_user_content off | |
258 | mmap_low_allowed off | |
259 | mock_enable_homedirs off | |
260 | mount_anyfile on | |
261 | mozilla_plugin_bind_unreserved_ports off | |
262 | mozilla_plugin_can_network_connect on | |
263 | mozilla_plugin_use_bluejeans off | |
264 | mozilla_plugin_use_gps off | |
265 | mozilla_plugin_use_spice off | |
266 | mozilla_read_content off | |
267 | mpd_enable_homedirs off | |
268 | mpd_use_cifs off | |
269 | mpd_use_nfs off | |
270 | mplayer_execstack off | |
271 | mysql_connect_any off | |
272 | mysql_connect_http off | |
273 | nagios_run_pnp4nagios off | |
274 | nagios_run_sudo off | |
275 | nagios_use_nfs off | |
276 | named_tcp_bind_http_port off | |
277 | named_write_master_zones off | |
278 | neutron_can_network off | |
279 | nfs_export_all_ro on | |
280 | nfs_export_all_rw on | |
281 | nfsd_anon_write off | |
282 | nis_enabled off | |
283 | nscd_use_shm on | |
284 | openshift_use_nfs off | |
285 | openvpn_can_network_connect on | |
286 | openvpn_enable_homedirs on | |
287 | openvpn_run_unconfined off | |
288 | pcp_bind_all_unreserved_ports off | |
289 | pcp_read_generic_logs off | |
290 | pdns_can_network_connect_db off | |
291 | piranha_lvs_can_network_connect off | |
292 | polipo_connect_all_unreserved off | |
293 | polipo_session_bind_all_unreserved_ports off | |
294 | polipo_session_users off | |
295 | polipo_use_cifs off | |
296 | polipo_use_nfs off | |
297 | polyinstantiation_enabled off | |
298 | postfix_local_write_mail_spool on | |
299 | postgresql_can_rsync off | |
300 | postgresql_selinux_transmit_client_label off | |
301 | postgresql_selinux_unconfined_dbadm on | |
302 | postgresql_selinux_users_ddl on | |
303 | pppd_can_insmod off | |
304 | pppd_for_user off | |
305 | privoxy_connect_any on | |
306 | prosody_bind_http_port off | |
307 | puppetagent_manage_all_files off | |
308 | puppetmaster_use_db off | |
309 | racoon_read_shadow off | |
310 | radius_use_jit off | |
311 | redis_enable_notify off | |
312 | rpcd_use_fusefs off | |
313 | rsync_anon_write off | |
314 | rsync_client off | |
315 | rsync_export_all_ro off | |
316 | rsync_full_access off | |
317 | samba_create_home_dirs off | |
318 | samba_domain_controller off | |
319 | samba_enable_home_dirs off | |
320 | samba_export_all_ro off | |
321 | samba_export_all_rw off | |
322 | samba_load_libgfapi off | |
323 | samba_portmapper off | |
324 | samba_run_unconfined off | |
325 | samba_share_fusefs off | |
326 | samba_share_nfs off | |
327 | sanlock_enable_home_dirs off | |
328 | sanlock_use_fusefs off | |
329 | sanlock_use_nfs off | |
330 | sanlock_use_samba off | |
331 | saslauthd_read_shadow off | |
332 | secadm_exec_content on | |
333 | secure_mode off | |
334 | secure_mode_insmod off | |
335 | secure_mode_policyload off | |
336 | selinuxuser_direct_dri_enabled on | |
337 | selinuxuser_execheap off | |
338 | selinuxuser_execmod on | |
339 | selinuxuser_execstack on | |
340 | selinuxuser_mysql_connect_enabled off | |
341 | selinuxuser_ping on | |
342 | selinuxuser_postgresql_connect_enabled off | |
343 | selinuxuser_rw_noexattrfile on | |
344 | selinuxuser_share_music off | |
345 | selinuxuser_tcp_server off | |
346 | selinuxuser_udp_server off | |
347 | selinuxuser_use_ssh_chroot off | |
348 | sge_domain_can_network_connect off | |
349 | sge_use_nfs off | |
350 | smartmon_3ware off | |
351 | smbd_anon_write off | |
352 | spamassassin_can_network off | |
353 | spamd_enable_home_dirs on | |
354 | spamd_update_can_network off | |
355 | squid_connect_any on | |
356 | squid_use_tproxy off | |
357 | ssh_chroot_rw_homedirs off | |
358 | ssh_keysign off | |
359 | ssh_sysadm_login off | |
360 | ssh_use_tcpd off | |
361 | sslh_can_bind_any_port off | |
362 | sslh_can_connect_any_port off | |
363 | staff_exec_content on | |
364 | staff_use_svirt off | |
365 | swift_can_network off | |
366 | sysadm_exec_content on | |
367 | telepathy_connect_all_ports off | |
368 | telepathy_tcp_connect_generic_network_ports on | |
369 | tftp_anon_write off | |
370 | tftp_home_dir off | |
371 | tmpreaper_use_cifs off | |
372 | tmpreaper_use_nfs off | |
373 | tmpreaper_use_samba off | |
374 | tomcat_can_network_connect_db off | |
375 | tomcat_read_rpm_db off | |
376 | tomcat_use_execmem off | |
377 | tor_bind_all_unreserved_ports off | |
378 | tor_can_network_relay off | |
379 | tor_can_onion_services off | |
380 | unconfined_chrome_sandbox_transition on | |
381 | unconfined_login on | |
382 | unconfined_mozilla_plugin_transition on | |
383 | unprivuser_use_svirt off | |
384 | use_ecryptfs_home_dirs off | |
385 | use_fusefs_home_dirs off | |
386 | use_lpd_server off | |
387 | use_nfs_home_dirs off | |
388 | use_samba_home_dirs off | |
389 | use_virtualbox off | |
390 | user_exec_content on | |
391 | varnishd_connect_any off | |
392 | virt_read_qemu_ga_data off | |
393 | virt_rw_qemu_ga_data off | |
394 | virt_sandbox_share_apache_content off | |
395 | virt_sandbox_use_all_caps on | |
396 | virt_sandbox_use_audit on | |
397 | virt_sandbox_use_fusefs off | |
398 | virt_sandbox_use_mknod off | |
399 | virt_sandbox_use_netlink off | |
400 | virt_sandbox_use_sys_admin off | |
401 | virt_transition_userdomain off | |
402 | virt_use_comm off | |
403 | virt_use_execmem off | |
404 | virt_use_fusefs off | |
405 | virt_use_glusterd off | |
406 | virt_use_nfs off | |
407 | virt_use_pcscd off | |
408 | virt_use_rawip off | |
409 | virt_use_samba off | |
410 | virt_use_sanlock off | |
411 | virt_use_usb on | |
412 | virt_use_xserver off | |
413 | webadm_manage_user_files off | |
414 | webadm_read_user_files off | |
415 | wine_mmap_zero_ignore off | |
416 | xdm_bind_vnc_tcp_port off | |
417 | xdm_exec_bootloader off | |
418 | xdm_sysadm_login off | |
419 | xdm_write_home off | |
420 | xen_use_nfs off | |
421 | xend_run_blktap on | |
422 | xend_run_qemu on | |
423 | xguest_connect_network on | |
424 | xguest_exec_content on | |
425 | xguest_mount_media on | |
426 | xguest_use_bluetooth on | |
427 | xserver_clients_write_xshm off | |
428 | xserver_execmem off | |
429 | xserver_object_manager off | |
430 | zabbix_can_network off | |
431 | zabbix_run_sudo off | |
432 | zarafa_setrlimit off | |
433 | zebra_write_config off | |
434 | zoneminder_anon_write off | |
435 | zoneminder_run_sudo off | |
436 | ''' | |
437 | return returncode, output | |
438 | ||
439 | ||
440 | class Test_Linux_Fedora_29_X86_64_Ryzen_7(unittest.TestCase): | |
441 | def setUp(self): | |
442 | helpers.backup_data_source(cpuinfo) | |
443 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) | |
444 | ||
445 | def tearDown(self): | |
446 | helpers.restore_data_source(cpuinfo) | |
447 | ||
448 | ''' | |
449 | Make sure calls return the expected number of fields. | |
450 | ''' | |
451 | def test_returns(self): | |
452 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_registry())) | |
453 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpufreq_info())) | |
454 | self.assertEqual(14, len(cpuinfo._get_cpu_info_from_lscpu())) | |
455 | self.assertEqual(11, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) | |
456 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) | |
457 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_kstat())) | |
458 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_dmesg())) | |
459 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) | |
460 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) | |
461 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) | |
462 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
463 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
464 | ||
465 | def test_get_cpu_info_from_lscpu(self): | |
466 | info = cpuinfo._get_cpu_info_from_lscpu() | |
467 | ||
468 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
469 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
470 | self.assertEqual('3.6931 GHz', info['hz_advertised_friendly']) | |
471 | self.assertEqual('3.6931 GHz', info['hz_actual_friendly']) | |
472 | self.assertEqual((3693060000, 0), info['hz_advertised']) | |
473 | self.assertEqual((3693060000, 0), info['hz_actual']) | |
474 | ||
475 | self.assertEqual(2, info['stepping']) | |
476 | self.assertEqual(8, info['model']) | |
477 | self.assertEqual(23, info['family']) | |
478 | ||
479 | self.assertEqual(64 * 1024, info['l1_instruction_cache_size']) | |
480 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
481 | self.assertEqual(512 * 1024, info['l2_cache_size']) | |
482 | self.assertEqual(16384 * 1024, info['l3_cache_size']) | |
483 | ||
484 | self.assertEqual( | |
485 | ['3dnowprefetch', 'abm', 'aes', 'apic', 'arat', 'avx', 'avx2', | |
486 | 'clflush', 'clflushopt', 'cmov', 'cmp_legacy', 'constant_tsc', | |
487 | 'cpb', 'cpuid', 'cr8_legacy', 'cx16', 'cx8', 'de', 'extd_apicid', | |
488 | 'fpu', 'fsgsbase', 'fxsr', 'fxsr_opt', 'ht', 'hypervisor', | |
489 | 'lahf_lm', 'lm', 'mca', 'mce', 'misalignsse', 'mmx', 'mmxext', | |
490 | 'movbe', 'msr', 'mtrr', 'nonstop_tsc', 'nopl', 'nx', 'pae', 'pat', | |
491 | 'pclmulqdq', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'rdrand', | |
492 | 'rdseed', 'rdtscp', 'rep_good', 'sep', 'ssbd', 'sse', 'sse2', | |
493 | 'sse4_1', 'sse4_2', 'sse4a', 'ssse3', 'syscall', 'tsc', | |
494 | 'tsc_known_freq', 'vme', 'vmmcall', 'x2apic', 'xsave'] | |
495 | , | |
496 | info['flags'] | |
497 | ) | |
498 | ||
499 | def test_get_cpu_info_from_proc_cpuinfo(self): | |
500 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() | |
501 | ||
502 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
503 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
504 | self.assertEqual('3.6931 GHz', info['hz_advertised_friendly']) | |
505 | self.assertEqual('3.6931 GHz', info['hz_actual_friendly']) | |
506 | self.assertEqual((3693060000, 0), info['hz_advertised']) | |
507 | self.assertEqual((3693060000, 0), info['hz_actual']) | |
508 | ||
509 | # FIXME: This is l2 cache size not l3 cache size | |
510 | self.assertEqual(512 * 1024, info['l3_cache_size']) | |
511 | ||
512 | self.assertEqual(2, info['stepping']) | |
513 | self.assertEqual(8, info['model']) | |
514 | self.assertEqual(23, info['family']) | |
515 | self.assertEqual( | |
516 | ['3dnowprefetch', 'abm', 'aes', 'apic', 'arat', 'avx', 'avx2', | |
517 | 'clflush', 'clflushopt', 'cmov', 'cmp_legacy', 'constant_tsc', | |
518 | 'cpb', 'cpuid', 'cr8_legacy', 'cx16', 'cx8', 'de', 'extd_apicid', | |
519 | 'fpu', 'fsgsbase', 'fxsr', 'fxsr_opt', 'ht', 'hypervisor', | |
520 | 'lahf_lm', 'lm', 'mca', 'mce', 'misalignsse', 'mmx', 'mmxext', | |
521 | 'movbe', 'msr', 'mtrr', 'nonstop_tsc', 'nopl', 'nx', 'pae', | |
522 | 'pat', 'pclmulqdq', 'pge', 'pni', 'popcnt', 'pse', 'pse36', | |
523 | 'rdrand', 'rdseed', 'rdtscp', 'rep_good', 'sep', 'ssbd', 'sse', | |
524 | 'sse2', 'sse4_1', 'sse4_2', 'sse4a', 'ssse3', 'syscall', 'tsc', | |
525 | 'tsc_known_freq', 'vme', 'vmmcall', 'x2apic', 'xsave'] | |
526 | , | |
527 | info['flags'] | |
528 | ) | |
529 | ||
530 | def test_all(self): | |
531 | info = cpuinfo._get_cpu_info_internal() | |
532 | ||
533 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
534 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
535 | self.assertEqual('3.6931 GHz', info['hz_advertised_friendly']) | |
536 | self.assertEqual('3.6931 GHz', info['hz_actual_friendly']) | |
537 | self.assertEqual((3693060000, 0), info['hz_advertised']) | |
538 | self.assertEqual((3693060000, 0), info['hz_actual']) | |
539 | self.assertEqual('X86_64', info['arch']) | |
540 | self.assertEqual(64, info['bits']) | |
541 | self.assertEqual(8, info['count']) | |
542 | ||
543 | self.assertEqual('x86_64', info['arch_string_raw']) | |
544 | ||
545 | self.assertEqual(64 * 1024, info['l1_instruction_cache_size']) | |
546 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
547 | ||
548 | self.assertEqual(512 * 1024, info['l2_cache_size']) | |
549 | # FIXME: This is l2 cache size not l3 cache size | |
550 | # it is wrong in /proc/cpuinfo | |
551 | self.assertEqual(512 * 1024, info['l3_cache_size']) | |
552 | ||
553 | self.assertEqual(2, info['stepping']) | |
554 | self.assertEqual(8, info['model']) | |
555 | self.assertEqual(23, info['family']) | |
556 | self.assertEqual( | |
557 | ['3dnowprefetch', 'abm', 'aes', 'apic', 'arat', 'avx', 'avx2', | |
558 | 'clflush', 'clflushopt', 'cmov', 'cmp_legacy', 'constant_tsc', | |
559 | 'cpb', 'cpuid', 'cr8_legacy', 'cx16', 'cx8', 'de', 'extd_apicid', | |
560 | 'fpu', 'fsgsbase', 'fxsr', 'fxsr_opt', 'ht', 'hypervisor', | |
561 | 'lahf_lm', 'lm', 'mca', 'mce', 'misalignsse', 'mmx', 'mmxext', | |
562 | 'movbe', 'msr', 'mtrr', 'nonstop_tsc', 'nopl', 'nx', 'pae', 'pat', | |
563 | 'pclmulqdq', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'rdrand', | |
564 | 'rdseed', 'rdtscp', 'rep_good', 'sep', 'ssbd', 'sse', 'sse2', | |
565 | 'sse4_1', 'sse4_2', 'sse4a', 'ssse3', 'syscall', 'tsc', | |
566 | 'tsc_known_freq', 'vme', 'vmmcall', 'x2apic', 'xsave'] | |
567 | , | |
568 | info['flags'] | |
569 | ) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource(object): | |
8 | bits = '64bit' | |
9 | cpu_count = 4 | |
10 | is_windows = False | |
11 | arch_string_raw = 's390x' | |
12 | uname_string_raw = '' | |
13 | can_cpuid = False | |
14 | ||
15 | @staticmethod | |
16 | def has_proc_cpuinfo(): | |
17 | return True | |
18 | ||
19 | @staticmethod | |
20 | def has_dmesg(): | |
21 | return True | |
22 | ||
23 | @staticmethod | |
24 | def has_lscpu(): | |
25 | return True | |
26 | ||
27 | @staticmethod | |
28 | def cat_proc_cpuinfo(): | |
29 | returncode = 0 | |
30 | output = r''' | |
31 | vendor_id : IBM/S390 | |
32 | # processors : 4 | |
33 | bogomips per cpu: 2913.00 | |
34 | max thread id : 0 | |
35 | features : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te sie | |
36 | cache0 : level=1 type=Data scope=Private size=96K line_size=256 associativity=6 | |
37 | cache1 : level=1 type=Instruction scope=Private size=64K line_size=256 associativity=4 | |
38 | cache2 : level=2 type=Data scope=Private size=1024K line_size=256 associativity=8 | |
39 | cache3 : level=2 type=Instruction scope=Private size=1024K line_size=256 associativity=8 | |
40 | cache4 : level=3 type=Unified scope=Shared size=49152K line_size=256 associativity=12 | |
41 | cache5 : level=4 type=Unified scope=Shared size=393216K line_size=256 associativity=24 | |
42 | processor 0: version = FF, identification = 14C047, machine = 2827 | |
43 | processor 1: version = FF, identification = 14C047, machine = 2827 | |
44 | processor 2: version = FF, identification = 14C047, machine = 2827 | |
45 | processor 3: version = FF, identification = 14C047, machine = 2827 | |
46 | cpu number : 0 | |
47 | cpu MHz dynamic : 5504 | |
48 | cpu MHz static : 5504 | |
49 | cpu number : 1 | |
50 | cpu MHz dynamic : 5504 | |
51 | cpu MHz static : 5504 | |
52 | cpu number : 2 | |
53 | cpu MHz dynamic : 5504 | |
54 | cpu MHz static : 5504 | |
55 | cpu number : 3 | |
56 | cpu MHz dynamic : 5504 | |
57 | cpu MHz static : 5504 | |
58 | ||
59 | ||
60 | ''' | |
61 | return returncode, output | |
62 | ||
63 | @staticmethod | |
64 | def lscpu(): | |
65 | returncode = 0 | |
66 | output = r''' | |
67 | Architecture: s390x | |
68 | CPU op-mode(s): 32-bit, 64-bit | |
69 | Byte Order: Big Endian | |
70 | CPU(s): 4 | |
71 | On-line CPU(s) list: 0-3 | |
72 | Thread(s) per core: 1 | |
73 | Core(s) per socket: 1 | |
74 | Socket(s) per book: 1 | |
75 | Book(s) per drawer: 1 | |
76 | Drawer(s): 4 | |
77 | Vendor ID: IBM/S390 | |
78 | Machine type: 2827 | |
79 | CPU dynamic MHz: 5504 | |
80 | CPU static MHz: 5504 | |
81 | BogoMIPS: 2913.00 | |
82 | Hypervisor: z/VM 5.4.0 | |
83 | Hypervisor vendor: IBM | |
84 | Virtualization type: full | |
85 | Dispatching mode: horizontal | |
86 | L1d cache: 96K | |
87 | L1i cache: 64K | |
88 | L2d cache: 1024K | |
89 | L2i cache: 1024K | |
90 | L3 cache: 49152K | |
91 | L4 cache: 393216K | |
92 | Flags: esan3 zarch stfle msa ldisp eimm dfp etf3eh highgprs sie | |
93 | ||
94 | ||
95 | ''' | |
96 | return returncode, output | |
97 | ||
98 | @staticmethod | |
99 | def dmesg_a(): | |
100 | returncode = 0 | |
101 | output = r''' | |
102 | [623985.026158] 000003ffda1f9118 00e1526ff184ab35 00000000800008a0 000003ffda1f90f0 | |
103 | [623985.026161] 0000000080000740 0000000000000000 000002aa4b1cf0a0 000003ffaa476f30 | |
104 | [623985.026165] 000003ffaa428f58 000002aa4b1bf6b0 000003ffa9e22b9e 000003ffda1f8ee0 | |
105 | [623985.026175] User Code: 0000000080000828: c0f4ffffffc0 brcl 15,800007a8 | |
106 | [623985.026175] 000000008000082e: 0707 bcr 0,%r7 | |
107 | [623985.026175] #0000000080000830: a7f40001 brc 15,80000832 | |
108 | [623985.026175] >0000000080000834: 0707 bcr 0,%r7 | |
109 | [623985.026175] 0000000080000836: 0707 bcr 0,%r7 | |
110 | [623985.026175] 0000000080000838: eb7ff0380024 stmg %r7,%r15,56(%r15) | |
111 | [623985.026175] 000000008000083e: e3f0ff60ff71 lay %r15,-160(%r15) | |
112 | [623985.026175] 0000000080000844: b9040092 lgr %r9,%r2 | |
113 | [623985.026211] Last Breaking-Event-Address: | |
114 | [623985.026214] [<0000000080000830>] 0x80000830 | |
115 | [624418.306980] User process fault: interruption code 0038 ilc:3 in libstdc++.so.6.0.23[3ff9d000000+1b9000] | |
116 | [624418.306992] Failing address: 46726f6200005000 TEID: 46726f6200005800 | |
117 | [624418.306994] Fault in primary space mode while using user ASCE. | |
118 | [624418.306997] AS:0000000081d081c7 R3:0000000000000024 | |
119 | [624418.307003] CPU: 3 PID: 56744 Comm: try-catch-2.exe Not tainted 4.8.15-300.fc25.s390x #1 | |
120 | [624418.307005] Hardware name: IBM 2827 H43 400 (z/VM) | |
121 | [624418.307009] task: 00000000f74c1c80 task.stack: 00000000ab6f0000 | |
122 | [624418.307012] User PSW : 0705000180000000 000003ff9d0a7f58 | |
123 | [624418.307016] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
124 | [624418.307016] User GPRS: 0000000000000000 46726f6200005465 0000000080003528 000003ff9d1bba00 | |
125 | [624418.307024] 000003fff8278e88 000003fff8278dc0 000000008000187a fffffffffffffffd | |
126 | [624418.307028] 000003ff00000000 000003fff8278e88 0000000080003528 000003ff9d1bba00 | |
127 | [624418.307032] 0000000080003428 000003ff9d172658 000003ff9d0a7f32 000003fff8278d20 | |
128 | [624418.307050] User Code: 000003ff9d0a7f4a: e310a0000004 lg %r1,0(%r10) | |
129 | [624418.307050] 000003ff9d0a7f50: b904003b lgr %r3,%r11 | |
130 | [624418.307050] #000003ff9d0a7f54: b904002a lgr %r2,%r10 | |
131 | [624418.307050] >000003ff9d0a7f58: e31010200004 lg %r1,32(%r1) | |
132 | [624418.307050] 000003ff9d0a7f5e: a7590001 lghi %r5,1 | |
133 | [624418.307050] 000003ff9d0a7f62: 4140f0a0 la %r4,160(%r15) | |
134 | [624418.307050] 000003ff9d0a7f66: 0de1 basr %r14,%r1 | |
135 | [624418.307050] 000003ff9d0a7f68: ec280009007c cgij %r2,0,8,3ff9d0a7f7a | |
136 | [624418.307061] Last Breaking-Event-Address: | |
137 | [624418.307065] [<000003ff9d0a7f32>] 0x3ff9d0a7f32 | |
138 | [624418.806616] User process fault: interruption code 0038 ilc:3 in libstdc++.so.6.0.23[3ffac780000+1b9000] | |
139 | [624418.806627] Failing address: 5465737473756000 TEID: 5465737473756800 | |
140 | [624418.806629] Fault in primary space mode while using user ASCE. | |
141 | [624418.806633] AS:00000000a44441c7 R3:0000000000000024 | |
142 | [624418.806638] CPU: 3 PID: 56971 Comm: try-catch-9.exe Not tainted 4.8.15-300.fc25.s390x #1 | |
143 | [624418.806641] Hardware name: IBM 2827 H43 400 (z/VM) | |
144 | [624418.806644] task: 0000000001a9b900 task.stack: 0000000082968000 | |
145 | [624418.806647] User PSW : 0705000180000000 000003ffac827f58 | |
146 | [624418.806650] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
147 | [624418.806650] User GPRS: 0000000000000000 5465737473756974 00000000800032a4 000003ffac93ba00 | |
148 | [624418.806658] 000003ffdd4f8bb0 000003ffdd4f8ae8 0000000080001338 0000000000000000 | |
149 | [624418.806662] 000003ff00000000 000003ffdd4f8bb0 00000000800032a4 000003ffac93ba00 | |
150 | [624418.806666] 0000000087919e90 000003ffac8f2658 000003ffac827f32 000003ffdd4f8a48 | |
151 | [624418.806683] User Code: 000003ffac827f4a: e310a0000004 lg %r1,0(%r10) | |
152 | [624418.806683] 000003ffac827f50: b904003b lgr %r3,%r11 | |
153 | [624418.806683] #000003ffac827f54: b904002a lgr %r2,%r10 | |
154 | [624418.806683] >000003ffac827f58: e31010200004 lg %r1,32(%r1) | |
155 | [624418.806683] 000003ffac827f5e: a7590001 lghi %r5,1 | |
156 | [624418.806683] 000003ffac827f62: 4140f0a0 la %r4,160(%r15) | |
157 | [624418.806683] 000003ffac827f66: 0de1 basr %r14,%r1 | |
158 | [624418.806683] 000003ffac827f68: ec280009007c cgij %r2,0,8,3ffac827f7a | |
159 | [624418.806694] Last Breaking-Event-Address: | |
160 | [624418.806697] [<000003ffac827f32>] 0x3ffac827f32 | |
161 | [624457.542811] User process fault: interruption code 0038 ilc:3 in libstdc++.so.6.0.23[3ffbc080000+1b9000] | |
162 | [624457.542823] Failing address: 46726f6200005000 TEID: 46726f6200005800 | |
163 | [624457.542825] Fault in primary space mode while using user ASCE. | |
164 | [624457.542829] AS:0000000002e701c7 R3:0000000000000024 | |
165 | [624457.542834] CPU: 2 PID: 6763 Comm: try-catch-2.exe Not tainted 4.8.15-300.fc25.s390x #1 | |
166 | [624457.542837] Hardware name: IBM 2827 H43 400 (z/VM) | |
167 | [624457.542840] task: 00000000f7aa0000 task.stack: 0000000003530000 | |
168 | [624457.542844] User PSW : 0705000180000000 000003ffbc127f58 | |
169 | [624457.542847] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
170 | [624457.542847] User GPRS: 0000000000000000 46726f6200005465 0000000080003528 000003ffbc23ba00 | |
171 | [624457.542856] 000003ffc14f8dd8 000003ffc14f8d10 000000008000187a fffffffffffffffd | |
172 | [624457.542859] 000003ff00000000 000003ffc14f8dd8 0000000080003528 000003ffbc23ba00 | |
173 | [624457.542863] 0000000080003428 000003ffbc1f2658 000003ffbc127f32 000003ffc14f8c70 | |
174 | [624457.542882] User Code: 000003ffbc127f4a: e310a0000004 lg %r1,0(%r10) | |
175 | [624457.542882] 000003ffbc127f50: b904003b lgr %r3,%r11 | |
176 | [624457.542882] #000003ffbc127f54: b904002a lgr %r2,%r10 | |
177 | [624457.542882] >000003ffbc127f58: e31010200004 lg %r1,32(%r1) | |
178 | [624457.542882] 000003ffbc127f5e: a7590001 lghi %r5,1 | |
179 | [624457.542882] 000003ffbc127f62: 4140f0a0 la %r4,160(%r15) | |
180 | [624457.542882] 000003ffbc127f66: 0de1 basr %r14,%r1 | |
181 | [624457.542882] 000003ffbc127f68: ec280009007c cgij %r2,0,8,3ffbc127f7a | |
182 | [624457.542893] Last Breaking-Event-Address: | |
183 | [624457.542896] [<000003ffbc127f32>] 0x3ffbc127f32 | |
184 | [624458.013783] User process fault: interruption code 0038 ilc:3 in libstdc++.so.6.0.23[3ff94f00000+1b9000] | |
185 | [624458.013795] Failing address: 5465737473756000 TEID: 5465737473756800 | |
186 | [624458.013797] Fault in primary space mode while using user ASCE. | |
187 | [624458.013801] AS:0000000004be41c7 R3:0000000000000024 | |
188 | [624458.013806] CPU: 1 PID: 6896 Comm: try-catch-9.exe Not tainted 4.8.15-300.fc25.s390x #1 | |
189 | [624458.013809] Hardware name: IBM 2827 H43 400 (z/VM) | |
190 | [624458.013812] task: 00000000f5b4b900 task.stack: 00000000061f4000 | |
191 | [624458.013815] User PSW : 0705000180000000 000003ff94fa7f58 | |
192 | [624458.013818] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
193 | [624458.013818] User GPRS: 0000000000000000 5465737473756974 00000000800032a4 000003ff950bba00 | |
194 | [624458.013826] 000003ffd0df96f0 000003ffd0df9628 0000000080001338 0000000000000000 | |
195 | [624458.013830] 000003ff00000000 000003ffd0df96f0 00000000800032a4 000003ff950bba00 | |
196 | [624458.013834] 00000000a19d4e90 000003ff95072658 000003ff94fa7f32 000003ffd0df9588 | |
197 | [624458.013852] User Code: 000003ff94fa7f4a: e310a0000004 lg %r1,0(%r10) | |
198 | [624458.013852] 000003ff94fa7f50: b904003b lgr %r3,%r11 | |
199 | [624458.013852] #000003ff94fa7f54: b904002a lgr %r2,%r10 | |
200 | [624458.013852] >000003ff94fa7f58: e31010200004 lg %r1,32(%r1) | |
201 | [624458.013852] 000003ff94fa7f5e: a7590001 lghi %r5,1 | |
202 | [624458.013852] 000003ff94fa7f62: 4140f0a0 la %r4,160(%r15) | |
203 | [624458.013852] 000003ff94fa7f66: 0de1 basr %r14,%r1 | |
204 | [624458.013852] 000003ff94fa7f68: ec280009007c cgij %r2,0,8,3ff94fa7f7a | |
205 | [624458.013863] Last Breaking-Event-Address: | |
206 | [624458.013866] [<000003ff94fa7f32>] 0x3ff94fa7f32 | |
207 | [682281.933336] User process fault: interruption code 003b ilc:3 in cmsysTestProcess[2aa16200000+9000] | |
208 | [682281.933347] Failing address: 0000000000000000 TEID: 0000000000000400 | |
209 | [682281.933349] Fault in primary space mode while using user ASCE. | |
210 | [682281.933353] AS:00000000829e01c7 R3:0000000000000024 | |
211 | [682281.933358] CPU: 0 PID: 29755 Comm: cmsysTestProces Not tainted 4.8.15-300.fc25.s390x #1 | |
212 | [682281.933362] Hardware name: IBM 2827 H43 400 (z/VM) | |
213 | [682281.933365] task: 00000000f5f13900 task.stack: 00000000c2610000 | |
214 | [682281.933368] User PSW : 0705000180000000 000002aa162027a2 | |
215 | [682281.933371] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
216 | [682281.933371] User GPRS: 0000000000000000 000003ff00000000 0000000000000000 0000000000000001 | |
217 | [682281.933380] 000000000000002e 000003ff7f848c88 000002aa16207430 000003ffe33ff0a0 | |
218 | [682281.933383] 000002aa1620769e 0000000000000000 000003ff7f848d70 000003ff7f848d68 | |
219 | [682281.933388] 000003ff7f928f58 000002aa16207df0 000002aa16202794 000003ffe33feb68 | |
220 | [682281.934367] User Code: 000002aa16202794: e350a0000004 lg %r5,0(%r10) | |
221 | [682281.934367] 000002aa1620279a: a749002e lghi %r4,46 | |
222 | [682281.934367] #000002aa1620279e: a7390001 lghi %r3,1 | |
223 | [682281.934367] >000002aa162027a2: e54c00040000 mvhi 4,0 | |
224 | [682281.934367] 000002aa162027a8: c02000002867 larl %r2,2aa16207876 | |
225 | [682281.934367] 000002aa162027ae: c0e5fffffabd brasl %r14,2aa16201d28 | |
226 | [682281.934367] 000002aa162027b4: e350b0000004 lg %r5,0(%r11) | |
227 | [682281.934367] 000002aa162027ba: a749002e lghi %r4,46 | |
228 | [682281.934379] Last Breaking-Event-Address: | |
229 | [682281.934382] [<000003ff7f6fccb8>] 0x3ff7f6fccb8 | |
230 | [682281.935888] User process fault: interruption code 003b ilc:3 in cmsysTestProcess[2aa36500000+9000] | |
231 | [682281.935896] Failing address: 0000000000000000 TEID: 0000000000000400 | |
232 | [682281.935900] Fault in primary space mode while using user ASCE. | |
233 | [682281.935910] AS:00000000ab3f01c7 R3:0000000000000024 | |
234 | [682281.935917] CPU: 0 PID: 29759 Comm: cmsysTestProces Not tainted 4.8.15-300.fc25.s390x #1 | |
235 | [682281.935940] Hardware name: IBM 2827 H43 400 (z/VM) | |
236 | [682281.935941] task: 0000000083025580 task.stack: 00000000bebf4000 | |
237 | [682281.935942] User PSW : 0705000180000000 000002aa365027a2 | |
238 | [682281.935943] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
239 | [682281.935943] User GPRS: 0000000000000000 000003ff00000000 0000000000000000 0000000000000001 | |
240 | [682281.935946] 000000000000002e 000003ff9ce48c88 000002aa36507430 000003ffd60febe0 | |
241 | [682281.935947] 000002aa3650769e 0000000000000000 000003ff9ce48d70 000003ff9ce48d68 | |
242 | [682281.935948] 000003ff9cf28f58 000002aa36507df0 000002aa36502794 000003ffd60fe6a8 | |
243 | [682281.935954] User Code: 000002aa36502794: e350a0000004 lg %r5,0(%r10) | |
244 | [682281.935954] 000002aa3650279a: a749002e lghi %r4,46 | |
245 | [682281.935954] #000002aa3650279e: a7390001 lghi %r3,1 | |
246 | [682281.935954] >000002aa365027a2: e54c00040000 mvhi 4,0 | |
247 | [682281.935954] 000002aa365027a8: c02000002867 larl %r2,2aa36507876 | |
248 | [682281.935954] 000002aa365027ae: c0e5fffffabd brasl %r14,2aa36501d28 | |
249 | [682281.935954] 000002aa365027b4: e350b0000004 lg %r5,0(%r11) | |
250 | [682281.935954] 000002aa365027ba: a749002e lghi %r4,46 | |
251 | [682281.935964] Last Breaking-Event-Address: | |
252 | [682281.935965] [<000003ff9ccfccb8>] 0x3ff9ccfccb8 | |
253 | [682695.568959] User process fault: interruption code 0010 ilc:3 in Crash[1000000+1000] | |
254 | [682695.568971] Failing address: 0000000000000000 TEID: 0000000000000400 | |
255 | [682695.568973] Fault in primary space mode while using user ASCE. | |
256 | [682695.568977] AS:00000000549a41c7 R3:000000006654c007 S:0000000000000020 | |
257 | [682695.568983] CPU: 0 PID: 6485 Comm: Crash Not tainted 4.8.15-300.fc25.s390x #1 | |
258 | [682695.568986] Hardware name: IBM 2827 H43 400 (z/VM) | |
259 | [682695.568989] task: 00000000f81fb900 task.stack: 0000000004058000 | |
260 | [682695.568992] User PSW : 0705100180000000 0000000001000776 | |
261 | [682695.568995] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:1 PM:0 RI:0 EA:3 | |
262 | [682695.568995] User GPRS: 0000000000000000 0000000000000000 0000000000000001 000003ffd4cfe438 | |
263 | [682695.569003] 000003ffd4cfe448 0090305969303276 0000000001000800 000003ffd4cfe420 | |
264 | [682695.569007] 0000000001000668 0000000000000000 000002aa3e31b1f0 000003ffd4cfe168 | |
265 | [682695.569011] 000003ff91328f58 000002aa3e3251f0 000003ff90d22b9e 000003ffd4cfe168 | |
266 | [682695.572673] User Code: 0000000001000766: b90400bf lgr %r11,%r15 | |
267 | [682695.572673] 000000000100076a: e548b0a00000 mvghi 160(%r11),0 | |
268 | [682695.572673] #0000000001000770: e310b0a00004 lg %r1,160(%r11) | |
269 | [682695.572673] >0000000001000776: e54c10000001 mvhi 0(%r1),1 | |
270 | [682695.572673] 000000000100077c: a7180000 lhi %r1,0 | |
271 | [682695.572673] 0000000001000780: b9140011 lgfr %r1,%r1 | |
272 | [682695.572673] 0000000001000784: b9040021 lgr %r2,%r1 | |
273 | [682695.572673] 0000000001000788: b3cd00b2 lgdr %r11,%f2 | |
274 | [682695.572686] Last Breaking-Event-Address: | |
275 | [682695.572690] [<000003ff90d22b9c>] 0x3ff90d22b9c | |
276 | [699521.918071] User process fault: interruption code 0004 ilc:3 in conftest[1000000+c5000] | |
277 | [699521.918083] Failing address: 00000000010c6000 TEID: 00000000010c6404 | |
278 | [699521.918085] Fault in primary space mode while using user ASCE. | |
279 | [699521.918089] AS:00000000a80d41c7 R3:00000000a462c007 S:000000008267e000 P:00000000918ff21d | |
280 | [699521.918095] CPU: 2 PID: 42951 Comm: conftest Not tainted 4.8.15-300.fc25.s390x #1 | |
281 | [699521.918098] Hardware name: IBM 2827 H43 400 (z/VM) | |
282 | [699521.918101] task: 00000000f4a41c80 task.stack: 0000000082ff0000 | |
283 | [699521.918104] User PSW : 0705000180000000 000000000100de62 | |
284 | [699521.918107] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
285 | [699521.918107] User GPRS: fffffffffffffff0 0000000000000000 000003ffde67c020 0000000000000001 | |
286 | [699521.918116] 000003ffde67c0d8 000000000100e590 000000000100e638 000003ffde67c0c0 | |
287 | [699521.918120] 000000000100dca8 000002aa3f932170 0000000000000000 000002aa3f9d0e10 | |
288 | [699521.918124] 000000000100e590 000002aa3f9d1010 000000000100dce6 000003ffde67beb0 | |
289 | [699521.918140] User Code: 000000000100de54: a71affff ahi %r1,-1 | |
290 | [699521.918140] 000000000100de58: 8810001f srl %r1,31 | |
291 | [699521.918140] #000000000100de5c: c41f0005d5a6 strl %r1,10c89a8 | |
292 | [699521.918140] >000000000100de62: c42b0005c7ff stgrl %r2,10c6e60 | |
293 | [699521.918140] 000000000100de68: e310f0a00004 lg %r1,160(%r15) | |
294 | [699521.918140] 000000000100de6e: ec21000100d9 aghik %r2,%r1,1 | |
295 | [699521.918140] 000000000100de74: eb220003000d sllg %r2,%r2,3 | |
296 | [699521.918140] 000000000100de7a: e320f0a80008 ag %r2,168(%r15) | |
297 | [699521.918152] Last Breaking-Event-Address: | |
298 | [699521.918155] [<000000000100dce0>] 0x100dce0 | |
299 | [701836.544344] User process fault: interruption code 0004 ilc:3 in conftest[1000000+c5000] | |
300 | [701836.544354] Failing address: 00000000010c6000 TEID: 00000000010c6404 | |
301 | [701836.544357] Fault in primary space mode while using user ASCE. | |
302 | [701836.544360] AS:00000000ef6401c7 R3:00000000b52c0007 S:00000000a9721000 P:00000000ce7c021d | |
303 | [701836.544367] CPU: 3 PID: 48640 Comm: conftest Not tainted 4.8.15-300.fc25.s390x #1 | |
304 | [701836.544370] Hardware name: IBM 2827 H43 400 (z/VM) | |
305 | [701836.544374] task: 00000000f5b4b900 task.stack: 000000008287c000 | |
306 | [701836.544377] User PSW : 0705000180000000 000000000100de62 | |
307 | [701836.544380] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
308 | [701836.544380] User GPRS: fffffffffffffff0 0000000000000000 000003ffeaf7bfa0 0000000000000001 | |
309 | [701836.544389] 000003ffeaf7c058 000000000100e590 000000000100e638 000003ffeaf7c040 | |
310 | [701836.544393] 000000000100dca8 000002aa48a418c0 0000000000000000 000002aa48a4b240 | |
311 | [701836.544397] 000000000100e590 000002aa48a52730 000000000100dce6 000003ffeaf7be30 | |
312 | [701836.544414] User Code: 000000000100de54: a71affff ahi %r1,-1 | |
313 | [701836.544414] 000000000100de58: 8810001f srl %r1,31 | |
314 | [701836.544414] #000000000100de5c: c41f0005d5a6 strl %r1,10c89a8 | |
315 | [701836.544414] >000000000100de62: c42b0005c7ff stgrl %r2,10c6e60 | |
316 | [701836.544414] 000000000100de68: e310f0a00004 lg %r1,160(%r15) | |
317 | [701836.544414] 000000000100de6e: ec21000100d9 aghik %r2,%r1,1 | |
318 | [701836.544414] 000000000100de74: eb220003000d sllg %r2,%r2,3 | |
319 | [701836.544414] 000000000100de7a: e320f0a80008 ag %r2,168(%r15) | |
320 | [701836.544427] Last Breaking-Event-Address: | |
321 | [701836.544429] [<000000000100dce0>] 0x100dce0 | |
322 | [702856.049112] User process fault: interruption code 0004 ilc:3 in conftest[1000000+c5000] | |
323 | [702856.049125] Failing address: 00000000010c6000 TEID: 00000000010c6404 | |
324 | [702856.049127] Fault in primary space mode while using user ASCE. | |
325 | [702856.049131] AS:00000000801581c7 R3:00000000a7da4007 S:00000000802e9000 P:00000000a540621d | |
326 | [702856.049138] CPU: 2 PID: 53342 Comm: conftest Not tainted 4.8.15-300.fc25.s390x #1 | |
327 | [702856.049141] Hardware name: IBM 2827 H43 400 (z/VM) | |
328 | [702856.049144] task: 00000000f5b49c80 task.stack: 00000000f3f70000 | |
329 | [702856.049147] User PSW : 0705000180000000 000000000100de62 | |
330 | [702856.049151] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
331 | [702856.049151] User GPRS: fffffffffffffff0 0000000000000000 000003fff267b9b0 0000000000000001 | |
332 | [702856.049160] 000003fff267ba68 000000000100e590 000000000100e638 000003fff267ba50 | |
333 | [702856.049163] 000000000100dca8 000002aa1fc0f9b0 0000000000000000 000002aa1fced3e0 | |
334 | [702856.049168] 000000000100e590 000002aa1fceda20 000000000100dce6 000003fff267b840 | |
335 | [702856.049188] User Code: 000000000100de54: a71affff ahi %r1,-1 | |
336 | [702856.049188] 000000000100de58: 8810001f srl %r1,31 | |
337 | [702856.049188] #000000000100de5c: c41f0005d5a6 strl %r1,10c89a8 | |
338 | [702856.049188] >000000000100de62: c42b0005c7ff stgrl %r2,10c6e60 | |
339 | [702856.049188] 000000000100de68: e310f0a00004 lg %r1,160(%r15) | |
340 | [702856.049188] 000000000100de6e: ec21000100d9 aghik %r2,%r1,1 | |
341 | [702856.049188] 000000000100de74: eb220003000d sllg %r2,%r2,3 | |
342 | [702856.049188] 000000000100de7a: e320f0a80008 ag %r2,168(%r15) | |
343 | [702856.049200] Last Breaking-Event-Address: | |
344 | [702856.049203] [<000000000100dce0>] 0x100dce0 | |
345 | [703009.939101] User process fault: interruption code 0004 ilc:3 in conftest[1000000+c5000] | |
346 | [703009.939113] Failing address: 00000000010c6000 TEID: 00000000010c6404 | |
347 | [703009.939116] Fault in primary space mode while using user ASCE. | |
348 | [703009.939119] AS:0000000000dd41c7 R3:00000000014e8007 S:0000000000ea3000 P:00000000405c321d | |
349 | [703009.939126] CPU: 0 PID: 47870 Comm: conftest Not tainted 4.8.15-300.fc25.s390x #1 | |
350 | [703009.939129] Hardware name: IBM 2827 H43 400 (z/VM) | |
351 | [703009.939132] task: 0000000005645580 task.stack: 000000000c554000 | |
352 | [703009.939135] User PSW : 0705000180000000 000000000100de62 | |
353 | [703009.939139] R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:1 AS:0 CC:0 PM:0 RI:0 EA:3 | |
354 | [703009.939139] User GPRS: fffffffffffffff0 0000000000000000 000003fff327c090 0000000000000001 | |
355 | [703009.939147] 000003fff327c148 000000000100e590 000000000100e638 000003fff327c130 | |
356 | [703009.939151] 000000000100dca8 000002aa309f3570 0000000000000000 000002aa309ee380 | |
357 | [703009.939155] 000000000100e590 000002aa30a96c80 000000000100dce6 000003fff327bf20 | |
358 | [703009.939894] User Code: 000000000100de54: a71affff ahi %r1,-1 | |
359 | [703009.939894] 000000000100de58: 8810001f srl %r1,31 | |
360 | [703009.939894] #000000000100de5c: c41f0005d5a6 strl %r1,10c89a8 | |
361 | [703009.939894] >000000000100de62: c42b0005c7ff stgrl %r2,10c6e60 | |
362 | [703009.939894] 000000000100de68: e310f0a00004 lg %r1,160(%r15) | |
363 | [703009.939894] 000000000100de6e: ec21000100d9 aghik %r2,%r1,1 | |
364 | [703009.939894] 000000000100de74: eb220003000d sllg %r2,%r2,3 | |
365 | [703009.939894] 000000000100de7a: e320f0a80008 ag %r2,168(%r15) | |
366 | [703009.939931] Last Breaking-Event-Address: | |
367 | [703009.939936] [<000000000100dce0>] 0x100dce0 | |
368 | [703026.481842] User process fault: interruption code 0004 ilc:3 in conftest[1000000+c5000] | |
369 | [703026.481852] Failing address: 00000000010c6000 TEID: 00000000010c6404 | |
370 | [703026.481854] | |
371 | ||
372 | ''' | |
373 | return returncode, output | |
374 | ||
375 | ||
376 | class TestLinuxFedora_5_s390x(unittest.TestCase): | |
377 | def setUp(self): | |
378 | helpers.backup_data_source(cpuinfo) | |
379 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) | |
380 | ||
381 | def tearDown(self): | |
382 | helpers.restore_data_source(cpuinfo) | |
383 | ||
384 | ''' | |
385 | Make sure calls return the expected number of fields. | |
386 | ''' | |
387 | def test_returns(self): | |
388 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_registry())) | |
389 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpufreq_info())) | |
390 | self.assertEqual(10, len(cpuinfo._get_cpu_info_from_lscpu())) | |
391 | self.assertEqual(7, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) | |
392 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) | |
393 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_kstat())) | |
394 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_dmesg())) | |
395 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) | |
396 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) | |
397 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) | |
398 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
399 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
400 | ||
401 | def test_get_cpu_info_from_lscpu(self): | |
402 | info = cpuinfo._get_cpu_info_from_lscpu() | |
403 | ||
404 | self.assertEqual('IBM/S390', info['vendor_id_raw']) | |
405 | #self.assertEqual('FIXME', info['brand']) | |
406 | self.assertEqual('5.5040 GHz', info['hz_advertised_friendly']) | |
407 | self.assertEqual('5.5040 GHz', info['hz_actual_friendly']) | |
408 | self.assertEqual((5504000000, 0), info['hz_advertised']) | |
409 | self.assertEqual((5504000000, 0), info['hz_actual']) | |
410 | ||
411 | #self.assertEqual(7, info['stepping']) | |
412 | #self.assertEqual(42, info['model']) | |
413 | #self.assertEqual(6, info['family']) | |
414 | ||
415 | self.assertEqual(64 * 1024, info['l1_instruction_cache_size']) | |
416 | self.assertEqual(96 * 1024, info['l1_data_cache_size']) | |
417 | ||
418 | self.assertEqual(1024 * 1024, info['l2_cache_size']) | |
419 | self.assertEqual(49152 * 1024, info['l3_cache_size']) | |
420 | ||
421 | self.assertEqual( | |
422 | ['dfp', 'eimm', 'esan3', 'etf3eh', 'highgprs', 'ldisp', | |
423 | 'msa', 'sie', 'stfle', 'zarch'] | |
424 | , | |
425 | info['flags'] | |
426 | ) | |
427 | ||
428 | def test_get_cpu_info_from_dmesg(self): | |
429 | info = cpuinfo._get_cpu_info_from_dmesg() | |
430 | ||
431 | #self.assertEqual('FIXME', info['brand']) | |
432 | ||
433 | def test_get_cpu_info_from_proc_cpuinfo(self): | |
434 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() | |
435 | ||
436 | self.assertEqual('IBM/S390', info['vendor_id_raw']) | |
437 | #self.assertEqual('FIXME', info['brand']) | |
438 | self.assertEqual('5.5040 GHz', info['hz_advertised_friendly']) | |
439 | self.assertEqual('5.5040 GHz', info['hz_actual_friendly']) | |
440 | self.assertEqual((5504000000, 0), info['hz_advertised']) | |
441 | self.assertEqual((5504000000, 0), info['hz_actual']) | |
442 | ||
443 | self.assertEqual(49152 * 1024, info['l3_cache_size']) | |
444 | ||
445 | #self.assertEqual(7, info['stepping']) | |
446 | #self.assertEqual(42, info['model']) | |
447 | #self.assertEqual(6, info['family']) | |
448 | self.assertEqual( | |
449 | ['dfp', 'edat', 'eimm', 'esan3', 'etf3eh', 'highgprs', 'ldisp', | |
450 | 'msa', 'sie', 'stfle', 'te', 'zarch'] | |
451 | , | |
452 | info['flags'] | |
453 | ) | |
454 | ||
455 | def test_all(self): | |
456 | info = cpuinfo._get_cpu_info_internal() | |
457 | self.assertEqual('IBM/S390', info['vendor_id_raw']) | |
458 | #self.assertEqual('FIXME', info['brand']) | |
459 | self.assertEqual('5.5040 GHz', info['hz_advertised_friendly']) | |
460 | self.assertEqual('5.5040 GHz', info['hz_actual_friendly']) | |
461 | self.assertEqual((5504000000, 0), info['hz_advertised']) | |
462 | self.assertEqual((5504000000, 0), info['hz_actual']) | |
463 | self.assertEqual('S390X', info['arch']) | |
464 | self.assertEqual(64, info['bits']) | |
465 | self.assertEqual(4, info['count']) | |
466 | ||
467 | self.assertEqual('s390x', info['arch_string_raw']) | |
468 | ||
469 | self.assertEqual(64 * 1024, info['l1_instruction_cache_size']) | |
470 | self.assertEqual(96 * 1024, info['l1_data_cache_size']) | |
471 | ||
472 | self.assertEqual(1024 * 1024, info['l2_cache_size']) | |
473 | self.assertEqual(49152 * 1024, info['l3_cache_size']) | |
474 | ||
475 | #self.assertEqual(7, info['stepping']) | |
476 | #self.assertEqual(42, info['model']) | |
477 | #self.assertEqual(6, info['family']) | |
478 | self.assertEqual( | |
479 | ['dfp', 'edat', 'eimm', 'esan3', 'etf3eh', 'highgprs', 'ldisp', | |
480 | 'msa', 'sie', 'stfle', 'te', 'zarch'], | |
481 | info['flags'] | |
482 | ) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 2 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
26 | 27 | @staticmethod |
27 | 28 | def cat_proc_cpuinfo(): |
28 | 29 | returncode = 0 |
29 | output = ''' | |
30 | output = r''' | |
30 | 31 | processor : 0 |
31 | 32 | vendor_id : GenuineIntel |
32 | 33 | cpu family : 6 |
86 | 87 | @staticmethod |
87 | 88 | def dmesg_a(): |
88 | 89 | returncode = 0 |
89 | output = ''' | |
90 | output = r''' | |
90 | 91 | =============================================================================== |
91 | 92 | [ 0.000000] Linux version 4.5.2-aufs-r1 (root@jasmin) (gcc version 5.4.0 (Gentoo 5.4.0 p1.0, pie-0.6.5) ) #1 SMP Sun Jul 3 17:17:11 UTC 2016 |
92 | 93 | [ 0.000000] Command line: BOOT_IMAGE=/isolinux/gentoo root=/dev/ram0 init=/linuxrc dokeymap aufs looptype=squashfs loop=/image.squashfs cdroot initrd=/isolinux/gentoo.xz console=tty1 |
411 | 412 | @staticmethod |
412 | 413 | def lscpu(): |
413 | 414 | returncode = 0 |
414 | output = ''' | |
415 | output = r''' | |
415 | 416 | Architecture: x86_64 |
416 | 417 | CPU op-mode(s): 32-bit, 64-bit |
417 | 418 | Byte Order: Little Endian |
463 | 464 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
464 | 465 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
465 | 466 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
466 | self.assertEqual(20, len(cpuinfo._get_cpu_info_internal())) | |
467 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
467 | 468 | |
468 | 469 | def test_get_cpu_info_from_lscpu(self): |
469 | 470 | info = cpuinfo._get_cpu_info_from_lscpu() |
470 | 471 | |
471 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
472 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
473 | self.assertEqual('2.7937 GHz', info['hz_advertised']) | |
474 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
475 | self.assertEqual((2793652000, 0), info['hz_advertised_raw']) | |
476 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
472 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
473 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
474 | self.assertEqual('2.7937 GHz', info['hz_advertised_friendly']) | |
475 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
476 | self.assertEqual((2793652000, 0), info['hz_advertised']) | |
477 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
477 | 478 | |
478 | 479 | self.assertEqual(7, info['stepping']) |
479 | 480 | self.assertEqual(42, info['model']) |
480 | 481 | self.assertEqual(6, info['family']) |
481 | 482 | |
482 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
483 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
484 | self.assertEqual('256 KB', info['l2_cache_size']) | |
485 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
483 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
484 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
485 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
486 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
486 | 487 | |
487 | 488 | self.assertEqual( |
488 | 489 | ['apic', 'clflush', 'cmov', 'constant_tsc', 'cx16', 'cx8', 'de', |
498 | 499 | def test_get_cpu_info_from_dmesg(self): |
499 | 500 | info = cpuinfo._get_cpu_info_from_dmesg() |
500 | 501 | |
501 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
502 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
503 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
504 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
505 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
502 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
503 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
504 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
505 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
506 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
506 | 507 | |
507 | 508 | self.assertEqual(7, info['stepping']) |
508 | 509 | self.assertEqual(42, info['model']) |
511 | 512 | def test_get_cpu_info_from_proc_cpuinfo(self): |
512 | 513 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
513 | 514 | |
514 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
515 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
516 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
517 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
518 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
519 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
520 | ||
521 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
515 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
516 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
517 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
518 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
519 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
520 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
521 | ||
522 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
522 | 523 | |
523 | 524 | self.assertEqual(7, info['stepping']) |
524 | 525 | self.assertEqual(42, info['model']) |
537 | 538 | def test_all(self): |
538 | 539 | info = cpuinfo._get_cpu_info_internal() |
539 | 540 | |
540 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
541 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
542 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
543 | self.assertEqual('2.7937 GHz', info['hz_actual']) | |
544 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
545 | self.assertEqual((2793652000, 0), info['hz_actual_raw']) | |
541 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
542 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
543 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
544 | self.assertEqual('2.7937 GHz', info['hz_actual_friendly']) | |
545 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
546 | self.assertEqual((2793652000, 0), info['hz_actual']) | |
546 | 547 | self.assertEqual('X86_64', info['arch']) |
547 | 548 | self.assertEqual(64, info['bits']) |
548 | 549 | self.assertEqual(2, info['count']) |
549 | 550 | |
550 | self.assertEqual('x86_64', info['raw_arch_string']) | |
551 | ||
552 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
553 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
554 | self.assertEqual('256 KB', info['l2_cache_size']) | |
555 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
551 | self.assertEqual('x86_64', info['arch_string_raw']) | |
552 | ||
553 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
554 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
555 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
556 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
556 | 557 | |
557 | 558 | self.assertEqual(7, info['stepping']) |
558 | 559 | self.assertEqual(42, info['model']) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 4 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'aarch64' | |
11 | arch_string_raw = 'aarch64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
26 | 27 | @staticmethod |
27 | 28 | def cat_proc_cpuinfo(): |
28 | 29 | returncode = 0 |
29 | output = ''' | |
30 | output = r''' | |
30 | 31 | processor : 0 |
31 | 32 | BogoMIPS : 2.00 |
32 | 33 | Features : fp asimd crc32 |
73 | 74 | @staticmethod |
74 | 75 | def lscpu(): |
75 | 76 | returncode = 0 |
76 | output = ''' | |
77 | output = r''' | |
77 | 78 | Architecture: aarch64 |
78 | 79 | Byte Order: Little Endian |
79 | 80 | CPU(s): 4 |
89 | 90 | @staticmethod |
90 | 91 | def cpufreq_info(): |
91 | 92 | returncode = 0 |
92 | output = ''' | |
93 | output = r''' | |
93 | 94 | cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 |
94 | 95 | Report errors and bugs to cpufreq@vger.kernel.org, please. |
95 | 96 | analyzing CPU 0: |
172 | 173 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
173 | 174 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
174 | 175 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
175 | self.assertEqual(12, len(cpuinfo._get_cpu_info_internal())) | |
176 | self.assertEqual(13, len(cpuinfo._get_cpu_info_internal())) | |
176 | 177 | |
177 | 178 | def test_get_cpu_info_from_cpufreq_info(self): |
178 | 179 | info = cpuinfo._get_cpu_info_from_cpufreq_info() |
179 | 180 | |
180 | self.assertEqual('1.5400 GHz', info['hz_advertised']) | |
181 | self.assertEqual('1.5400 GHz', info['hz_actual']) | |
182 | self.assertEqual((1540000000, 0), info['hz_advertised_raw']) | |
183 | self.assertEqual((1540000000, 0), info['hz_actual_raw']) | |
181 | self.assertEqual('1.5400 GHz', info['hz_advertised_friendly']) | |
182 | self.assertEqual('1.5400 GHz', info['hz_actual_friendly']) | |
183 | self.assertEqual((1540000000, 0), info['hz_advertised']) | |
184 | self.assertEqual((1540000000, 0), info['hz_actual']) | |
184 | 185 | |
185 | 186 | def test_get_cpu_info_from_lscpu(self): |
186 | 187 | info = cpuinfo._get_cpu_info_from_lscpu() |
187 | 188 | |
188 | self.assertEqual('1.5360 GHz', info['hz_advertised']) | |
189 | self.assertEqual('1.5360 GHz', info['hz_actual']) | |
190 | self.assertEqual((1536000000, 0), info['hz_advertised_raw']) | |
191 | self.assertEqual((1536000000, 0), info['hz_actual_raw']) | |
189 | self.assertEqual('1.5360 GHz', info['hz_advertised_friendly']) | |
190 | self.assertEqual('1.5360 GHz', info['hz_actual_friendly']) | |
191 | self.assertEqual((1536000000, 0), info['hz_advertised']) | |
192 | self.assertEqual((1536000000, 0), info['hz_actual']) | |
192 | 193 | |
193 | 194 | def test_get_cpu_info_from_proc_cpuinfo(self): |
194 | 195 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
195 | 196 | |
196 | self.assertEqual('ODROID-C2', info['hardware']) | |
197 | self.assertEqual('ODROID-C2', info['hardware_raw']) | |
197 | 198 | |
198 | 199 | self.assertEqual( |
199 | 200 | ['asimd', 'crc32', 'fp'], |
203 | 204 | def test_all(self): |
204 | 205 | info = cpuinfo._get_cpu_info_internal() |
205 | 206 | |
206 | self.assertEqual('ODROID-C2', info['hardware']) | |
207 | self.assertEqual('1.5400 GHz', info['hz_advertised']) | |
208 | self.assertEqual('1.5400 GHz', info['hz_actual']) | |
209 | self.assertEqual((1540000000, 0), info['hz_advertised_raw']) | |
210 | self.assertEqual((1540000000, 0), info['hz_actual_raw']) | |
207 | self.assertEqual('ODROID-C2', info['hardware_raw']) | |
208 | self.assertEqual('1.5400 GHz', info['hz_advertised_friendly']) | |
209 | self.assertEqual('1.5400 GHz', info['hz_actual_friendly']) | |
210 | self.assertEqual((1540000000, 0), info['hz_advertised']) | |
211 | self.assertEqual((1540000000, 0), info['hz_actual']) | |
211 | 212 | self.assertEqual('ARM_8', info['arch']) |
212 | 213 | self.assertEqual(64, info['bits']) |
213 | 214 | self.assertEqual(4, info['count']) |
214 | 215 | |
215 | self.assertEqual('aarch64', info['raw_arch_string']) | |
216 | self.assertEqual('aarch64', info['arch_string_raw']) | |
216 | 217 | |
217 | 218 | self.assertEqual( |
218 | 219 | ['asimd', 'crc32', 'fp'], |
8 | 8 | bits = '32bit' |
9 | 9 | cpu_count = 8 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'armv7l' | |
11 | arch_string_raw = 'armv7l' | |
12 | uname_string_raw = '' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
26 | 27 | @staticmethod |
27 | 28 | def cat_proc_cpuinfo(): |
28 | 29 | returncode = 0 |
29 | output = ''' | |
30 | output = r''' | |
30 | 31 | processor : 0 |
31 | 32 | model name : ARMv7 Processor rev 3 (v7l) |
32 | 33 | BogoMIPS : 84.00 |
118 | 119 | @staticmethod |
119 | 120 | def lscpu(): |
120 | 121 | returncode = 0 |
121 | output = ''' | |
122 | output = r''' | |
122 | 123 | Architecture: armv7l |
123 | 124 | Byte Order: Little Endian |
124 | 125 | CPU(s): 8 |
136 | 137 | @staticmethod |
137 | 138 | def cpufreq_info(): |
138 | 139 | returncode = 0 |
139 | output = ''' | |
140 | output = r''' | |
140 | 141 | cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 |
141 | 142 | Report errors and bugs to cpufreq@vger.kernel.org, please. |
142 | 143 | analyzing CPU 0: |
263 | 264 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
264 | 265 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
265 | 266 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
266 | self.assertEqual(13, len(cpuinfo._get_cpu_info_internal())) | |
267 | self.assertEqual(14, len(cpuinfo._get_cpu_info_internal())) | |
267 | 268 | |
268 | 269 | def test_get_cpu_info_from_cpufreq_info(self): |
269 | 270 | info = cpuinfo._get_cpu_info_from_cpufreq_info() |
270 | 271 | |
271 | self.assertEqual('1.4000 GHz', info['hz_advertised']) | |
272 | self.assertEqual('1.4000 GHz', info['hz_actual']) | |
273 | self.assertEqual((1400000000, 0), info['hz_advertised_raw']) | |
274 | self.assertEqual((1400000000, 0), info['hz_actual_raw']) | |
272 | self.assertEqual('1.4000 GHz', info['hz_advertised_friendly']) | |
273 | self.assertEqual('1.4000 GHz', info['hz_actual_friendly']) | |
274 | self.assertEqual((1400000000, 0), info['hz_advertised']) | |
275 | self.assertEqual((1400000000, 0), info['hz_actual']) | |
275 | 276 | |
276 | 277 | def test_get_cpu_info_from_lscpu(self): |
277 | 278 | info = cpuinfo._get_cpu_info_from_lscpu() |
278 | 279 | |
279 | self.assertEqual('ARMv7 Processor rev 3 (v7l)', info['brand']) | |
280 | self.assertEqual('1.4000 GHz', info['hz_advertised']) | |
281 | self.assertEqual('1.4000 GHz', info['hz_actual']) | |
282 | self.assertEqual((1400000000, 0), info['hz_advertised_raw']) | |
283 | self.assertEqual((1400000000, 0), info['hz_actual_raw']) | |
280 | self.assertEqual('ARMv7 Processor rev 3 (v7l)', info['brand_raw']) | |
281 | self.assertEqual('1.4000 GHz', info['hz_advertised_friendly']) | |
282 | self.assertEqual('1.4000 GHz', info['hz_actual_friendly']) | |
283 | self.assertEqual((1400000000, 0), info['hz_advertised']) | |
284 | self.assertEqual((1400000000, 0), info['hz_actual']) | |
284 | 285 | |
285 | 286 | def test_get_cpu_info_from_proc_cpuinfo(self): |
286 | 287 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
287 | 288 | |
288 | self.assertEqual('ARMv7 Processor rev 3 (v7l)', info['brand']) | |
289 | self.assertEqual('ODROID-XU3', info['hardware']) | |
289 | self.assertEqual('ARMv7 Processor rev 3 (v7l)', info['brand_raw']) | |
290 | self.assertEqual('ODROID-XU3', info['hardware_raw']) | |
290 | 291 | |
291 | 292 | self.assertEqual( |
292 | 293 | ['edsp', 'fastmult', 'half', 'idiva', 'idivt', 'neon', 'swp', |
297 | 298 | def test_all(self): |
298 | 299 | info = cpuinfo._get_cpu_info_internal() |
299 | 300 | |
300 | self.assertEqual('ARMv7 Processor rev 3 (v7l)', info['brand']) | |
301 | self.assertEqual('ODROID-XU3', info['hardware']) | |
302 | self.assertEqual('1.4000 GHz', info['hz_advertised']) | |
303 | self.assertEqual('1.4000 GHz', info['hz_actual']) | |
304 | self.assertEqual((1400000000, 0), info['hz_advertised_raw']) | |
305 | self.assertEqual((1400000000, 0), info['hz_actual_raw']) | |
301 | self.assertEqual('ARMv7 Processor rev 3 (v7l)', info['brand_raw']) | |
302 | self.assertEqual('ODROID-XU3', info['hardware_raw']) | |
303 | self.assertEqual('1.4000 GHz', info['hz_advertised_friendly']) | |
304 | self.assertEqual('1.4000 GHz', info['hz_actual_friendly']) | |
305 | self.assertEqual((1400000000, 0), info['hz_advertised']) | |
306 | self.assertEqual((1400000000, 0), info['hz_actual']) | |
306 | 307 | self.assertEqual('ARM_7', info['arch']) |
307 | 308 | self.assertEqual(32, info['bits']) |
308 | 309 | self.assertEqual(8, info['count']) |
309 | 310 | |
310 | self.assertEqual('armv7l', info['raw_arch_string']) | |
311 | self.assertEqual('armv7l', info['arch_string_raw']) | |
311 | 312 | |
312 | 313 | self.assertEqual( |
313 | 314 | ['edsp', 'fastmult', 'half', 'idiva', 'idivt', 'neon', 'swp', |
8 | 8 | bits = '32bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'armv6l' | |
11 | arch_string_raw = 'armv6l' | |
12 | uname_string_raw = '' | |
12 | 13 | |
13 | 14 | @staticmethod |
14 | 15 | def has_proc_cpuinfo(): |
21 | 22 | @staticmethod |
22 | 23 | def cat_proc_cpuinfo(): |
23 | 24 | returncode = 0 |
24 | output = ''' | |
25 | output = r''' | |
25 | 26 | Processor : ARMv6-compatible processor rev 7 (v6l) |
26 | 27 | BogoMIPS : 697.95 |
27 | 28 | Features : swp half thumb fastmult vfp edsp java tls |
42 | 43 | @staticmethod |
43 | 44 | def lscpu(): |
44 | 45 | returncode = 0 |
45 | output = ''' | |
46 | output = r''' | |
46 | 47 | Architecture: armv6l |
47 | 48 | Byte Order: Little Endian |
48 | 49 | CPU(s): 1 |
80 | 81 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
81 | 82 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
82 | 83 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
83 | self.assertEqual(13, len(cpuinfo._get_cpu_info_internal())) | |
84 | self.assertEqual(14, len(cpuinfo._get_cpu_info_internal())) | |
84 | 85 | |
85 | 86 | def test_get_cpu_info_from_lscpu(self): |
86 | 87 | info = cpuinfo._get_cpu_info_from_lscpu() |
87 | 88 | |
88 | self.assertEqual('700.0000 MHz', info['hz_advertised']) | |
89 | self.assertEqual('700.0000 MHz', info['hz_actual']) | |
90 | self.assertEqual((700000000, 0), info['hz_advertised_raw']) | |
91 | self.assertEqual((700000000, 0), info['hz_actual_raw']) | |
89 | self.assertEqual('700.0000 MHz', info['hz_advertised_friendly']) | |
90 | self.assertEqual('700.0000 MHz', info['hz_actual_friendly']) | |
91 | self.assertEqual((700000000, 0), info['hz_advertised']) | |
92 | self.assertEqual((700000000, 0), info['hz_actual']) | |
92 | 93 | |
93 | 94 | def test_get_cpu_info_from_proc_cpuinfo(self): |
94 | 95 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
95 | 96 | |
96 | self.assertEqual('BCM2708', info['hardware']) | |
97 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand']) | |
97 | self.assertEqual('BCM2708', info['hardware_raw']) | |
98 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand_raw']) | |
98 | 99 | |
99 | 100 | self.assertEqual( |
100 | 101 | ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp'] |
105 | 106 | def test_all(self): |
106 | 107 | info = cpuinfo._get_cpu_info_internal() |
107 | 108 | |
108 | self.assertEqual('BCM2708', info['hardware']) | |
109 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand']) | |
110 | self.assertEqual('700.0000 MHz', info['hz_advertised']) | |
111 | self.assertEqual('700.0000 MHz', info['hz_actual']) | |
112 | self.assertEqual((700000000, 0), info['hz_advertised_raw']) | |
113 | self.assertEqual((700000000, 0), info['hz_actual_raw']) | |
109 | self.assertEqual('BCM2708', info['hardware_raw']) | |
110 | self.assertEqual('ARMv6-compatible processor rev 7 (v6l)', info['brand_raw']) | |
111 | self.assertEqual('700.0000 MHz', info['hz_advertised_friendly']) | |
112 | self.assertEqual('700.0000 MHz', info['hz_actual_friendly']) | |
113 | self.assertEqual((700000000, 0), info['hz_advertised']) | |
114 | self.assertEqual((700000000, 0), info['hz_actual']) | |
114 | 115 | self.assertEqual('ARM_7', info['arch']) |
115 | 116 | self.assertEqual(32, info['bits']) |
116 | 117 | self.assertEqual(1, info['count']) |
117 | 118 | |
118 | self.assertEqual('armv6l', info['raw_arch_string']) | |
119 | self.assertEqual('armv6l', info['arch_string_raw']) | |
119 | 120 | |
120 | 121 | self.assertEqual( |
121 | 122 | ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp'] |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 16 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'ppc64le' | |
11 | arch_string_raw = 'ppc64le' | |
12 | uname_string_raw = '' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
30 | 31 | @staticmethod |
31 | 32 | def ibm_pa_features(): |
32 | 33 | returncode = 0 |
33 | output = ''' | |
34 | output = r''' | |
34 | 35 | /proc/device-tree/cpus/PowerPC,POWER7@1/ibm,pa-features 3ff60006 c08000c7 |
35 | 36 | |
36 | 37 | ''' |
39 | 40 | @staticmethod |
40 | 41 | def cat_proc_cpuinfo(): |
41 | 42 | returncode = 0 |
42 | output = ''' | |
43 | output = r''' | |
43 | 44 | processor : 0 |
44 | 45 | cpu : POWER8E (raw), altivec supported |
45 | 46 | clock : 3425.000000MHz |
131 | 132 | @staticmethod |
132 | 133 | def dmesg_a(): |
133 | 134 | returncode = 0 |
134 | output = ''' | |
135 | output = r''' | |
135 | 136 | [3269512.154534] convolution_var[11236]: unhandled signal 4 at 00003fff6c390004 nip 00003fff6c390004 lr 00003fff9a648d58 code 30001 |
136 | 137 | [3269512.234818] convolution_var[11344]: unhandled signal 5 at 00003fff84390000 nip 00003fff84390000 lr 00003fffb2217ce0 code 30001 |
137 | 138 | [3269512.234823] convolution_var[11347]: unhandled signal 11 at 0000000000000304 nip 00003fff8439001c lr 00003fffb2217ce0 code 30001 |
299 | 300 | @staticmethod |
300 | 301 | def lscpu(): |
301 | 302 | returncode = 0 |
302 | output = ''' | |
303 | output = r''' | |
303 | 304 | Architecture: ppc64le |
304 | 305 | Byte Order: Little Endian |
305 | 306 | CPU(s): 16 |
341 | 342 | self.assertEqual(1, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
342 | 343 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
343 | 344 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
344 | self.assertEqual(14, len(cpuinfo._get_cpu_info_internal())) | |
345 | self.assertEqual(15, len(cpuinfo._get_cpu_info_internal())) | |
345 | 346 | |
346 | 347 | def test_get_cpu_info_from_lscpu(self): |
347 | 348 | info = cpuinfo._get_cpu_info_from_lscpu() |
348 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
349 | self.assertEqual('64 KB', info['l1_data_cache_size']) | |
350 | self.assertEqual('POWER8E (raw), altivec supported', info['brand']) | |
349 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
350 | self.assertEqual(64 * 1024, info['l1_data_cache_size']) | |
351 | self.assertEqual('POWER8E (raw), altivec supported', info['brand_raw']) | |
351 | 352 | |
352 | 353 | def test_get_cpu_info_from_ibm_pa_features(self): |
353 | 354 | info = cpuinfo._get_cpu_info_from_ibm_pa_features() |
359 | 360 | def test_get_cpu_info_from_proc_cpuinfo(self): |
360 | 361 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
361 | 362 | |
362 | self.assertEqual('POWER8E (raw), altivec supported', info['brand']) | |
363 | self.assertEqual('3.4250 GHz', info['hz_advertised']) | |
364 | self.assertEqual('3.4250 GHz', info['hz_actual']) | |
365 | self.assertEqual((3425000000, 0), info['hz_advertised_raw']) | |
366 | self.assertEqual((3425000000, 0), info['hz_actual_raw']) | |
363 | self.assertEqual('POWER8E (raw), altivec supported', info['brand_raw']) | |
364 | self.assertEqual('3.4250 GHz', info['hz_advertised_friendly']) | |
365 | self.assertEqual('3.4250 GHz', info['hz_actual_friendly']) | |
366 | self.assertEqual((3425000000, 0), info['hz_advertised']) | |
367 | self.assertEqual((3425000000, 0), info['hz_actual']) | |
367 | 368 | |
368 | 369 | def test_all(self): |
369 | 370 | info = cpuinfo._get_cpu_info_internal() |
370 | 371 | |
371 | self.assertEqual('POWER8E (raw), altivec supported', info['brand']) | |
372 | self.assertEqual('3.4250 GHz', info['hz_advertised']) | |
373 | self.assertEqual('3.4250 GHz', info['hz_actual']) | |
374 | self.assertEqual((3425000000, 0), info['hz_advertised_raw']) | |
375 | self.assertEqual((3425000000, 0), info['hz_actual_raw']) | |
372 | self.assertEqual('POWER8E (raw), altivec supported', info['brand_raw']) | |
373 | self.assertEqual('3.4250 GHz', info['hz_advertised_friendly']) | |
374 | self.assertEqual('3.4250 GHz', info['hz_actual_friendly']) | |
375 | self.assertEqual((3425000000, 0), info['hz_advertised']) | |
376 | self.assertEqual((3425000000, 0), info['hz_actual']) | |
376 | 377 | self.assertEqual('PPC_64', info['arch']) |
377 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
378 | self.assertEqual('64 KB', info['l1_data_cache_size']) | |
378 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
379 | self.assertEqual(64 * 1024, info['l1_data_cache_size']) | |
379 | 380 | self.assertEqual(64, info['bits']) |
380 | 381 | self.assertEqual(16, info['count']) |
381 | self.assertEqual('ppc64le', info['raw_arch_string']) | |
382 | self.assertEqual('ppc64le', info['arch_string_raw']) | |
382 | 383 | self.assertEqual( |
383 | 384 | ['dss_2.02', 'dss_2.05', 'dss_2.06', 'fpu', 'lsd_in_dscr', 'ppr', 'slb', 'sso_2.06', 'ugr_in_dscr'], |
384 | 385 | info['flags'] |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 2 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
26 | 27 | @staticmethod |
27 | 28 | def cat_proc_cpuinfo(): |
28 | 29 | returncode = 0 |
29 | output = ''' | |
30 | output = r''' | |
30 | 31 | processor : 0 |
31 | 32 | vendor_id : GenuineIntel |
32 | 33 | cpu family : 6 |
88 | 89 | @staticmethod |
89 | 90 | def lscpu(): |
90 | 91 | returncode = 0 |
91 | output = ''' | |
92 | output = r''' | |
92 | 93 | Architecture: x86_64 |
93 | 94 | CPU op-mode(s): 32-bit, 64-bit |
94 | 95 | Byte Order: Little Endian |
122 | 123 | @staticmethod |
123 | 124 | def dmesg_a(): |
124 | 125 | returncode = 0 |
125 | output = ''' | |
126 | output = r''' | |
126 | 127 | [ 0.000000] microcode: CPU0 microcode updated early to revision 0x29, date = 2013-06-12 |
127 | 128 | [ 0.000000] Initializing cgroup subsys cpuset |
128 | 129 | [ 0.000000] Initializing cgroup subsys cpu |
464 | 465 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
465 | 466 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
466 | 467 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
467 | self.assertEqual(20, len(cpuinfo._get_cpu_info_internal())) | |
468 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
468 | 469 | |
469 | 470 | def test_get_cpu_info_from_lscpu(self): |
470 | 471 | info = cpuinfo._get_cpu_info_from_lscpu() |
471 | 472 | |
472 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
473 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
474 | self.assertEqual('2.0708 GHz', info['hz_advertised']) | |
475 | self.assertEqual('2.0708 GHz', info['hz_actual']) | |
476 | self.assertEqual((2070796000, 0), info['hz_advertised_raw']) | |
477 | self.assertEqual((2070796000, 0), info['hz_actual_raw']) | |
473 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
474 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
475 | self.assertEqual('2.0708 GHz', info['hz_advertised_friendly']) | |
476 | self.assertEqual('2.0708 GHz', info['hz_actual_friendly']) | |
477 | self.assertEqual((2070796000, 0), info['hz_advertised']) | |
478 | self.assertEqual((2070796000, 0), info['hz_actual']) | |
478 | 479 | |
479 | 480 | self.assertEqual(7, info['stepping']) |
480 | 481 | self.assertEqual(42, info['model']) |
481 | 482 | self.assertEqual(6, info['family']) |
482 | 483 | |
483 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
484 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
485 | self.assertEqual('256 KB', info['l2_cache_size']) | |
486 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
484 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
485 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
486 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
487 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
487 | 488 | self.assertEqual( |
488 | 489 | ['acpi', 'aperfmperf', 'apic', 'arat', 'arch_perfmon', 'bts', |
489 | 490 | 'clflush', 'cmov', 'constant_tsc', 'cx16', 'cx8', 'de', 'ds_cpl', |
503 | 504 | def test_get_cpu_info_from_dmesg(self): |
504 | 505 | info = cpuinfo._get_cpu_info_from_dmesg() |
505 | 506 | |
506 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
507 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
508 | self.assertEqual('2.8000 GHz', info['hz_actual']) | |
509 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
510 | self.assertEqual((2800000000, 0), info['hz_actual_raw']) | |
507 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
508 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
509 | self.assertEqual('2.8000 GHz', info['hz_actual_friendly']) | |
510 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
511 | self.assertEqual((2800000000, 0), info['hz_actual']) | |
511 | 512 | |
512 | 513 | self.assertEqual(7, info['stepping']) |
513 | 514 | self.assertEqual(42, info['model']) |
516 | 517 | def test_get_cpu_info_from_proc_cpuinfo(self): |
517 | 518 | info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
518 | 519 | |
519 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
520 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
521 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
522 | self.assertEqual('1.9014 GHz', info['hz_actual']) | |
523 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
524 | self.assertEqual((1901375000, 0), info['hz_actual_raw']) | |
525 | ||
526 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
520 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
521 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
522 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
523 | self.assertEqual('1.9014 GHz', info['hz_actual_friendly']) | |
524 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
525 | self.assertEqual((1901375000, 0), info['hz_actual']) | |
526 | ||
527 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
527 | 528 | |
528 | 529 | self.assertEqual(7, info['stepping']) |
529 | 530 | self.assertEqual(42, info['model']) |
547 | 548 | def test_all(self): |
548 | 549 | info = cpuinfo._get_cpu_info_internal() |
549 | 550 | |
550 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
551 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand']) | |
552 | self.assertEqual('2.8000 GHz', info['hz_advertised']) | |
553 | self.assertEqual('1.9014 GHz', info['hz_actual']) | |
554 | self.assertEqual((2800000000, 0), info['hz_advertised_raw']) | |
555 | self.assertEqual((1901375000, 0), info['hz_actual_raw']) | |
551 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
552 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', info['brand_raw']) | |
553 | self.assertEqual('2.8000 GHz', info['hz_advertised_friendly']) | |
554 | self.assertEqual('1.9014 GHz', info['hz_actual_friendly']) | |
555 | self.assertEqual((2800000000, 0), info['hz_advertised']) | |
556 | self.assertEqual((1901375000, 0), info['hz_actual']) | |
556 | 557 | self.assertEqual('X86_64', info['arch']) |
557 | 558 | self.assertEqual(64, info['bits']) |
558 | 559 | self.assertEqual(2, info['count']) |
559 | 560 | |
560 | self.assertEqual('x86_64', info['raw_arch_string']) | |
561 | ||
562 | self.assertEqual('32 KB', info['l1_instruction_cache_size']) | |
563 | self.assertEqual('32 KB', info['l1_data_cache_size']) | |
564 | ||
565 | self.assertEqual('256 KB', info['l2_cache_size']) | |
566 | ||
567 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
561 | self.assertEqual('x86_64', info['arch_string_raw']) | |
562 | ||
563 | self.assertEqual(32 * 1024, info['l1_instruction_cache_size']) | |
564 | self.assertEqual(32 * 1024, info['l1_data_cache_size']) | |
565 | ||
566 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
567 | ||
568 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
568 | 569 | |
569 | 570 | self.assertEqual(7, info['stepping']) |
570 | 571 | self.assertEqual(42, info['model']) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource(object): | |
8 | bits = '32bit' | |
9 | cpu_count = 8 | |
10 | is_windows = False | |
11 | arch_string_raw = 'i86pc' | |
12 | uname_string_raw = 'i386' | |
13 | can_cpuid = False | |
14 | ||
15 | @staticmethod | |
16 | def has_isainfo(): | |
17 | return True | |
18 | ||
19 | @staticmethod | |
20 | def has_kstat(): | |
21 | return True | |
22 | ||
23 | @staticmethod | |
24 | def isainfo_vb(): | |
25 | returncode = 0 | |
26 | output = r''' | |
27 | 64-bit amd64 applications | |
28 | rdseed avx2 rdrand avx xsave pclmulqdq aes movbe sse4.2 sse4.1 | |
29 | ssse3 amd_lzcnt popcnt amd_sse4a tscp ahf cx16 sse3 sse2 sse fxsr | |
30 | amd_mmx mmx cmov amd_sysc cx8 tsc fpu | |
31 | ||
32 | ''' | |
33 | return returncode, output | |
34 | ||
35 | @staticmethod | |
36 | def kstat_m_cpu_info(): | |
37 | returncode = 0 | |
38 | output = r''' | |
39 | module: cpu_info instance: 0 | |
40 | name: cpu_info0 class: misc | |
41 | brand AMD Ryzen 7 2700X Eight-Core Processor | |
42 | cache_id 0 | |
43 | chip_id 0 | |
44 | clock_MHz 3693 | |
45 | clog_id 0 | |
46 | core_id 0 | |
47 | cpu_type i386 | |
48 | crtime 22.539390752 | |
49 | current_clock_Hz 3692643590 | |
50 | current_cstate 1 | |
51 | family 23 | |
52 | fpu_type i387 compatible | |
53 | implementation x86 (chipid 0x0 AuthenticAMD 800F82 family 23 model 8 step 2 clock 3693 MHz) | |
54 | model 8 | |
55 | ncore_per_chip 8 | |
56 | ncpu_per_chip 8 | |
57 | pg_id 1 | |
58 | pkg_core_id 0 | |
59 | snaptime 120.971135132 | |
60 | socket_type Unknown | |
61 | state on-line | |
62 | state_begin 1553482276 | |
63 | stepping 2 | |
64 | supported_frequencies_Hz 3692643590 | |
65 | supported_max_cstates 0 | |
66 | vendor_id AuthenticAMD | |
67 | ||
68 | ||
69 | ''' | |
70 | return returncode, output | |
71 | ||
72 | ||
73 | ||
74 | class TestOpenIndiana_5_11_Ryzen_7(unittest.TestCase): | |
75 | def setUp(self): | |
76 | helpers.backup_data_source(cpuinfo) | |
77 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) | |
78 | ||
79 | def tearDown(self): | |
80 | helpers.restore_data_source(cpuinfo) | |
81 | ||
82 | ''' | |
83 | Make sure calls return the expected number of fields. | |
84 | ''' | |
85 | def test_returns(self): | |
86 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_registry())) | |
87 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpufreq_info())) | |
88 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_lscpu())) | |
89 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) | |
90 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) | |
91 | self.assertEqual(10, len(cpuinfo._get_cpu_info_from_kstat())) | |
92 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_dmesg())) | |
93 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) | |
94 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) | |
95 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) | |
96 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
97 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
98 | ||
99 | def test_get_cpu_info_from_kstat(self): | |
100 | info = cpuinfo._get_cpu_info_from_kstat() | |
101 | ||
102 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
103 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
104 | self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
105 | self.assertEqual('3.6926 GHz', info['hz_actual_friendly']) | |
106 | self.assertEqual((3693000000, 0), info['hz_advertised']) | |
107 | self.assertEqual((3692643590, 0), info['hz_actual']) | |
108 | ||
109 | self.assertEqual(2, info['stepping']) | |
110 | self.assertEqual(8, info['model']) | |
111 | self.assertEqual(23, info['family']) | |
112 | self.assertEqual( | |
113 | ['amd_mmx', 'amd_sysc', 'cmov', 'cx8', 'fpu', 'mmx', 'tsc'] | |
114 | , | |
115 | info['flags'] | |
116 | ) | |
117 | ||
118 | def test_all(self): | |
119 | info = cpuinfo._get_cpu_info_internal() | |
120 | ||
121 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
122 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
123 | self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
124 | self.assertEqual('3.6926 GHz', info['hz_actual_friendly']) | |
125 | self.assertEqual((3693000000, 0), info['hz_advertised']) | |
126 | self.assertEqual((3692643590, 0), info['hz_actual']) | |
127 | self.assertEqual('X86_32', info['arch']) | |
128 | self.assertEqual(32, info['bits']) | |
129 | self.assertEqual(8, info['count']) | |
130 | ||
131 | self.assertEqual('i86pc', info['arch_string_raw']) | |
132 | ||
133 | self.assertEqual(2, info['stepping']) | |
134 | self.assertEqual(8, info['model']) | |
135 | self.assertEqual(23, info['family']) | |
136 | self.assertEqual( | |
137 | ['amd_mmx', 'amd_sysc', 'cmov', 'cx8', 'fpu', 'mmx', 'tsc'] | |
138 | , | |
139 | info['flags'] | |
140 | ) |
10 | 10 | bits = '64bit' |
11 | 11 | cpu_count = 4 |
12 | 12 | is_windows = False |
13 | raw_arch_string = 'x86_64' | |
13 | arch_string_raw = 'x86_64' | |
14 | uname_string_raw = 'x86_64' | |
14 | 15 | can_cpuid = False |
15 | 16 | |
16 | 17 | @staticmethod |
20 | 21 | @staticmethod |
21 | 22 | def sysctl_machdep_cpu_hw_cpufrequency(): |
22 | 23 | returncode = 0 |
23 | output = ''' | |
24 | output = r''' | |
24 | 25 | machdep.cpu.tsc_ccc.denominator: 0 |
25 | 26 | machdep.cpu.tsc_ccc.numerator: 0 |
26 | 27 | machdep.cpu.thread_count: 4 |
107 | 108 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
108 | 109 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
109 | 110 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
110 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
111 | self.assertEqual(18, len(cpuinfo._get_cpu_info_internal())) | |
111 | 112 | |
112 | 113 | def test_get_cpu_info_from_sysctl(self): |
113 | 114 | info = cpuinfo._get_cpu_info_from_sysctl() |
114 | 115 | |
115 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
116 | self.assertEqual('Intel(R) Core(TM) i5-2557M CPU @ 1.70GHz', info['brand']) | |
117 | self.assertEqual('1.7000 GHz', info['hz_advertised']) | |
118 | self.assertEqual('1.7000 GHz', info['hz_actual']) | |
119 | self.assertEqual((1700000000, 0), info['hz_advertised_raw']) | |
120 | self.assertEqual((1700000000, 0), info['hz_actual_raw']) | |
116 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
117 | self.assertEqual('Intel(R) Core(TM) i5-2557M CPU @ 1.70GHz', info['brand_raw']) | |
118 | self.assertEqual('1.7000 GHz', info['hz_advertised_friendly']) | |
119 | self.assertEqual('1.7000 GHz', info['hz_actual_friendly']) | |
120 | self.assertEqual((1700000000, 0), info['hz_advertised']) | |
121 | self.assertEqual((1700000000, 0), info['hz_actual']) | |
121 | 122 | |
122 | self.assertEqual('256', info['l2_cache_size']) | |
123 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
123 | 124 | |
124 | 125 | self.assertEqual(7, info['stepping']) |
125 | 126 | self.assertEqual(42, info['model']) |
141 | 142 | def test_all(self): |
142 | 143 | info = cpuinfo._get_cpu_info_internal() |
143 | 144 | |
144 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
145 | self.assertEqual('Intel(R) Core(TM) i5-2557M CPU @ 1.70GHz', info['brand']) | |
146 | self.assertEqual('1.7000 GHz', info['hz_advertised']) | |
147 | self.assertEqual('1.7000 GHz', info['hz_actual']) | |
148 | self.assertEqual((1700000000, 0), info['hz_advertised_raw']) | |
149 | self.assertEqual((1700000000, 0), info['hz_actual_raw']) | |
145 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
146 | self.assertEqual('Intel(R) Core(TM) i5-2557M CPU @ 1.70GHz', info['brand_raw']) | |
147 | self.assertEqual('1.7000 GHz', info['hz_advertised_friendly']) | |
148 | self.assertEqual('1.7000 GHz', info['hz_actual_friendly']) | |
149 | self.assertEqual((1700000000, 0), info['hz_advertised']) | |
150 | self.assertEqual((1700000000, 0), info['hz_actual']) | |
150 | 151 | self.assertEqual('X86_64', info['arch']) |
151 | 152 | self.assertEqual(64, info['bits']) |
152 | 153 | self.assertEqual(4, info['count']) |
153 | 154 | |
154 | self.assertEqual('x86_64', info['raw_arch_string']) | |
155 | self.assertEqual('x86_64', info['arch_string_raw']) | |
155 | 156 | |
156 | self.assertEqual('256', info['l2_cache_size']) | |
157 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
157 | 158 | |
158 | 159 | self.assertEqual(7, info['stepping']) |
159 | 160 | self.assertEqual(42, info['model']) |
10 | 10 | bits = '64bit' |
11 | 11 | cpu_count = 4 |
12 | 12 | is_windows = False |
13 | raw_arch_string = 'x86_64' | |
13 | arch_string_raw = 'x86_64' | |
14 | uname_string_raw = 'x86_64' | |
14 | 15 | can_cpuid = False |
15 | 16 | |
16 | 17 | @staticmethod |
20 | 21 | @staticmethod |
21 | 22 | def sysctl_machdep_cpu_hw_cpufrequency(): |
22 | 23 | returncode = 0 |
23 | output = ''' | |
24 | output = r''' | |
24 | 25 | machdep.cpu.max_basic: 5 |
25 | 26 | machdep.cpu.max_ext: 2147483656 |
26 | 27 | machdep.cpu.vendor: GenuineIntel |
87 | 88 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
88 | 89 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
89 | 90 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
90 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
91 | self.assertEqual(18, len(cpuinfo._get_cpu_info_internal())) | |
91 | 92 | |
92 | 93 | def test_get_cpu_info_from_sysctl(self): |
93 | 94 | info = cpuinfo._get_cpu_info_from_sysctl() |
94 | 95 | |
95 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
96 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand']) | |
97 | self.assertEqual('3.1000 GHz', info['hz_advertised']) | |
98 | self.assertEqual('2.8900 GHz', info['hz_actual']) | |
99 | self.assertEqual((3100000000, 0), info['hz_advertised_raw']) | |
100 | self.assertEqual((2890000000, 0), info['hz_actual_raw']) | |
96 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
97 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand_raw']) | |
98 | self.assertEqual('3.1000 GHz', info['hz_advertised_friendly']) | |
99 | self.assertEqual('2.8900 GHz', info['hz_actual_friendly']) | |
100 | self.assertEqual((3100000000, 0), info['hz_advertised']) | |
101 | self.assertEqual((2890000000, 0), info['hz_actual']) | |
101 | 102 | |
102 | self.assertEqual('256', info['l2_cache_size']) | |
103 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
103 | 104 | |
104 | 105 | self.assertEqual(9, info['stepping']) |
105 | 106 | self.assertEqual(58, info['model']) |
117 | 118 | def test_all(self): |
118 | 119 | info = cpuinfo._get_cpu_info_internal() |
119 | 120 | |
120 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
121 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand']) | |
122 | self.assertEqual('3.1000 GHz', info['hz_advertised']) | |
123 | self.assertEqual('2.8900 GHz', info['hz_actual']) | |
124 | self.assertEqual((3100000000, 0), info['hz_advertised_raw']) | |
125 | self.assertEqual((2890000000, 0), info['hz_actual_raw']) | |
121 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
122 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand_raw']) | |
123 | self.assertEqual('3.1000 GHz', info['hz_advertised_friendly']) | |
124 | self.assertEqual('2.8900 GHz', info['hz_actual_friendly']) | |
125 | self.assertEqual((3100000000, 0), info['hz_advertised']) | |
126 | self.assertEqual((2890000000, 0), info['hz_actual']) | |
126 | 127 | self.assertEqual('X86_64', info['arch']) |
127 | 128 | self.assertEqual(64, info['bits']) |
128 | 129 | self.assertEqual(4, info['count']) |
129 | 130 | |
130 | self.assertEqual('x86_64', info['raw_arch_string']) | |
131 | self.assertEqual('x86_64', info['arch_string_raw']) | |
131 | 132 | |
132 | self.assertEqual('256', info['l2_cache_size']) | |
133 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
133 | 134 | |
134 | 135 | self.assertEqual(9, info['stepping']) |
135 | 136 | self.assertEqual(58, info['model']) |
5 | 5 | |
6 | 6 | |
7 | 7 | |
8 | ||
8 | 9 | class TestParseCPUString(unittest.TestCase): |
9 | def test_parse_cpu_string(self): | |
10 | processor_brand, hz_actual, scale, vendor_id, stepping, model, family = \ | |
11 | cpuinfo._parse_cpu_string("Intel(R) Pentium(R) CPU G640 @ 2.80GHz (fam: 06, model: 2a, stepping: 07)") | |
12 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', processor_brand) | |
13 | self.assertEqual('2.8', hz_actual) | |
14 | self.assertEqual(9, scale) | |
15 | self.assertEqual(None, vendor_id) | |
16 | self.assertEqual(7, stepping) | |
17 | self.assertEqual(42, model) | |
18 | self.assertEqual(6, family) | |
10 | def test_to_decimal_string(self): | |
11 | self.assertEqual('2.8', cpuinfo._to_decimal_string('2.80')) | |
12 | self.assertEqual('2.0', cpuinfo._to_decimal_string('2')) | |
13 | self.assertEqual('3.0', cpuinfo._to_decimal_string(3)) | |
14 | self.assertEqual('6.5', cpuinfo._to_decimal_string(6.5)) | |
15 | self.assertEqual('7.002', cpuinfo._to_decimal_string(7.002)) | |
16 | self.assertEqual('4.00000000001', cpuinfo._to_decimal_string('4.00000000001')) | |
17 | self.assertEqual('5.0', cpuinfo._to_decimal_string('5.000000000000')) | |
19 | 18 | |
20 | processor_brand, hz_actual, scale, vendor_id, stepping, model, family = \ | |
21 | cpuinfo._parse_cpu_string("Intel(R) Pentium(R) CPU G640 @ 2.80GHz (family: 0x6, model: 0x2a, stepping: 0x7)") | |
22 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', processor_brand) | |
23 | self.assertEqual('2.8', hz_actual) | |
24 | self.assertEqual(9, scale) | |
25 | self.assertEqual(None, vendor_id) | |
26 | self.assertEqual(7, stepping) | |
27 | self.assertEqual(42, model) | |
28 | self.assertEqual(6, family) | |
19 | self.assertEqual('0.0', cpuinfo._to_decimal_string('invalid')) | |
20 | self.assertEqual('0.0', cpuinfo._to_decimal_string('8.778.9')) | |
21 | self.assertEqual('0.0', cpuinfo._to_decimal_string('')) | |
22 | self.assertEqual('0.0', cpuinfo._to_decimal_string(None)) | |
29 | 23 | |
30 | processor_brand, hz_actual, scale, vendor_id, stepping, model, family = \ | |
31 | cpuinfo._parse_cpu_string("Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz") | |
32 | self.assertEqual("Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz", processor_brand) | |
33 | self.assertEqual('2.93', hz_actual) | |
34 | self.assertEqual(9, scale) | |
35 | self.assertEqual(None, vendor_id) | |
36 | self.assertEqual(None, stepping) | |
37 | self.assertEqual(None, model) | |
38 | self.assertEqual(None, family) | |
24 | def test_hz_short_to_full(self): | |
25 | self.assertEqual((2800000000, 0), cpuinfo._hz_short_to_full('2.8', 9)) | |
26 | self.assertEqual((1200000, 0), cpuinfo._hz_short_to_full('1.2', 6)) | |
27 | self.assertEqual((3200000000, 0), cpuinfo._hz_short_to_full('3.2', 9)) | |
28 | self.assertEqual((9001200000, 0), cpuinfo._hz_short_to_full('9001.2', 6)) | |
29 | self.assertEqual((0, 0), cpuinfo._hz_short_to_full('0.0', 0)) | |
30 | self.assertEqual((2, 87), cpuinfo._hz_short_to_full('2.87', 0)) | |
39 | 31 | |
40 | processor_brand, hz_actual, scale, vendor_id, stepping, model, family = \ | |
41 | cpuinfo._parse_cpu_string("Intel(R) Pentium(R) CPU G640 @ 2.80GHz (2793.73-MHz K8-class CPU)") | |
42 | self.assertEqual("Intel(R) Pentium(R) CPU G640 @ 2.80GHz", processor_brand) | |
43 | self.assertEqual('2.8', hz_actual) | |
44 | self.assertEqual(9, scale) | |
45 | self.assertEqual(None, vendor_id) | |
46 | self.assertEqual(None, stepping) | |
47 | self.assertEqual(None, model) | |
48 | self.assertEqual(None, family) | |
32 | self.assertEqual((0, 0), cpuinfo._hz_short_to_full('invalid', 0)) | |
33 | self.assertEqual((0, 0), cpuinfo._hz_short_to_full('8.778.9', 0)) | |
34 | self.assertEqual((0, 0), cpuinfo._hz_short_to_full('', 0)) | |
35 | self.assertEqual((0, 0), cpuinfo._hz_short_to_full(None, 0)) | |
36 | ||
37 | def test_hz_friendly_to_full(self): | |
38 | self.assertEqual((2800000000, 0), cpuinfo._hz_friendly_to_full('2.80GHz')) | |
39 | self.assertEqual((1200000, 0), cpuinfo._hz_friendly_to_full('1.20 mHz')) | |
40 | self.assertEqual((3693150000, 0), cpuinfo._hz_friendly_to_full('3693.15-MHz')) | |
41 | self.assertEqual((12000000000, 0), cpuinfo._hz_friendly_to_full('12 GHz')) | |
42 | self.assertEqual((2, 6), cpuinfo._hz_friendly_to_full('2.6 Hz')) | |
43 | self.assertEqual((0, 0), cpuinfo._hz_friendly_to_full('0 Hz')) | |
44 | ||
45 | self.assertEqual((0, 0), cpuinfo._hz_friendly_to_full('invalid')) | |
46 | self.assertEqual((0, 0), cpuinfo._hz_friendly_to_full('8.778.9')) | |
47 | self.assertEqual((0, 0), cpuinfo._hz_friendly_to_full('')) | |
48 | self.assertEqual((0, 0), cpuinfo._hz_friendly_to_full(None)) | |
49 | ||
50 | def test_hz_short_to_friendly(self): | |
51 | self.assertEqual('2.8000 GHz', cpuinfo._hz_short_to_friendly('2.8', 9)) | |
52 | self.assertEqual('1.2000 MHz', cpuinfo._hz_short_to_friendly('1.2', 6)) | |
53 | self.assertEqual('3.2000 GHz', cpuinfo._hz_short_to_friendly('3.2', 9)) | |
54 | self.assertEqual('1.3000 Hz', cpuinfo._hz_short_to_friendly('1.3', 0)) | |
55 | self.assertEqual('0.0000 Hz', cpuinfo._hz_short_to_friendly('0.0', 0)) | |
56 | ||
57 | self.assertEqual('0.0000 Hz', cpuinfo._hz_short_to_friendly('invalid', 0)) | |
58 | self.assertEqual('0.0000 Hz', cpuinfo._hz_short_to_friendly('8.778.9', 0)) | |
59 | self.assertEqual('0.0000 Hz', cpuinfo._hz_short_to_friendly('', 0)) | |
60 | self.assertEqual('0.0000 Hz', cpuinfo._hz_short_to_friendly(None, 0)) | |
61 | ||
62 | def test_parse_cpu_brand_string(self): | |
63 | hz, scale = cpuinfo._parse_cpu_brand_string('Intel(R) Pentium(R) CPU G640 @ 2.80GHz') | |
64 | self.assertEqual((hz, scale), ('2.8', 9)) | |
65 | ||
66 | hz, scale = cpuinfo._parse_cpu_brand_string('Intel(R) Pentium(R) CPU @ 1.20MHz') | |
67 | self.assertEqual((hz, scale), ('1.2', 6)) | |
49 | 68 | |
50 | 69 | # NOTE: No @ symbol |
51 | processor_brand, hz_actual, scale, vendor_id, stepping, model, family = \ | |
52 | cpuinfo._parse_cpu_string("Intel(R) Pentium(R) D CPU 3.20GHz") | |
53 | self.assertEqual("Intel(R) Pentium(R) D CPU 3.20GHz", processor_brand) | |
54 | self.assertEqual('3.2', hz_actual) | |
55 | self.assertEqual(9, scale) | |
56 | self.assertEqual(None, vendor_id) | |
57 | self.assertEqual(None, stepping) | |
58 | self.assertEqual(None, model) | |
59 | self.assertEqual(None, family) | |
70 | hz, scale = cpuinfo._parse_cpu_brand_string('Intel(R) Pentium(R) D CPU 3.20GHz') | |
71 | self.assertEqual((hz, scale), ('3.2', 9)) | |
60 | 72 | |
61 | def test_to_friendly_hz(self): | |
62 | scale, hz_brand = cpuinfo._get_hz_string_from_brand('Intel(R) Pentium(R) CPU G640 @ 2.80GHz') | |
63 | self.assertEqual(9, scale) | |
64 | self.assertEqual('2.8', hz_brand) | |
65 | self.assertEqual('2.8000 GHz', cpuinfo._to_friendly_hz(hz_brand, scale)) | |
73 | # NOTE: No @ symbol and no Hz | |
74 | hz, scale = cpuinfo._parse_cpu_brand_string('AMD Ryzen 7 2700X Eight-Core Processor') | |
75 | self.assertEqual((hz, scale), ('0.0', 0)) | |
66 | 76 | |
67 | scale, hz_brand = cpuinfo._get_hz_string_from_brand('Intel(R) Pentium(R) CPU @ 1.20MHz') | |
68 | self.assertEqual(6, scale) | |
69 | self.assertEqual('1.2', hz_brand) | |
70 | self.assertEqual('1.2000 MHz', cpuinfo._to_friendly_hz(hz_brand, scale)) | |
77 | def test_parse_cpu_brand_string_dx(self): | |
78 | hz, scale, brand, vendor_id, stepping, model, family = \ | |
79 | cpuinfo._parse_cpu_brand_string_dx("Intel(R) Pentium(R) CPU G640 @ 2.80GHz (fam: 06, model: 2a, stepping: 07)") | |
80 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', brand) | |
81 | self.assertEqual((hz, scale), ('2.8', 9)) | |
82 | self.assertEqual((vendor_id, stepping, model, family), (None, 7, 42, 6)) | |
71 | 83 | |
72 | scale, hz_brand = cpuinfo._get_hz_string_from_brand('Intel(R) Pentium(R) D CPU 3.20GHz') | |
73 | self.assertEqual(9, scale) | |
74 | self.assertEqual('3.2', hz_brand) | |
75 | self.assertEqual('3.2000 GHz', cpuinfo._to_friendly_hz(hz_brand, scale)) | |
84 | hz, scale, brand, vendor_id, stepping, model, family = \ | |
85 | cpuinfo._parse_cpu_brand_string_dx("Intel(R) Pentium(R) CPU G640 @ 2.80GHz (family: 0x6, model: 0x2a, stepping: 0x7)") | |
86 | self.assertEqual('Intel(R) Pentium(R) CPU G640 @ 2.80GHz', brand) | |
87 | self.assertEqual((hz, scale), ('2.8', 9)) | |
88 | self.assertEqual((vendor_id, stepping, model, family), (None, 7, 42, 6)) | |
76 | 89 | |
77 | def test_to_raw_hz(self): | |
78 | scale, hz_brand = cpuinfo._get_hz_string_from_brand('Intel(R) Pentium(R) CPU G640 @ 2.80GHz') | |
79 | self.assertEqual(9, scale) | |
80 | self.assertEqual('2.8', hz_brand) | |
81 | self.assertEqual((2800000000, 0), cpuinfo._to_raw_hz(hz_brand, scale)) | |
90 | hz, scale, brand, vendor_id, stepping, model, family = \ | |
91 | cpuinfo._parse_cpu_brand_string_dx("Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz") | |
92 | self.assertEqual("Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz", brand) | |
93 | self.assertEqual((hz, scale), ('2.93', 9)) | |
94 | self.assertEqual((vendor_id, stepping, model, family), (None, None, None, None)) | |
82 | 95 | |
83 | scale, hz_brand = cpuinfo._get_hz_string_from_brand('Intel(R) Pentium(R) CPU @ 1.20MHz') | |
84 | self.assertEqual(6, scale) | |
85 | self.assertEqual('1.2', hz_brand) | |
86 | self.assertEqual((1200000, 0), cpuinfo._to_raw_hz(hz_brand, scale)) | |
96 | hz, scale, brand, vendor_id, stepping, model, family = \ | |
97 | cpuinfo._parse_cpu_brand_string_dx("Intel(R) Pentium(R) CPU G640 @ 2.80GHz (2793.73-MHz K8-class CPU)") | |
98 | self.assertEqual("Intel(R) Pentium(R) CPU G640 @ 2.80GHz", brand) | |
99 | self.assertEqual((hz, scale), ('2.8', 9)) | |
100 | self.assertEqual((vendor_id, stepping, model, family), (None, None, None, None)) | |
87 | 101 | |
88 | 102 | # NOTE: No @ symbol |
89 | scale, hz_brand = cpuinfo._get_hz_string_from_brand('Intel(R) Pentium(R) D CPU 3.20GHz') | |
90 | self.assertEqual(9, scale) | |
91 | self.assertEqual('3.2', hz_brand) | |
92 | self.assertEqual((3200000000, 0), cpuinfo._to_raw_hz(hz_brand, scale)) | |
103 | hz, scale, brand, vendor_id, stepping, model, family = \ | |
104 | cpuinfo._parse_cpu_brand_string_dx("Intel(R) Pentium(R) D CPU 3.20GHz") | |
105 | self.assertEqual("Intel(R) Pentium(R) D CPU 3.20GHz", brand) | |
106 | self.assertEqual((hz, scale), ('3.2', 9)) | |
107 | self.assertEqual((vendor_id, stepping, model, family), (None, None, None, None)) | |
108 | ||
109 | # NOTE: No @ symbol and no Hz | |
110 | hz, scale, brand, vendor_id, stepping, model, family = \ | |
111 | cpuinfo._parse_cpu_brand_string_dx("AMD Ryzen 7 2700X Eight-Core Processor (3693.15-MHz K8-class CPU) (fam: 06, model: 2a, stepping: 07)") | |
112 | self.assertEqual("AMD Ryzen 7 2700X Eight-Core Processor", brand) | |
113 | self.assertEqual((hz, scale), ('3693.15', 6)) | |
114 | self.assertEqual((vendor_id, stepping, model, family), (None, 7, 42, 6)) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = True |
11 | raw_arch_string = 'x86_64' | |
11 | arch_string_raw = 'x86_64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
56 | 57 | return 0, "" |
57 | 58 | |
58 | 59 | @staticmethod |
59 | def sestatus_allow_execheap(): | |
60 | return True | |
61 | ||
62 | @staticmethod | |
63 | def sestatus_allow_execmem(): | |
64 | return True | |
60 | def sestatus_b(): | |
61 | return 0, "" | |
65 | 62 | |
66 | 63 | @staticmethod |
67 | 64 | def dmesg_a(): |
93 | 90 | return {} |
94 | 91 | |
95 | 92 | @staticmethod |
96 | def winreg_vendor_id(): | |
93 | def winreg_vendor_id_raw(): | |
97 | 94 | return {} |
98 | 95 | |
99 | 96 | @staticmethod |
100 | def winreg_raw_arch_string(): | |
97 | def winreg_arch_string_raw(): | |
101 | 98 | return {} |
102 | 99 | |
103 | 100 | @staticmethod |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 1 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'amd64' | |
11 | arch_string_raw = 'amd64' | |
12 | uname_string_raw = 'x86_64' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
18 | 19 | @staticmethod |
19 | 20 | def dmesg_a(): |
20 | 21 | retcode = 0 |
21 | output = '''Copyright (c) 1992-2014 The FreeBSD Project. | |
22 | output = r'''Copyright (c) 1992-2014 The FreeBSD Project. | |
22 | 23 | Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 |
23 | 24 | The Regents of the University of California. All rights reserved. |
24 | 25 | FreeBSD is a registered trademark of The FreeBSD Foundation. |
61 | 62 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
62 | 63 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
63 | 64 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
64 | self.assertEqual(12, len(cpuinfo._get_cpu_info_internal())) | |
65 | self.assertEqual(13, len(cpuinfo._get_cpu_info_internal())) | |
65 | 66 | |
66 | 67 | def test_get_cpu_info_from_dmesg(self): |
67 | 68 | info = cpuinfo._get_cpu_info_from_dmesg() |
68 | 69 | |
69 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand']) | |
70 | self.assertEqual('3.1000 GHz', info['hz_advertised']) | |
71 | self.assertEqual('3.1000 GHz', info['hz_actual']) | |
72 | self.assertEqual((3100000000, 0), info['hz_advertised_raw']) | |
73 | self.assertEqual((3100000000, 0), info['hz_actual_raw']) | |
70 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand_raw']) | |
71 | self.assertEqual('3.1000 GHz', info['hz_advertised_friendly']) | |
72 | self.assertEqual('3.1000 GHz', info['hz_actual_friendly']) | |
73 | self.assertEqual((3100000000, 0), info['hz_advertised']) | |
74 | self.assertEqual((3100000000, 0), info['hz_actual']) | |
74 | 75 | |
75 | 76 | self.assertEqual( |
76 | 77 | ['apic', 'clflush', 'cmov', 'cx8', 'de', 'fpu', 'fxsr', 'lahf', |
84 | 85 | def test_all(self): |
85 | 86 | info = cpuinfo._get_cpu_info_internal() |
86 | 87 | |
87 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand']) | |
88 | self.assertEqual('3.1000 GHz', info['hz_advertised']) | |
89 | self.assertEqual('3.1000 GHz', info['hz_actual']) | |
90 | self.assertEqual((3100000000, 0), info['hz_advertised_raw']) | |
91 | self.assertEqual((3100000000, 0), info['hz_actual_raw']) | |
88 | self.assertEqual('Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz', info['brand_raw']) | |
89 | self.assertEqual('3.1000 GHz', info['hz_advertised_friendly']) | |
90 | self.assertEqual('3.1000 GHz', info['hz_actual_friendly']) | |
91 | self.assertEqual((3100000000, 0), info['hz_advertised']) | |
92 | self.assertEqual((3100000000, 0), info['hz_actual']) | |
92 | 93 | self.assertEqual('X86_64', info['arch']) |
93 | 94 | self.assertEqual(64, info['bits']) |
94 | 95 | self.assertEqual(1, info['count']) |
95 | 96 | |
96 | self.assertEqual('amd64', info['raw_arch_string']) | |
97 | self.assertEqual('amd64', info['arch_string_raw']) | |
97 | 98 | |
98 | 99 | self.assertEqual( |
99 | 100 | ['apic', 'clflush', 'cmov', 'cx8', 'de', 'fpu', 'fxsr', 'lahf', |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource_enforcing(object): | |
8 | @staticmethod | |
9 | def has_sestatus(): | |
10 | return True | |
11 | ||
12 | @staticmethod | |
13 | def sestatus_b(): | |
14 | returncode = 0 | |
15 | output = r''' | |
16 | SELinux status: enabled | |
17 | SELinuxfs mount: /sys/fs/selinux | |
18 | SELinux root directory: /etc/selinux | |
19 | Loaded policy name: targeted | |
20 | Current mode: enforcing | |
21 | Mode from config file: enforcing | |
22 | Policy MLS status: enabled | |
23 | Policy deny_unknown status: allowed | |
24 | Memory protection checking: actual (secure) | |
25 | Max kernel policy version: 31 | |
26 | ''' | |
27 | return returncode, output | |
28 | ||
29 | class MockDataSource_not_enforcing(object): | |
30 | @staticmethod | |
31 | def has_sestatus(): | |
32 | return True | |
33 | ||
34 | @staticmethod | |
35 | def sestatus_b(): | |
36 | returncode = 0 | |
37 | output = r''' | |
38 | SELinux status: enabled | |
39 | SELinuxfs mount: /sys/fs/selinux | |
40 | SELinux root directory: /etc/selinux | |
41 | Loaded policy name: targeted | |
42 | Current mode: eating | |
43 | Mode from config file: enforcing | |
44 | Policy MLS status: enabled | |
45 | Policy deny_unknown status: allowed | |
46 | Memory protection checking: actual (secure) | |
47 | Max kernel policy version: 31 | |
48 | ''' | |
49 | return returncode, output | |
50 | ||
51 | class MockDataSource_exec_mem_and_heap(object): | |
52 | @staticmethod | |
53 | def has_sestatus(): | |
54 | return True | |
55 | ||
56 | @staticmethod | |
57 | def sestatus_b(): | |
58 | returncode = 0 | |
59 | output = r''' | |
60 | allow_execheap on | |
61 | allow_execmem on | |
62 | ''' | |
63 | return returncode, output | |
64 | ||
65 | class MockDataSource_no_exec_mem_and_heap(object): | |
66 | @staticmethod | |
67 | def has_sestatus(): | |
68 | return True | |
69 | ||
70 | @staticmethod | |
71 | def sestatus_b(): | |
72 | returncode = 0 | |
73 | output = r''' | |
74 | allow_execheap off | |
75 | allow_execmem off | |
76 | ''' | |
77 | return returncode, output | |
78 | ||
79 | ||
80 | class TestSELinux(unittest.TestCase): | |
81 | def setUp(self): | |
82 | helpers.backup_data_source(cpuinfo) | |
83 | ||
84 | def tearDown(self): | |
85 | helpers.restore_data_source(cpuinfo) | |
86 | ||
87 | def test_enforcing(self): | |
88 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource_enforcing) | |
89 | self.assertEqual(True, cpuinfo._is_selinux_enforcing()) | |
90 | ||
91 | def test_not_enforcing(self): | |
92 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource_not_enforcing) | |
93 | self.assertEqual(False, cpuinfo._is_selinux_enforcing()) | |
94 | ||
95 | def test_exec_mem_and_heap(self): | |
96 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource_exec_mem_and_heap) | |
97 | self.assertEqual(False, cpuinfo._is_selinux_enforcing()) | |
98 | ||
99 | def test_no_exec_mem_and_heap(self): | |
100 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource_no_exec_mem_and_heap) | |
101 | self.assertEqual(True, cpuinfo._is_selinux_enforcing()) |
8 | 8 | bits = '32bit' |
9 | 9 | cpu_count = 4 |
10 | 10 | is_windows = False |
11 | raw_arch_string = 'i86pc' | |
11 | arch_string_raw = 'i86pc' | |
12 | uname_string_raw = 'x86_32' | |
12 | 13 | can_cpuid = False |
13 | 14 | |
14 | 15 | @staticmethod |
22 | 23 | @staticmethod |
23 | 24 | def isainfo_vb(): |
24 | 25 | returncode = 0 |
25 | output = ''' | |
26 | output = r''' | |
26 | 27 | 64-bit amd64 applications |
27 | 28 | ssse3 tscp ahf sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu |
28 | 29 | |
32 | 33 | @staticmethod |
33 | 34 | def kstat_m_cpu_info(): |
34 | 35 | returncode = 0 |
35 | output = ''' | |
36 | output = r''' | |
36 | 37 | module: cpu_info instance: 0 |
37 | 38 | name: cpu_info0 class: misc |
38 | 39 | brand Intel(r) Core(tm) i7 CPU 870 @ 2.93GHz |
78 | 79 | |
79 | 80 | |
80 | 81 | |
81 | class TestSolaris(unittest.TestCase): | |
82 | class TestSolaris_11(unittest.TestCase): | |
82 | 83 | def setUp(self): |
83 | 84 | helpers.backup_data_source(cpuinfo) |
84 | 85 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
101 | 102 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
102 | 103 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
103 | 104 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
104 | self.assertEqual(16, len(cpuinfo._get_cpu_info_internal())) | |
105 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
105 | 106 | |
106 | 107 | def test_get_cpu_info_from_kstat(self): |
107 | 108 | info = cpuinfo._get_cpu_info_from_kstat() |
108 | 109 | |
109 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
110 | self.assertEqual('Intel(r) Core(tm) i7 CPU 870 @ 2.93GHz', info['brand']) | |
111 | self.assertEqual('2.9310 GHz', info['hz_advertised']) | |
112 | self.assertEqual('2.9305 GHz', info['hz_actual']) | |
113 | self.assertEqual((2931000000, 0), info['hz_advertised_raw']) | |
114 | self.assertEqual((2930505167, 0), info['hz_actual_raw']) | |
110 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
111 | self.assertEqual('Intel(r) Core(tm) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
112 | self.assertEqual('2.9310 GHz', info['hz_advertised_friendly']) | |
113 | self.assertEqual('2.9305 GHz', info['hz_actual_friendly']) | |
114 | self.assertEqual((2931000000, 0), info['hz_advertised']) | |
115 | self.assertEqual((2930505167, 0), info['hz_actual']) | |
115 | 116 | |
116 | 117 | self.assertEqual(5, info['stepping']) |
117 | 118 | self.assertEqual(30, info['model']) |
125 | 126 | def test_all(self): |
126 | 127 | info = cpuinfo._get_cpu_info_internal() |
127 | 128 | |
128 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
129 | self.assertEqual('Intel(r) Core(tm) i7 CPU 870 @ 2.93GHz', info['brand']) | |
130 | self.assertEqual('2.9310 GHz', info['hz_advertised']) | |
131 | self.assertEqual('2.9305 GHz', info['hz_actual']) | |
132 | self.assertEqual((2931000000, 0), info['hz_advertised_raw']) | |
133 | self.assertEqual((2930505167, 0), info['hz_actual_raw']) | |
129 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
130 | self.assertEqual('Intel(r) Core(tm) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
131 | self.assertEqual('2.9310 GHz', info['hz_advertised_friendly']) | |
132 | self.assertEqual('2.9305 GHz', info['hz_actual_friendly']) | |
133 | self.assertEqual((2931000000, 0), info['hz_advertised']) | |
134 | self.assertEqual((2930505167, 0), info['hz_actual']) | |
134 | 135 | self.assertEqual('X86_32', info['arch']) |
135 | 136 | self.assertEqual(32, info['bits']) |
136 | 137 | self.assertEqual(4, info['count']) |
137 | 138 | |
138 | self.assertEqual('i86pc', info['raw_arch_string']) | |
139 | self.assertEqual('i86pc', info['arch_string_raw']) | |
139 | 140 | |
140 | 141 | self.assertEqual(5, info['stepping']) |
141 | 142 | self.assertEqual(30, info['model']) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource(object): | |
8 | bits = '64bit' | |
9 | cpu_count = 8 | |
10 | is_windows = False | |
11 | arch_string_raw = 'amd64' | |
12 | uname_string_raw = 'amd64' | |
13 | can_cpuid = False | |
14 | ||
15 | @staticmethod | |
16 | def has_dmesg(): | |
17 | return True | |
18 | ||
19 | @staticmethod | |
20 | def dmesg_a(): | |
21 | retcode = 0 | |
22 | output = r'''Copyright (c) 1992-2018 The FreeBSD Project. | |
23 | Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 | |
24 | The Regents of the University of California. All rights reserved. | |
25 | FreeBSD is a registered trademark of The FreeBSD Foundation. | |
26 | FreeBSD 12.0-CURRENT #26 fa797a5a3(trueos-stable-18.03): Mon Mar 26 00:24:47 UTC 2018 | |
27 | root@chimera:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64 | |
28 | FreeBSD clang version 6.0.0 (branches/release_60 324090) (based on LLVM 6.0.0) | |
29 | VT(vga): text 80x25 | |
30 | CPU: AMD Ryzen 7 2700X Eight-Core Processor (3693.15-MHz K8-class CPU) | |
31 | Origin="AuthenticAMD" Id=0x800f82 Family=0x17 Model=0x8 Stepping=2 | |
32 | Features=0x1783fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE,SSE2,HTT> | |
33 | Features2=0x5ed82203<SSE3,PCLMULQDQ,SSSE3,CX16,SSE4.1,SSE4.2,MOVBE,POPCNT,AESNI,XSAVE,OSXSAVE,AVX,RDRAND> | |
34 | AMD Features=0x2a500800<SYSCALL,NX,MMX+,FFXSR,RDTSCP,LM> | |
35 | AMD Features2=0x1f3<LAHF,CMP,CR8,ABM,SSE4A,MAS,Prefetch> | |
36 | Structured Extended Features=0x40021<FSGSBASE,AVX2,RDSEED> | |
37 | TSC: P-state invariant | |
38 | ||
39 | ''' | |
40 | return retcode, output | |
41 | ||
42 | class TestTrueOS_18_X86_64_Ryzen7(unittest.TestCase): | |
43 | def setUp(self): | |
44 | helpers.backup_data_source(cpuinfo) | |
45 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) | |
46 | ||
47 | def tearDown(self): | |
48 | helpers.restore_data_source(cpuinfo) | |
49 | ||
50 | ''' | |
51 | Make sure calls return the expected number of fields. | |
52 | ''' | |
53 | def test_returns(self): | |
54 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_registry())) | |
55 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpufreq_info())) | |
56 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_lscpu())) | |
57 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) | |
58 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) | |
59 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_kstat())) | |
60 | self.assertEqual(10, len(cpuinfo._get_cpu_info_from_dmesg())) | |
61 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) | |
62 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) | |
63 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) | |
64 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
65 | self.assertEqual(17, len(cpuinfo._get_cpu_info_internal())) | |
66 | ||
67 | def test_get_cpu_info_from_dmesg(self): | |
68 | info = cpuinfo._get_cpu_info_from_dmesg() | |
69 | ||
70 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
71 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
72 | self.assertEqual('3.6932 GHz', info['hz_advertised_friendly']) | |
73 | self.assertEqual('3.6932 GHz', info['hz_actual_friendly']) | |
74 | self.assertEqual((3693150000, 0), info['hz_advertised']) | |
75 | self.assertEqual((3693150000, 0), info['hz_actual']) | |
76 | ||
77 | self.assertEqual(2, info['stepping']) | |
78 | self.assertEqual(8, info['model']) | |
79 | self.assertEqual(23, info['family']) | |
80 | ||
81 | self.assertEqual( | |
82 | ['abm', 'aesni', 'apic', 'avx', 'cmov', 'cmp', 'cr8', 'cx16', | |
83 | 'cx8', 'de', 'ffxsr', 'fpu', 'fxsr', 'htt', 'lahf', 'lm', 'mas', | |
84 | 'mca', 'mce', 'mmx', 'mmx+', 'movbe', 'msr', 'mtrr', 'nx', | |
85 | 'osxsave', 'pae', 'pat', 'pclmulqdq', 'pge', 'popcnt', 'prefetch', | |
86 | 'pse', 'pse36', 'rdrand', 'rdtscp', 'sep', 'sse', 'sse2', 'sse3', | |
87 | 'sse4.1', 'sse4.2', 'sse4a', 'ssse3', 'syscall', 'tsc', 'vme', | |
88 | 'xsave'] | |
89 | , | |
90 | info['flags'] | |
91 | ) | |
92 | ||
93 | def test_all(self): | |
94 | info = cpuinfo._get_cpu_info_internal() | |
95 | ||
96 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
97 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
98 | self.assertEqual('3.6932 GHz', info['hz_advertised_friendly']) | |
99 | self.assertEqual('3.6932 GHz', info['hz_actual_friendly']) | |
100 | self.assertEqual((3693150000, 0), info['hz_advertised']) | |
101 | self.assertEqual((3693150000, 0), info['hz_actual']) | |
102 | ||
103 | self.assertEqual('X86_64', info['arch']) | |
104 | self.assertEqual(64, info['bits']) | |
105 | self.assertEqual(8, info['count']) | |
106 | self.assertEqual('amd64', info['arch_string_raw']) | |
107 | ||
108 | self.assertEqual(2, info['stepping']) | |
109 | self.assertEqual(8, info['model']) | |
110 | self.assertEqual(23, info['family']) | |
111 | ||
112 | self.assertEqual( | |
113 | ['abm', 'aesni', 'apic', 'avx', 'cmov', 'cmp', 'cr8', 'cx16', | |
114 | 'cx8', 'de', 'ffxsr', 'fpu', 'fxsr', 'htt', 'lahf', 'lm', 'mas', | |
115 | 'mca', 'mce', 'mmx', 'mmx+', 'movbe', 'msr', 'mtrr', 'nx', | |
116 | 'osxsave', 'pae', 'pat', 'pclmulqdq', 'pge', 'popcnt', 'prefetch', | |
117 | 'pse', 'pse36', 'rdrand', 'rdtscp', 'sep', 'sse', 'sse2', 'sse3', | |
118 | 'sse4.1', 'sse4.2', 'sse4a', 'ssse3', 'syscall', 'tsc', 'vme', | |
119 | 'xsave'] | |
120 | , | |
121 | info['flags'] | |
122 | ) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 4 |
10 | 10 | is_windows = True |
11 | raw_arch_string = 'AMD64' | |
12 | can_cpuid = False | |
11 | arch_string_raw = 'AMD64' | |
12 | uname_string_raw = 'Intel64 Family 6 Model 69 Stepping 1, GenuineIntel' | |
13 | can_cpuid = True | |
13 | 14 | |
14 | 15 | @staticmethod |
15 | 16 | def has_wmic(): |
18 | 19 | @staticmethod |
19 | 20 | def wmic_cpu(): |
20 | 21 | returncode = 0 |
21 | output = ''' | |
22 | output = r''' | |
22 | 23 | Caption=Intel64 Family 6 Model 69 Stepping 1 |
23 | 24 | CurrentClockSpeed=2494 |
24 | 25 | Description=Intel64 Family 6 Model 69 Stepping 1 |
35 | 36 | return 'Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz' |
36 | 37 | |
37 | 38 | @staticmethod |
38 | def winreg_vendor_id(): | |
39 | def winreg_vendor_id_raw(): | |
39 | 40 | return 'GenuineIntel' |
40 | 41 | |
41 | 42 | @staticmethod |
42 | def winreg_raw_arch_string(): | |
43 | def winreg_arch_string_raw(): | |
43 | 44 | return 'AMD64' |
44 | 45 | |
45 | 46 | @staticmethod |
55 | 56 | |
56 | 57 | class TestWindows_10_X86_64(unittest.TestCase): |
57 | 58 | def setUp(self): |
59 | cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = False | |
58 | 60 | helpers.backup_data_source(cpuinfo) |
59 | 61 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
60 | 62 | |
63 | helpers.backup_cpuid(cpuinfo) | |
64 | helpers.monkey_patch_cpuid(cpuinfo, 2494000000, [ | |
65 | # max_extension_support | |
66 | 0x80000008, | |
67 | # get_cache | |
68 | 0x1006040, | |
69 | # get_info | |
70 | 0x40651, | |
71 | # get_processor_brand | |
72 | 0x65746e49, 0x2952286c, 0x726f4320, | |
73 | 0x4d542865, 0x35692029, 0x3033342d, | |
74 | 0x43205530, 0x40205550, 0x392e3120, | |
75 | 0x7a484730, 0x0, 0x0, | |
76 | # get_vendor_id | |
77 | 0x756e6547, 0x6c65746e, 0x49656e69, | |
78 | # get_flags | |
79 | 0xbfebfbff, 0x7ffafbff, 0x27ab, | |
80 | 0x0, 0x0, 0x21, | |
81 | ]) | |
82 | ||
61 | 83 | def tearDown(self): |
62 | 84 | helpers.restore_data_source(cpuinfo) |
85 | helpers.restore_cpuid(cpuinfo) | |
86 | cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = True | |
63 | 87 | |
64 | 88 | ''' |
65 | 89 | Make sure calls return the expected number of fields. |
76 | 100 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) |
77 | 101 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
78 | 102 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
79 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
80 | self.assertEqual(18, len(cpuinfo._get_cpu_info_internal())) | |
103 | self.assertEqual(13, len(cpuinfo._get_cpu_info_from_cpuid())) | |
104 | self.assertEqual(3, len(cpuinfo._get_cpu_info_from_platform_uname())) | |
105 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
106 | ||
107 | def test_get_cpu_info_from_cpuid(self): | |
108 | info = cpuinfo._get_cpu_info_from_cpuid() | |
109 | ||
110 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
111 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand_raw']) | |
112 | #self.assertEqual('2.4940 GHz', info['hz_advertised_friendly']) | |
113 | self.assertEqual('2.4940 GHz', info['hz_actual_friendly']) | |
114 | #self.assertEqual((2494000000, 0), info['hz_advertised']) | |
115 | self.assertEqual((2494000000, 0), info['hz_actual']) | |
116 | ||
117 | self.assertEqual(1, info['stepping']) | |
118 | self.assertEqual(69, info['model']) | |
119 | self.assertEqual(6, info['family']) | |
120 | ||
121 | self.assertEqual(64 * 1024, info['l2_cache_size']) | |
122 | self.assertEqual(256, info['l2_cache_line_size']) | |
123 | self.assertEqual(6, info['l2_cache_associativity']) | |
124 | ||
125 | self.assertEqual( | |
126 | ['abm', 'acpi', 'aes', 'apic', 'avx', 'avx2', 'bmi1', 'bmi2', | |
127 | 'clflush', 'cmov', 'cx16', 'cx8', 'de', 'ds_cpl', 'dtes64', | |
128 | 'dts', 'erms', 'est', 'f16c', 'fma', 'fpu', 'fxsr', 'ht', | |
129 | 'invpcid', 'lahf_lm', 'mca', 'mce', 'mmx', 'monitor', 'movbe', | |
130 | 'msr', 'mtrr', 'osxsave', 'pae', 'pat', 'pbe', 'pcid', | |
131 | 'pclmulqdq', 'pdcm', 'pge', 'pni', 'popcnt', 'pse', 'pse36', | |
132 | 'rdrnd', 'sep', 'smep', 'smx', 'ss', 'sse', 'sse2', 'sse4_1', | |
133 | 'sse4_2', 'ssse3', 'tm', 'tm2', 'tsc', 'tscdeadline', 'vme', | |
134 | 'vmx', 'x2apic', 'xsave', 'xtpr'] | |
135 | , | |
136 | info['flags'] | |
137 | ) | |
138 | ||
139 | def test_get_cpu_info_from_platform_uname(self): | |
140 | info = cpuinfo._get_cpu_info_from_platform_uname() | |
141 | ||
142 | self.assertEqual(1, info['stepping']) | |
143 | self.assertEqual(69, info['model']) | |
144 | self.assertEqual(6, info['family']) | |
81 | 145 | |
82 | 146 | def test_get_cpu_info_from_wmic(self): |
83 | 147 | info = cpuinfo._get_cpu_info_from_wmic() |
84 | 148 | |
85 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
86 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand']) | |
87 | self.assertEqual('1.9000 GHz', info['hz_advertised']) | |
88 | self.assertEqual('2.4940 GHz', info['hz_actual']) | |
89 | self.assertEqual((1900000000, 0), info['hz_advertised_raw']) | |
90 | self.assertEqual((2494000000, 0), info['hz_actual_raw']) | |
91 | ||
92 | self.assertEqual(1, info['stepping']) | |
93 | self.assertEqual(69, info['model']) | |
94 | self.assertEqual(6, info['family']) | |
95 | ||
96 | self.assertEqual('512 KB', info['l2_cache_size']) | |
97 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
149 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
150 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand_raw']) | |
151 | self.assertEqual('1.9000 GHz', info['hz_advertised_friendly']) | |
152 | self.assertEqual('2.4940 GHz', info['hz_actual_friendly']) | |
153 | self.assertEqual((1900000000, 0), info['hz_advertised']) | |
154 | self.assertEqual((2494000000, 0), info['hz_actual']) | |
155 | ||
156 | self.assertEqual(1, info['stepping']) | |
157 | self.assertEqual(69, info['model']) | |
158 | self.assertEqual(6, info['family']) | |
159 | ||
160 | self.assertEqual(512 * 1024, info['l2_cache_size']) | |
161 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
98 | 162 | |
99 | 163 | def test_get_cpu_info_from_registry(self): |
100 | 164 | info = cpuinfo._get_cpu_info_from_registry() |
101 | 165 | |
102 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
103 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand']) | |
104 | self.assertEqual('1.9000 GHz', info['hz_advertised']) | |
105 | self.assertEqual('2.4940 GHz', info['hz_actual']) | |
106 | self.assertEqual((1900000000, 0), info['hz_advertised_raw']) | |
107 | self.assertEqual((2494000000, 0), info['hz_actual_raw']) | |
108 | ||
109 | if "logger" in dir(unittest): unittest.logger("FIXME: Missing flags such as sse3 and sse4") | |
166 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
167 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand_raw']) | |
168 | self.assertEqual('1.9000 GHz', info['hz_advertised_friendly']) | |
169 | self.assertEqual('2.4940 GHz', info['hz_actual_friendly']) | |
170 | self.assertEqual((1900000000, 0), info['hz_advertised']) | |
171 | self.assertEqual((2494000000, 0), info['hz_actual']) | |
110 | 172 | |
111 | 173 | self.assertEqual( |
112 | 174 | ['3dnow', 'acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr', |
119 | 181 | def test_all(self): |
120 | 182 | info = cpuinfo._get_cpu_info_internal() |
121 | 183 | |
122 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
123 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand']) | |
124 | self.assertEqual('1.9000 GHz', info['hz_advertised']) | |
125 | self.assertEqual('2.4940 GHz', info['hz_actual']) | |
126 | self.assertEqual((1900000000, 0), info['hz_advertised_raw']) | |
127 | self.assertEqual((2494000000, 0), info['hz_actual_raw']) | |
184 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
185 | self.assertEqual('Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz', info['brand_raw']) | |
186 | self.assertEqual('1.9000 GHz', info['hz_advertised_friendly']) | |
187 | self.assertEqual('2.4940 GHz', info['hz_actual_friendly']) | |
188 | self.assertEqual((1900000000, 0), info['hz_advertised']) | |
189 | self.assertEqual((2494000000, 0), info['hz_actual']) | |
128 | 190 | self.assertEqual('X86_64', info['arch']) |
129 | 191 | self.assertEqual(64, info['bits']) |
130 | 192 | self.assertEqual(4, info['count']) |
131 | 193 | |
132 | self.assertEqual('AMD64', info['raw_arch_string']) | |
133 | ||
134 | self.assertEqual(1, info['stepping']) | |
135 | self.assertEqual(69, info['model']) | |
136 | self.assertEqual(6, info['family']) | |
137 | ||
138 | self.assertEqual('512 KB', info['l2_cache_size']) | |
139 | self.assertEqual('3072 KB', info['l3_cache_size']) | |
140 | ||
141 | if "logger" in dir(unittest): unittest.logger("FIXME: Missing flags such as sse3 and sse4") | |
194 | self.assertEqual('AMD64', info['arch_string_raw']) | |
195 | ||
196 | self.assertEqual(1, info['stepping']) | |
197 | self.assertEqual(69, info['model']) | |
198 | self.assertEqual(6, info['family']) | |
199 | ||
200 | self.assertEqual(512 * 1024, info['l2_cache_size']) | |
201 | self.assertEqual(3072 * 1024, info['l3_cache_size']) | |
202 | self.assertEqual(6, info['l2_cache_associativity']) | |
203 | self.assertEqual(256, info['l2_cache_line_size']) | |
142 | 204 | |
143 | 205 | self.assertEqual( |
144 | ['3dnow', 'acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr', | |
145 | 'ia64', 'mca', 'mce', 'mmx', 'msr', 'mtrr', 'pse', 'sep', | |
146 | 'serial', 'ss', 'sse', 'sse2', 'tm', 'tsc'] | |
206 | ['3dnow', 'abm', 'acpi', 'aes', 'apic', 'avx', 'avx2', 'bmi1', | |
207 | 'bmi2', 'clflush', 'cmov', 'cx16', 'cx8', 'de', 'ds_cpl', | |
208 | 'dtes64', 'dts', 'erms', 'est', 'f16c', 'fma', 'fpu', 'fxsr', | |
209 | 'ht', 'ia64', 'invpcid', 'lahf_lm', 'mca', 'mce', 'mmx', | |
210 | 'monitor', 'movbe', 'msr', 'mtrr', 'osxsave', 'pae', 'pat', | |
211 | 'pbe', 'pcid', 'pclmulqdq', 'pdcm', 'pge', 'pni', 'popcnt', | |
212 | 'pse', 'pse36', 'rdrnd', 'sep', 'serial', 'smep', 'smx', 'ss', | |
213 | 'sse', 'sse2', 'sse4_1', 'sse4_2', 'ssse3', 'tm', 'tm2', 'tsc', | |
214 | 'tscdeadline', 'vme', 'vmx', 'x2apic', 'xsave', 'xtpr'] | |
147 | 215 | , |
148 | 216 | info['flags'] |
149 | 217 | ) |
0 | ||
1 | ||
2 | import unittest | |
3 | from cpuinfo import * | |
4 | import helpers | |
5 | ||
6 | ||
7 | class MockDataSource(object): | |
8 | bits = '64bit' | |
9 | cpu_count = 16 | |
10 | is_windows = True | |
11 | arch_string_raw = 'AMD64' | |
12 | uname_string_raw = 'AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD' | |
13 | can_cpuid = True | |
14 | ||
15 | @staticmethod | |
16 | def winreg_processor_brand(): | |
17 | return 'AMD Ryzen 7 2700X Eight-Core Processor ' | |
18 | ||
19 | @staticmethod | |
20 | def winreg_vendor_id_raw(): | |
21 | return 'AuthenticAMD' | |
22 | ||
23 | @staticmethod | |
24 | def winreg_arch_string_raw(): | |
25 | return 'AMD64' | |
26 | ||
27 | @staticmethod | |
28 | def winreg_hz_actual(): | |
29 | return 3693 | |
30 | ||
31 | @staticmethod | |
32 | def winreg_feature_bits(): | |
33 | return 1010515455 | |
34 | ||
35 | ||
36 | ||
37 | ||
38 | class TestWindows_10_X86_64_Ryzen7(unittest.TestCase): | |
39 | def setUp(self): | |
40 | cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = False | |
41 | helpers.backup_data_source(cpuinfo) | |
42 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) | |
43 | ||
44 | helpers.backup_cpuid(cpuinfo) | |
45 | helpers.monkey_patch_cpuid(cpuinfo, 3693000000, [ | |
46 | # get_max_extension_support | |
47 | 0x8000001f, | |
48 | # get_cache | |
49 | 0x2006140, | |
50 | # get_info | |
51 | 0x800f82, | |
52 | # get_processor_brand | |
53 | 0x20444d41, 0x657a7952, 0x2037206e, | |
54 | 0x30303732, 0x69452058, 0x2d746867, | |
55 | 0x65726f43, 0x6f725020, 0x73736563, | |
56 | 0x2020726f, 0x20202020, 0x202020, | |
57 | # get_vendor_id | |
58 | 0x68747541, 0x444d4163, 0x69746e65, | |
59 | # get_flags | |
60 | 0x178bfbff, 0x7ed8320b, 0x209c01a9, | |
61 | 0x0, 0x20000000, 0x35c233ff, | |
62 | ]) | |
63 | ||
64 | def tearDown(self): | |
65 | helpers.restore_data_source(cpuinfo) | |
66 | helpers.restore_cpuid(cpuinfo) | |
67 | cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = True | |
68 | ||
69 | ''' | |
70 | Make sure calls return the expected number of fields. | |
71 | ''' | |
72 | def test_returns(self): | |
73 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_wmic())); | |
74 | self.assertEqual(7, len(cpuinfo._get_cpu_info_from_registry())) | |
75 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpufreq_info())) | |
76 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_lscpu())) | |
77 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) | |
78 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) | |
79 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_kstat())) | |
80 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_dmesg())) | |
81 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) | |
82 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) | |
83 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) | |
84 | self.assertEqual(11, len(cpuinfo._get_cpu_info_from_cpuid())) | |
85 | self.assertEqual(3, len(cpuinfo._get_cpu_info_from_platform_uname())) | |
86 | self.assertEqual(20, len(cpuinfo._get_cpu_info_internal())) | |
87 | ||
88 | ||
89 | def test_get_cpu_info_from_cpuid(self): | |
90 | info = cpuinfo._get_cpu_info_from_cpuid() | |
91 | ||
92 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
93 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
94 | #self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
95 | self.assertEqual('3.6930 GHz', info['hz_actual_friendly']) | |
96 | #self.assertEqual((3693000000, 0), info['hz_advertised']) | |
97 | self.assertEqual((3693000000, 0), info['hz_actual']) | |
98 | ||
99 | self.assertEqual(2, info['stepping']) | |
100 | self.assertEqual(8, info['model']) | |
101 | self.assertEqual(23, info['family']) | |
102 | ||
103 | self.assertEqual(64 * 1024, info['l2_cache_size']) | |
104 | self.assertEqual(512, info['l2_cache_line_size']) | |
105 | self.assertEqual(6, info['l2_cache_associativity']) | |
106 | ||
107 | self.assertEqual( | |
108 | ['3dnowprefetch', 'abm', 'adx', 'aes', 'apic', 'avx', 'avx2', | |
109 | 'bmi1', 'bmi2', 'clflush', 'clflushopt', 'cmov', 'cmp_legacy', | |
110 | 'cr8_legacy', 'cx16', 'cx8', 'dbx', 'de', 'extapic', 'f16c', | |
111 | 'fma', 'fpu', 'fxsr', 'ht', 'lahf_lm', 'lm', 'mca', 'mce', | |
112 | 'misalignsse', 'mmx', 'monitor', 'movbe', 'msr', 'mtrr', 'osvw', | |
113 | 'osxsave', 'pae', 'pat', 'pci_l2i', 'pclmulqdq', 'perfctr_core', | |
114 | 'perfctr_nb', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'rdrnd', | |
115 | 'rdseed', 'sep', 'sha', 'skinit', 'smap', 'smep', 'sse', 'sse2', | |
116 | 'sse4_1', 'sse4_2', 'sse4a', 'ssse3', 'svm', 'tce', 'topoext', | |
117 | 'tsc', 'vme', 'wdt', 'xsave'] | |
118 | , | |
119 | info['flags'] | |
120 | ) | |
121 | ||
122 | def test_get_cpu_info_from_platform_uname(self): | |
123 | info = cpuinfo._get_cpu_info_from_platform_uname() | |
124 | ||
125 | self.assertEqual(2, info['stepping']) | |
126 | self.assertEqual(8, info['model']) | |
127 | self.assertEqual(23, info['family']) | |
128 | ||
129 | def test_get_cpu_info_from_registry(self): | |
130 | info = cpuinfo._get_cpu_info_from_registry() | |
131 | ||
132 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
133 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
134 | self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
135 | self.assertEqual('3.6930 GHz', info['hz_actual_friendly']) | |
136 | self.assertEqual((3693000000, 0), info['hz_advertised']) | |
137 | self.assertEqual((3693000000, 0), info['hz_actual']) | |
138 | ||
139 | self.assertEqual( | |
140 | ['3dnow', 'clflush', 'cmov', 'de', 'dts', 'fxsr', 'ia64', 'mca', | |
141 | 'mmx', 'msr', 'mtrr', 'pse', 'sep', 'sepamd', 'serial', 'ss', | |
142 | 'sse', 'sse2', 'tm', 'tsc'] | |
143 | , | |
144 | info['flags'] | |
145 | ) | |
146 | ||
147 | def test_all(self): | |
148 | info = cpuinfo._get_cpu_info_internal() | |
149 | ||
150 | self.assertEqual('AuthenticAMD', info['vendor_id_raw']) | |
151 | self.assertEqual('AMD Ryzen 7 2700X Eight-Core Processor', info['brand_raw']) | |
152 | self.assertEqual('3.6930 GHz', info['hz_advertised_friendly']) | |
153 | self.assertEqual('3.6930 GHz', info['hz_actual_friendly']) | |
154 | self.assertEqual((3693000000, 0), info['hz_advertised']) | |
155 | self.assertEqual((3693000000, 0), info['hz_actual']) | |
156 | self.assertEqual('X86_64', info['arch']) | |
157 | self.assertEqual(64, info['bits']) | |
158 | self.assertEqual(16, info['count']) | |
159 | ||
160 | self.assertEqual('AMD64', info['arch_string_raw']) | |
161 | ||
162 | self.assertEqual(2, info['stepping']) | |
163 | self.assertEqual(8, info['model']) | |
164 | self.assertEqual(23, info['family']) | |
165 | ||
166 | self.assertEqual(64 * 1024, info['l2_cache_size']) | |
167 | self.assertEqual(6, info['l2_cache_associativity']) | |
168 | self.assertEqual(512, info['l2_cache_line_size']) | |
169 | ||
170 | self.assertEqual( | |
171 | ['3dnow', '3dnowprefetch', 'abm', 'adx', 'aes', 'apic', 'avx', | |
172 | 'avx2', 'bmi1', 'bmi2', 'clflush', 'clflushopt', 'cmov', | |
173 | 'cmp_legacy', 'cr8_legacy', 'cx16', 'cx8', 'dbx', 'de', 'dts', | |
174 | 'extapic', 'f16c', 'fma', 'fpu', 'fxsr', 'ht', 'ia64', 'lahf_lm', | |
175 | 'lm', 'mca', 'mce', 'misalignsse', 'mmx', 'monitor', 'movbe', | |
176 | 'msr', 'mtrr', 'osvw', 'osxsave', 'pae', 'pat', 'pci_l2i', | |
177 | 'pclmulqdq', 'perfctr_core', 'perfctr_nb', 'pge', 'pni', | |
178 | 'popcnt', 'pse', 'pse36', 'rdrnd', 'rdseed', 'sep', 'sepamd', | |
179 | 'serial', 'sha', 'skinit', 'smap', 'smep', 'ss', 'sse', 'sse2', | |
180 | 'sse4_1', 'sse4_2', 'sse4a', 'ssse3', 'svm', 'tce', 'tm', | |
181 | 'topoext', 'tsc', 'vme', 'wdt', 'xsave'] | |
182 | , | |
183 | info['flags'] | |
184 | ) |
8 | 8 | bits = '64bit' |
9 | 9 | cpu_count = 4 |
10 | 10 | is_windows = True |
11 | raw_arch_string = 'AMD64' | |
12 | can_cpuid = False | |
11 | arch_string_raw = 'AMD64' | |
12 | uname_string_raw = 'AMD64 Family 6 Model 30 Stepping 5, GenuineIntel' | |
13 | can_cpuid = True | |
13 | 14 | |
14 | 15 | @staticmethod |
15 | 16 | def has_wmic(): |
18 | 19 | @staticmethod |
19 | 20 | def wmic_cpu(): |
20 | 21 | returncode = 0 |
21 | output = ''' | |
22 | output = r''' | |
22 | 23 | Caption=Intel64 Family 6 Model 30 Stepping 5 |
23 | 24 | CurrentClockSpeed=2933 |
24 | 25 | Description=Intel64 Family 6 Model 30 Stepping 5 |
35 | 36 | return 'Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz' |
36 | 37 | |
37 | 38 | @staticmethod |
38 | def winreg_vendor_id(): | |
39 | def winreg_vendor_id_raw(): | |
39 | 40 | return 'GenuineIntel' |
40 | 41 | |
41 | 42 | @staticmethod |
42 | def winreg_raw_arch_string(): | |
43 | def winreg_arch_string_raw(): | |
43 | 44 | return 'AMD64' |
44 | 45 | |
45 | 46 | @staticmethod |
55 | 56 | |
56 | 57 | class TestWindows_8_X86_64(unittest.TestCase): |
57 | 58 | def setUp(self): |
59 | cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = False | |
58 | 60 | helpers.backup_data_source(cpuinfo) |
59 | 61 | helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
60 | 62 | |
63 | helpers.backup_cpuid(cpuinfo) | |
64 | helpers.monkey_patch_cpuid(cpuinfo, 2930000000, [ | |
65 | # max_extension_support | |
66 | 0x80000008, | |
67 | # get_cache | |
68 | 0x1006040, | |
69 | # get_info | |
70 | 0x106e5, | |
71 | # get_processor_brand | |
72 | 0x65746e49, 0x2952286c, 0x726f4320, | |
73 | 0x4d542865, 0x37692029, 0x55504320, | |
74 | 0x20202020, 0x20202020, 0x30373820, | |
75 | 0x20402020, 0x33392e32, 0x7a4847, | |
76 | # get_vendor_id | |
77 | 0x756e6547, 0x6c65746e, 0x49656e69, | |
78 | # get_flags | |
79 | 0xbfebfbff, 0x98e3fd, 0x0, | |
80 | 0x0, 0x0, 0x1, | |
81 | ]) | |
82 | ||
61 | 83 | def tearDown(self): |
62 | 84 | helpers.restore_data_source(cpuinfo) |
85 | helpers.restore_cpuid(cpuinfo) | |
86 | cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = True | |
63 | 87 | |
64 | 88 | ''' |
65 | 89 | Make sure calls return the expected number of fields. |
76 | 100 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) |
77 | 101 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
78 | 102 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
79 | self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) | |
80 | self.assertEqual(18, len(cpuinfo._get_cpu_info_internal())) | |
103 | self.assertEqual(13, len(cpuinfo._get_cpu_info_from_cpuid())) | |
104 | self.assertEqual(3, len(cpuinfo._get_cpu_info_from_platform_uname())) | |
105 | self.assertEqual(21, len(cpuinfo._get_cpu_info_internal())) | |
106 | ||
107 | def test_get_cpu_info_from_cpuid(self): | |
108 | info = cpuinfo._get_cpu_info_from_cpuid() | |
109 | ||
110 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
111 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
112 | #self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
113 | self.assertEqual('2.9300 GHz', info['hz_actual_friendly']) | |
114 | #self.assertEqual((2930000000, 0), info['hz_advertised']) | |
115 | self.assertEqual((2930000000, 0), info['hz_actual']) | |
116 | ||
117 | self.assertEqual(5, info['stepping']) | |
118 | self.assertEqual(30, info['model']) | |
119 | self.assertEqual(6, info['family']) | |
120 | ||
121 | self.assertEqual(64 * 1024, info['l2_cache_size']) | |
122 | self.assertEqual(256, info['l2_cache_line_size']) | |
123 | self.assertEqual(6, info['l2_cache_associativity']) | |
124 | ||
125 | self.assertEqual( | |
126 | ['acpi', 'apic', 'clflush', 'cmov', 'cx16', 'cx8', 'de', 'ds_cpl', | |
127 | 'dtes64', 'dts', 'est', 'fpu', 'fxsr', 'ht', 'lahf_lm', 'mca', | |
128 | 'mce', 'mmx', 'monitor', 'msr', 'mtrr', 'pae', 'pat', 'pbe', | |
129 | 'pdcm', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'sep', 'smx', | |
130 | 'ss', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'ssse3', 'tm', 'tm2', | |
131 | 'tsc', 'vme', 'vmx', 'xtpr'] | |
132 | , | |
133 | info['flags'] | |
134 | ) | |
135 | ||
136 | def test_get_cpu_info_from_platform_uname(self): | |
137 | info = cpuinfo._get_cpu_info_from_platform_uname() | |
138 | ||
139 | self.assertEqual(5, info['stepping']) | |
140 | self.assertEqual(30, info['model']) | |
141 | self.assertEqual(6, info['family']) | |
81 | 142 | |
82 | 143 | def test_get_cpu_info_from_wmic(self): |
83 | 144 | info = cpuinfo._get_cpu_info_from_wmic() |
84 | 145 | |
85 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
86 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
87 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
88 | self.assertEqual('2.9330 GHz', info['hz_actual']) | |
89 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
90 | self.assertEqual((2933000000, 0), info['hz_actual_raw']) | |
91 | ||
92 | self.assertEqual(5, info['stepping']) | |
93 | self.assertEqual(30, info['model']) | |
94 | self.assertEqual(6, info['family']) | |
95 | ||
96 | self.assertEqual('256 KB', info['l2_cache_size']) | |
97 | self.assertEqual('8192 KB', info['l3_cache_size']) | |
146 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
147 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
148 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
149 | self.assertEqual('2.9330 GHz', info['hz_actual_friendly']) | |
150 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
151 | self.assertEqual((2933000000, 0), info['hz_actual']) | |
152 | ||
153 | self.assertEqual(5, info['stepping']) | |
154 | self.assertEqual(30, info['model']) | |
155 | self.assertEqual(6, info['family']) | |
156 | ||
157 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
158 | self.assertEqual(8192 * 1024, info['l3_cache_size']) | |
98 | 159 | |
99 | 160 | def test_get_cpu_info_from_registry(self): |
100 | 161 | info = cpuinfo._get_cpu_info_from_registry() |
101 | 162 | |
102 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
103 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
104 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
105 | self.assertEqual('2.9330 GHz', info['hz_actual']) | |
106 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
107 | self.assertEqual((2933000000, 0), info['hz_actual_raw']) | |
108 | ||
109 | if "logger" in dir(unittest): unittest.logger("FIXME: Missing flags such as sse3 and sse4") | |
163 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
164 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
165 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
166 | self.assertEqual('2.9330 GHz', info['hz_actual_friendly']) | |
167 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
168 | self.assertEqual((2933000000, 0), info['hz_actual']) | |
110 | 169 | |
111 | 170 | self.assertEqual( |
112 | 171 | ['acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr', 'ia64', |
119 | 178 | def test_all(self): |
120 | 179 | info = cpuinfo._get_cpu_info_internal() |
121 | 180 | |
122 | self.assertEqual('GenuineIntel', info['vendor_id']) | |
123 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand']) | |
124 | self.assertEqual('2.9300 GHz', info['hz_advertised']) | |
125 | self.assertEqual('2.9330 GHz', info['hz_actual']) | |
126 | self.assertEqual((2930000000, 0), info['hz_advertised_raw']) | |
127 | self.assertEqual((2933000000, 0), info['hz_actual_raw']) | |
181 | self.assertEqual('GenuineIntel', info['vendor_id_raw']) | |
182 | self.assertEqual('Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz', info['brand_raw']) | |
183 | self.assertEqual('2.9300 GHz', info['hz_advertised_friendly']) | |
184 | self.assertEqual('2.9330 GHz', info['hz_actual_friendly']) | |
185 | self.assertEqual((2930000000, 0), info['hz_advertised']) | |
186 | self.assertEqual((2933000000, 0), info['hz_actual']) | |
128 | 187 | self.assertEqual('X86_64', info['arch']) |
129 | 188 | self.assertEqual(64, info['bits']) |
130 | 189 | self.assertEqual(4, info['count']) |
131 | 190 | |
132 | self.assertEqual('AMD64', info['raw_arch_string']) | |
133 | ||
134 | self.assertEqual(5, info['stepping']) | |
135 | self.assertEqual(30, info['model']) | |
136 | self.assertEqual(6, info['family']) | |
137 | ||
138 | self.assertEqual('256 KB', info['l2_cache_size']) | |
139 | self.assertEqual('8192 KB', info['l3_cache_size']) | |
140 | ||
141 | if "logger" in dir(unittest): unittest.logger("FIXME: Missing flags such as sse3 and sse4") | |
191 | self.assertEqual('AMD64', info['arch_string_raw']) | |
192 | ||
193 | self.assertEqual(5, info['stepping']) | |
194 | self.assertEqual(30, info['model']) | |
195 | self.assertEqual(6, info['family']) | |
196 | ||
197 | self.assertEqual(256 * 1024, info['l2_cache_size']) | |
198 | self.assertEqual(8192 * 1024, info['l3_cache_size']) | |
199 | self.assertEqual(6, info['l2_cache_associativity']) | |
200 | self.assertEqual(256, info['l2_cache_line_size']) | |
142 | 201 | |
143 | 202 | self.assertEqual( |
144 | ['acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr', 'ia64', | |
145 | 'mce', 'mmx', 'msr', 'mtrr', 'sep', 'serial', 'ss', | |
146 | 'sse', 'sse2', 'tm', 'tsc'] | |
203 | ['acpi', 'apic', 'clflush', 'cmov', 'cx16', 'cx8', 'de', 'ds_cpl', | |
204 | 'dtes64', 'dts', 'est', 'fpu', 'fxsr', 'ht', 'ia64', 'lahf_lm', | |
205 | 'mca', 'mce', 'mmx', 'monitor', 'msr', 'mtrr', 'pae', 'pat', | |
206 | 'pbe', 'pdcm', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'sep', | |
207 | 'serial', 'smx', 'ss', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'ssse3', | |
208 | 'tm', 'tm2', 'tsc', 'vme', 'vmx', 'xtpr'] | |
147 | 209 | , |
148 | 210 | info['flags'] |
149 | 211 | ) |