aboutsummaryrefslogtreecommitdiff
path: root/core/testing
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-28 19:05:20 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-28 19:43:03 -0400
commit13539d3be1f3398f1a2152197dabd8a13456d540 (patch)
treec2d4fa18d08d09dd309131bf39cc1bdde2d2c3ac /core/testing
parent929cc48703e30913cf17330bcf3f77dd0909ee57 (diff)
Catch `SIGTRAP` in the test runner
Fixes `panic` for Darwin.
Diffstat (limited to 'core/testing')
-rw-r--r--core/testing/signal_handler.odin1
-rw-r--r--core/testing/signal_handler_libc.odin10
2 files changed, 11 insertions, 0 deletions
diff --git a/core/testing/signal_handler.odin b/core/testing/signal_handler.odin
index 891f6bbb6..0b06852ce 100644
--- a/core/testing/signal_handler.odin
+++ b/core/testing/signal_handler.odin
@@ -9,6 +9,7 @@ Stop_Reason :: enum {
Illegal_Instruction,
Arithmetic_Error,
Segmentation_Fault,
+ Unhandled_Trap,
}
test_assertion_failure_proc :: proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! {
diff --git a/core/testing/signal_handler_libc.odin b/core/testing/signal_handler_libc.odin
index 0ab34776e..d89d84fae 100644
--- a/core/testing/signal_handler_libc.odin
+++ b/core/testing/signal_handler_libc.odin
@@ -19,6 +19,11 @@ import "core:os"
@(private="file", thread_local)
local_test_index: libc.sig_atomic_t
+// Windows does not appear to have a SIGTRAP, so this is defined here, instead
+// of in the libc package, just so there's no confusion about it being
+// available there.
+SIGTRAP :: 5
+
@(private="file")
stop_runner_callback :: proc "c" (sig: libc.int) {
prev := intrinsics.atomic_add(&stop_runner_flag, 1)
@@ -110,6 +115,10 @@ _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).
@@ -141,6 +150,7 @@ _should_stop_test :: proc() -> (test_index: int, reason: Stop_Reason, ok: bool)
case libc.SIGFPE: reason = .Arithmetic_Error
case libc.SIGILL: reason = .Illegal_Instruction
case libc.SIGSEGV: reason = .Segmentation_Fault
+ case SIGTRAP: reason = .Unhandled_Trap
}
ok = true
}