]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/testsanitizers/tsan_test.go
runtime: remove crash_cgo_test CgoRaceSignal timeout
[gostls13.git] / misc / cgo / testsanitizers / tsan_test.go
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.
4
5 package sanitizers_test
6
7 import (
8         "strings"
9         "testing"
10 )
11
12 func TestTSAN(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         // 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)
24         }
25
26         t.Parallel()
27         requireOvercommit(t)
28         config := configure("thread")
29         config.skipIfCSanitizerBroken(t)
30
31         mustRun(t, config.goCmd("build", "std"))
32
33         cases := []struct {
34                 src          string
35                 needsRuntime bool
36         }{
37                 {src: "tsan.go"},
38                 {src: "tsan2.go"},
39                 {src: "tsan3.go"},
40                 {src: "tsan4.go"},
41                 {src: "tsan5.go", needsRuntime: true},
42                 {src: "tsan6.go", needsRuntime: true},
43                 {src: "tsan7.go", needsRuntime: true},
44                 {src: "tsan8.go"},
45                 {src: "tsan9.go"},
46                 {src: "tsan10.go", needsRuntime: true},
47                 {src: "tsan11.go", needsRuntime: true},
48                 {src: "tsan12.go", needsRuntime: true},
49                 {src: "tsan13.go", needsRuntime: true},
50         }
51         for _, tc := range cases {
52                 tc := tc
53                 name := strings.TrimSuffix(tc.src, ".go")
54                 t.Run(name, func(t *testing.T) {
55                         t.Parallel()
56
57                         dir := newTempDir(t)
58                         defer dir.RemoveAll(t)
59
60                         outPath := dir.Join(name)
61                         mustRun(t, config.goCmd("build", "-o", outPath, srcPath(tc.src)))
62
63                         cmd := hangProneCmd(outPath)
64                         if tc.needsRuntime {
65                                 config.skipIfRuntimeIncompatible(t)
66                         }
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")
70                         mustRun(t, cmd)
71                 })
72         }
73 }