Source file
src/simd/testdata_test.go
1
2
3
4
5
6
7 package simd_test
8
9 import (
10 "internal/testenv"
11 "os"
12 "runtime"
13 "strings"
14 "testing"
15 )
16
17 func common(t *testing.T, dir, what, failWith string, moreEnv ...string) {
18 t.Helper()
19 t.Logf("subprocess test in testdata")
20 testenv.MustHaveGoRun(t)
21 args := []string{"test", "-C", dir}
22 if testing.Verbose() {
23 args = append(args, "-v")
24 }
25 args = append(args, what)
26 cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
27
28 goexp := os.Getenv("GOEXPERIMENT")
29 if !strings.Contains(","+goexp+",", ",simd,") {
30 if goexp != "" {
31 goexp += ","
32 }
33 goexp += "simd"
34 }
35 cmd.Env = append(cmd.Environ(), "GOEXPERIMENT="+goexp)
36 cmd.Env = append(cmd.Env, moreEnv...)
37
38 if failWith == "" {
39 cmd.Stdout = os.Stdout
40 cmd.Stderr = os.Stderr
41 if err := cmd.Run(); err != nil {
42 t.Error(err)
43 }
44 } else {
45 combined, err := cmd.CombinedOutput()
46 combinedString := string(combined)
47 sawFailure := strings.Contains(combinedString, failWith)
48 if err == nil && !sawFailure {
49 t.Errorf("Saw no error and did not see expected failure string '%s' in '%s'", failWith, combinedString)
50 } else if err == nil && sawFailure {
51 t.Errorf("Saw no error but did see expected failure string '%s'", failWith)
52 } else if err != nil && !sawFailure {
53 t.Errorf("Saw error %v but did see expected failure string '%s' in '%s'", err, failWith, combinedString)
54 } else {
55 t.Logf("Saw error %v and expected failure string '%s'", err, failWith)
56 }
57 }
58 }
59 func TestIFace(t *testing.T) {
60 common(t, "testdata", "iface_test.go", "")
61 }
62
63 func TestSizeof(t *testing.T) {
64 common(t, "testdata", "sizeof_test.go", "")
65 }
66
67 func TestCompileOk(t *testing.T) {
68 common(t, "testdata", "compiles_test.go", "")
69 }
70
71 func TestCompileError(t *testing.T) {
72 common(t, "testdata", "errors_test.go",
73 "array length unsafe.Sizeof(v_from_simd) (value of type uintptr) must be constant")
74 }
75
76 func TestToString(t *testing.T) {
77 common(t, "testdata", "tostring_test.go", "")
78 if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" {
79 common(t, "testdata", "tostring_test.go", "", "GODEBUG=simd=0")
80 }
81 }
82
View as plain text