1
2
3
4
5
6
7 package sanitizers_test
8
9 import (
10 "internal/platform"
11 "internal/testenv"
12 "strings"
13 "testing"
14 )
15
16 func TestMSAN(t *testing.T) {
17 testenv.MustHaveGoBuild(t)
18 testenv.MustHaveCGO(t)
19 goos, err := goEnv("GOOS")
20 if err != nil {
21 t.Fatal(err)
22 }
23 goarch, err := goEnv("GOARCH")
24 if err != nil {
25 t.Fatal(err)
26 }
27
28 if !platform.MSanSupported(goos, goarch) {
29 t.Skipf("skipping on %s/%s; -msan option is not supported.", goos, goarch)
30 }
31
32 t.Parallel()
33
34
35 if goos == "linux" {
36 requireOvercommit(t)
37 }
38 config := configure("memory")
39 config.skipIfCSanitizerBroken(t)
40
41 mustRun(t, config.goCmd("build", "std"))
42
43 cases := []struct {
44 src string
45 wantErr bool
46 experiments []string
47 }{
48 {src: "msan.go"},
49 {src: "msan2.go"},
50 {src: "msan2_cmsan.go"},
51 {src: "msan3.go"},
52 {src: "msan4.go"},
53 {src: "msan5.go"},
54 {src: "msan6.go"},
55 {src: "msan7.go"},
56 {src: "msan8.go"},
57 {src: "msan_fail.go", wantErr: true},
58
59
60
61
62 {src: "arena_fail.go", wantErr: true, experiments: []string{"arenas"}},
63 }
64 for _, tc := range cases {
65 tc := tc
66 name := strings.TrimSuffix(tc.src, ".go")
67 t.Run(name, func(t *testing.T) {
68 t.Parallel()
69
70 dir := newTempDir(t)
71 defer dir.RemoveAll(t)
72
73 outPath := dir.Join(name)
74 mustRun(t, config.goCmdWithExperiments("build", []string{"-o", outPath, srcPath(tc.src)}, tc.experiments))
75
76 cmd := hangProneCmd(outPath)
77 if tc.wantErr {
78 out, err := cmd.CombinedOutput()
79 if err != nil {
80 return
81 }
82 t.Fatalf("%#q exited without error; want MSAN failure\n%s", strings.Join(cmd.Args, " "), out)
83 }
84 mustRun(t, cmd)
85 })
86 }
87 }
88
View as plain text