Browse Source

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.
Laytan Laats 9 months ago
parent
commit
f798f0b446

+ 4 - 17
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) {

+ 22 - 0
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()
+}

+ 6 - 0
core/testing/signal_handler_windows.odin

@@ -0,0 +1,6 @@
+#+private
+package testing
+
+__setup_signal_handler :: proc() {}
+
+_test_thread_cancel :: proc "contextless" () {}