if len(extraEnv) > 0 {
cmd.Env = append(os.Environ(), extraEnv...)
}
+ stderr := new(strings.Builder)
+ cmd.Stderr = stderr
if GOOS != "windows" {
// TestUnexportedSymbols relies on file descriptor 30
cmd.ExtraFiles = make([]*os.File, 28)
}
- out, err := cmd.CombinedOutput()
+ t.Logf("run: %v", args)
+ out, err := cmd.Output()
+ if stderr.Len() > 0 {
+ t.Logf("stderr:\n%s", stderr)
+ }
if err != nil {
t.Fatalf("command failed: %v\n%v\n%s\n", args, err, out)
- } else {
- t.Logf("run: %v", args)
}
return string(out)
}
defer os.Remove(bin)
defer os.Remove(pkgname + ".h")
- out := runExe(t, nil, bin, "./"+libname)
+ args := []string{bin, "./" + libname}
+ if testing.Verbose() {
+ args = append(args, "verbose")
+ }
+ out := runExe(t, nil, args...)
if strings.TrimSpace(out) != "PASS" {
- t.Error(run(t, nil, bin, libname, "verbose"))
+ t.Errorf("%v%s", args, out)
}
}
setsid();
if (verbose) {
- printf("calling sigaction\n");
+ fprintf(stderr, "calling sigaction\n");
}
memset(&sa, 0, sizeof sa);
}
if (verbose) {
- printf("calling dlopen\n");
+ fprintf(stderr, "calling dlopen\n");
}
handle = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL);
}
if (verbose) {
- printf("calling dlsym\n");
+ fprintf(stderr, "calling dlsym\n");
}
// Start some goroutines.
}
if (verbose) {
- printf("calling RunGoroutines\n");
+ fprintf(stderr, "calling RunGoroutines\n");
}
fn();
// will be delivered to a goroutine.
if (verbose) {
- printf("calling pthread_sigmask\n");
+ fprintf(stderr, "calling pthread_sigmask\n");
}
if (sigemptyset(&mask) < 0) {
}
if (verbose) {
- printf("calling kill\n");
+ fprintf(stderr, "calling kill\n");
}
if (kill(0, SIGIO) < 0) {
}
if (verbose) {
- printf("waiting for sigioSeen\n");
+ fprintf(stderr, "waiting for sigioSeen\n");
}
// Wait until the signal has been delivered.
}
if (verbose) {
- printf("calling setjmp\n");
+ fprintf(stderr, "calling setjmp\n");
}
// Test that a SIGSEGV on this thread is delivered to us.
if (setjmp(jmp) == 0) {
if (verbose) {
- printf("triggering SIGSEGV\n");
+ fprintf(stderr, "triggering SIGSEGV\n");
}
*nullPointer = '\0';
}
if (verbose) {
- printf("calling dlsym\n");
+ fprintf(stderr, "calling dlsym\n");
}
// Make sure that a SIGSEGV in Go causes a run-time panic.
}
if (verbose) {
- printf("calling TestSEGV\n");
+ fprintf(stderr, "calling TestSEGV\n");
}
fn();
// This is a lot like ../testcarchive/main3.c.
#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int verbose;
struct sigaction sa;
void* handle;
- void (*fn1)(void);
- int (*sawSIGIO)(void);
+ void (*catchSIGIO)(void);
+ void (*resetSIGIO)(void);
+ void (*awaitSIGIO)();
+ bool (*sawSIGIO)();
int i;
struct timespec ts;
setvbuf(stdout, NULL, _IONBF, 0);
if (verbose) {
- printf("calling sigaction\n");
+ fprintf(stderr, "calling sigaction\n");
}
memset(&sa, 0, sizeof sa);
}
if (verbose) {
- printf("calling dlopen\n");
+ fprintf(stderr, "calling dlopen\n");
}
handle = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL);
// installed for SIGIO.
if (verbose) {
- printf("raising SIGIO\n");
+ fprintf(stderr, "raising SIGIO\n");
}
if (raise(SIGIO) < 0) {
}
if (verbose) {
- printf("waiting for sigioSeen\n");
+ fprintf(stderr, "waiting for sigioSeen\n");
}
// Wait until the signal has been delivered.
// Tell the Go code to catch SIGIO.
if (verbose) {
- printf("calling dlsym\n");
+ fprintf(stderr, "calling dlsym\n");
}
- fn1 = (void(*)(void))dlsym(handle, "CatchSIGIO");
- if (fn1 == NULL) {
+ catchSIGIO = (void(*)(void))dlsym(handle, "CatchSIGIO");
+ if (catchSIGIO == NULL) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
if (verbose) {
- printf("calling CatchSIGIO\n");
+ fprintf(stderr, "calling CatchSIGIO\n");
}
- fn1();
+ catchSIGIO();
if (verbose) {
- printf("raising SIGIO\n");
+ fprintf(stderr, "raising SIGIO\n");
}
if (raise(SIGIO) < 0) {
}
if (verbose) {
- printf("calling dlsym\n");
+ fprintf(stderr, "calling dlsym\n");
}
// Check that the Go code saw SIGIO.
- sawSIGIO = (int (*)(void))dlsym(handle, "SawSIGIO");
- if (sawSIGIO == NULL) {
+ awaitSIGIO = (void (*)(void))dlsym(handle, "AwaitSIGIO");
+ if (awaitSIGIO == NULL) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
if (verbose) {
- printf("calling SawSIGIO\n");
+ fprintf(stderr, "calling AwaitSIGIO\n");
}
- if (!sawSIGIO()) {
- fprintf(stderr, "Go handler did not see SIGIO\n");
- exit(EXIT_FAILURE);
- }
+ awaitSIGIO();
if (sigioSeen != 0) {
fprintf(stderr, "C handler saw SIGIO when only Go handler should have\n");
// Tell the Go code to stop catching SIGIO.
if (verbose) {
- printf("calling dlsym\n");
+ fprintf(stderr, "calling dlsym\n");
}
- fn1 = (void(*)(void))dlsym(handle, "ResetSIGIO");
- if (fn1 == NULL) {
+ resetSIGIO = (void (*)(void))dlsym(handle, "ResetSIGIO");
+ if (resetSIGIO == NULL) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
if (verbose) {
- printf("calling ResetSIGIO\n");
+ fprintf(stderr, "calling ResetSIGIO\n");
}
- fn1();
+ resetSIGIO();
+
+ sawSIGIO = (bool (*)(void))dlsym(handle, "SawSIGIO");
+ if (sawSIGIO == NULL) {
+ fprintf(stderr, "%s\n", dlerror());
+ exit(EXIT_FAILURE);
+ }
if (verbose) {
- printf("raising SIGIO\n");
+ fprintf(stderr, "raising SIGIO\n");
}
if (raise(SIGIO) < 0) {
}
if (verbose) {
- printf("calling SawSIGIO\n");
+ fprintf(stderr, "calling SawSIGIO\n");
}
if (sawSIGIO()) {
}
if (verbose) {
- printf("waiting for sigioSeen\n");
+ fprintf(stderr, "waiting for sigioSeen\n");
}
// Wait until the signal has been delivered.