diff options
author | Austin Clements <austin@google.com> | 2022-10-14 14:50:19 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2022-10-17 15:15:33 +0000 |
commit | dacf88e40a0a3d395988d226b5e43e046dd7e68f (patch) | |
tree | 0d3b3c7c3ef8990f0dadc6ed28b5d67435f50f98 /misc/cgo | |
parent | abd592b3d7c3e05eaa9dd6a69749e497b1973002 (diff) | |
download | go-dacf88e40a0a3d395988d226b5e43e046dd7e68f.tar.gz go-dacf88e40a0a3d395988d226b5e43e046dd7e68f.zip |
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>
Diffstat (limited to 'misc/cgo')
-rw-r--r-- | misc/cgo/testsigfwd/main.go | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/misc/cgo/testsigfwd/main.go b/misc/cgo/testsigfwd/main.go deleted file mode 100644 index 1d8633971d..0000000000 --- a/misc/cgo/testsigfwd/main.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2015 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. - -package main - -import "fmt" - -/* -#include <signal.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -int *p; -static void sigsegv() { - *p = 1; - fprintf(stderr, "ERROR: C SIGSEGV not thrown on caught?.\n"); - exit(2); -} - -static void segvhandler(int signum) { - if (signum == SIGSEGV) { - fprintf(stdout, "ok\ttestsigfwd\n"); - exit(0); // success - } -} - -static void __attribute__ ((constructor)) sigsetup(void) { - struct sigaction act; - - memset(&act, 0, sizeof act); - act.sa_handler = segvhandler; - sigaction(SIGSEGV, &act, NULL); -} -*/ -import "C" - -var p *byte - -func f() (ret bool) { - defer func() { - if recover() == nil { - fmt.Errorf("ERROR: couldn't raise SIGSEGV in Go.") - C.exit(2) - } - ret = true - }() - *p = 1 - return false -} - -func main() { - // Test that the signal originating in Go is handled (and recovered) by Go. - if !f() { - fmt.Errorf("couldn't recover from SIGSEGV in Go.") - C.exit(2) - } - - // Test that the signal originating in C is handled by C. - C.sigsegv() -} |