Commit 3c9ad7cb authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Martin Möhrmann

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/145118Reviewed-by: default avatarKeith Randall <khr@golang.org>
Run-TryBot: Martin Möhrmann <martisch@uos.de>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 80b83770
// 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")
}
}
...@@ -40,6 +40,7 @@ func doinit() { ...@@ -40,6 +40,7 @@ func doinit() {
{Name: "scv", Feature: &PPC64.HasSCV}, {Name: "scv", Feature: &PPC64.HasSCV},
// These capabilities should always be enabled on ppc64 and ppc64le: // 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: "vmx", Feature: &PPC64.HasVMX, Required: true},
{Name: "dfp", Feature: &PPC64.HasDFP, Required: true}, {Name: "dfp", Feature: &PPC64.HasDFP, Required: true},
{Name: "vsx", Feature: &PPC64.HasVSX, Required: true}, {Name: "vsx", Feature: &PPC64.HasVSX, Required: true},
......
// 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")
}
}
...@@ -9,10 +9,27 @@ import ( ...@@ -9,10 +9,27 @@ import (
"internal/testenv" "internal/testenv"
"os" "os"
"os/exec" "os/exec"
"runtime"
"strings" "strings"
"testing" "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) { func MustHaveDebugOptionsSupport(t *testing.T) {
if !DebugOptions { if !DebugOptions {
t.Skipf("skipping test: cpu feature options not supported by OS") t.Skipf("skipping test: cpu feature options not supported by OS")
......
...@@ -13,16 +13,6 @@ import ( ...@@ -13,16 +13,6 @@ import (
"testing" "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) { func TestX86ifAVX2hasAVX(t *testing.T) {
if X86.HasAVX2 && !X86.HasAVX { if X86.HasAVX2 && !X86.HasAVX {
t.Fatalf("HasAVX expected true when HasAVX2 is true, got false") t.Fatalf("HasAVX expected true when HasAVX2 is true, got false")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment