]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: improve coverage of TestCgoSigfwd
authorAustin Clements <austin@google.com>
Fri, 14 Oct 2022 19:36:58 +0000 (15:36 -0400)
committerAustin Clements <austin@google.com>
Mon, 17 Oct 2022 15:15:34 +0000 (15:15 +0000)
Currently, TestCgoSigfwd will pass incorrectly if the SIGSEGV that
originates in Go mistakenly goes to the C SIGSEGV handler. Fix this by
adding a signal-atomic variable that tracks what the expected behavior
is.

Change-Id: Id2a9fa3b209299dccf90bb60720b89ad96838a9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/443072
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/testdata/testprogcgo/sigfwd.go

index 16942897005771ef7509e5513fceff4123de67c1..b27d436f82b90f956a87131d1ace91450eece8f5 100644 (file)
@@ -17,8 +17,11 @@ import (
 #include <stdio.h>
 #include <string.h>
 
+sig_atomic_t expectCSigsegv;
 int *sigfwdP;
+
 static void sigsegv() {
+       expectCSigsegv = 1;
        *sigfwdP = 1;
        fprintf(stderr, "ERROR: C SIGSEGV not thrown on caught?.\n");
        exit(2);
@@ -26,6 +29,10 @@ static void sigsegv() {
 
 static void segvhandler(int signum) {
        if (signum == SIGSEGV) {
+               if (expectCSigsegv == 0) {
+                       fprintf(stderr, "SIGSEGV caught in C unexpectedly\n");
+                       exit(1);
+               }
                fprintf(stdout, "OK\n");
                exit(0);  // success
        }