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)
27 // Overcommit is enabled by default on FreeBSD (vm.overcommit=0, see tuning(7)).
28 // Do not skip tests with stricter overcommit settings unless testing shows that FreeBSD has similar issues.
32 config := configure("memory")
33 config.skipIfCSanitizerBroken(t)
35 mustRun(t, config.goCmd("build", "std"))
44 {src: "msan2_cmsan.go"},
51 {src: "msan_fail.go", wantErr: true},
52 // This may not always fail specifically due to MSAN. It may sometimes
53 // fail because of a fault. However, we don't care what kind of error we
54 // get here, just that we get an error. This is an MSAN test because without
55 // MSAN it would not fail deterministically.
56 {src: "arena_fail.go", wantErr: true, experiments: []string{"arenas"}},
58 for _, tc := range cases {
60 name := strings.TrimSuffix(tc.src, ".go")
61 t.Run(name, func(t *testing.T) {
65 defer dir.RemoveAll(t)
67 outPath := dir.Join(name)
68 mustRun(t, config.goCmdWithExperiments("build", []string{"-o", outPath, srcPath(tc.src)}, tc.experiments))
70 cmd := hangProneCmd(outPath)
72 out, err := cmd.CombinedOutput()
76 t.Fatalf("%#q exited without error; want MSAN failure\n%s", strings.Join(cmd.Args, " "), out)