| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
from cpuinfo import * |
| 5 |
import helpers |
| 6 |
|
| 7 |
|
| 8 |
class MockDataSource: |
| 9 |
bits = '64bit' |
| 10 |
cpu_count = 1 |
| 11 |
is_windows = False |
| 12 |
arch_string_raw = 'x86_64' |
| 13 |
uname_string_raw = 'x86_64' |
| 14 |
can_cpuid = False |
| 15 |
|
| 16 |
@staticmethod |
| 17 |
def has_proc_cpuinfo(): |
| 18 |
return True |
| 19 |
|
| 20 |
@staticmethod |
| 21 |
def has_lscpu(): |
| 22 |
return True |
| 23 |
|
| 24 |
@staticmethod |
| 25 |
def cat_proc_cpuinfo(): |
| 26 |
returncode = 0 |
| 27 |
output = r''' |
| 28 |
processor : 0 |
| 29 |
vendor_id : GenuineIntel |
| 30 |
cpu family : 0 |
| 31 |
model : 0 |
| 32 |
model name : Intel(R) Pentium(R) CPU G640 @ 2.80GHz |
| 33 |
stepping : 0 |
| 34 |
microcode : 0x29 |
| 35 |
cpu MHz : 1901.375 |
| 36 |
cache size : 3072 KB |
| 37 |
physical id : 0 |
| 38 |
siblings : 2 |
| 39 |
core id : 0 |
| 40 |
cpu cores : 2 |
| 41 |
apicid : 0 |
| 42 |
initial apicid : 0 |
| 43 |
fpu : yes |
| 44 |
fpu_exception : yes |
| 45 |
cpuid level : 13 |
| 46 |
wp : yes |
| 47 |
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave lahf_lm epb tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm arat pln pts |
| 48 |
bugs : |
| 49 |
bogomips : 5587.32 |
| 50 |
clflush size : 64 |
| 51 |
cache_alignment : 64 |
| 52 |
address sizes : 36 bits physical, 48 bits virtual |
| 53 |
power management: |
| 54 |
|
| 55 |
|
| 56 |
''' |
| 57 |
return returncode, output |
| 58 |
|
| 59 |
@staticmethod |
| 60 |
def lscpu(): |
| 61 |
returncode = 0 |
| 62 |
output = r''' |
| 63 |
Architecture: x86_64 |
| 64 |
CPU op-mode(s): 32-bit, 64-bit |
| 65 |
Byte Order: Little Endian |
| 66 |
CPU(s): 2 |
| 67 |
On-line CPU(s) list: 0,1 |
| 68 |
Thread(s) per core: 1 |
| 69 |
Core(s) per socket: 2 |
| 70 |
Socket(s): 1 |
| 71 |
NUMA node(s): 1 |
| 72 |
Vendor ID: GenuineIntel |
| 73 |
CPU family: 0 |
| 74 |
Model: 0 |
| 75 |
Model name: Intel(R) Pentium(R) CPU G640 @ 2.80GHz |
| 76 |
Stepping: 0 |
| 77 |
CPU MHz: 2070.796 |
| 78 |
CPU max MHz: 2800.0000 |
| 79 |
CPU min MHz: 1600.0000 |
| 80 |
BogoMIPS: 5587.32 |
| 81 |
Virtualization: VT-x |
| 82 |
L1d cache: 32K |
| 83 |
L1i cache: 32K |
| 84 |
L2 cache: 256K |
| 85 |
L3 cache: 3072K |
| 86 |
NUMA node0 CPU(s): 0,1 |
| 87 |
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave lahf_lm epb tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm arat pln pts |
| 88 |
|
| 89 |
|
| 90 |
''' |
| 91 |
return returncode, output |
| 92 |
|
| 93 |
# Confirms fix for: https://github.com/workhorsy/py-cpuinfo/issues/152 |
| 94 |
# CPU stepping, model, and family values are blank if 0 |
| 95 |
class TestBug152(unittest.TestCase): |
| 96 |
def setUp(self): |
| 97 |
helpers.backup_data_source(cpuinfo) |
| 98 |
helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
| 99 |
|
| 100 |
def tearDown(self): |
| 101 |
helpers.restore_data_source(cpuinfo) |
| 102 |
|
| 103 |
def test_get_cpu_info_from_lscpu(self): |
| 104 |
info = cpuinfo._get_cpu_info_from_lscpu() |
| 105 |
|
| 106 |
# Make sure fields with 0 are not filtered out |
| 107 |
self.assertIn('stepping', info.keys()) |
| 108 |
self.assertIn('model', info.keys()) |
| 109 |
self.assertIn('family', info.keys()) |
| 110 |
|
| 111 |
self.assertEqual(0, info['stepping']) |
| 112 |
self.assertEqual(0, info['model']) |
| 113 |
self.assertEqual(0, info['family']) |
| 114 |
|
| 115 |
def test_get_cpu_info_from_proc_cpuinfo(self): |
| 116 |
info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
| 117 |
|
| 118 |
# Make sure fields with 0 are not filtered out |
| 119 |
self.assertIn('stepping', info.keys()) |
| 120 |
self.assertIn('model', info.keys()) |
| 121 |
self.assertIn('family', info.keys()) |
| 122 |
|
| 123 |
self.assertEqual(0, info['stepping']) |
| 124 |
self.assertEqual(0, info['model']) |
| 125 |
self.assertEqual(0, info['family']) |