Source file src/internal/buildcfg/cfg_test.go

     1  // Copyright 2021 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 buildcfg
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  )
    11  
    12  func TestConfigFlags(t *testing.T) {
    13  	os.Setenv("GOAMD64", "v1")
    14  	if goamd64() != 1 {
    15  		t.Errorf("Wrong parsing of GOAMD64=v1")
    16  	}
    17  	os.Setenv("GOAMD64", "v4")
    18  	if goamd64() != 4 {
    19  		t.Errorf("Wrong parsing of GOAMD64=v4")
    20  	}
    21  	Error = nil
    22  	os.Setenv("GOAMD64", "1")
    23  	if goamd64(); Error == nil {
    24  		t.Errorf("Wrong parsing of GOAMD64=1")
    25  	}
    26  
    27  	os.Setenv("GORISCV64", "rva20u64")
    28  	if goriscv64() != 20 {
    29  		t.Errorf("Wrong parsing of RISCV64=rva20u64")
    30  	}
    31  	os.Setenv("GORISCV64", "rva22u64")
    32  	if goriscv64() != 22 {
    33  		t.Errorf("Wrong parsing of RISCV64=rva22u64")
    34  	}
    35  	Error = nil
    36  	os.Setenv("GORISCV64", "rva22")
    37  	if _ = goriscv64(); Error == nil {
    38  		t.Errorf("Wrong parsing of RISCV64=rva22")
    39  	}
    40  	Error = nil
    41  	os.Setenv("GOARM64", "v7.0")
    42  	if _ = goarm64(); Error == nil {
    43  		t.Errorf("Wrong parsing of GOARM64=7.0")
    44  	}
    45  	Error = nil
    46  	os.Setenv("GOARM64", "8.0")
    47  	if _ = goarm64(); Error == nil {
    48  		t.Errorf("Wrong parsing of GOARM64=8.0")
    49  	}
    50  	Error = nil
    51  	os.Setenv("GOARM64", "v8.0,lsb")
    52  	if _ = goarm64(); Error == nil {
    53  		t.Errorf("Wrong parsing of GOARM64=v8.0,lsb")
    54  	}
    55  	os.Setenv("GOARM64", "v8.0,lse")
    56  	if goarm64().Version != "v8.0" || goarm64().LSE != true || goarm64().Crypto != false {
    57  		t.Errorf("Wrong parsing of GOARM64=v8.0,lse")
    58  	}
    59  	os.Setenv("GOARM64", "v8.0,crypto")
    60  	if goarm64().Version != "v8.0" || goarm64().LSE != false || goarm64().Crypto != true {
    61  		t.Errorf("Wrong parsing of GOARM64=v8.0,crypto")
    62  	}
    63  	os.Setenv("GOARM64", "v8.0,crypto,lse")
    64  	if goarm64().Version != "v8.0" || goarm64().LSE != true || goarm64().Crypto != true {
    65  		t.Errorf("Wrong parsing of GOARM64=v8.0,crypto,lse")
    66  	}
    67  	os.Setenv("GOARM64", "v8.0,lse,crypto")
    68  	if goarm64().Version != "v8.0" || goarm64().LSE != true || goarm64().Crypto != true {
    69  		t.Errorf("Wrong parsing of GOARM64=v8.0,lse,crypto")
    70  	}
    71  	os.Setenv("GOARM64", "v9.0")
    72  	if goarm64().Version != "v9.0" || goarm64().LSE != true || goarm64().Crypto != false {
    73  		t.Errorf("Wrong parsing of GOARM64=v9.0")
    74  	}
    75  }
    76  
    77  func TestGoarm64FeaturesSupports(t *testing.T) {
    78  	g, _ := ParseGoarm64("v9.3")
    79  
    80  	if !g.Supports("v9.3") {
    81  		t.Errorf("Wrong goarm64Features.Supports for v9.3, v9.3")
    82  	}
    83  
    84  	if g.Supports("v9.4") {
    85  		t.Errorf("Wrong goarm64Features.Supports for v9.3, v9.4")
    86  	}
    87  
    88  	if !g.Supports("v8.8") {
    89  		t.Errorf("Wrong goarm64Features.Supports for v9.3, v8.8")
    90  	}
    91  
    92  	if g.Supports("v8.9") {
    93  		t.Errorf("Wrong goarm64Features.Supports for v9.3, v8.9")
    94  	}
    95  
    96  	if g.Supports(",lse") {
    97  		t.Errorf("Wrong goarm64Features.Supports for v9.3, ,lse")
    98  	}
    99  }
   100  
   101  func TestGogoarchTags(t *testing.T) {
   102  	old_goarch := GOARCH
   103  	old_goarm64 := GOARM64
   104  
   105  	GOARCH = "arm64"
   106  
   107  	os.Setenv("GOARM64", "v9.5")
   108  	GOARM64 = goarm64()
   109  	tags := gogoarchTags()
   110  	want := []string{"arm64.v9.0", "arm64.v9.1", "arm64.v9.2", "arm64.v9.3", "arm64.v9.4", "arm64.v9.5",
   111  		"arm64.v8.0", "arm64.v8.1", "arm64.v8.2", "arm64.v8.3", "arm64.v8.4", "arm64.v8.5", "arm64.v8.6", "arm64.v8.7", "arm64.v8.8", "arm64.v8.9"}
   112  	if len(tags) != len(want) {
   113  		t.Errorf("Wrong number of tags for GOARM64=v9.5")
   114  	} else {
   115  		for i, v := range tags {
   116  			if v != want[i] {
   117  				t.Error("Wrong tags for GOARM64=v9.5")
   118  				break
   119  			}
   120  		}
   121  	}
   122  
   123  	GOARCH = old_goarch
   124  	GOARM64 = old_goarm64
   125  }
   126  

View as plain text