diff options
| author | Andrew Donnellan <ajd@linux.ibm.com> | 2020-10-01 16:30:52 +1000 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-10-09 10:51:54 +0200 |
| commit | 4bc26ea554f0996f4df1627539aa0d5d7c8079c7 (patch) | |
| tree | 43127188c8a934e19eb004a0082fa3184c9f76de /pkg/host/machine_info_linux_test.go | |
| parent | fa79ed2ae1c546ca48519cfcd80d43b51b502750 (diff) | |
pkg/host: test for different cpuinfo fields depending on arch
Not all architectures have fields in /proc/cpuinfo for vendor, model and
flags, e.g. powerpc doesn't have an equivalent for vendor or flags.
Rather than testing for the presence of at least one field name for each
category, have a separate list per architecture.
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Diffstat (limited to 'pkg/host/machine_info_linux_test.go')
| -rw-r--r-- | pkg/host/machine_info_linux_test.go | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/pkg/host/machine_info_linux_test.go b/pkg/host/machine_info_linux_test.go index e70c62a59..d318c08b3 100644 --- a/pkg/host/machine_info_linux_test.go +++ b/pkg/host/machine_info_linux_test.go @@ -6,6 +6,7 @@ package host import ( "bufio" "bytes" + "runtime" "strings" "testing" ) @@ -46,22 +47,20 @@ func checkCPUInfo(t *testing.T, scanner *bufio.Scanner) { keys[key] = true } - importantKeys := [][]string{ - {"vendor", "vendor_id", "CPU implementer"}, - {"model", "CPU part", "cpu model", "machine", "processor 0"}, - {"flags", "features", "Features", "ASEs implemented", "type"}, + importantKeys := map[string][]string{ + "ppc64le": {"cpu", "revision", "platform", "model", "machine"}, + "amd64": {"vendor_id", "model", "flags"}, + "s390x": {"vendor_id", "processor 0", "features"}, + "386": {"vendor_id", "model", "flags"}, + "arm64": {"CPU implementer", "CPU part", "Features"}, + "arm": {"CPU implementer", "CPU part", "Features"}, + "mips64le": {"system type", "cpu model", "ASEs implemented"}, + "riscv64": {"processor", "isa", "mmu"}, } - for _, possibleNames := range importantKeys { - exists := false - for _, name := range possibleNames { - if keys[name] { - exists = true - break - } - } - if !exists { - t.Fatalf("one of {%s} should exists in the output, but not found", - strings.Join(possibleNames, ", ")) + archKeys := importantKeys[runtime.GOARCH] + for _, name := range archKeys { + if !keys[name] { + t.Fatalf("key '%s' not found", name) } } } |
