]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: refactor test constraints for misc/cgo/testsantizers
authorfanzha02 <fannie.zhang@arm.com>
Mon, 1 Mar 2021 02:34:08 +0000 (10:34 +0800)
committerfannie zhang <Fannie.Zhang@arm.com>
Thu, 11 Mar 2021 05:38:13 +0000 (05:38 +0000)
Currently, the cmd/dist runs test cases in misc/cgo/testsantizers only
when memeory sanitizer is supported, but the tsan tests in
misc/cgo/testsanitizers do not require support for -msan option, which
makes tsan tests can not be run on some unsupported -msan option platforms.

Therefore, this patch moves the test constraints from cmd/dist to
msan_test.go, so that the tsan tests in misc/cgo/testsanitizers
can be run on any system where the C compiler supports -fsanitize=thread
option.

Change-Id: I779c92eedd0270050f1a0b1a69ecce50c3712bc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/297774
Trust: fannie zhang <Fannie.Zhang@arm.com>
Run-TryBot: fannie zhang <Fannie.Zhang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/testsanitizers/cc_test.go
misc/cgo/testsanitizers/cshared_test.go
misc/cgo/testsanitizers/msan_test.go
src/cmd/dist/test.go
src/cmd/internal/sys/supported.go

index 0192a663dddabe58ea68c34f010e09fdfa552d04..dab13364b862b4022f4fd78aa867656fa3c664ef 100644 (file)
@@ -440,3 +440,14 @@ func hangProneCmd(name string, arg ...string) *exec.Cmd {
        }
        return cmd
 }
+
+// mSanSupported is a copy of the function cmd/internal/sys.MSanSupported,
+// because the internal pacakage can't be used here.
+func mSanSupported(goos, goarch string) bool {
+       switch goos {
+       case "linux":
+               return goarch == "amd64" || goarch == "arm64"
+       default:
+               return false
+       }
+}
index 56063ea620162c8ae5ab6a99dc9c3ad5bae59512..b98360c4ae34d36593443b078bd6ded3e751548e 100644 (file)
@@ -19,6 +19,12 @@ func TestShared(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
+
+       GOARCH, err := goEnv("GOARCH")
+       if err != nil {
+               t.Fatal(err)
+       }
+
        libExt := "so"
        if GOOS == "darwin" {
                libExt = "dylib"
@@ -41,6 +47,11 @@ func TestShared(t *testing.T) {
        for _, tc := range cases {
                tc := tc
                name := strings.TrimSuffix(tc.src, ".go")
+               //The memory sanitizer tests require support for the -msan option.
+               if tc.sanitizer == "memory" && !mSanSupported(GOOS, GOARCH) {
+                       t.Logf("skipping %s test on %s/%s; -msan option is not supported.", name, GOOS, GOARCH)
+                       continue
+               }
                t.Run(name, func(t *testing.T) {
                        t.Parallel()
                        config := configure(tc.sanitizer)
index 5e2f9759baef49c1f92b9feed27f0de24e6c3000..2a3494fbfc1d3f4eff846a0f9582440c49e1db97 100644 (file)
@@ -10,6 +10,19 @@ import (
 )
 
 func TestMSAN(t *testing.T) {
+       goos, err := goEnv("GOOS")
+       if err != nil {
+               t.Fatal(err)
+       }
+       goarch, err := goEnv("GOARCH")
+       if err != nil {
+               t.Fatal(err)
+       }
+       // The msan tests require support for the -msan option.
+       if !mSanSupported(goos, goarch) {
+               t.Skipf("skipping on %s/%s; -msan option is not supported.", goos, goarch)
+       }
+
        t.Parallel()
        requireOvercommit(t)
        config := configure("memory")
index 0c8e2c56bc3d23b07025c35b1a74a7bddfd442c0..cbf3ec6d8826a9c277b7ee861c79dbfc34fb18e5 100644 (file)
@@ -736,8 +736,9 @@ func (t *tester) registerTests() {
                if gohostos == "linux" && goarch == "amd64" {
                        t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", ".")
                }
-               if mSanSupported(goos, goarch) {
-                       t.registerHostTest("testsanitizers/msan", "../misc/cgo/testsanitizers", "misc/cgo/testsanitizers", ".")
+               if goos == "linux" {
+                       // because syscall.SysProcAttri struct used in misc/cgo/testsanitizers is only built on linux.
+                       t.registerHostTest("testsanitizers", "../misc/cgo/testsanitizers", "misc/cgo/testsanitizers", ".")
                }
                if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
                        t.registerHostTest("cgo_errors", "../misc/cgo/errors", "misc/cgo/errors", ".")
@@ -1640,17 +1641,6 @@ func raceDetectorSupported(goos, goarch string) bool {
        }
 }
 
-// mSanSupported is a copy of the function cmd/internal/sys.MSanSupported,
-// which can't be used here because cmd/dist has to be buildable by Go 1.4.
-func mSanSupported(goos, goarch string) bool {
-       switch goos {
-       case "linux":
-               return goarch == "amd64" || goarch == "arm64"
-       default:
-               return false
-       }
-}
-
 // isUnsupportedVMASize reports whether the failure is caused by an unsupported
 // VMA for the race detector (for example, running the race detector on an
 // arm64 machine configured with 39-bit VMA)
index 291acf086203a334f224ddac395a375705971002..fa477b837ffa8cb75de61aef204136ed4e1afd01 100644 (file)
@@ -23,7 +23,8 @@ func RaceDetectorSupported(goos, goarch string) bool {
 }
 
 // MSanSupported reports whether goos/goarch supports the memory
-// sanitizer option. There is a copy of this function in cmd/dist/test.go.
+// sanitizer option.
+// There is a copy of this function in misc/cgo/testsanitizers/cc_test.go.
 func MSanSupported(goos, goarch string) bool {
        switch goos {
        case "linux":