aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-05-21 12:01:39 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-05-21 13:21:00 +0000
commit7e63c8b765c30823131bd136d190afbe4c21abc9 (patch)
treeb2541afd74abd5d0d7098e89454452940ecd2731 /src/runtime/testdata
parent831573cd21e65c37b4e1bf5d44dc23b125084b7a (diff)
downloadgo-7e63c8b765c30823131bd136d190afbe4c21abc9.tar.xz
runtime: wait for Go runtime to initialize in Windows signal test
The test harness waits for "ready" as a sign that the Go runtime has installed its signal handler and is ready to be tested. But actually, while LoadLibrary starts the loading of the Go runtime, it does so asynchronously, so the "ready" sign is potentially premature and certainly racy. However, all exported cgo entry points make a call to _cgo_wait_runtime_init_done which waits for that asynchronous initialization to complete. Therefore, this commit fixes the test to call into the exported "Dummy" cgo function before emitting the "ready" sign, so that we're sure the Go runtime is actually loaded. Updates #45638. Change-Id: I9b12b172d45bdcc09d54dd301de3a3e499544834 Reviewed-on: https://go-review.googlesource.com/c/go/+/321769 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/testdata')
-rw-r--r--src/runtime/testdata/testwinlibsignal/main.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/runtime/testdata/testwinlibsignal/main.c b/src/runtime/testdata/testwinlibsignal/main.c
index 1787fef3b9..37f24823e6 100644
--- a/src/runtime/testdata/testwinlibsignal/main.c
+++ b/src/runtime/testdata/testwinlibsignal/main.c
@@ -19,13 +19,13 @@ int main(void)
{
waitForCtrlBreakEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!waitForCtrlBreakEvent) {
- fprintf(stderr, "ERROR: Could not create event");
+ fprintf(stderr, "ERROR: Could not create event\n");
return 1;
}
if (!SetConsoleCtrlHandler(CtrlHandler, TRUE))
{
- fprintf(stderr, "ERROR: Could not set control handler");
+ fprintf(stderr, "ERROR: Could not set control handler\n");
return 1;
}
@@ -34,7 +34,14 @@ int main(void)
// This way the library handler gets called first.
HMODULE dummyDll = LoadLibrary("dummy.dll");
if (!dummyDll) {
- fprintf(stderr, "ERROR: Could not load dummy.dll");
+ fprintf(stderr, "ERROR: Could not load dummy.dll\n");
+ return 1;
+ }
+
+ // Call the Dummy function so that Go initialization completes, since
+ // all cgo entry points call out to _cgo_wait_runtime_init_done.
+ if (((int(*)(void))GetProcAddress(dummyDll, "Dummy"))() != 42) {
+ fprintf(stderr, "ERROR: Dummy function did not return 42\n");
return 1;
}
@@ -42,7 +49,7 @@ int main(void)
fflush(stdout);
if (WaitForSingleObject(waitForCtrlBreakEvent, 5000) != WAIT_OBJECT_0) {
- fprintf(stderr, "FAILURE: No signal received");
+ fprintf(stderr, "FAILURE: No signal received\n");
return 1;
}