1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:50:03 -07:00

internal/cpu: replace arch dependent with generic minimal feature test

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>
This commit is contained in:
Martin Möhrmann 2018-10-26 21:04:45 +02:00 committed by Martin Möhrmann
parent 80b8377049
commit 3c9ad7cb41
5 changed files with 18 additions and 69 deletions

View File

@ -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")
}
}

View 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},

View File

@ -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")
}
}

View 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")

View 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")