...

Source file src/internal/cpu/cpu_s390x_test.go

Documentation: internal/cpu

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

View as plain text