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 TestTSAN(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 !compilerRequiredTsanVersion(goos, goarch) {
23 t.Skipf("skipping on %s/%s; compiler version for -tsan option is too old.", goos, goarch)
28 config := configure("thread")
29 config.skipIfCSanitizerBroken(t)
31 mustRun(t, config.goCmd("build", "std"))
41 {src: "tsan5.go", needsRuntime: true},
42 {src: "tsan6.go", needsRuntime: true},
43 {src: "tsan7.go", needsRuntime: true},
46 {src: "tsan10.go", needsRuntime: true},
47 {src: "tsan11.go", needsRuntime: true},
48 {src: "tsan12.go", needsRuntime: true},
49 {src: "tsan13.go", needsRuntime: true},
51 for _, tc := range cases {
53 name := strings.TrimSuffix(tc.src, ".go")
54 t.Run(name, func(t *testing.T) {
58 defer dir.RemoveAll(t)
60 outPath := dir.Join(name)
61 mustRun(t, config.goCmd("build", "-o", outPath, srcPath(tc.src)))
63 cmd := hangProneCmd(outPath)
65 config.skipIfRuntimeIncompatible(t)
67 // If we don't see halt_on_error, the program
68 // will only exit non-zero if we call C.exit.
69 cmd.Env = append(cmd.Environ(), "TSAN_OPTIONS=halt_on_error=1")