| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
from cpuinfo import * |
| 5 |
import helpers |
| 6 |
|
| 7 |
|
| 8 |
class MockDataSource: |
| 9 |
bits = '64bit' |
| 10 |
cpu_count = 4 |
| 11 |
is_windows = False |
| 12 |
arch_string_raw = 'aarch64' |
| 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 has_cpufreq_info(): |
| 26 |
return True |
| 27 |
|
| 28 |
@staticmethod |
| 29 |
def cat_proc_cpuinfo(): |
| 30 |
returncode = 0 |
| 31 |
output = r''' |
| 32 |
processor : 0 |
| 33 |
BogoMIPS : 2.00 |
| 34 |
Features : fp asimd crc32 |
| 35 |
CPU implementer : 0x41 |
| 36 |
CPU architecture: 8 |
| 37 |
CPU variant : 0x0 |
| 38 |
CPU part : 0xd03 |
| 39 |
CPU revision : 4 |
| 40 |
|
| 41 |
processor : 1 |
| 42 |
BogoMIPS : 2.00 |
| 43 |
Features : fp asimd crc32 |
| 44 |
CPU implementer : 0x41 |
| 45 |
CPU architecture: 8 |
| 46 |
CPU variant : 0x0 |
| 47 |
CPU part : 0xd03 |
| 48 |
CPU revision : 4 |
| 49 |
|
| 50 |
processor : 2 |
| 51 |
BogoMIPS : 2.00 |
| 52 |
Features : fp asimd crc32 |
| 53 |
CPU implementer : 0x41 |
| 54 |
CPU architecture: 8 |
| 55 |
CPU variant : 0x0 |
| 56 |
CPU part : 0xd03 |
| 57 |
CPU revision : 4 |
| 58 |
|
| 59 |
processor : 3 |
| 60 |
BogoMIPS : 2.00 |
| 61 |
Features : fp asimd crc32 |
| 62 |
CPU implementer : 0x41 |
| 63 |
CPU architecture: 8 |
| 64 |
CPU variant : 0x0 |
| 65 |
CPU part : 0xd03 |
| 66 |
CPU revision : 4 |
| 67 |
|
| 68 |
Hardware : ODROID-C2 |
| 69 |
Revision : 020c |
| 70 |
|
| 71 |
|
| 72 |
''' |
| 73 |
return returncode, output |
| 74 |
|
| 75 |
@staticmethod |
| 76 |
def lscpu(): |
| 77 |
returncode = 0 |
| 78 |
output = r''' |
| 79 |
Architecture: aarch64 |
| 80 |
Byte Order: Little Endian |
| 81 |
CPU(s): 4 |
| 82 |
On-line CPU(s) list: 0-3 |
| 83 |
Thread(s) per core: 1 |
| 84 |
Core(s) per socket: 1 |
| 85 |
Socket(s): 4 |
| 86 |
CPU max MHz: 1536.0000 |
| 87 |
CPU min MHz: 100.0000 |
| 88 |
''' |
| 89 |
return returncode, output |
| 90 |
|
| 91 |
@staticmethod |
| 92 |
def cpufreq_info(): |
| 93 |
returncode = 0 |
| 94 |
output = r''' |
| 95 |
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 |
| 96 |
Report errors and bugs to [email protected], please. |
| 97 |
analyzing CPU 0: |
| 98 |
driver: meson_cpufreq |
| 99 |
CPUs which run at the same hardware frequency: 0 1 2 3 |
| 100 |
CPUs which need to have their frequency coordinated by software: 0 1 2 3 |
| 101 |
maximum transition latency: 200 us. |
| 102 |
hardware limits: 100.0 MHz - 1.54 GHz |
| 103 |
available frequency steps: 100.0 MHz, 250 MHz, 500 MHz, 1000 MHz, 1.30 GHz, 1.54 GHz |
| 104 |
available cpufreq governors: hotplug, interactive, conservative, ondemand, userspace, powersave, performance |
| 105 |
current policy: frequency should be within 100.0 MHz and 1.54 GHz. |
| 106 |
The governor "interactive" may decide which speed to use |
| 107 |
within this range. |
| 108 |
current CPU frequency is 1.54 GHz. |
| 109 |
cpufreq stats: 100.0 MHz:0.00%, 250 MHz:0.00%, 500 MHz:0.00%, 1000 MHz:0.00%, 1.30 GHz:0.00%, 1.54 GHz:100.00% (439) |
| 110 |
analyzing CPU 1: |
| 111 |
driver: meson_cpufreq |
| 112 |
CPUs which run at the same hardware frequency: 0 1 2 3 |
| 113 |
CPUs which need to have their frequency coordinated by software: 0 1 2 3 |
| 114 |
maximum transition latency: 200 us. |
| 115 |
hardware limits: 100.0 MHz - 1.54 GHz |
| 116 |
available frequency steps: 100.0 MHz, 250 MHz, 500 MHz, 1000 MHz, 1.30 GHz, 1.54 GHz |
| 117 |
available cpufreq governors: hotplug, interactive, conservative, ondemand, userspace, powersave, performance |
| 118 |
current policy: frequency should be within 100.0 MHz and 1.54 GHz. |
| 119 |
The governor "interactive" may decide which speed to use |
| 120 |
within this range. |
| 121 |
current CPU frequency is 1.54 GHz. |
| 122 |
cpufreq stats: 100.0 MHz:0.00%, 250 MHz:0.00%, 500 MHz:0.00%, 1000 MHz:0.00%, 1.30 GHz:0.00%, 1.54 GHz:100.00% (439) |
| 123 |
analyzing CPU 2: |
| 124 |
driver: meson_cpufreq |
| 125 |
CPUs which run at the same hardware frequency: 0 1 2 3 |
| 126 |
CPUs which need to have their frequency coordinated by software: 0 1 2 3 |
| 127 |
maximum transition latency: 200 us. |
| 128 |
hardware limits: 100.0 MHz - 1.54 GHz |
| 129 |
available frequency steps: 100.0 MHz, 250 MHz, 500 MHz, 1000 MHz, 1.30 GHz, 1.54 GHz |
| 130 |
available cpufreq governors: hotplug, interactive, conservative, ondemand, userspace, powersave, performance |
| 131 |
current policy: frequency should be within 100.0 MHz and 1.54 GHz. |
| 132 |
The governor "interactive" may decide which speed to use |
| 133 |
within this range. |
| 134 |
current CPU frequency is 1.54 GHz. |
| 135 |
cpufreq stats: 100.0 MHz:0.00%, 250 MHz:0.00%, 500 MHz:0.00%, 1000 MHz:0.00%, 1.30 GHz:0.00%, 1.54 GHz:100.00% (439) |
| 136 |
analyzing CPU 3: |
| 137 |
driver: meson_cpufreq |
| 138 |
CPUs which run at the same hardware frequency: 0 1 2 3 |
| 139 |
CPUs which need to have their frequency coordinated by software: 0 1 2 3 |
| 140 |
maximum transition latency: 200 us. |
| 141 |
hardware limits: 100.0 MHz - 1.54 GHz |
| 142 |
available frequency steps: 100.0 MHz, 250 MHz, 500 MHz, 1000 MHz, 1.30 GHz, 1.54 GHz |
| 143 |
available cpufreq governors: hotplug, interactive, conservative, ondemand, userspace, powersave, performance |
| 144 |
current policy: frequency should be within 100.0 MHz and 1.54 GHz. |
| 145 |
The governor "interactive" may decide which speed to use |
| 146 |
within this range. |
| 147 |
current CPU frequency is 1.54 GHz. |
| 148 |
cpufreq stats: 100.0 MHz:0.00%, 250 MHz:0.00%, 500 MHz:0.00%, 1000 MHz:0.00%, 1.30 GHz:0.00%, 1.54 GHz:100.00% (439) |
| 149 |
|
| 150 |
''' |
| 151 |
return returncode, output |
| 152 |
|
| 153 |
|
| 154 |
class TestLinux_Odroid_C2_Aarch_64(unittest.TestCase): |
| 155 |
def setUp(self): |
| 156 |
helpers.backup_data_source(cpuinfo) |
| 157 |
helpers.monkey_patch_data_source(cpuinfo, MockDataSource) |
| 158 |
|
| 159 |
def tearDown(self): |
| 160 |
helpers.restore_data_source(cpuinfo) |
| 161 |
|
| 162 |
''' |
| 163 |
Make sure calls return the expected number of fields. |
| 164 |
''' |
| 165 |
def test_returns(self): |
| 166 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_registry())) |
| 167 |
self.assertEqual(4, len(cpuinfo._get_cpu_info_from_cpufreq_info())) |
| 168 |
self.assertEqual(4, len(cpuinfo._get_cpu_info_from_lscpu())) |
| 169 |
self.assertEqual(2, len(cpuinfo._get_cpu_info_from_proc_cpuinfo())) |
| 170 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysctl())) |
| 171 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_kstat())) |
| 172 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_dmesg())) |
| 173 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cat_var_run_dmesg_boot())) |
| 174 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_ibm_pa_features())) |
| 175 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_sysinfo())) |
| 176 |
self.assertEqual(0, len(cpuinfo._get_cpu_info_from_cpuid())) |
| 177 |
self.assertEqual(13, len(cpuinfo._get_cpu_info_internal())) |
| 178 |
|
| 179 |
def test_get_cpu_info_from_cpufreq_info(self): |
| 180 |
info = cpuinfo._get_cpu_info_from_cpufreq_info() |
| 181 |
|
| 182 |
self.assertEqual('1.5400 GHz', info['hz_advertised_friendly']) |
| 183 |
self.assertEqual('1.5400 GHz', info['hz_actual_friendly']) |
| 184 |
self.assertEqual((1540000000, 0), info['hz_advertised']) |
| 185 |
self.assertEqual((1540000000, 0), info['hz_actual']) |
| 186 |
|
| 187 |
def test_get_cpu_info_from_lscpu(self): |
| 188 |
info = cpuinfo._get_cpu_info_from_lscpu() |
| 189 |
|
| 190 |
self.assertEqual('1.5360 GHz', info['hz_advertised_friendly']) |
| 191 |
self.assertEqual('1.5360 GHz', info['hz_actual_friendly']) |
| 192 |
self.assertEqual((1536000000, 0), info['hz_advertised']) |
| 193 |
self.assertEqual((1536000000, 0), info['hz_actual']) |
| 194 |
|
| 195 |
def test_get_cpu_info_from_proc_cpuinfo(self): |
| 196 |
info = cpuinfo._get_cpu_info_from_proc_cpuinfo() |
| 197 |
|
| 198 |
self.assertEqual('ODROID-C2', info['hardware_raw']) |
| 199 |
|
| 200 |
self.assertEqual( |
| 201 |
['asimd', 'crc32', 'fp'], |
| 202 |
info['flags'] |
| 203 |
) |
| 204 |
|
| 205 |
def test_all(self): |
| 206 |
info = cpuinfo._get_cpu_info_internal() |
| 207 |
|
| 208 |
self.assertEqual('ODROID-C2', info['hardware_raw']) |
| 209 |
self.assertEqual('1.5400 GHz', info['hz_advertised_friendly']) |
| 210 |
self.assertEqual('1.5400 GHz', info['hz_actual_friendly']) |
| 211 |
self.assertEqual((1540000000, 0), info['hz_advertised']) |
| 212 |
self.assertEqual((1540000000, 0), info['hz_actual']) |
| 213 |
self.assertEqual('ARM_8', info['arch']) |
| 214 |
self.assertEqual(64, info['bits']) |
| 215 |
self.assertEqual(4, info['count']) |
| 216 |
|
| 217 |
self.assertEqual('aarch64', info['arch_string_raw']) |
| 218 |
|
| 219 |
self.assertEqual( |
| 220 |
['asimd', 'crc32', 'fp'], |
| 221 |
info['flags'] |
| 222 |
) |