mirror of https://github.com/golang/go.git
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 <austin@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
abd592b3d7
commit
dacf88e40a
|
|
@ -831,9 +831,6 @@ func (t *tester) registerTests() {
|
||||||
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
|
if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" {
|
||||||
t.registerHostTest("cgo_errors", "../misc/cgo/errors", "misc/cgo/errors", ".")
|
t.registerHostTest("cgo_errors", "../misc/cgo/errors", "misc/cgo/errors", ".")
|
||||||
}
|
}
|
||||||
if gohostos == "linux" && t.extLink() {
|
|
||||||
t.registerTest("testsigfwd", "../misc/cgo/testsigfwd", "go", "run", ".")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if goos != "android" && !t.iOS() {
|
if goos != "android" && !t.iOS() {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ package runtime_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"internal/goos"
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
@ -753,3 +754,15 @@ func TestCgoTraceParserWithOneProc(t *testing.T) {
|
||||||
t.Fatalf("GOMAXPROCS=1, want %s, got %s\n", want, output)
|
t.Fatalf("GOMAXPROCS=1, want %s, got %s\n", want, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCgoSigfwd(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
if goos.IsLinux == 0 {
|
||||||
|
t.Skipf("only supported on Linux")
|
||||||
|
}
|
||||||
|
|
||||||
|
got := runTestProg(t, "testprogcgo", "CgoSigfwd", "GO_TEST_CGOSIGFWD=1")
|
||||||
|
if want := "OK\n"; got != want {
|
||||||
|
t.Fatalf("expected %q, but got:\n%s", want, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
@ -12,21 +17,25 @@ import "fmt"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int *p;
|
int *sigfwdP;
|
||||||
static void sigsegv() {
|
static void sigsegv() {
|
||||||
*p = 1;
|
*sigfwdP = 1;
|
||||||
fprintf(stderr, "ERROR: C SIGSEGV not thrown on caught?.\n");
|
fprintf(stderr, "ERROR: C SIGSEGV not thrown on caught?.\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void segvhandler(int signum) {
|
static void segvhandler(int signum) {
|
||||||
if (signum == SIGSEGV) {
|
if (signum == SIGSEGV) {
|
||||||
fprintf(stdout, "ok\ttestsigfwd\n");
|
fprintf(stdout, "OK\n");
|
||||||
exit(0); // success
|
exit(0); // success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __attribute__ ((constructor)) sigsetup(void) {
|
static void __attribute__ ((constructor)) sigsetup(void) {
|
||||||
|
if (getenv("GO_TEST_CGOSIGFWD") == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
|
||||||
memset(&act, 0, sizeof act);
|
memset(&act, 0, sizeof act);
|
||||||
|
|
@ -36,7 +45,11 @@ static void __attribute__ ((constructor)) sigsetup(void) {
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
var p *byte
|
func init() {
|
||||||
|
register("CgoSigfwd", CgoSigfwd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var nilPtr *byte
|
||||||
|
|
||||||
func f() (ret bool) {
|
func f() (ret bool) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -46,14 +59,19 @@ func f() (ret bool) {
|
||||||
}
|
}
|
||||||
ret = true
|
ret = true
|
||||||
}()
|
}()
|
||||||
*p = 1
|
*nilPtr = 1
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func CgoSigfwd() {
|
||||||
|
if os.Getenv("GO_TEST_CGOSIGFWD") == "" {
|
||||||
|
fmt.Fprintf(os.Stderr, "test must be run with GO_TEST_CGOSIGFWD set\n")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// Test that the signal originating in Go is handled (and recovered) by Go.
|
// Test that the signal originating in Go is handled (and recovered) by Go.
|
||||||
if !f() {
|
if !f() {
|
||||||
fmt.Errorf("couldn't recover from SIGSEGV in Go.")
|
fmt.Fprintf(os.Stderr, "couldn't recover from SIGSEGV in Go.\n")
|
||||||
C.exit(2)
|
C.exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue