]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo/internal/testsanitizers: build on all platforms
authorAustin Clements <austin@google.com>
Fri, 12 May 2023 19:19:23 +0000 (15:19 -0400)
committerGopher Robot <gobot@golang.org>
Fri, 12 May 2023 19:43:56 +0000 (19:43 +0000)
This test package uses the Pdeathsig field of syscall.SysProcAttr,
which is only available on a few platforms. Currently, dist test
checks for compatible platforms and only registers it as part of
all.bash on platforms where it can build. But this doesn't help if
you're just trying to type check everything in cmd.

Make this package pass type checking by moving the condition from dist
into build tags on the test package itself.

For #60164.
Updates #37486.

Change-Id: I58b12d547c323cec895320baa5fca1b82e99d1b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/494658
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Austin Clements <austin@google.com>

src/cmd/cgo/internal/testsanitizers/asan_test.go
src/cmd/cgo/internal/testsanitizers/cc_test.go
src/cmd/cgo/internal/testsanitizers/cshared_test.go
src/cmd/cgo/internal/testsanitizers/empty_test.go [new file with mode: 0644]
src/cmd/cgo/internal/testsanitizers/libfuzzer_test.go
src/cmd/cgo/internal/testsanitizers/msan_test.go
src/cmd/cgo/internal/testsanitizers/tsan_test.go
src/cmd/dist/test.go

index 1e85a5dda0e583afc07ddd6fb33b7d67331847e1..9bf48915e24c19c19a6cf7e505713c45ccf78039 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build linux || (freebsd && amd64)
+
 package sanitizers_test
 
 import (
index 67d281a8c5018653c78e106d1e91f91c0c8bb6fa..5facb37e68a516247c2cf32795dfa9dd081db716 100644 (file)
@@ -2,6 +2,11 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// This test uses the Pdeathsig field of syscall.SysProcAttr, so it only works
+// on platforms that support that.
+
+//go:build linux || (freebsd && amd64)
+
 // sanitizers_test checks the use of Go with sanitizers like msan, asan, etc.
 // See https://github.com/google/sanitizers.
 package sanitizers_test
index 21b13ce4ed0dc53b4c3c23e793b19d33c4ee255c..5a8e93d101ca872b21d2d28bc722ac5c0cfde257 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build linux || (freebsd && amd64)
+
 package sanitizers_test
 
 import (
diff --git a/src/cmd/cgo/internal/testsanitizers/empty_test.go b/src/cmd/cgo/internal/testsanitizers/empty_test.go
new file mode 100644 (file)
index 0000000..e7fed99
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// All of the actual test files have limited build constraints. This file
+// ensures there's at least one test file on every platform.
+
+package sanitizers_test
index 345751b9c761ffd2f4d7451802051d5b8ac53d5c..f84c9f37ae82ffd22a34192da166b3a673c51dda 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build linux || (freebsd && amd64)
+
 package sanitizers_test
 
 import (
index 96397e0a876a3bbb8d8166083f231c1e1d5003da..a05c545d2afdad5c1e1abc9ed9e69541d0cd0330 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build linux || (freebsd && amd64)
+
 package sanitizers_test
 
 import (
index f65d842363242e40a7ec417a10dda0c3cbb628f9..cb63f873f90136ddcc3a9d4247be92ed1dbb83cb 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build linux || (freebsd && amd64)
+
 package sanitizers_test
 
 import (
index 8cd8abc19ec172ca4467abc395e5518158ceeff0..1d8125c51d0b4a29e784b04558375d88dfe7a8d9 100644 (file)
@@ -832,11 +832,7 @@ func (t *tester) registerTests() {
                if t.supportedBuildmode("plugin") {
                        t.registerTest("cgo_testplugin", "", &goTest{pkg: "cmd/cgo/internal/testplugin", timeout: 600 * time.Second})
                }
-               if goos == "linux" || (goos == "freebsd" && goarch == "amd64") {
-                       // because Pdeathsig of syscall.SysProcAttr struct used in cmd/cgo/internal/testsanitizers is only
-                       // supported on Linux and FreeBSD.
-                       t.registerTest("cgo_testsanitizers", "", &goTest{pkg: "cmd/cgo/internal/testsanitizers", timeout: 5 * time.Minute})
-               }
+               t.registerTest("cgo_testsanitizers", "", &goTest{pkg: "cmd/cgo/internal/testsanitizers", timeout: 5 * time.Minute})
                if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
                        t.registerTest("cgo_errors", "", &goTest{pkg: "cmd/cgo/internal/testerrors", timeout: 5 * time.Minute})
                }