From 7b50c8785888d24d3a478fade11f03b2b4166276 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 20 Nov 2025 12:52:25 +0100 Subject: [PATCH] - Fix issue when tests encounter a segmentation fault or similar. --- lib/std/core/runtime_test.c3 | 15 +++++++++++++++ releasenotes.md | 1 + 2 files changed, 16 insertions(+) diff --git a/lib/std/core/runtime_test.c3 b/lib/std/core/runtime_test.c3 index 676f6e262..964c462b2 100644 --- a/lib/std/core/runtime_test.c3 +++ b/lib/std/core/runtime_test.c3 @@ -86,6 +86,16 @@ fn bool terminal_has_ansi_codes() @local => @pool() $endif } +fn void sig_bus_error(CInt i) @local +{ + test_panic("Bus error", "Unknown", "Unknown", 0); +} + +fn void sig_segmentation_fault(CInt i) @local +{ + test_panic("Segmentation fault", "Unknown", "Unknown", 0); +} + fn void test_panic(String message, String file, String function, uint line) @local { if (test_context.is_in_panic) return; @@ -165,6 +175,7 @@ fn void unmute_output(bool has_error) @local (void)stdout.flush(); } + fn bool run_tests(String[] args, TestUnit[] tests) @private { usz max_name; @@ -175,6 +186,10 @@ fn bool run_tests(String[] args, TestUnit[] tests) @private io::printn("There are no test units to run."); return true; // no tests == technically a pass } +$if !env::NO_LIBC: + libc::signal(libc::SIGBUS, &sig_bus_error); + libc::signal(libc::SIGSEGV, &sig_segmentation_fault); +$endif foreach (&unit : tests) { if (max_name < unit.name.len) max_name = unit.name.len; diff --git a/releasenotes.md b/releasenotes.md index 636b6f25c..88f2d7e96 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -34,6 +34,7 @@ - Fix decl attribute in the wrong place causing an assertion. #2581 - Passing a single value to `@wasm` would ignore the renaming. - `*(int*)1` incorrectly yielded an assert in LLVM IR lowering #2584. +- Fix issue when tests encounter a segmentation fault or similar. ### Stdlib changes