diff --git a/core/testing/signal_handler_libc.odin b/core/testing/signal_handler_libc.odin index 6b82b59bf..281fbde40 100644 --- a/core/testing/signal_handler_libc.odin +++ b/core/testing/signal_handler_libc.odin @@ -15,7 +15,6 @@ import "core:c/libc" import "core:encoding/ansi" import "core:sync" import "core:os" -@require import "core:sys/posix" @(private="file") stop_runner_flag: libc.sig_atomic_t @@ -45,7 +44,7 @@ stop_runner_callback :: proc "c" (sig: libc.int) { } } -@(private="file") +@(private) stop_test_callback :: proc "c" (sig: libc.int) { if !local_test_index_set { // We're a thread created by a test thread. @@ -106,17 +105,7 @@ This is a dire bug and should be reported to the Odin developers. // otherwise we may continue to generate signals. intrinsics.cpu_relax() - when ODIN_OS != .Windows { - // NOTE(Feoramund): Some UNIX-like platforms may require this. - // - // During testing, I found that NetBSD 10.0 refused to - // terminate a task thread, even when its thread had been - // properly set to PTHREAD_CANCEL_ASYNCHRONOUS. - // - // The runner would stall after returning from `pthread_cancel`. - - posix.pthread_testcancel() - } + _test_thread_cancel() } } } @@ -133,14 +122,12 @@ _setup_signal_handler :: proc() { // For tests: // Catch asserts and panics. libc.signal(libc.SIGILL, stop_test_callback) - when ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .Haiku || ODIN_OS == .OpenBSD || ODIN_OS == .NetBSD || ODIN_OS == .Darwin { - // Catch panics on Darwin and unhandled calls to `debug_trap`. - libc.signal(SIGTRAP, stop_test_callback) - } // Catch arithmetic errors. libc.signal(libc.SIGFPE, stop_test_callback) // Catch segmentation faults (illegal memory access). libc.signal(libc.SIGSEGV, stop_test_callback) + + __setup_signal_handler() } _setup_task_signal_handler :: proc(test_index: int) { diff --git a/core/testing/signal_handler_posix.odin b/core/testing/signal_handler_posix.odin new file mode 100644 index 000000000..1bfcc875b --- /dev/null +++ b/core/testing/signal_handler_posix.odin @@ -0,0 +1,22 @@ +#+build linux, darwin, netbsd, openbsd, freebsd +#+private +package testing + +import "core:c/libc" +import "core:sys/posix" + +__setup_signal_handler :: proc() { + libc.signal(posix.SIGTRAP, stop_test_callback) +} + +_test_thread_cancel :: proc "contextless" () { + // NOTE(Feoramund): Some UNIX-like platforms may require this. + // + // During testing, I found that NetBSD 10.0 refused to + // terminate a task thread, even when its thread had been + // properly set to PTHREAD_CANCEL_ASYNCHRONOUS. + // + // The runner would stall after returning from `pthread_cancel`. + + posix.pthread_testcancel() +} diff --git a/core/testing/signal_handler_windows.odin b/core/testing/signal_handler_windows.odin new file mode 100644 index 000000000..74ebe2998 --- /dev/null +++ b/core/testing/signal_handler_windows.odin @@ -0,0 +1,6 @@ +#+private +package testing + +__setup_signal_handler :: proc() {} + +_test_thread_cancel :: proc "contextless" () {}