2017-04-03 22:38:09 +02:00
|
|
|
// Copyright 2017 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 (
|
2018-01-26 12:14:27 +01:00
|
|
|
. "internal/cpu"
|
|
|
|
|
"internal/testenv"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"strings"
|
2017-04-03 22:38:09 +02:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2018-10-12 16:48:38 +02:00
|
|
|
func MustHaveDebugOptionsSupport(t *testing.T) {
|
2018-01-26 12:14:27 +01:00
|
|
|
if !DebugOptions {
|
2018-10-12 16:48:38 +02:00
|
|
|
t.Skipf("skipping test: cpu feature options not supported by OS")
|
2017-04-03 22:38:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 12:14:27 +01:00
|
|
|
func runDebugOptionsTest(t *testing.T, test string, options string) {
|
2018-10-12 16:48:38 +02:00
|
|
|
MustHaveDebugOptionsSupport(t)
|
2017-07-10 15:28:27 -03:00
|
|
|
|
2018-01-26 12:14:27 +01:00
|
|
|
testenv.MustHaveExec(t)
|
|
|
|
|
|
|
|
|
|
env := "GODEBUGCPU=" + options
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(os.Args[0], "-test.run="+test)
|
|
|
|
|
cmd.Env = append(cmd.Env, env)
|
|
|
|
|
|
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
|
|
|
got := strings.TrimSpace(string(output))
|
|
|
|
|
want := "PASS"
|
|
|
|
|
if err != nil || got != want {
|
|
|
|
|
t.Fatalf("%s with %s: want %s, got %v", test, env, want, got)
|
2017-07-10 15:28:27 -03:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-31 10:07:03 +08:00
|
|
|
|
2018-01-26 12:14:27 +01:00
|
|
|
func TestDisableAllCapabilities(t *testing.T) {
|
2018-10-12 18:01:50 +02:00
|
|
|
runDebugOptionsTest(t, "TestAllCapabilitiesDisabled", "all=off")
|
2018-01-26 12:14:27 +01:00
|
|
|
}
|
2018-04-08 10:30:15 +08:00
|
|
|
|
2018-01-26 12:14:27 +01:00
|
|
|
func TestAllCapabilitiesDisabled(t *testing.T) {
|
2018-10-12 16:48:38 +02:00
|
|
|
MustHaveDebugOptionsSupport(t)
|
2018-04-08 10:30:15 +08:00
|
|
|
|
2018-10-12 18:01:50 +02:00
|
|
|
if os.Getenv("GODEBUGCPU") != "all=off" {
|
|
|
|
|
t.Skipf("skipping test: GODEBUGCPU=all=off not set")
|
2018-04-08 10:30:15 +08:00
|
|
|
}
|
|
|
|
|
|
2018-01-26 12:14:27 +01:00
|
|
|
for _, o := range Options {
|
|
|
|
|
if got := *o.Feature; got != false {
|
|
|
|
|
t.Errorf("%v: expected false, got %v", o.Name, got)
|
|
|
|
|
}
|
2018-03-31 10:07:03 +08:00
|
|
|
}
|
|
|
|
|
}
|