1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package sanitizers_test
12 func TestMSAN(t *testing.T) {
13 goos, err := goEnv("GOOS")
17 goarch, err := goEnv("GOARCH")
21 // The msan tests require support for the -msan option.
22 if !mSanSupported(goos, goarch) {
23 t.Skipf("skipping on %s/%s; -msan option is not supported.", goos, goarch)
28 config := configure("memory")
29 config.skipIfCSanitizerBroken(t)
31 mustRun(t, config.goCmd("build", "std"))
40 {src: "msan2_cmsan.go"},
47 {src: "msan_fail.go", wantErr: true},
48 // This may not always fail specifically due to MSAN. It may sometimes
49 // fail because of a fault. However, we don't care what kind of error we
50 // get here, just that we get an error. This is an MSAN test because without
51 // MSAN it would not fail deterministically.
52 {src: "arena_fail.go", wantErr: true, experiments: []string{"arenas"}},
54 for _, tc := range cases {
56 name := strings.TrimSuffix(tc.src, ".go")
57 t.Run(name, func(t *testing.T) {
61 defer dir.RemoveAll(t)
63 outPath := dir.Join(name)
64 mustRun(t, config.goCmdWithExperiments("build", []string{"-o", outPath, srcPath(tc.src)}, tc.experiments))
66 cmd := hangProneCmd(outPath)
68 out, err := cmd.CombinedOutput()
72 t.Fatalf("%#q exited without error; want MSAN failure\n%s", strings.Join(cmd.Args, " "), out)