/usr/lib/python3/dist-packages/checkbox_support/parsers/tests/test_cpuinfo.py is in python3-checkbox-support 0.22-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #
# This file is part of Checkbox.
#
# Copyright 2014 Canonical Ltd.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from io import open
from unittest import TestCase
from pkg_resources import resource_filename
from checkbox_support.parsers.cpuinfo import CpuinfoParser
class CpuinfoResult(object):
def __init__(self):
self.processors = []
def setProcessor(self, device):
self.processors.append(device)
class TestCpuinfoParser(TestCase):
def setUp(self):
self.cpu_attributes = ["platform",
"count",
"type",
"model",
"model_number",
"model_version",
"model_revision",
"cache",
"bogomips",
"speed",
"other"]
def parse(self, name, machine):
resource = 'parsers/tests/cpuinfo_data/{}.txt'.format(name)
filename = resource_filename('checkbox_support', resource)
with open(filename, 'rt', encoding='UTF-8') as stream:
parser = CpuinfoParser(stream, machine)
result = CpuinfoResult()
parser.run(result)
# Before returning, do basic sanity checks on processors
self.sanity_checks(result.processors)
return result
def sanity_checks(self, processors):
# ALL cpuinfo elements should comply with these checks.
self.assertIsNotNone(processors)
# Look at only the first processor
processor = processors[0]
# Check we have all required attributes and they are not empty
for attr in self.cpu_attributes:
self.assertIn(attr, processor.keys())
self.assertTrue(processor[attr] is not None and
processor[attr] != "", "{} is empty".format(attr))
# Check speed is an integer
self.assertIsInstance(processor['speed'], int)
def test_aarch64(self):
# Note that we need to specify the file name (first parameter) and the
# GNU identifier for the architecture. This mimics what the submission
# parser does.
cpuinforesult = self.parse("aarch64", "aarch64")
processors = cpuinforesult.processors
processor = processors[0]
self.assertEqual(processor['type'], "Unspecified Server Cartridge")
self.assertEqual(processor['count'], 8)
self.assertEqual(processor['model'],
"AArch64 Processor rev 1 (aarch64)")
self.assertEqual(processor['model_number'], '0x0')
self.assertEqual(processor['model_revision'], '1')
self.assertEqual(processor['model_version'], 'AArch64')
self.assertEqual(processor['platform'], 'aarch64')
self.assertEqual(processor['other'], 'fp asimd evtstrm')
def test_ppc64el(self):
# Note that we need to specify the file name (first parameter) and the
# GNU identifier for the architecture. This mimics what the submission
# parser does.
cpuinforesult = self.parse("ppc64el", "ppc64el")
processors = cpuinforesult.processors
processor = processors[0]
self.assertEqual(processor['type'], "pSeries")
self.assertEqual(processor['count'], 1)
self.assertEqual(processor['model'],
"POWER8E (raw), altivec supported")
self.assertEqual(processor['model_number'],
'IBM pSeries (emulated by qemu)')
self.assertEqual(processor['model_revision'], '2.0 ')
self.assertEqual(processor['model_version'], 'pvr 004b 0200')
self.assertEqual(processor['platform'], 'pSeries')
self.assertEqual(processor['other'], 'emulated by qemu')
self.assertEqual(processor['cache'], -1)
self.assertEqual(processor['bogomips'], -1)
self.assertEqual(processor['speed'], 3457)
def test_amd64(self):
cpuinforesult = self.parse("amd64", "x86_64")
processors = cpuinforesult.processors
processor = processors[0]
# Check for specific values.
self.assertEqual(processor['type'], "GenuineIntel")
self.assertEqual(processor['count'], 4)
self.assertEqual(processor['model'],
"Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz")
self.assertEqual(processor['bogomips'], 4789)
self.assertEqual(processor['cache'], 4194304)
self.assertEqual(processor['model_number'], '6')
self.assertEqual(processor['model_revision'], '1')
self.assertEqual(processor['model_version'], '69')
self.assertEqual(processor['platform'], 'x86_64')
self.assertEqual(processor['speed'], 1199)
self.assertEqual(processor['other'],
'fpu vme de pse tsc msr pae mce cx8 apic sep mtrr '
'pge mca cmov pat pse36 clflush dts acpi mmx fxsr '
'sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp '
'lm constant_tsc arch_perfmon pebs bts rep_good '
'nopl xtopology nonstop_tsc aperfmperf eagerfpu '
'pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 '
'ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe '
'popcnt tsc_deadline_timer aes xsave avx f16c '
'rdrand lahf_lm abm ida arat epb xsaveopt pln pts '
'dtherm tpr_shadow vnmi flexpriority ept vpid '
'fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms '
'invpcid')
|