]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/testsanitizers/msan_test.go
runtime: remove crash_cgo_test CgoRaceSignal timeout
[gostls13.git] / misc / cgo / testsanitizers / msan_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 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         // 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)
24         }
25
26         t.Parallel()
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.
29         if goos == "linux" {
30                 requireOvercommit(t)
31         }
32         config := configure("memory")
33         config.skipIfCSanitizerBroken(t)
34
35         mustRun(t, config.goCmd("build", "std"))
36
37         cases := []struct {
38                 src         string
39                 wantErr     bool
40                 experiments []string
41         }{
42                 {src: "msan.go"},
43                 {src: "msan2.go"},
44                 {src: "msan2_cmsan.go"},
45                 {src: "msan3.go"},
46                 {src: "msan4.go"},
47                 {src: "msan5.go"},
48                 {src: "msan6.go"},
49                 {src: "msan7.go"},
50                 {src: "msan8.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"}},
57         }
58         for _, tc := range cases {
59                 tc := tc
60                 name := strings.TrimSuffix(tc.src, ".go")
61                 t.Run(name, func(t *testing.T) {
62                         t.Parallel()
63
64                         dir := newTempDir(t)
65                         defer dir.RemoveAll(t)
66
67                         outPath := dir.Join(name)
68                         mustRun(t, config.goCmdWithExperiments("build", []string{"-o", outPath, srcPath(tc.src)}, tc.experiments))
69
70                         cmd := hangProneCmd(outPath)
71                         if tc.wantErr {
72                                 out, err := cmd.CombinedOutput()
73                                 if err != nil {
74                                         return
75                                 }
76                                 t.Fatalf("%#q exited without error; want MSAN failure\n%s", strings.Join(cmd.Args, " "), out)
77                         }
78                         mustRun(t, cmd)
79                 })
80         }
81 }