aboutsummaryrefslogtreecommitdiff
path: root/core/testing
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-11-01 16:27:45 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2024-11-01 16:27:45 +0100
commitf798f0b44669f3b3bc00fb63ca74dc597d8b18dc (patch)
tree305981660821aab48cdea3ee1e530400bbb12495 /core/testing
parentc3971fe5fa1c2e32c3dc17aed057cd5819de1fb8 (diff)
testing: separate the posix import into target files
This is needed for the docs generator to generate all the docs for the posix package, if it is imported like it was on Windows it would generate docs for the Windows version of the package which has much less symbols exposed.
Diffstat (limited to 'core/testing')
-rw-r--r--core/testing/signal_handler_libc.odin21
-rw-r--r--core/testing/signal_handler_posix.odin22
-rw-r--r--core/testing/signal_handler_windows.odin6
3 files changed, 32 insertions, 17 deletions
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" () {}