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