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 "strings"
13 "testing"
14 )
15
16 func common(t *testing.T, dir, what, failWith string) {
17 t.Helper()
18 t.Logf("subprocess test in testdata")
19 testenv.MustHaveGoRun(t)
20 args := []string{"test", "-C", dir}
21 if testing.Verbose() {
22 args = append(args, "-v")
23 }
24 args = append(args, what)
25 cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
26
27 goexp := os.Getenv("GOEXPERIMENT")
28 if !strings.Contains(","+goexp+",", ",simd,") {
29 if goexp != "" {
30 goexp += ","
31 }
32 goexp += "simd"
33 }
34 cmd.Env = append(cmd.Environ(), "GOEXPERIMENT="+goexp)
35
36 if failWith == "" {
37 cmd.Stdout = os.Stdout
38 cmd.Stderr = os.Stderr
39 if err := cmd.Run(); err != nil {
40 t.Error(err)
41 }
42 } else {
43 combined, err := cmd.CombinedOutput()
44 combinedString := string(combined)
45 sawFailure := strings.Contains(combinedString, failWith)
46 if err == nil && !sawFailure {
47 t.Errorf("Saw no error and did not see expected failure string '%s' in '%s'", failWith, combinedString)
48 } else if err == nil && sawFailure {
49 t.Errorf("Saw no error but did see expected failure string '%s'", failWith)
50 } else if err != nil && !sawFailure {
51 t.Errorf("Saw error %v but did see expected failure string '%s' in '%s'", err, failWith, combinedString)
52 } else {
53 t.Logf("Saw error %v and expected failure string '%s'", err, failWith)
54 }
55 }
56 }
57 func TestIFace(t *testing.T) {
58 common(t, "testdata", "iface_test.go", "")
59 }
60
61 func TestSizeof(t *testing.T) {
62 common(t, "testdata", "sizeof_test.go", "")
63 }
64
65 func TestCompileOk(t *testing.T) {
66 common(t, "testdata", "compiles_test.go", "")
67 }
68
69 func TestCompileError(t *testing.T) {
70 common(t, "testdata", "errors_test.go",
71 "array length unsafe.Sizeof(v_from_simd) (value of type uintptr) must be constant")
72 }
73
View as plain text