]> Cypherpunks repositories - gostls13.git/commitdiff
internal/cpu: replace arch dependent with generic minimal feature test
authorMartin Möhrmann <moehrmann@google.com>
Fri, 26 Oct 2018 19:04:45 +0000 (21:04 +0200)
committerMartin Möhrmann <martisch@uos.de>
Sun, 28 Oct 2018 14:03:47 +0000 (14:03 +0000)
Use information about required CPU features stored in the CPU feature
options slice to test if minimal CPU requirements are met instead
of hard coding this information in the tests directly.

Change-Id: I72d89b1cff305b8e751995d4230a2217e32f4236
Reviewed-on: https://go-review.googlesource.com/c/145118
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Martin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/cpu/cpu_arm64_test.go [deleted file]
src/internal/cpu/cpu_ppc64x.go
src/internal/cpu/cpu_ppc64x_test.go [deleted file]
src/internal/cpu/cpu_test.go
src/internal/cpu/cpu_x86_test.go

diff --git a/src/internal/cpu/cpu_arm64_test.go b/src/internal/cpu/cpu_arm64_test.go
deleted file mode 100644 (file)
index f4c419a..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package cpu_test
-
-import (
-       . "internal/cpu"
-       "runtime"
-       "testing"
-)
-
-func TestARM64minimalFeatures(t *testing.T) {
-       switch runtime.GOOS {
-       case "linux", "android":
-       default:
-               t.Skipf("%s/arm64 is not supported", runtime.GOOS)
-       }
-
-       if !ARM64.HasASIMD {
-               t.Fatalf("HasASIMD expected true, got false")
-       }
-       if !ARM64.HasFP {
-               t.Fatalf("HasFP expected true, got false")
-       }
-}
index f59bb9dc8d0064e9460f78756dc03c2f55a1efd2..6bb83bb66715ae015f66699c5f40313d799be3b1 100644 (file)
@@ -40,6 +40,7 @@ func doinit() {
                {Name: "scv", Feature: &PPC64.HasSCV},
 
                // These capabilities should always be enabled on ppc64 and ppc64le:
+               {Name: "power8", Feature: &PPC64.IsPOWER8, Required: true},
                {Name: "vmx", Feature: &PPC64.HasVMX, Required: true},
                {Name: "dfp", Feature: &PPC64.HasDFP, Required: true},
                {Name: "vsx", Feature: &PPC64.HasVSX, Required: true},
diff --git a/src/internal/cpu/cpu_ppc64x_test.go b/src/internal/cpu/cpu_ppc64x_test.go
deleted file mode 100644 (file)
index 9c43d1e..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build ppc64 ppc64le
-
-package cpu_test
-
-import (
-       . "internal/cpu"
-       "testing"
-)
-
-func TestPPC64minimalFeatures(t *testing.T) {
-       if !PPC64.IsPOWER8 {
-               t.Fatalf("IsPOWER8 expected true, got false")
-       }
-       if !PPC64.HasVMX {
-               t.Fatalf("HasVMX expected true, got false")
-       }
-       if !PPC64.HasDFP {
-               t.Fatalf("HasDFP expected true, got false")
-       }
-       if !PPC64.HasVSX {
-               t.Fatalf("HasVSX expected true, got false")
-       }
-       if !PPC64.HasISEL {
-               t.Fatalf("HasISEL expected true, got false")
-       }
-       if !PPC64.HasVCRYPTO {
-               t.Fatalf("HasVCRYPTO expected true, got false")
-       }
-}
index 46a351cfbc7f29966aa8e172930e2f0b514e9486..b01e212ce8b5c9e4067d199222eec1160ec7c9bc 100644 (file)
@@ -9,10 +9,27 @@ import (
        "internal/testenv"
        "os"
        "os/exec"
+       "runtime"
        "strings"
        "testing"
 )
 
+func TestMinimalFeatures(t *testing.T) {
+       if runtime.GOARCH == "arm64" {
+               switch runtime.GOOS {
+               case "linux", "android":
+               default:
+                       t.Skipf("%s/%s is not supported", runtime.GOOS, runtime.GOARCH)
+               }
+       }
+
+       for _, o := range Options {
+               if o.Required && !*o.Feature {
+                       t.Errorf("%v expected true, got false", o.Name)
+               }
+       }
+}
+
 func MustHaveDebugOptionsSupport(t *testing.T) {
        if !DebugOptions {
                t.Skipf("skipping test: cpu feature options not supported by OS")
index a8d0466e06fc26f925a09051a63f602cd38a63fd..a79be41811f462600fc8ee0ec8903b881fb7b1f9 100644 (file)
@@ -13,16 +13,6 @@ import (
        "testing"
 )
 
-func TestAMD64minimalFeatures(t *testing.T) {
-       if runtime.GOARCH != "amd64" {
-               return
-       }
-
-       if !X86.HasSSE2 {
-               t.Fatalf("HasSSE2 expected true, got false")
-       }
-}
-
 func TestX86ifAVX2hasAVX(t *testing.T) {
        if X86.HasAVX2 && !X86.HasAVX {
                t.Fatalf("HasAVX expected true when HasAVX2 is true, got false")