mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Catch SIGTRAP in the test runner
Fixes `panic` for Darwin.
This commit is contained in:
@@ -9,6 +9,7 @@ Stop_Reason :: enum {
|
|||||||
Illegal_Instruction,
|
Illegal_Instruction,
|
||||||
Arithmetic_Error,
|
Arithmetic_Error,
|
||||||
Segmentation_Fault,
|
Segmentation_Fault,
|
||||||
|
Unhandled_Trap,
|
||||||
}
|
}
|
||||||
|
|
||||||
test_assertion_failure_proc :: proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! {
|
test_assertion_failure_proc :: proc(prefix, message: string, loc: runtime.Source_Code_Location) -> ! {
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ import "core:os"
|
|||||||
@(private="file", thread_local)
|
@(private="file", thread_local)
|
||||||
local_test_index: libc.sig_atomic_t
|
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")
|
@(private="file")
|
||||||
stop_runner_callback :: proc "c" (sig: libc.int) {
|
stop_runner_callback :: proc "c" (sig: libc.int) {
|
||||||
prev := intrinsics.atomic_add(&stop_runner_flag, 1)
|
prev := intrinsics.atomic_add(&stop_runner_flag, 1)
|
||||||
@@ -110,6 +115,10 @@ _setup_signal_handler :: proc() {
|
|||||||
// For tests:
|
// For tests:
|
||||||
// Catch asserts and panics.
|
// Catch asserts and panics.
|
||||||
libc.signal(libc.SIGILL, stop_test_callback)
|
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.
|
// Catch arithmetic errors.
|
||||||
libc.signal(libc.SIGFPE, stop_test_callback)
|
libc.signal(libc.SIGFPE, stop_test_callback)
|
||||||
// Catch segmentation faults (illegal memory access).
|
// 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.SIGFPE: reason = .Arithmetic_Error
|
||||||
case libc.SIGILL: reason = .Illegal_Instruction
|
case libc.SIGILL: reason = .Illegal_Instruction
|
||||||
case libc.SIGSEGV: reason = .Segmentation_Fault
|
case libc.SIGSEGV: reason = .Segmentation_Fault
|
||||||
|
case SIGTRAP: reason = .Unhandled_Trap
|
||||||
}
|
}
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user