Skip to content

Commit dacf88e

Browse files
committed
misc/cgo/testsigfwd: move to runtime/testprog/testprogcgo
This migrates testsigfwd, which uses some one-off build infrastructure, to be part of the runtime's testprogcgo. The test is largely unchanged. Because it's part of a larger binary, this CL renames a few things and gates the constructor-time signal handler registration on an environment variable. This CL also replaces an errant fmt.Errorf with fmt.Fprintf. For #37486, since it eliminates a non-go-test from dist. Change-Id: I0efd146ea0a0a3f0b361431349a419af0f0ecc61 Reviewed-on: https://go-review.googlesource.com/c/go/+/443068 Run-TryBot: Austin Clements <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent abd592b commit dacf88e

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

src/cmd/dist/test.go

-3
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,6 @@ func (t *tester) registerTests() {
831831
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
832832
t.registerHostTest("cgo_errors", "../misc/cgo/errors", "misc/cgo/errors", ".")
833833
}
834-
if gohostos == "linux" && t.extLink() {
835-
t.registerTest("testsigfwd", "../misc/cgo/testsigfwd", "go", "run", ".")
836-
}
837834
}
838835

839836
if goos != "android" && !t.iOS() {

src/runtime/crash_cgo_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package runtime_test
88

99
import (
1010
"fmt"
11+
"internal/goos"
1112
"internal/testenv"
1213
"os"
1314
"os/exec"
@@ -753,3 +754,15 @@ func TestCgoTraceParserWithOneProc(t *testing.T) {
753754
t.Fatalf("GOMAXPROCS=1, want %s, got %s\n", want, output)
754755
}
755756
}
757+
758+
func TestCgoSigfwd(t *testing.T) {
759+
t.Parallel()
760+
if goos.IsLinux == 0 {
761+
t.Skipf("only supported on Linux")
762+
}
763+
764+
got := runTestProg(t, "testprogcgo", "CgoSigfwd", "GO_TEST_CGOSIGFWD=1")
765+
if want := "OK\n"; got != want {
766+
t.Fatalf("expected %q, but got:\n%s", want, got)
767+
}
768+
}

misc/cgo/testsigfwd/main.go renamed to src/runtime/testdata/testprogcgo/sigfwd.go

+26-8
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build linux
6+
57
package main
68

7-
import "fmt"
9+
import (
10+
"fmt"
11+
"os"
12+
)
813

914
/*
1015
#include <signal.h>
1116
#include <stdlib.h>
1217
#include <stdio.h>
1318
#include <string.h>
1419
15-
int *p;
20+
int *sigfwdP;
1621
static void sigsegv() {
17-
*p = 1;
22+
*sigfwdP = 1;
1823
fprintf(stderr, "ERROR: C SIGSEGV not thrown on caught?.\n");
1924
exit(2);
2025
}
2126
2227
static void segvhandler(int signum) {
2328
if (signum == SIGSEGV) {
24-
fprintf(stdout, "ok\ttestsigfwd\n");
29+
fprintf(stdout, "OK\n");
2530
exit(0); // success
2631
}
2732
}
2833
2934
static void __attribute__ ((constructor)) sigsetup(void) {
35+
if (getenv("GO_TEST_CGOSIGFWD") == NULL) {
36+
return;
37+
}
38+
3039
struct sigaction act;
3140
3241
memset(&act, 0, sizeof act);
@@ -36,7 +45,11 @@ static void __attribute__ ((constructor)) sigsetup(void) {
3645
*/
3746
import "C"
3847

39-
var p *byte
48+
func init() {
49+
register("CgoSigfwd", CgoSigfwd)
50+
}
51+
52+
var nilPtr *byte
4053

4154
func f() (ret bool) {
4255
defer func() {
@@ -46,14 +59,19 @@ func f() (ret bool) {
4659
}
4760
ret = true
4861
}()
49-
*p = 1
62+
*nilPtr = 1
5063
return false
5164
}
5265

53-
func main() {
66+
func CgoSigfwd() {
67+
if os.Getenv("GO_TEST_CGOSIGFWD") == "" {
68+
fmt.Fprintf(os.Stderr, "test must be run with GO_TEST_CGOSIGFWD set\n")
69+
os.Exit(1)
70+
}
71+
5472
// Test that the signal originating in Go is handled (and recovered) by Go.
5573
if !f() {
56-
fmt.Errorf("couldn't recover from SIGSEGV in Go.")
74+
fmt.Fprintf(os.Stderr, "couldn't recover from SIGSEGV in Go.\n")
5775
C.exit(2)
5876
}
5977

0 commit comments

Comments
 (0)