summaryrefslogtreecommitdiffstats
path: root/src/runtime/testdata/testwinlibsignal/main.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
commit73df946d56c74384511a194dd01dbe099584fd1a (patch)
treefd0bcea490dd81327ddfbb31e215439672c9a068 /src/runtime/testdata/testwinlibsignal/main.c
parentInitial commit. (diff)
downloadgolang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.tar.xz
golang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.zip
Adding upstream version 1.16.10.upstream/1.16.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/runtime/testdata/testwinlibsignal/main.c')
-rw-r--r--src/runtime/testdata/testwinlibsignal/main.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/runtime/testdata/testwinlibsignal/main.c b/src/runtime/testdata/testwinlibsignal/main.c
new file mode 100644
index 0000000..1787fef
--- /dev/null
+++ b/src/runtime/testdata/testwinlibsignal/main.c
@@ -0,0 +1,50 @@
+#include <windows.h>
+#include <stdio.h>
+
+HANDLE waitForCtrlBreakEvent;
+
+BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
+{
+ switch (fdwCtrlType)
+ {
+ case CTRL_BREAK_EVENT:
+ SetEvent(waitForCtrlBreakEvent);
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+int main(void)
+{
+ waitForCtrlBreakEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (!waitForCtrlBreakEvent) {
+ fprintf(stderr, "ERROR: Could not create event");
+ return 1;
+ }
+
+ if (!SetConsoleCtrlHandler(CtrlHandler, TRUE))
+ {
+ fprintf(stderr, "ERROR: Could not set control handler");
+ return 1;
+ }
+
+ // The library must be loaded after the SetConsoleCtrlHandler call
+ // so that the library handler registers after the main program.
+ // This way the library handler gets called first.
+ HMODULE dummyDll = LoadLibrary("dummy.dll");
+ if (!dummyDll) {
+ fprintf(stderr, "ERROR: Could not load dummy.dll");
+ return 1;
+ }
+
+ printf("ready\n");
+ fflush(stdout);
+
+ if (WaitForSingleObject(waitForCtrlBreakEvent, 5000) != WAIT_OBJECT_0) {
+ fprintf(stderr, "FAILURE: No signal received");
+ return 1;
+ }
+
+ return 0;
+}