github.com/primecitizens/pcz/std@v0.2.1/core/cpu/cpu_s390x_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2018 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 //go:build s390x 9 10 package cpu_test 11 12 import ( 13 "errors" 14 "os" 15 "regexp" 16 "testing" 17 18 . "github.com/primecitizens/pcz/std/core/cpu" 19 ) 20 21 func getFeatureList() ([]string, error) { 22 cpuinfo, err := os.ReadFile("/proc/cpuinfo") 23 if err != nil { 24 return nil, err 25 } 26 r := regexp.MustCompile("features\\s*:\\s*(.*)") 27 b := r.FindSubmatch(cpuinfo) 28 if len(b) < 2 { 29 return nil, errors.New("no feature list in /proc/cpuinfo") 30 } 31 return regexp.MustCompile("\\s+").Split(string(b[1]), -1), nil 32 } 33 34 func TestS390XAgainstCPUInfo(t *testing.T) { 35 // mapping of linux feature strings to S390X fields 36 mapping := make(map[string]*bool) 37 for _, option := range Options { 38 mapping[option.Name] = option.Feature 39 } 40 41 // these must be true on the machines Go supports 42 mandatory := make(map[string]bool) 43 mandatory["zarch"] = false 44 mandatory["eimm"] = false 45 mandatory["ldisp"] = false 46 mandatory["stfle"] = false 47 48 features, err := getFeatureList() 49 if err != nil { 50 t.Error(err) 51 } 52 for _, feature := range features { 53 if _, ok := mandatory[feature]; ok { 54 mandatory[feature] = true 55 } 56 if flag, ok := mapping[feature]; ok { 57 if !*flag { 58 t.Errorf("feature '%v' not detected", feature) 59 } 60 } else { 61 t.Logf("no entry for '%v'", feature) 62 } 63 } 64 for k, v := range mandatory { 65 if !v { 66 t.Errorf("mandatory feature '%v' not detected", k) 67 } 68 } 69 }