github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/misc/cgo/testsanitizers/msan_test.go (about)

     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  	t.Parallel()
    14  	requireOvercommit(t)
    15  	config := configure("memory")
    16  	config.skipIfCSanitizerBroken(t)
    17  
    18  	mustRun(t, config.goCmd("build", "std"))
    19  
    20  	cases := []struct {
    21  		src     string
    22  		wantErr bool
    23  	}{
    24  		{src: "msan.go"},
    25  		{src: "msan2.go"},
    26  		{src: "msan2_cmsan.go"},
    27  		{src: "msan3.go"},
    28  		{src: "msan4.go"},
    29  		{src: "msan5.go"},
    30  		{src: "msan_fail.go", wantErr: true},
    31  	}
    32  	for _, tc := range cases {
    33  		tc := tc
    34  		name := strings.TrimSuffix(tc.src, ".go")
    35  		t.Run(name, func(t *testing.T) {
    36  			t.Parallel()
    37  
    38  			dir := newTempDir(t)
    39  			defer dir.RemoveAll(t)
    40  
    41  			outPath := dir.Join(name)
    42  			mustRun(t, config.goCmd("build", "-o", outPath, srcPath(tc.src)))
    43  
    44  			cmd := hangProneCmd(outPath)
    45  			if tc.wantErr {
    46  				out, err := cmd.CombinedOutput()
    47  				if err != nil {
    48  					return
    49  				}
    50  				t.Fatalf("%#q exited without error; want MSAN failure\n%s", strings.Join(cmd.Args, " "), out)
    51  			}
    52  			mustRun(t, cmd)
    53  		})
    54  	}
    55  }