Skip to content

Commit

Permalink
cmd/cgo/internal/testsanitizers: build on all platforms
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aclements authored and gopherbot committed May 12, 2023
1 parent f2fcea5 commit 57009d4
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/asan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/cc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/cshared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 8 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/empty_test.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/libfuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/msan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/cgo/internal/testsanitizers/tsan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 1 addition & 5 deletions src/cmd/dist/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down

0 comments on commit 57009d4

Please sign in to comment.