Codebase list python-cpuinfo / upstream/7.0.0
Import upstream version 7.0.0, md5 1c20faea9100e7c938e03cec92172393 Debian Janitor 3 years ago
45 changed file(s) with 3678 addition(s) and 1190 deletion(s). Raw diff Collapse all Expand all
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
020 03/20/2019 Release 5.0.0
121 * Fixed Bug #117: Remove PyInstaller hacks
222 * Fixed Bug #108: Client script runs multiple times without __main__
00 The MIT License (MIT)
11
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>
33
44 Permission is hereby granted, free of charge, to any person obtaining a copy of
55 this software and associated documentation files (the "Software"), to deal in
00 Metadata-Version: 1.1
11 Name: py-cpuinfo
2 Version: 5.0.0
2 Version: 7.0.0
33 Summary: Get CPU info with pure Python 2 & 3
44 Home-page: https://github.com/workhorsy/py-cpuinfo
55 Author: Matthew Brennan Jones
00 #!/usr/bin/env python
11 # -*- coding: UTF-8 -*-
22
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>
44 # Py-cpuinfo gets CPU info with pure Python 2 & 3
55 # It uses the MIT License
66 # It is hosted at: https://github.com/workhorsy/py-cpuinfo
2424 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2525 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626
27 CPUINFO_VERSION = (5, 0, 0)
27 CPUINFO_VERSION = (7, 0, 0)
28 CPUINFO_VERSION_STRING = '.'.join([str(n) for n in CPUINFO_VERSION])
2829
2930 import os, sys
3031 import platform
3132 import multiprocessing
3233 import ctypes
3334
34 try:
35 import _winreg as winreg
36 except ImportError as err:
37 try:
38 import winreg
39 except ImportError as err:
40 pass
4135
4236 IS_PY2 = sys.version_info[0] == 2
37 CAN_CALL_CPUID_IN_SUBPROCESS = True
4338
4439
4540 class DataSource(object):
4641 bits = platform.architecture()[0]
4742 cpu_count = multiprocessing.cpu_count()
4843 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]
5046 can_cpuid = True
5147
5248 @staticmethod
8480
8581 @staticmethod
8682 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
8886
8987 @staticmethod
9088 def has_lscpu():
108106 return _run_and_get_stdout(['cpufreq-info'])
109107
110108 @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'])
117111
118112 @staticmethod
119113 def dmesg_a():
157151
158152 @staticmethod
159153 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
178166
179167 @staticmethod
180168 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)
185171 return hz_actual
186172
187173 @staticmethod
188174 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")
192176 return feature_bits
193177
194178
224208 output = output.decode(encoding='UTF-8')
225209 return p2.returncode, output
226210
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
227225 # Make sure we are running on a supported system
228226 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.")
232230
233231 def _obj_to_b64(thing):
234232 import pickle
264262
265263 def _copy_new_fields(info, new_info):
266264 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',
272271 'l3_cache_size', 'l1_data_cache_size', 'l1_instruction_cache_size'
273272 ]
274273
313312
314313 return retval
315314
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'
398417
399418 def _to_friendly_bytes(input):
400419 import re
416435
417436 return input
418437
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
439494 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]
451500 if name == 'origin':
452501 vendor_id = value.strip('"')
453502 elif name == 'stepping':
456505 model = int(value.lstrip('0x'), 16)
457506 elif name in ['fam', 'family']:
458507 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)
464535
465536 def _parse_dmesg_output(output):
466537 try:
474545 lines = [l.split('\n')[0].strip() for l in lines]
475546
476547 # 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]
478549
479550 # Find the CPU string that has the most fields
480551 best_string = None
489560 if not best_string:
490561 return {}
491562
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
493564
494565 # Origin
495566 if ' Origin=' in output:
497568 fields = fields.strip().split()
498569 fields = [n.strip().split('=') for n in fields]
499570 fields = [{n[0].strip().lower() : n[1].strip()} for n in fields]
500 #print('fields: ', fields)
571
501572 for field in fields:
502573 name = list(field.keys())[0]
503574 value = list(field.values())[0]
504 #print('name:{0}, value:{1}'.format(name, value))
575
505576 if name == 'origin':
506577 vendor_id = value.strip('"')
507578 elif name == 'stepping':
510581 model = int(value.lstrip('0x'), 16)
511582 elif name in ['fam', 'family']:
512583 family = int(value.lstrip('0x'), 16)
513 #print('FIELDS: ', (vendor_id, stepping, model, family))
514584
515585 # Features
516586 flag_lines = []
526596 flags.sort()
527597
528598 # 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)
530605
531606 info = {
532 'vendor_id' : vendor_id,
533 'brand' : processor_brand,
607 'vendor_id_raw' : vendor_id,
608 'brand_raw' : processor_brand,
534609
535610 'stepping' : stepping,
536611 'model' : model,
539614 }
540615
541616 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)
544619
545620 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)
548623
549624 return {k: v for k, v in info.items() if v}
550625 except:
553628
554629 return {}
555630
556 def _parse_arch(raw_arch_string):
631 def _parse_arch(arch_string_raw):
557632 import re
558633
559634 arch, bits = None, None
560 raw_arch_string = raw_arch_string.lower()
635 arch_string_raw = arch_string_raw.lower()
561636
562637 # 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):
564639 arch = 'X86_32'
565640 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):
567642 arch = 'X86_64'
568643 bits = 64
569644 # ARM
570 elif re.match('^armv8-a|aarch64$', raw_arch_string):
645 elif re.match(r'^armv8-a|aarch64$', arch_string_raw):
571646 arch = 'ARM_8'
572647 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):
574649 arch = 'ARM_7'
575650 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):
577652 arch = 'ARM_8'
578653 bits = 32
579654 # PPC
580 elif re.match('^ppc32$|^prep$|^pmac$|^powermac$', raw_arch_string):
655 elif re.match(r'^ppc32$|^prep$|^pmac$|^powermac$', arch_string_raw):
581656 arch = 'PPC_32'
582657 bits = 32
583 elif re.match('^powerpc$|^ppc64$|^ppc64le$', raw_arch_string):
658 elif re.match(r'^powerpc$|^ppc64$|^ppc64le$', arch_string_raw):
584659 arch = 'PPC_64'
585660 bits = 64
586661 # SPARC
587 elif re.match('^sparc32$|^sparc$', raw_arch_string):
662 elif re.match(r'^sparc32$|^sparc$', arch_string_raw):
588663 arch = 'SPARC_32'
589664 bits = 32
590 elif re.match('^sparc64$|^sun4u$|^sun4v$', raw_arch_string):
665 elif re.match(r'^sparc64$|^sun4u$|^sun4v$', arch_string_raw):
591666 arch = 'SPARC_64'
667 bits = 64
668 # S390X
669 elif re.match(r'^s390x$', arch_string_raw):
670 arch = 'S390X'
592671 bits = 64
593672
594673 return (arch, bits)
599678 return is_set
600679
601680
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
604730 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))
621740
622741 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)
625744 # Alloc at least 1 page to ensure we own all pages that we want to change protection on
626745 if size < 0x1000: size = 0x1000
627746 MEM_COMMIT = ctypes.c_ulong(0x1000)
628747 PAGE_READWRITE = ctypes.c_ulong(0x4)
629748 pfnVirtualAlloc = ctypes.windll.kernel32.VirtualAlloc
630749 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:
633752 raise Exception("Failed to VirtualAlloc")
634753
635 # Copy the byte code into the memory segment
754 # Copy the machine code into the memory segment
636755 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:
638757 raise Exception("Failed to memmove")
639758
640759 # Enable execute permissions
641760 PAGE_EXECUTE = ctypes.c_ulong(0x10)
642761 old_protect = ctypes.c_ulong(0)
643762 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))
645764 if not res:
646765 raise Exception("Failed VirtualProtect")
647766
652771 pfnGetCurrentProcess.restype = ctypes.c_void_p
653772 self.prochandle = ctypes.c_void_p(pfnGetCurrentProcess())
654773 # 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))
656775 if not res:
657776 raise Exception("Failed FlushInstructionCache")
658777 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))
682788
683789 # 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):
700800 # Free the function memory segment
701801 if DataSource.is_windows:
702802 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)
704804 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()
712829 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 )
729830
730831 # http://en.wikipedia.org/wiki/CPUID#EAX.3D0:_Get_vendor_ID
731832 def get_vendor_id(self):
732833 # EBX
733834 ebx = self._run_asm(
734 self._zero_eax(),
835 b"\x31\xC0", # xor eax,eax
735836 b"\x0F\xA2" # cpuid
736837 b"\x89\xD8" # mov ax,bx
737838 b"\xC3" # ret
739840
740841 # ECX
741842 ecx = self._run_asm(
742 self._zero_eax(),
843 b"\x31\xC0", # xor eax,eax
743844 b"\x0f\xa2" # cpuid
744845 b"\x89\xC8" # mov ax,cx
745846 b"\xC3" # ret
747848
748849 # EDX
749850 edx = self._run_asm(
750 self._zero_eax(),
851 b"\x31\xC0", # xor eax,eax
751852 b"\x0f\xa2" # cpuid
752853 b"\x89\xD0" # mov ax,dx
753854 b"\xC3" # ret
766867 def get_info(self):
767868 # EAX
768869 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
772873 )
773874
774875 # Get the CPU info
775 stepping = (eax >> 0) & 0xF # 4 bits
876 stepping_id = (eax >> 0) & 0xF # 4 bits
776877 model = (eax >> 4) & 0xF # 4 bits
777 family = (eax >> 8) & 0xF # 4 bits
878 family_id = (eax >> 8) & 0xF # 4 bits
778879 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
781891
782892 return {
783 'stepping' : stepping,
893 'stepping' : stepping_id,
784894 'model' : model,
785895 'family' : family,
786 'processor_type' : processor_type,
787 'extended_model' : extended_model,
788 'extended_family' : extended_family
896 'processor_type' : processor_type
789897 }
790898
791899 # http://en.wikipedia.org/wiki/CPUID#EAX.3D80000000h:_Get_Highest_Extended_Function_Supported
803911 def get_flags(self, max_extension_support):
804912 # EDX
805913 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
810918 )
811919
812920 # ECX
813921 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
818926 )
819927
820928 # Get the CPU flags
8931001 if max_extension_support >= 7:
8941002 # EBX
8951003 ebx = self._run_asm(
896 self._zero_ecx(),
1004 b"\x31\xC9", # xor ecx,ecx
8971005 b"\xB8\x07\x00\x00\x00" # mov eax,7
8981006 b"\x0f\xa2" # cpuid
8991007 b"\x89\xD8" # mov ax,bx
9021010
9031011 # ECX
9041012 ecx = self._run_asm(
905 self._zero_ecx(),
1013 b"\x31\xC9", # xor ecx,ecx
9061014 b"\xB8\x07\x00\x00\x00" # mov eax,7
9071015 b"\x0f\xa2" # cpuid
9081016 b"\x89\xC8" # mov ax,cx
11471255 )
11481256
11491257 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
11531261 }
11541262
11551263 return cache_info
11561264
1157 def get_ticks(self):
1265 def get_ticks_func(self):
11581266 retval = None
11591267
11601268 if DataSource.bits == '32bit':
11611269 # Works on x86_32
11621270 restype = None
11631271 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,
11651273 [
11661274 b"\x55", # push bp
11671275 b"\x89\xE5", # mov bp,sp
11771285 ]
11781286 )
11791287
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
11851302 elif DataSource.bits == '64bit':
11861303 # Works on x86_64
11871304 restype = ctypes.c_uint64
11881305 argtypes = ()
1189 get_ticks_x86_64, address = self._asm_func(restype, argtypes,
1306 get_ticks_x86_64 = self._asm_func(restype, argtypes,
11901307 [
11911308 b"\x48", # dec ax
11921309 b"\x31\xC0", # xor ax,ax
11991316 b"\xC3", # ret
12001317 ]
12011318 )
1202 retval = get_ticks_x86_64()
1203
1319
1320 retval = get_ticks_x86_64
12041321 return retval
12051322
12061323 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()
12141331
12151332 ticks = (end - start)
1333 ticks_fn.free()
12161334
12171335 return ticks
12181336
1219 def _actual_get_cpu_info_from_cpuid(queue):
1337 def _get_cpu_info_from_cpuid_actual():
12201338 '''
12211339 Warning! This function has the potential to crash the Python runtime.
12221340 Do not call it directly. Use the _get_cpu_info_from_cpuid function instead.
12231341 It will safely call this function in another process.
12241342 '''
12251343
1226 # Pipe all output to nothing
1227 sys.stdout = open(os.devnull, 'w')
1228 sys.stderr = open(os.devnull, 'w')
1229
12301344 # Get the CPU arch and bits
1231 arch, bits = _parse_arch(DataSource.raw_arch_string)
1345 arch, bits = _parse_arch(DataSource.arch_string_raw)
12321346
12331347 # Return none if this is not an X86 CPU
12341348 if not arch in ['X86_32', 'X86_64']:
1235 queue.put(_obj_to_b64({}))
1236 return
1349 return {}
12371350
12381351 # Return none if SE Linux is in enforcing mode
12391352 cpuid = CPUID()
12401353 if cpuid.is_selinux_enforcing:
1241 queue.put(_obj_to_b64({}))
1242 return
1354 return {}
12431355
12441356 # Get the cpu info from the CPUID register
12451357 max_extension_support = cpuid.get_max_extension_support()
12501362
12511363 # Get the Hz and scale
12521364 hz_actual = cpuid.get_raw_hz()
1253 hz_actual = _to_hz_string(hz_actual)
1365 hz_actual = _to_decimal_string(hz_actual)
12541366
12551367 # 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)
12571369 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'],
12681380 'l2_cache_line_size' : cache_info['line_size_b'],
1269 'l2_cache_associativity' : hex(cache_info['associativity']),
1381 'l2_cache_associativity' : cache_info['associativity'],
12701382
12711383 'stepping' : info['stepping'],
12721384 'model' : info['model'],
12731385 'family' : info['family'],
12741386 'processor_type' : info['processor_type'],
1275 'extended_model' : info['extended_model'],
1276 'extended_family' : info['extended_family'],
12771387 'flags' : cpuid.get_flags(max_extension_support)
12781388 }
12791389
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
12811399 queue.put(_obj_to_b64(info))
12821400
12831401 def _get_cpu_info_from_cpuid():
12931411 return {}
12941412
12951413 # Get the CPU arch and bits
1296 arch, bits = _parse_arch(DataSource.raw_arch_string)
1414 arch, bits = _parse_arch(DataSource.arch_string_raw)
12971415
12981416 # Return {} if this is not an X86 CPU
12991417 if not arch in ['X86_32', 'X86_64']:
13001418 return {}
13011419
13021420 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
13201442 except:
13211443 pass
13221444
13451467 model = _get_field(False, output, int, 0, 'model')
13461468 family = _get_field(False, output, int, 0, 'cpu family')
13471469 hardware = _get_field(False, output, None, '', 'Hardware')
1470
13481471 # Flags
13491472 flags = _get_field(False, output, None, None, 'flags', 'Features')
13501473 if flags:
13511474 flags = flags.split()
13521475 flags.sort()
13531476
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
13541492 # 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')
13561494 hz_actual = hz_actual.lower().rstrip('mhz').strip()
1357 hz_actual = _to_hz_string(hz_actual)
1495 hz_actual = _to_decimal_string(hz_actual)
13581496
13591497 # Convert from GHz/MHz string to Hz
1360 scale, hz_advertised = (0, None)
1498 hz_advertised, scale = (None, 0)
13611499 try:
1362 scale, hz_advertised = _get_hz_string_from_brand(processor_brand)
1500 hz_advertised, scale = _parse_cpu_brand_string(processor_brand)
13631501 except Exception:
13641502 pass
13651503
13661504 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),
13711509 'flags' : flags,
1372 'vendor_id' : vendor_id,
1510 'vendor_id_raw' : vendor_id,
13731511 'stepping' : stepping,
13741512 'model' : model,
13751513 'family' : family,
13831521 hz_actual = hz_advertised
13841522
13851523 # 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)
13951532 except:
13961533 #raise # NOTE: To have this throw on error, uncomment this line
13971534 return {}
14021539 Returns {} if cpufreq-info is not found.
14031540 '''
14041541 try:
1405 scale, hz_brand = 1, '0.0'
1542 hz_brand, scale = '0.0', 0
14061543
14071544 if not DataSource.has_cpufreq_info():
14081545 return {}
14211558 elif hz_brand.endswith('ghz'):
14221559 scale = 9
14231560 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)
14251562
14261563 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),
14311568 }
14321569
1433 info = {k: v for k, v in info.items() if v}
1434 return info
1570 return _filter_dict_keys_with_empty_values(info)
14351571 except:
14361572 #raise # NOTE: To have this throw on error, uncomment this line
14371573 return {}
14531589
14541590 new_hz = _get_field(False, output, None, None, 'CPU max MHz', 'CPU MHz')
14551591 if new_hz:
1456 new_hz = _to_hz_string(new_hz)
1592 new_hz = _to_decimal_string(new_hz)
14571593 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)
14621607
14631608 vendor_id = _get_field(False, output, None, None, 'Vendor ID')
14641609 if vendor_id:
1465 info['vendor_id'] = vendor_id
1610 info['vendor_id_raw'] = vendor_id
14661611
14671612 brand = _get_field(False, output, None, None, 'Model name')
14681613 if brand:
1469 info['brand'] = brand
1614 info['brand_raw'] = brand
14701615
14711616 family = _get_field(False, output, None, None, 'CPU family')
14721617 if family and family.isdigit():
14821627
14831628 l1_data_cache_size = _get_field(False, output, None, None, 'L1d cache')
14841629 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)
14861631
14871632 l1_instruction_cache_size = _get_field(False, output, None, None, 'L1i cache')
14881633 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')
14921637 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)
14941639
14951640 l3_cache_size = _get_field(False, output, None, None, 'L3 cache')
14961641 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)
14981643
14991644 # Flags
15001645 flags = _get_field(False, output, None, None, 'flags', 'Features')
15031648 flags.sort()
15041649 info['flags'] = flags
15051650
1506 info = {k: v for k, v in info.items() if v}
1507 return info
1651 return _filter_dict_keys_with_empty_values(info)
15081652 except:
15091653 #raise # NOTE: To have this throw on error, uncomment this line
15101654 return {}
15141658 Returns the CPU info gathered from dmesg.
15151659 Returns {} if dmesg is not found or does not have the desired info.
15161660 '''
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
15171667 # Just return {} if there is no dmesg
15181668 if not DataSource.has_dmesg():
15191669 return {}
16421792 info = {
16431793 'flags' : flags
16441794 }
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)
16481796 except:
16491797 return {}
16501798
16961844 flags.sort()
16971845
16981846 # 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)
17001848 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)
17021850
17031851 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,
17131861
17141862 'stepping' : stepping,
17151863 'model' : model,
17171865 'flags' : flags
17181866 }
17191867
1720 info = {k: v for k, v in info.items() if v}
1721 return info
1868 return _filter_dict_keys_with_empty_values(info)
17221869 except:
17231870 return {}
17241871
17491896
17501897 # Various fields
17511898 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()
17531900 cache_size = '' #_get_field(False, output, None, None, 'machdep.cpu.cache.size')
17541901 stepping = int(output.split(', stepping ')[1].split(',')[0].strip())
17551902 model = int(output.split(', model ')[1].split(',')[0].strip())
17641911 flags.sort()
17651912
17661913 # 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)
17681915 hz_actual = hz_advertised
17691916
17701917 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),
17781925
17791926 'l2_cache_size' : _to_friendly_bytes(cache_size),
17801927
17841931 'flags' : flags
17851932 }
17861933
1787 info = {k: v for k, v in info.items() if v}
1788 return info
1934 return _filter_dict_keys_with_empty_values(info)
17891935 except:
1936 #raise # NOTE: To have this throw on error, uncomment this line
17901937 return {}
17911938
17921939 def _get_cpu_info_from_sysinfo_v2():
18061953
18071954 # Various fields
18081955 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()
18101957 cache_size = '' #_get_field(False, output, None, None, 'machdep.cpu.cache.size')
18111958 signature = output.split('Signature:')[1].split('\n')[0].strip()
18121959 #
18181965 def get_subsection_flags(output):
18191966 retval = []
18201967 for line in output.split('\n')[1:]:
1821 if not line.startswith(' '): break
1968 if not line.startswith(' ') and not line.startswith(' '): break
18221969 for entry in line.strip().lower().split(' '):
18231970 retval.append(entry)
18241971 return retval
18291976 flags.sort()
18301977
18311978 # 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)
18331983 hz_actual = hz_advertised
18341984
1985 scale = 0
1986 if raw_hz.endswith('mhz'):
1987 scale = 6
1988 elif raw_hz.endswith('ghz'):
1989 scale = 9
1990
18351991 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),
18431999
18442000 'l2_cache_size' : _to_friendly_bytes(cache_size),
18452001
18492005 'flags' : flags
18502006 }
18512007
1852 info = {k: v for k, v in info.items() if v}
1853 return info
2008 return _filter_dict_keys_with_empty_values(info)
18542009 except:
2010 #raise # NOTE: To have this throw on error, uncomment this line
18552011 return {}
18562012
18572013 def _get_cpu_info_from_wmic():
18762032
18772033 # Get the advertised MHz
18782034 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)
18802036
18812037 # Get the actual MHz
18822038 hz_actual = value.get('CurrentClockSpeed')
18832039 scale_actual = 6
18842040 if hz_actual:
1885 hz_actual = _to_hz_string(hz_actual)
2041 hz_actual = _to_decimal_string(hz_actual)
18862042
18872043 # Get cache sizes
1888 l2_cache_size = value.get('L2CacheSize')
2044 l2_cache_size = value.get('L2CacheSize') # NOTE: L2CacheSize is in kilobytes
18892045 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
18932049 if l3_cache_size:
1894 l3_cache_size = l3_cache_size + ' KB'
2050 l3_cache_size = int(l3_cache_size) * 1024
18952051
18962052 # Get family, model, and stepping
18972053 family, model, stepping = '', '', ''
19112067 stepping = int(entries[i + 1])
19122068
19132069 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),
19212077
19222078 'l2_cache_size' : l2_cache_size,
19232079 'l3_cache_size' : l3_cache_size,
19272083 'family' : family,
19282084 }
19292085
1930 info = {k: v for k, v in info.items() if v}
1931 return info
2086 return _filter_dict_keys_with_empty_values(info)
19322087 except:
19332088 #raise # NOTE: To have this throw on error, uncomment this line
19342089 return {}
19352090
19362091 def _get_cpu_info_from_registry():
19372092 '''
1938 FIXME: Is missing many of the newer CPU flags like sse3
19392093 Returns the CPU info gathered from the Windows Registry.
19402094 Returns {} if not on Windows.
19412095 '''
19452099 return {}
19462100
19472101 # Get the CPU name
1948 processor_brand = DataSource.winreg_processor_brand()
2102 processor_brand = DataSource.winreg_processor_brand().strip()
19492103
19502104 # Get the CPU vendor id
1951 vendor_id = DataSource.winreg_vendor_id()
2105 vendor_id = DataSource.winreg_vendor_id_raw()
19522106
19532107 # 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)
19562110
19572111 # Get the actual CPU Hz
19582112 hz_actual = DataSource.winreg_hz_actual()
1959 hz_actual = _to_hz_string(hz_actual)
2113 hz_actual = _to_decimal_string(hz_actual)
19602114
19612115 # 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)
19632122
19642123 # Get the CPU features
19652124 feature_bits = DataSource.winreg_feature_bits()
20122171 flags.sort()
20132172
20142173 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),
20222181
20232182 'flags' : flags
20242183 }
20252184
2026 info = {k: v for k, v in info.items() if v}
2027 return info
2185 return _filter_dict_keys_with_empty_values(info)
20282186 except:
20292187 return {}
20302188
20622220 # Convert from GHz/MHz string to Hz
20632221 scale = 6
20642222 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)
20662224
20672225 # Convert from GHz/MHz string to Hz
20682226 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)
20702228
20712229 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),
20792237
20802238 'stepping' : stepping,
20812239 'model' : model,
20832241 'flags' : flags
20842242 }
20852243
2086 info = {k: v for k, v in info.items() if v}
2087 return info
2244 return _filter_dict_keys_with_empty_values(info)
20882245 except:
20892246 return {}
20902247
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
20912276 def _get_cpu_info_internal():
20922277 '''
20932278 Returns the CPU info by using the best sources of information for your OS.
20952280 '''
20962281
20972282 # Get the CPU arch and bits
2098 arch, bits = _parse_arch(DataSource.raw_arch_string)
2283 arch, bits = _parse_arch(DataSource.arch_string_raw)
20992284
21002285 friendly_maxsize = { 2**31-1: '32 bit', 2**63-1: '64 bit' }.get(sys.maxsize) or 'unknown bits'
21012286 friendly_version = "{0}.{1}.{2}.{3}.{4}".format(*sys.version_info)
21042289 info = {
21052290 'python_version' : PYTHON_VERSION,
21062291 'cpuinfo_version' : CPUINFO_VERSION,
2292 'cpuinfo_version_string' : CPUINFO_VERSION_STRING,
21072293 'arch' : arch,
21082294 'bits' : bits,
21092295 'count' : DataSource.cpu_count,
2110 'raw_arch_string' : DataSource.raw_arch_string,
2296 'arch_string_raw' : DataSource.arch_string_raw,
21112297 }
21122298
21132299 # Try the Windows wmic
21452331
21462332 # Try querying the CPU cpuid register
21472333 _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())
21482337
21492338 return info
21502339
22032392 # Parse args
22042393 parser = ArgumentParser(description='Gets CPU info with pure Python 2 & 3')
22052394 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')
22062396 args = parser.parse_args()
22072397
22082398 try:
22192409
22202410 if args.json:
22212411 print(json.dumps(info))
2412 elif args.version:
2413 print(CPUINFO_VERSION_STRING)
22222414 else:
22232415 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', '')))
22282422 print('Hz Advertised: {0}'.format(info.get('hz_advertised', '')))
22292423 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', '')))
22322424 print('Arch: {0}'.format(info.get('arch', '')))
22332425 print('Bits: {0}'.format(info.get('bits', '')))
22342426 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', '')))
22382428 print('L1 Data Cache Size: {0}'.format(info.get('l1_data_cache_size', '')))
22392429 print('L1 Instruction Cache Size: {0}'.format(info.get('l1_instruction_cache_size', '')))
22402430 print('L2 Cache Size: {0}'.format(info.get('l2_cache_size', '')))
22452435 print('Model: {0}'.format(info.get('model', '')))
22462436 print('Family: {0}'.format(info.get('family', '')))
22472437 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', '')))
22502438 print('Flags: {0}'.format(', '.join(info.get('flags', ''))))
22512439
22522440
00 Metadata-Version: 1.1
11 Name: py-cpuinfo
2 Version: 5.0.0
2 Version: 7.0.0
33 Summary: Get CPU info with pure Python 2 & 3
44 Home-page: https://github.com/workhorsy/py-cpuinfo
55 Author: Matthew Brennan Jones
1414 tests/helpers.py
1515 tests/test_actual.py
1616 tests/test_cli.py
17 tests/test_compile_errors.py
1718 tests/test_cpuid.py
1819 tests/test_example.py
1920 tests/test_free_bsd_11_x86_64.py
2021 tests/test_haiku_x86_32.py
2122 tests/test_haiku_x86_64.py
23 tests/test_haiku_x86_64_beta_1_ryzen_7.py
2224 tests/test_invalid_cpu.py
2325 tests/test_linux_aarch64_64.py
2426 tests/test_linux_beagle_bone_arm.py
2729 tests/test_linux_debian_8_x86_64.py
2830 tests/test_linux_fedora_24_ppc64le.py
2931 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
3034 tests/test_linux_gentoo_2_2_x86_64.py
3135 tests/test_linux_odroid_c2_aarch64.py
3236 tests/test_linux_odroid_xu3_arm_32.py
3337 tests/test_linux_raspberry_pi_model_b_arm.py
3438 tests/test_linux_rhel_7_3_ppc64le.py
3539 tests/test_linux_ubuntu_16_04_x86_64.py
40 tests/test_open_indiana_5_11_x86_64_ryzen_7.py
3641 tests/test_osx_10_12_x86_64.py
3742 tests/test_osx_10_9_x86_64.py
3843 tests/test_parse_cpu_string.py
3944 tests/test_parse_errors.py
4045 tests/test_pcbsd_10_x86_64.py
46 tests/test_selinux.py
4147 tests/test_solaris_11_x86_32.py
48 tests/test_true_os_18_x86_64_ryzen_7.py
4249 tests/test_windows_10_x86_64.py
50 tests/test_windows_10_x86_64_ryzen_7.py
4351 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>
11 # Py-cpuinfo gets CPU info with pure Python 2 & 3
22 # It uses the MIT License
33 # It is hosted at: https://github.com/workhorsy/py-cpuinfo
1010
1111 setup(
1212 name = "py-cpuinfo",
13 version = "5.0.0",
13 version = "7.0.0",
1414 author = "Matthew Brennan Jones",
1515 author_email = "matthew.brennan.jones@gmail.com",
1616 description = "Get CPU info with pure Python 2 & 3",
00 #!/usr/bin/env python
11 # -*- coding: UTF-8 -*-
22
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>
44 # Py-cpuinfo gets CPU info with pure Python 2 & 3
55 # It uses the MIT License
66 # It is hosted at: https://github.com/workhorsy/py-cpuinfo
3434
3535
3636 # Import all the test files
37 from test_compile_errors import TestCompileErrors
3738 from test_example import TestExample
3839 from test_parse_errors import TestParseErrors
3940 from test_parse_cpu_string import TestParseCPUString
4041 from test_invalid_cpu import TestInvalidCPU
42 from test_selinux import TestSELinux
4143 from test_linux_debian_8_x86_64 import TestLinuxDebian_8_X86_64
4244 from test_linux_debian_8_5_x86_64 import TestLinuxDebian_8_5_X86_64
4345 from test_linux_debian_8_7_1_ppc64le import TestLinuxDebian_8_7_1_ppc64le
4446 from test_linux_ubuntu_16_04_x86_64 import TestLinuxUbuntu_16_04_X86_64
4547 from test_linux_fedora_24_x86_64 import TestLinuxFedora_24_X86_64
4648 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
4751 from test_linux_aarch64_64 import TestLinux_Aarch_64
4852 from test_linux_gentoo_2_2_x86_64 import TestLinuxGentoo_2_2_X86_64
4953 from test_linux_rhel_7_3_ppc64le import TestLinuxRHEL_7_3_ppc64le
5559 from test_free_bsd_11_x86_64 import TestFreeBSD_11_X86_64
5660 from test_osx_10_9_x86_64 import TestOSX_10_9
5761 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
5964 from test_haiku_x86_32 import TestHaiku_x86_32
6065 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
6168 from test_windows_8_x86_64 import TestWindows_8_X86_64
6269 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
6371 from test_cpuid import TestCPUID
6472 from test_actual import TestActual
6573 from test_cli import TestCLI
7280
7381 # Get all the tests
7482 tests = [
83 TestCompileErrors,
7584 TestParseCPUString,
7685 TestExample,
7786 TestParseErrors,
7887 TestInvalidCPU,
88 TestSELinux,
7989 TestLinuxDebian_8_X86_64,
8090 TestLinuxDebian_8_5_X86_64,
8191 TestLinuxDebian_8_7_1_ppc64le,
8292 TestLinuxUbuntu_16_04_X86_64,
8393 TestLinuxFedora_24_X86_64,
8494 TestLinuxFedora_24_ppc64le,
95 Test_Linux_Fedora_29_X86_64_Ryzen_7,
96 TestLinuxFedora_5_s390x,
8597 TestLinux_Aarch_64,
8698 TestLinuxGentoo_2_2_X86_64,
8799 TestLinuxRHEL_7_3_ppc64le,
93105 TestPCBSD,
94106 TestOSX_10_9,
95107 TestOSX_10_12,
96 TestSolaris,
108 TestSolaris_11,
109 TestOpenIndiana_5_11_Ryzen_7,
97110 TestHaiku_x86_32,
98111 TestHaiku_x86_64,
112 TestHaiku_x86_64_Beta_1_Ryzen7,
113 TestTrueOS_18_X86_64_Ryzen7,
99114 TestWindows_8_X86_64,
100115 TestWindows_10_X86_64,
116 TestWindows_10_X86_64_Ryzen7,
101117 TestCPUID,
102118 TestActual,
103119 TestCLI
00 #!/usr/bin/env python
11 # -*- coding: UTF-8 -*-
22
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>
44 # Py-cpuinfo gets CPU info with pure Python 2 & 3
55 # It uses the MIT License
66 # It is hosted at: https://github.com/workhorsy/py-cpuinfo
114114 cpuinfo.DataSource.cpu_count = NewDataSource.cpu_count
115115 if hasattr(NewDataSource, 'is_windows'):
116116 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
119121 if hasattr(NewDataSource, 'can_cpuid'):
120122 cpuinfo.DataSource.can_cpuid = NewDataSource.can_cpuid
121123
147149 cpuinfo.DataSource.cat_proc_cpuinfo = staticmethod(NewDataSource.cat_proc_cpuinfo)
148150 if hasattr(NewDataSource, 'cpufreq_info'):
149151 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)
154154 if hasattr(NewDataSource, 'dmesg_a'):
155155 cpuinfo.DataSource.dmesg_a = staticmethod(NewDataSource.dmesg_a)
156156 if hasattr(NewDataSource, 'cat_var_run_dmesg_boot'):
171171 cpuinfo.DataSource.sysinfo_cpu = staticmethod(NewDataSource.sysinfo_cpu)
172172 if hasattr(NewDataSource, 'winreg_processor_brand'):
173173 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)
178178 if hasattr(NewDataSource, 'winreg_hz_actual'):
179179 cpuinfo.DataSource.winreg_hz_actual = staticmethod(NewDataSource.winreg_hz_actual)
180180 if hasattr(NewDataSource, 'winreg_feature_bits'):
186186 cpuinfo.BackupDataSource.bits = cpuinfo.DataSource.bits
187187 cpuinfo.BackupDataSource.cpu_count = cpuinfo.DataSource.cpu_count
188188 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
190191 cpuinfo.BackupDataSource.can_cpuid = cpuinfo.DataSource.can_cpuid
191192
192193 cpuinfo.BackupDataSource.has_proc_cpuinfo = staticmethod(cpuinfo.DataSource.has_proc_cpuinfo)
203204 cpuinfo.BackupDataSource.has_wmic = staticmethod(cpuinfo.DataSource.has_wmic)
204205 cpuinfo.BackupDataSource.cat_proc_cpuinfo = staticmethod(cpuinfo.DataSource.cat_proc_cpuinfo)
205206 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)
208208 cpuinfo.BackupDataSource.dmesg_a = staticmethod(cpuinfo.DataSource.dmesg_a)
209209 cpuinfo.BackupDataSource.cat_var_run_dmesg_boot = staticmethod(cpuinfo.DataSource.cat_var_run_dmesg_boot)
210210 cpuinfo.BackupDataSource.sysctl_machdep_cpu_hw_cpufrequency = staticmethod(cpuinfo.DataSource.sysctl_machdep_cpu_hw_cpufrequency)
215215 cpuinfo.BackupDataSource.wmic_cpu = staticmethod(cpuinfo.DataSource.wmic_cpu)
216216 cpuinfo.BackupDataSource.sysinfo_cpu = staticmethod(cpuinfo.DataSource.sysinfo_cpu)
217217 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)
220220 cpuinfo.BackupDataSource.winreg_hz_actual = staticmethod(cpuinfo.DataSource.winreg_hz_actual)
221221 cpuinfo.BackupDataSource.winreg_feature_bits = staticmethod(cpuinfo.DataSource.winreg_feature_bits)
222222
224224 cpuinfo.DataSource.bits = cpuinfo.BackupDataSource.bits
225225 cpuinfo.DataSource.cpu_count = cpuinfo.BackupDataSource.cpu_count
226226 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
228229 cpuinfo.DataSource.can_cpuid = cpuinfo.BackupDataSource.can_cpuid
229230
230231 cpuinfo.DataSource.has_proc_cpuinfo = cpuinfo.BackupDataSource.has_proc_cpuinfo
241242 cpuinfo.DataSource.has_wmic = cpuinfo.BackupDataSource.has_wmic
242243 cpuinfo.DataSource.cat_proc_cpuinfo = cpuinfo.BackupDataSource.cat_proc_cpuinfo
243244 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
246246 cpuinfo.DataSource.dmesg_a = cpuinfo.BackupDataSource.dmesg_a
247247 cpuinfo.DataSource.cat_var_run_dmesg_boot = cpuinfo.BackupDataSource.cat_var_run_dmesg_boot
248248 cpuinfo.DataSource.sysctl_machdep_cpu_hw_cpufrequency = cpuinfo.BackupDataSource.sysctl_machdep_cpu_hw_cpufrequency
253253 cpuinfo.DataSource.wmic_cpu = cpuinfo.BackupDataSource.wmic_cpu
254254 cpuinfo.DataSource.sysinfo_cpu = cpuinfo.BackupDataSource.sysinfo_cpu
255255 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
258258 cpuinfo.DataSource.winreg_hz_actual = cpuinfo.BackupDataSource.winreg_hz_actual
259259 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
2828 info = json.loads(output, object_hook = cpuinfo._utf_to_str)
2929
3030 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)
3147
3248 def test_default(self):
3349 from subprocess import Popen, PIPE
4359
4460 version = output.split('Cpuinfo Version: ')[1].split('\n')[0].strip()
4561
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)
44 import helpers
55
66
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
7212
8213 class MockDataSource(object):
9214 bits = '64bit'
10215 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'
13219 can_cpuid = True
14220
15221
18224 helpers.backup_data_source(cpuinfo)
19225 helpers.monkey_patch_data_source(cpuinfo, MockDataSource)
20226
227 helpers.backup_asm(cpuinfo)
228 helpers.monkey_patch_asm(cpuinfo, MockASM)
229
21230 def tearDown(self):
22231 helpers.restore_data_source(cpuinfo)
232
233 helpers.restore_asm(cpuinfo)
23234
24235 # Make sure this returns {} on an invalid arch
25236 def test_return_empty(self):
26237 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)
88 bits = '64bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213
1314 @staticmethod
1415 def has_proc_cpuinfo():
5960 return 1, None
6061
6162 @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
6865
6966 @staticmethod
7067 def dmesg_a():
9996 return None
10097
10198 @staticmethod
102 def winreg_vendor_id():
99 def winreg_vendor_id_raw():
103100 return None
104101
105102 @staticmethod
106 def winreg_raw_arch_string():
103 def winreg_arch_string_raw():
107104 return None
108105
109106 @staticmethod
88 bits = '64bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'amd64'
11 arch_string_raw = 'amd64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
2223 @staticmethod
2324 def dmesg_a():
2425 retcode = 0
25 output = '''Copyright (c) 1992-2014 The FreeBSD Project.
26 output = r'''Copyright (c) 1992-2014 The FreeBSD Project.
2627 Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
2728 The Regents of the University of California. All rights reserved.
2829 FreeBSD is a registered trademark of The FreeBSD Foundation.
4344 @staticmethod
4445 def cat_var_run_dmesg_boot():
4546 retcode = 0
46 output = '''
47 output = r'''
4748 VT(vga): text 80x25
4849 CPU: Intel(R) Pentium(R) CPU G640 @ 2.80GHz (2793.73-MHz K8-class CPU)
4950 Origin="GenuineIntel" Id=0x206a7 Family=0x6 Model=02a Stepping=7
8081 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
8182 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
8283 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()))
8485
8586 def test_get_cpu_info_from_dmesg(self):
8687 info = cpuinfo._get_cpu_info_from_dmesg()
8788
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'])
9495
9596 self.assertEqual(7, info['stepping'])
9697 self.assertEqual(42, info['model'])
108109 def test_get_cpu_info_from_cat_var_run_dmesg_boot(self):
109110 info = cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot()
110111
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'])
117118
118119 self.assertEqual(7, info['stepping'])
119120 self.assertEqual(42, info['model'])
131132 def test_all(self):
132133 info = cpuinfo._get_cpu_info_internal()
133134
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'])
140141 self.assertEqual('X86_64', info['arch'])
141142 self.assertEqual(64, info['bits'])
142143 self.assertEqual(1, info['count'])
143144
144 self.assertEqual('amd64', info['raw_arch_string'])
145 self.assertEqual('amd64', info['arch_string_raw'])
145146
146147 self.assertEqual(7, info['stepping'])
147148 self.assertEqual(42, info['model'])
88 bits = '32bit'
99 cpu_count = 4
1010 is_windows = False
11 raw_arch_string = 'BePC'
11 arch_string_raw = 'BePC'
12 uname_string_raw = 'x86_32'
1213 can_cpuid = False
1314
1415 @staticmethod
1819 @staticmethod
1920 def sysinfo_cpu():
2021 returncode = 0
21 output = '''
22 output = r'''
2223 4 Intel Core i7, revision 46e5 running at 2928MHz (ID: 0x00000000 0x00000000)
2324
2425 CPU #0: "Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz"
7374 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
7475 self.assertEqual(9, len(cpuinfo._get_cpu_info_from_sysinfo()))
7576 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()))
7778
7879 def test_get_cpu_info_from_sysinfo(self):
7980 info = cpuinfo._get_cpu_info_from_sysinfo()
8081
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'])
8687
8788 self.assertEqual(5, info['stepping'])
8889 self.assertEqual(30, info['model'])
9899 def test_all(self):
99100 info = cpuinfo._get_cpu_info_internal()
100101
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'])
106107 self.assertEqual('X86_32', info['arch'])
107108 self.assertEqual(32, info['bits'])
108109 self.assertEqual(4, info['count'])
109110
110 self.assertEqual('BePC', info['raw_arch_string'])
111 self.assertEqual('BePC', info['arch_string_raw'])
111112
112113 self.assertEqual(5, info['stepping'])
113114 self.assertEqual(30, info['model'])
88 bits = '64bit'
99 cpu_count = 4
1010 is_windows = False
11 raw_arch_string = 'BePC'
11 arch_string_raw = 'BePC'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
1819 @staticmethod
1920 def sysinfo_cpu():
2021 returncode = 0
21 output = '''
22 output = r'''
2223 1 Intel Core i7, revision 106e5 running at 2933MHz
2324
2425 CPU #0: "Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz"
7374 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
7475 self.assertEqual(9, len(cpuinfo._get_cpu_info_from_sysinfo()))
7576 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()))
7778
7879 def test_get_cpu_info_from_sysinfo(self):
7980 info = cpuinfo._get_cpu_info_from_sysinfo()
8081
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'])
8687
8788 self.assertEqual(5, info['stepping'])
8889 self.assertEqual(30, info['model'])
99100 def test_all(self):
100101 info = cpuinfo._get_cpu_info_internal()
101102
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'])
107108 self.assertEqual('X86_32', info['arch'])
108109 self.assertEqual(32, info['bits'])
109110 self.assertEqual(4, info['count'])
110111
111 self.assertEqual('BePC', info['raw_arch_string'])
112 self.assertEqual('BePC', info['arch_string_raw'])
112113
113114 self.assertEqual(5, info['stepping'])
114115 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 )
88 bits = '32bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'unknown_cpu'
11 arch_string_raw = 'unknown_cpu'
12 uname_string_raw = 'unknown_cpu'
1213
1314
1415 class TestInvalidCPU(unittest.TestCase):
2122
2223 def test_arch_parse_unknown(self):
2324 # 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)
2526 self.assertIsNone(arch)
2627 self.assertIsNone(bits)
2728
3132 cpuinfo._check_arch()
3233 self.fail('Failed to raise Exception')
3334 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])
88 bits = '64bit'
99 cpu_count = 6
1010 is_windows = False
11 raw_arch_string = 'aarch64'
11 arch_string_raw = 'aarch64'
12 uname_string_raw = ''
1213 can_cpuid = False
1314
1415 @staticmethod
2223 @staticmethod
2324 def cat_proc_cpuinfo():
2425 returncode = 0
25 output = '''
26 output = r'''
2627 processor : 90
2728 BogoMIPS : 200.00
2829 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics
8485 @staticmethod
8586 def lscpu():
8687 returncode = 0
87 output = '''
88 output = r'''
8889 Architecture: aarch64
8990 Byte Order: Little Endian
9091 CPU(s): 96
125126 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
126127 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
127128 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()))
129130
130131 def test_get_cpu_info_from_lscpu(self):
131132 info = cpuinfo._get_cpu_info_from_lscpu()
132133
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'])
135136
136 self.assertEqual('16384 KB', info['l2_cache_size'])
137 self.assertEqual(16384 * 1024, info['l2_cache_size'])
137138
138139 self.assertEqual(3, len(info))
139140
151152 def test_all(self):
152153 info = cpuinfo._get_cpu_info_internal()
153154
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'])
161162 self.assertEqual('ARM_8', info['arch'])
162163 self.assertEqual(64, info['bits'])
163164 self.assertEqual(6, info['count'])
164165
165 self.assertEqual('aarch64', info['raw_arch_string'])
166 self.assertEqual('aarch64', info['arch_string_raw'])
166167
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'])
169170
170 self.assertEqual('16384K', info['l2_cache_size'])
171 self.assertEqual(16384 * 1024, info['l2_cache_size'])
171172 self.assertEqual(0, info['l2_cache_line_size'])
172173 self.assertEqual(0, info['l2_cache_associativity'])
173174
174 self.assertEqual('', info['l3_cache_size'])
175 self.assertEqual(0, info['l3_cache_size'])
175176
176177 self.assertEqual(0, info['stepping'])
177178 self.assertEqual(0, info['model'])
178179 self.assertEqual(0, info['family'])
179180 self.assertEqual(0, info['processor_type'])
180 self.assertEqual(0, info['extended_model'])
181 self.assertEqual(0, info['extended_family'])
182181 self.assertEqual(
183182 ['aes', 'asimd', 'atomics', 'crc32', 'evtstrm',
184183 'fp', 'pmull', 'sha1', 'sha2']
88 bits = '32bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'armv7l'
11 arch_string_raw = 'armv7l'
12 uname_string_raw = ''
1213
1314 @staticmethod
1415 def has_proc_cpuinfo():
2122 @staticmethod
2223 def cat_proc_cpuinfo():
2324 returncode = 0
24 output = '''
25 output = r'''
2526 processor : 0
2627 model name : ARMv6-compatible processor rev 7 (v6l)
2728 Features : swp half thumb fastmult vfp edsp java tls
4344 @staticmethod
4445 def cpufreq_info():
4546 returncode = 0
46 output = '''
47 output = r'''
4748 cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
4849 Report errors and bugs to cpufreq@vger.kernel.org, please.
4950 analyzing CPU 0:
8687 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
8788 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
8889 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()))
9091
9192 def test_get_cpu_info_from_cpufreq_info(self):
9293 info = cpuinfo._get_cpu_info_from_cpufreq_info()
9394
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'])
9899
99100 def test_get_cpu_info_from_proc_cpuinfo(self):
100101 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
101102
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'])
104105
105106 self.assertEqual(
106107 ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp']
111112 def test_all(self):
112113 info = cpuinfo._get_cpu_info_internal()
113114
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'])
120121 self.assertEqual('ARM_7', info['arch'])
121122 self.assertEqual(32, info['bits'])
122123 self.assertEqual(1, info['count'])
123124
124 self.assertEqual('armv7l', info['raw_arch_string'])
125 self.assertEqual('armv7l', info['arch_string_raw'])
125126
126127 self.assertEqual(
127128 ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp']
88 bits = '64bit'
99 cpu_count = 2
1010 is_windows = False
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
2627 @staticmethod
2728 def cat_proc_cpuinfo():
2829 returncode = 0
29 output = '''
30 output = r'''
3031 processor : 0
3132 vendor_id : GenuineIntel
3233 cpu family : 6
8485 @staticmethod
8586 def dmesg_a():
8687 returncode = 0
87 output = '''
88 output = r'''
8889 [ 0.000000] Initializing cgroup subsys cpuset
8990 [ 0.000000] Initializing cgroup subsys cpu
9091 [ 0.000000] Initializing cgroup subsys cpuacct
408409 @staticmethod
409410 def lscpu():
410411 returncode = 0
411 output = '''
412 output = r'''
412413 Architecture: x86_64
413414 CPU op-mode(s): 32-bit, 64-bit
414415 Byte Order: Little Endian
460461 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
461462 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
462463 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()))
464465
465466 def test_get_cpu_info_from_lscpu(self):
466467 info = cpuinfo._get_cpu_info_from_lscpu()
467468
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'])
474475
475476 self.assertEqual(7, info['stepping'])
476477 self.assertEqual(42, info['model'])
477478 self.assertEqual(6, info['family'])
478479
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'])
484485
485486 def test_get_cpu_info_from_dmesg(self):
486487 info = cpuinfo._get_cpu_info_from_dmesg()
487488
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'])
493494
494495 self.assertEqual(7, info['stepping'])
495496 self.assertEqual(42, info['model'])
498499 def test_get_cpu_info_from_proc_cpuinfo(self):
499500 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
500501
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'])
509510
510511 self.assertEqual(7, info['stepping'])
511512 self.assertEqual(42, info['model'])
524525 def test_all(self):
525526 info = cpuinfo._get_cpu_info_internal()
526527
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'])
533534 self.assertEqual('X86_64', info['arch'])
534535 self.assertEqual(64, info['bits'])
535536 self.assertEqual(2, info['count'])
536537
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'])
544545
545546 self.assertEqual(7, info['stepping'])
546547 self.assertEqual(42, info['model'])
88 bits = '64bit'
99 cpu_count = 2
1010 is_windows = False
11 raw_arch_string = 'ppc64le'
11 arch_string_raw = 'ppc64le'
12 uname_string_raw = ''
1213 can_cpuid = False
1314
1415 @staticmethod
3031 @staticmethod
3132 def ibm_pa_features():
3233 returncode = 0
33 output = '''
34 output = r'''
3435 /proc/device-tree/cpus/PowerPC,POWER8@0/ibm,pa-features
3536 18 00 f6 3f c7 c0 80 f0 80 00 00 00 00 00 00 00...?............
3637 00 00 80 00 80 00 80 00 80 00 ..........
4142 @staticmethod
4243 def cat_proc_cpuinfo():
4344 returncode = 0
44 output = '''
45 output = r'''
4546 processor : 0
4647 cpu : POWER7 (raw), altivec supported
4748 clock : 1000.000000MHz
6364 @staticmethod
6465 def dmesg_a():
6566 returncode = 0
66 output = '''
67 output = r'''
6768 [ 0.000000] Allocated 4718592 bytes for 2048 pacas at c00000000fb80000
6869 [ 0.000000] Using pSeries machine description
6970 [ 0.000000] Page sizes from device-tree:
388389 @staticmethod
389390 def lscpu():
390391 returncode = 0
391 output = '''
392 output = r'''
392393 Architecture: ppc64le
393394 Byte Order: Little Endian
394395 CPU(s): 2
430431 self.assertEqual(1, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
431432 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
432433 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()))
434435
435436 def test_get_cpu_info_from_lscpu(self):
436437 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'])
439440 self.assertEqual(2, len(info))
440441
441442 def test_get_cpu_info_from_ibm_pa_features(self):
448449 def test_get_cpu_info_from_proc_cpuinfo(self):
449450 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
450451
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'])
456457
457458 def test_all(self):
458459 info = cpuinfo._get_cpu_info_internal()
459460
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'])
465466 self.assertEqual('PPC_64', info['arch'])
466467 self.assertEqual(64, info['bits'])
467468 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'])
471472 self.assertEqual(
472473 ['dabr', 'dabrx', 'dsisr', 'fpu', 'lp', 'mmu', 'pp', 'rislb', 'run', 'slb', 'sprg3'],
473474 info['flags']
88 bits = '64bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
1819 @staticmethod
1920 def cat_proc_cpuinfo():
2021 returncode = 0
21 output = '''
22 output = r'''
2223 processor : 0
2324 vendor_id : GenuineIntel
2425 cpu family : 6
7475 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
7576 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
7677 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()))
7879
7980 def test_get_cpu_info_from_proc_cpuinfo(self):
8081 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
8182
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'])
8889
89 self.assertEqual('6144 KB', info['l3_cache_size'])
90 self.assertEqual(6144 * 1024, info['l3_cache_size'])
9091
9192 self.assertEqual(5, info['stepping'])
9293 self.assertEqual(30, info['model'])
103104 def test_all(self):
104105 info = cpuinfo._get_cpu_info_internal()
105106
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'])
112113 self.assertEqual('X86_64', info['arch'])
113114 self.assertEqual(64, info['bits'])
114115 self.assertEqual(1, info['count'])
115116
116 self.assertEqual('x86_64', info['raw_arch_string'])
117 self.assertEqual('x86_64', info['arch_string_raw'])
117118
118 self.assertEqual('6144 KB', info['l3_cache_size'])
119 self.assertEqual(6144 * 1024, info['l3_cache_size'])
119120
120121 self.assertEqual(5, info['stepping'])
121122 self.assertEqual(30, info['model'])
88 bits = '64bit'
99 cpu_count = 2
1010 is_windows = False
11 raw_arch_string = 'ppc64le'
11 arch_string_raw = 'ppc64le'
12 uname_string_raw = ''
1213 can_cpuid = False
1314
1415 @staticmethod
3031 @staticmethod
3132 def ibm_pa_features():
3233 returncode = 0
33 output = '''
34 output = r'''
3435 /proc/device-tree/cpus/PowerPC,POWER7@1/ibm,pa-features 3ff60006 c08000c7
3536
3637 '''
3940 @staticmethod
4041 def cat_proc_cpuinfo():
4142 returncode = 0
42 output = '''
43 output = r'''
4344 processor : 0
4445 cpu : POWER8E (raw), altivec supported
4546 clock : 3425.000000MHz
5960 @staticmethod
6061 def dmesg_a():
6162 returncode = 0
62 output = '''
63 output = r'''
6364 [ 0.000000] Allocated 2359296 bytes for 1024 pacas at c00000000fdc0000
6465 [ 0.000000] Using pSeries machine description
6566 [ 0.000000] Page sizes from device-tree:
319320 @staticmethod
320321 def lscpu():
321322 returncode = 0
322 output = '''
323 output = r'''
323324 Architecture: ppc64le
324325 Byte Order: Little Endian
325326 CPU(s): 2
363364 self.assertEqual(1, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
364365 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
365366 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()))
367368
368369 def test_get_cpu_info_from_lscpu(self):
369370 info = cpuinfo._get_cpu_info_from_lscpu()
370371
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'])
375376
376377 def test_get_cpu_info_from_ibm_pa_features(self):
377378 info = cpuinfo._get_cpu_info_from_ibm_pa_features()
383384 def test_get_cpu_info_from_proc_cpuinfo(self):
384385 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
385386
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'])
391392
392393 def test_all(self):
393394 info = cpuinfo._get_cpu_info_internal()
394395
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'])
400401 self.assertEqual('PPC_64', info['arch'])
401402 self.assertEqual(64, info['bits'])
402403 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'])
406407 self.assertEqual(
407408 ['dss_2.02', 'dss_2.05', 'dss_2.06', 'fpu', 'lsd_in_dscr', 'ppr', 'slb', 'sso_2.06', 'ugr_in_dscr'],
408409 info['flags']
88 bits = '64bit'
99 cpu_count = 2
1010 is_windows = False
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
2627 @staticmethod
2728 def cat_proc_cpuinfo():
2829 returncode = 0
29 output = '''
30 output = r'''
3031 processor : 0
3132 vendor_id : GenuineIntel
3233 cpu family : 6
8485 @staticmethod
8586 def dmesg_a():
8687 returncode = 0
87 output = '''
88 output = r'''
8889 [ 0.000000] Initializing cgroup subsys cpuset
8990 [ 0.000000] Initializing cgroup subsys cpu
9091 [ 0.000000] Initializing cgroup subsys cpuacct
408409 @staticmethod
409410 def lscpu():
410411 returncode = 0
411 output = '''
412 output = r'''
412413 Architecture: x86_64
413414 CPU op-mode(s): 32-bit, 64-bit
414415 Byte Order: Little Endian
460461 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
461462 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
462463 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()))
464465
465466 def test_get_cpu_info_from_lscpu(self):
466467 info = cpuinfo._get_cpu_info_from_lscpu()
467468
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'])
474475
475476 self.assertEqual(7, info['stepping'])
476477 self.assertEqual(42, info['model'])
477478 self.assertEqual(6, info['family'])
478479
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'])
484485
485486 def test_get_cpu_info_from_dmesg(self):
486487 info = cpuinfo._get_cpu_info_from_dmesg()
487488
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'])
493494
494495 self.assertEqual(7, info['stepping'])
495496 self.assertEqual(42, info['model'])
499500 def test_get_cpu_info_from_proc_cpuinfo(self):
500501 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
501502
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'])
510511
511512 self.assertEqual(7, info['stepping'])
512513 self.assertEqual(42, info['model'])
525526 def test_all(self):
526527 info = cpuinfo._get_cpu_info_internal()
527528
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'])
534535 self.assertEqual('X86_64', info['arch'])
535536 self.assertEqual(64, info['bits'])
536537 self.assertEqual(2, info['count'])
537538
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'])
545546
546547 self.assertEqual(7, info['stepping'])
547548 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 )
88 bits = '64bit'
99 cpu_count = 2
1010 is_windows = False
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
2627 @staticmethod
2728 def cat_proc_cpuinfo():
2829 returncode = 0
29 output = '''
30 output = r'''
3031 processor : 0
3132 vendor_id : GenuineIntel
3233 cpu family : 6
8687 @staticmethod
8788 def dmesg_a():
8889 returncode = 0
89 output = '''
90 output = r'''
9091 ===============================================================================
9192 [ 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
9293 [ 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
411412 @staticmethod
412413 def lscpu():
413414 returncode = 0
414 output = '''
415 output = r'''
415416 Architecture: x86_64
416417 CPU op-mode(s): 32-bit, 64-bit
417418 Byte Order: Little Endian
463464 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
464465 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
465466 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()))
467468
468469 def test_get_cpu_info_from_lscpu(self):
469470 info = cpuinfo._get_cpu_info_from_lscpu()
470471
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'])
477478
478479 self.assertEqual(7, info['stepping'])
479480 self.assertEqual(42, info['model'])
480481 self.assertEqual(6, info['family'])
481482
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'])
486487
487488 self.assertEqual(
488489 ['apic', 'clflush', 'cmov', 'constant_tsc', 'cx16', 'cx8', 'de',
498499 def test_get_cpu_info_from_dmesg(self):
499500 info = cpuinfo._get_cpu_info_from_dmesg()
500501
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'])
506507
507508 self.assertEqual(7, info['stepping'])
508509 self.assertEqual(42, info['model'])
511512 def test_get_cpu_info_from_proc_cpuinfo(self):
512513 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
513514
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'])
522523
523524 self.assertEqual(7, info['stepping'])
524525 self.assertEqual(42, info['model'])
537538 def test_all(self):
538539 info = cpuinfo._get_cpu_info_internal()
539540
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'])
546547 self.assertEqual('X86_64', info['arch'])
547548 self.assertEqual(64, info['bits'])
548549 self.assertEqual(2, info['count'])
549550
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'])
556557
557558 self.assertEqual(7, info['stepping'])
558559 self.assertEqual(42, info['model'])
88 bits = '64bit'
99 cpu_count = 4
1010 is_windows = False
11 raw_arch_string = 'aarch64'
11 arch_string_raw = 'aarch64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
2627 @staticmethod
2728 def cat_proc_cpuinfo():
2829 returncode = 0
29 output = '''
30 output = r'''
3031 processor : 0
3132 BogoMIPS : 2.00
3233 Features : fp asimd crc32
7374 @staticmethod
7475 def lscpu():
7576 returncode = 0
76 output = '''
77 output = r'''
7778 Architecture: aarch64
7879 Byte Order: Little Endian
7980 CPU(s): 4
8990 @staticmethod
9091 def cpufreq_info():
9192 returncode = 0
92 output = '''
93 output = r'''
9394 cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
9495 Report errors and bugs to cpufreq@vger.kernel.org, please.
9596 analyzing CPU 0:
172173 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
173174 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
174175 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()))
176177
177178 def test_get_cpu_info_from_cpufreq_info(self):
178179 info = cpuinfo._get_cpu_info_from_cpufreq_info()
179180
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'])
184185
185186 def test_get_cpu_info_from_lscpu(self):
186187 info = cpuinfo._get_cpu_info_from_lscpu()
187188
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'])
192193
193194 def test_get_cpu_info_from_proc_cpuinfo(self):
194195 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
195196
196 self.assertEqual('ODROID-C2', info['hardware'])
197 self.assertEqual('ODROID-C2', info['hardware_raw'])
197198
198199 self.assertEqual(
199200 ['asimd', 'crc32', 'fp'],
203204 def test_all(self):
204205 info = cpuinfo._get_cpu_info_internal()
205206
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'])
211212 self.assertEqual('ARM_8', info['arch'])
212213 self.assertEqual(64, info['bits'])
213214 self.assertEqual(4, info['count'])
214215
215 self.assertEqual('aarch64', info['raw_arch_string'])
216 self.assertEqual('aarch64', info['arch_string_raw'])
216217
217218 self.assertEqual(
218219 ['asimd', 'crc32', 'fp'],
88 bits = '32bit'
99 cpu_count = 8
1010 is_windows = False
11 raw_arch_string = 'armv7l'
11 arch_string_raw = 'armv7l'
12 uname_string_raw = ''
1213 can_cpuid = False
1314
1415 @staticmethod
2627 @staticmethod
2728 def cat_proc_cpuinfo():
2829 returncode = 0
29 output = '''
30 output = r'''
3031 processor : 0
3132 model name : ARMv7 Processor rev 3 (v7l)
3233 BogoMIPS : 84.00
118119 @staticmethod
119120 def lscpu():
120121 returncode = 0
121 output = '''
122 output = r'''
122123 Architecture: armv7l
123124 Byte Order: Little Endian
124125 CPU(s): 8
136137 @staticmethod
137138 def cpufreq_info():
138139 returncode = 0
139 output = '''
140 output = r'''
140141 cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
141142 Report errors and bugs to cpufreq@vger.kernel.org, please.
142143 analyzing CPU 0:
263264 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
264265 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
265266 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()))
267268
268269 def test_get_cpu_info_from_cpufreq_info(self):
269270 info = cpuinfo._get_cpu_info_from_cpufreq_info()
270271
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'])
275276
276277 def test_get_cpu_info_from_lscpu(self):
277278 info = cpuinfo._get_cpu_info_from_lscpu()
278279
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'])
284285
285286 def test_get_cpu_info_from_proc_cpuinfo(self):
286287 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
287288
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'])
290291
291292 self.assertEqual(
292293 ['edsp', 'fastmult', 'half', 'idiva', 'idivt', 'neon', 'swp',
297298 def test_all(self):
298299 info = cpuinfo._get_cpu_info_internal()
299300
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'])
306307 self.assertEqual('ARM_7', info['arch'])
307308 self.assertEqual(32, info['bits'])
308309 self.assertEqual(8, info['count'])
309310
310 self.assertEqual('armv7l', info['raw_arch_string'])
311 self.assertEqual('armv7l', info['arch_string_raw'])
311312
312313 self.assertEqual(
313314 ['edsp', 'fastmult', 'half', 'idiva', 'idivt', 'neon', 'swp',
88 bits = '32bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'armv6l'
11 arch_string_raw = 'armv6l'
12 uname_string_raw = ''
1213
1314 @staticmethod
1415 def has_proc_cpuinfo():
2122 @staticmethod
2223 def cat_proc_cpuinfo():
2324 returncode = 0
24 output = '''
25 output = r'''
2526 Processor : ARMv6-compatible processor rev 7 (v6l)
2627 BogoMIPS : 697.95
2728 Features : swp half thumb fastmult vfp edsp java tls
4243 @staticmethod
4344 def lscpu():
4445 returncode = 0
45 output = '''
46 output = r'''
4647 Architecture: armv6l
4748 Byte Order: Little Endian
4849 CPU(s): 1
8081 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
8182 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
8283 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()))
8485
8586 def test_get_cpu_info_from_lscpu(self):
8687 info = cpuinfo._get_cpu_info_from_lscpu()
8788
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'])
9293
9394 def test_get_cpu_info_from_proc_cpuinfo(self):
9495 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
9596
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'])
9899
99100 self.assertEqual(
100101 ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp']
105106 def test_all(self):
106107 info = cpuinfo._get_cpu_info_internal()
107108
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'])
114115 self.assertEqual('ARM_7', info['arch'])
115116 self.assertEqual(32, info['bits'])
116117 self.assertEqual(1, info['count'])
117118
118 self.assertEqual('armv6l', info['raw_arch_string'])
119 self.assertEqual('armv6l', info['arch_string_raw'])
119120
120121 self.assertEqual(
121122 ['edsp', 'fastmult', 'half', 'java', 'swp', 'thumb', 'tls', 'vfp']
88 bits = '64bit'
99 cpu_count = 16
1010 is_windows = False
11 raw_arch_string = 'ppc64le'
11 arch_string_raw = 'ppc64le'
12 uname_string_raw = ''
1213 can_cpuid = False
1314
1415 @staticmethod
3031 @staticmethod
3132 def ibm_pa_features():
3233 returncode = 0
33 output = '''
34 output = r'''
3435 /proc/device-tree/cpus/PowerPC,POWER7@1/ibm,pa-features 3ff60006 c08000c7
3536
3637 '''
3940 @staticmethod
4041 def cat_proc_cpuinfo():
4142 returncode = 0
42 output = '''
43 output = r'''
4344 processor : 0
4445 cpu : POWER8E (raw), altivec supported
4546 clock : 3425.000000MHz
131132 @staticmethod
132133 def dmesg_a():
133134 returncode = 0
134 output = '''
135 output = r'''
135136 [3269512.154534] convolution_var[11236]: unhandled signal 4 at 00003fff6c390004 nip 00003fff6c390004 lr 00003fff9a648d58 code 30001
136137 [3269512.234818] convolution_var[11344]: unhandled signal 5 at 00003fff84390000 nip 00003fff84390000 lr 00003fffb2217ce0 code 30001
137138 [3269512.234823] convolution_var[11347]: unhandled signal 11 at 0000000000000304 nip 00003fff8439001c lr 00003fffb2217ce0 code 30001
299300 @staticmethod
300301 def lscpu():
301302 returncode = 0
302 output = '''
303 output = r'''
303304 Architecture: ppc64le
304305 Byte Order: Little Endian
305306 CPU(s): 16
341342 self.assertEqual(1, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
342343 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
343344 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()))
345346
346347 def test_get_cpu_info_from_lscpu(self):
347348 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'])
351352
352353 def test_get_cpu_info_from_ibm_pa_features(self):
353354 info = cpuinfo._get_cpu_info_from_ibm_pa_features()
359360 def test_get_cpu_info_from_proc_cpuinfo(self):
360361 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
361362
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'])
367368
368369 def test_all(self):
369370 info = cpuinfo._get_cpu_info_internal()
370371
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'])
376377 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'])
379380 self.assertEqual(64, info['bits'])
380381 self.assertEqual(16, info['count'])
381 self.assertEqual('ppc64le', info['raw_arch_string'])
382 self.assertEqual('ppc64le', info['arch_string_raw'])
382383 self.assertEqual(
383384 ['dss_2.02', 'dss_2.05', 'dss_2.06', 'fpu', 'lsd_in_dscr', 'ppr', 'slb', 'sso_2.06', 'ugr_in_dscr'],
384385 info['flags']
88 bits = '64bit'
99 cpu_count = 2
1010 is_windows = False
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
2627 @staticmethod
2728 def cat_proc_cpuinfo():
2829 returncode = 0
29 output = '''
30 output = r'''
3031 processor : 0
3132 vendor_id : GenuineIntel
3233 cpu family : 6
8889 @staticmethod
8990 def lscpu():
9091 returncode = 0
91 output = '''
92 output = r'''
9293 Architecture: x86_64
9394 CPU op-mode(s): 32-bit, 64-bit
9495 Byte Order: Little Endian
122123 @staticmethod
123124 def dmesg_a():
124125 returncode = 0
125 output = '''
126 output = r'''
126127 [ 0.000000] microcode: CPU0 microcode updated early to revision 0x29, date = 2013-06-12
127128 [ 0.000000] Initializing cgroup subsys cpuset
128129 [ 0.000000] Initializing cgroup subsys cpu
464465 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
465466 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
466467 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()))
468469
469470 def test_get_cpu_info_from_lscpu(self):
470471 info = cpuinfo._get_cpu_info_from_lscpu()
471472
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'])
478479
479480 self.assertEqual(7, info['stepping'])
480481 self.assertEqual(42, info['model'])
481482 self.assertEqual(6, info['family'])
482483
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'])
487488 self.assertEqual(
488489 ['acpi', 'aperfmperf', 'apic', 'arat', 'arch_perfmon', 'bts',
489490 'clflush', 'cmov', 'constant_tsc', 'cx16', 'cx8', 'de', 'ds_cpl',
503504 def test_get_cpu_info_from_dmesg(self):
504505 info = cpuinfo._get_cpu_info_from_dmesg()
505506
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'])
511512
512513 self.assertEqual(7, info['stepping'])
513514 self.assertEqual(42, info['model'])
516517 def test_get_cpu_info_from_proc_cpuinfo(self):
517518 info = cpuinfo._get_cpu_info_from_proc_cpuinfo()
518519
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'])
527528
528529 self.assertEqual(7, info['stepping'])
529530 self.assertEqual(42, info['model'])
547548 def test_all(self):
548549 info = cpuinfo._get_cpu_info_internal()
549550
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'])
556557 self.assertEqual('X86_64', info['arch'])
557558 self.assertEqual(64, info['bits'])
558559 self.assertEqual(2, info['count'])
559560
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'])
568569
569570 self.assertEqual(7, info['stepping'])
570571 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 )
1010 bits = '64bit'
1111 cpu_count = 4
1212 is_windows = False
13 raw_arch_string = 'x86_64'
13 arch_string_raw = 'x86_64'
14 uname_string_raw = 'x86_64'
1415 can_cpuid = False
1516
1617 @staticmethod
2021 @staticmethod
2122 def sysctl_machdep_cpu_hw_cpufrequency():
2223 returncode = 0
23 output = '''
24 output = r'''
2425 machdep.cpu.tsc_ccc.denominator: 0
2526 machdep.cpu.tsc_ccc.numerator: 0
2627 machdep.cpu.thread_count: 4
107108 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
108109 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
109110 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()))
111112
112113 def test_get_cpu_info_from_sysctl(self):
113114 info = cpuinfo._get_cpu_info_from_sysctl()
114115
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'])
121122
122 self.assertEqual('256', info['l2_cache_size'])
123 self.assertEqual(256 * 1024, info['l2_cache_size'])
123124
124125 self.assertEqual(7, info['stepping'])
125126 self.assertEqual(42, info['model'])
141142 def test_all(self):
142143 info = cpuinfo._get_cpu_info_internal()
143144
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'])
150151 self.assertEqual('X86_64', info['arch'])
151152 self.assertEqual(64, info['bits'])
152153 self.assertEqual(4, info['count'])
153154
154 self.assertEqual('x86_64', info['raw_arch_string'])
155 self.assertEqual('x86_64', info['arch_string_raw'])
155156
156 self.assertEqual('256', info['l2_cache_size'])
157 self.assertEqual(256 * 1024, info['l2_cache_size'])
157158
158159 self.assertEqual(7, info['stepping'])
159160 self.assertEqual(42, info['model'])
1010 bits = '64bit'
1111 cpu_count = 4
1212 is_windows = False
13 raw_arch_string = 'x86_64'
13 arch_string_raw = 'x86_64'
14 uname_string_raw = 'x86_64'
1415 can_cpuid = False
1516
1617 @staticmethod
2021 @staticmethod
2122 def sysctl_machdep_cpu_hw_cpufrequency():
2223 returncode = 0
23 output = '''
24 output = r'''
2425 machdep.cpu.max_basic: 5
2526 machdep.cpu.max_ext: 2147483656
2627 machdep.cpu.vendor: GenuineIntel
8788 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
8889 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
8990 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()))
9192
9293 def test_get_cpu_info_from_sysctl(self):
9394 info = cpuinfo._get_cpu_info_from_sysctl()
9495
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'])
101102
102 self.assertEqual('256', info['l2_cache_size'])
103 self.assertEqual(256 * 1024, info['l2_cache_size'])
103104
104105 self.assertEqual(9, info['stepping'])
105106 self.assertEqual(58, info['model'])
117118 def test_all(self):
118119 info = cpuinfo._get_cpu_info_internal()
119120
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'])
126127 self.assertEqual('X86_64', info['arch'])
127128 self.assertEqual(64, info['bits'])
128129 self.assertEqual(4, info['count'])
129130
130 self.assertEqual('x86_64', info['raw_arch_string'])
131 self.assertEqual('x86_64', info['arch_string_raw'])
131132
132 self.assertEqual('256', info['l2_cache_size'])
133 self.assertEqual(256 * 1024, info['l2_cache_size'])
133134
134135 self.assertEqual(9, info['stepping'])
135136 self.assertEqual(58, info['model'])
55
66
77
8
89 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'))
1918
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))
2923
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))
3931
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))
4968
5069 # 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))
6072
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))
6676
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))
7183
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))
7689
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))
8295
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))
87101
88102 # 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))
88 bits = '64bit'
99 cpu_count = 1
1010 is_windows = True
11 raw_arch_string = 'x86_64'
11 arch_string_raw = 'x86_64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
5657 return 0, ""
5758
5859 @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, ""
6562
6663 @staticmethod
6764 def dmesg_a():
9390 return {}
9491
9592 @staticmethod
96 def winreg_vendor_id():
93 def winreg_vendor_id_raw():
9794 return {}
9895
9996 @staticmethod
100 def winreg_raw_arch_string():
97 def winreg_arch_string_raw():
10198 return {}
10299
103100 @staticmethod
88 bits = '64bit'
99 cpu_count = 1
1010 is_windows = False
11 raw_arch_string = 'amd64'
11 arch_string_raw = 'amd64'
12 uname_string_raw = 'x86_64'
1213 can_cpuid = False
1314
1415 @staticmethod
1819 @staticmethod
1920 def dmesg_a():
2021 retcode = 0
21 output = '''Copyright (c) 1992-2014 The FreeBSD Project.
22 output = r'''Copyright (c) 1992-2014 The FreeBSD Project.
2223 Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
2324 The Regents of the University of California. All rights reserved.
2425 FreeBSD is a registered trademark of The FreeBSD Foundation.
6162 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
6263 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
6364 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()))
6566
6667 def test_get_cpu_info_from_dmesg(self):
6768 info = cpuinfo._get_cpu_info_from_dmesg()
6869
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'])
7475
7576 self.assertEqual(
7677 ['apic', 'clflush', 'cmov', 'cx8', 'de', 'fpu', 'fxsr', 'lahf',
8485 def test_all(self):
8586 info = cpuinfo._get_cpu_info_internal()
8687
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'])
9293 self.assertEqual('X86_64', info['arch'])
9394 self.assertEqual(64, info['bits'])
9495 self.assertEqual(1, info['count'])
9596
96 self.assertEqual('amd64', info['raw_arch_string'])
97 self.assertEqual('amd64', info['arch_string_raw'])
9798
9899 self.assertEqual(
99100 ['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())
88 bits = '32bit'
99 cpu_count = 4
1010 is_windows = False
11 raw_arch_string = 'i86pc'
11 arch_string_raw = 'i86pc'
12 uname_string_raw = 'x86_32'
1213 can_cpuid = False
1314
1415 @staticmethod
2223 @staticmethod
2324 def isainfo_vb():
2425 returncode = 0
25 output = '''
26 output = r'''
2627 64-bit amd64 applications
2728 ssse3 tscp ahf sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu
2829
3233 @staticmethod
3334 def kstat_m_cpu_info():
3435 returncode = 0
35 output = '''
36 output = r'''
3637 module: cpu_info instance: 0
3738 name: cpu_info0 class: misc
3839 brand Intel(r) Core(tm) i7 CPU 870 @ 2.93GHz
7879
7980
8081
81 class TestSolaris(unittest.TestCase):
82 class TestSolaris_11(unittest.TestCase):
8283 def setUp(self):
8384 helpers.backup_data_source(cpuinfo)
8485 helpers.monkey_patch_data_source(cpuinfo, MockDataSource)
101102 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
102103 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo()))
103104 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()))
105106
106107 def test_get_cpu_info_from_kstat(self):
107108 info = cpuinfo._get_cpu_info_from_kstat()
108109
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'])
115116
116117 self.assertEqual(5, info['stepping'])
117118 self.assertEqual(30, info['model'])
125126 def test_all(self):
126127 info = cpuinfo._get_cpu_info_internal()
127128
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'])
134135 self.assertEqual('X86_32', info['arch'])
135136 self.assertEqual(32, info['bits'])
136137 self.assertEqual(4, info['count'])
137138
138 self.assertEqual('i86pc', info['raw_arch_string'])
139 self.assertEqual('i86pc', info['arch_string_raw'])
139140
140141 self.assertEqual(5, info['stepping'])
141142 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 )
88 bits = '64bit'
99 cpu_count = 4
1010 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
1314
1415 @staticmethod
1516 def has_wmic():
1819 @staticmethod
1920 def wmic_cpu():
2021 returncode = 0
21 output = '''
22 output = r'''
2223 Caption=Intel64 Family 6 Model 69 Stepping 1
2324 CurrentClockSpeed=2494
2425 Description=Intel64 Family 6 Model 69 Stepping 1
3536 return 'Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz'
3637
3738 @staticmethod
38 def winreg_vendor_id():
39 def winreg_vendor_id_raw():
3940 return 'GenuineIntel'
4041
4142 @staticmethod
42 def winreg_raw_arch_string():
43 def winreg_arch_string_raw():
4344 return 'AMD64'
4445
4546 @staticmethod
5556
5657 class TestWindows_10_X86_64(unittest.TestCase):
5758 def setUp(self):
59 cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = False
5860 helpers.backup_data_source(cpuinfo)
5961 helpers.monkey_patch_data_source(cpuinfo, MockDataSource)
6062
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
6183 def tearDown(self):
6284 helpers.restore_data_source(cpuinfo)
85 helpers.restore_cpuid(cpuinfo)
86 cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = True
6387
6488 '''
6589 Make sure calls return the expected number of fields.
76100 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot()))
77101 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
78102 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'])
81145
82146 def test_get_cpu_info_from_wmic(self):
83147 info = cpuinfo._get_cpu_info_from_wmic()
84148
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'])
98162
99163 def test_get_cpu_info_from_registry(self):
100164 info = cpuinfo._get_cpu_info_from_registry()
101165
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'])
110172
111173 self.assertEqual(
112174 ['3dnow', 'acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr',
119181 def test_all(self):
120182 info = cpuinfo._get_cpu_info_internal()
121183
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'])
128190 self.assertEqual('X86_64', info['arch'])
129191 self.assertEqual(64, info['bits'])
130192 self.assertEqual(4, info['count'])
131193
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'])
142204
143205 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']
147215 ,
148216 info['flags']
149217 )
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 )
88 bits = '64bit'
99 cpu_count = 4
1010 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
1314
1415 @staticmethod
1516 def has_wmic():
1819 @staticmethod
1920 def wmic_cpu():
2021 returncode = 0
21 output = '''
22 output = r'''
2223 Caption=Intel64 Family 6 Model 30 Stepping 5
2324 CurrentClockSpeed=2933
2425 Description=Intel64 Family 6 Model 30 Stepping 5
3536 return 'Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz'
3637
3738 @staticmethod
38 def winreg_vendor_id():
39 def winreg_vendor_id_raw():
3940 return 'GenuineIntel'
4041
4142 @staticmethod
42 def winreg_raw_arch_string():
43 def winreg_arch_string_raw():
4344 return 'AMD64'
4445
4546 @staticmethod
5556
5657 class TestWindows_8_X86_64(unittest.TestCase):
5758 def setUp(self):
59 cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = False
5860 helpers.backup_data_source(cpuinfo)
5961 helpers.monkey_patch_data_source(cpuinfo, MockDataSource)
6062
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
6183 def tearDown(self):
6284 helpers.restore_data_source(cpuinfo)
85 helpers.restore_cpuid(cpuinfo)
86 cpuinfo.CAN_CALL_CPUID_IN_SUBPROCESS = True
6387
6488 '''
6589 Make sure calls return the expected number of fields.
76100 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot()))
77101 self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features()))
78102 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'])
81142
82143 def test_get_cpu_info_from_wmic(self):
83144 info = cpuinfo._get_cpu_info_from_wmic()
84145
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'])
98159
99160 def test_get_cpu_info_from_registry(self):
100161 info = cpuinfo._get_cpu_info_from_registry()
101162
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'])
110169
111170 self.assertEqual(
112171 ['acpi', 'clflush', 'cmov', 'de', 'dts', 'fxsr', 'ia64',
119178 def test_all(self):
120179 info = cpuinfo._get_cpu_info_internal()
121180
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'])
128187 self.assertEqual('X86_64', info['arch'])
129188 self.assertEqual(64, info['bits'])
130189 self.assertEqual(4, info['count'])
131190
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'])
142201
143202 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']
147209 ,
148210 info['flags']
149211 )