canRun = true // whether we can run go or ./testgo
canRace = false // whether we can run the race detector
canCgo = false // whether we can use cgo
+ canMSan = false // whether we can run the memory sanitizer
exeSuffix string // ".exe" on Windows
}
}
+ // As of Sept 2017, MSan is only supported on linux/amd64.
+ // https://github.com/google/sanitizers/wiki/MemorySanitizer#getting-memorysanitizer
+ canMSan = canCgo && runtime.GOOS == "linux" && runtime.GOARCH == "amd64"
+
switch runtime.GOOS {
case "linux", "darwin", "freebsd", "windows":
// The race detector doesn't work on Alpine Linux:
canRace = canCgo && runtime.GOARCH == "amd64" && !isAlpineLinux()
}
}
-
// Don't let these environment variables confuse the test.
os.Unsetenv("GOBIN")
os.Unsetenv("GOPATH")
tg.grepStderr("build constraints exclude all Go files", "go install cgotest did not report 'build constraints exclude all Go files'")
}
+// Issue 21895
+func TestMSanAndRaceRequireCgo(t *testing.T) {
+ if !canMSan && !canRace {
+ t.Skip("skipping because both msan and the race detector are not supported")
+ }
+
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.tempFile("triv.go", `package main; func main() {}`)
+ tg.setenv("CGO_ENABLED", "0")
+ if canRace {
+ tg.runFail("install", "-race", "triv.go")
+ tg.grepStderr("-race requires cgo", "did not correctly report that -race requires cgo")
+ tg.grepStderrNot("-msan", "reported that -msan instead of -race requires cgo")
+ }
+ if canMSan {
+ tg.runFail("install", "-msan", "triv.go")
+ tg.grepStderr("-msan requires cgo", "did not correctly report that -msan requires cgo")
+ tg.grepStderrNot("-race", "reported that -race instead of -msan requires cgo")
+ }
+}
+
func TestRelativeGOBINFail(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()