From dd385a413c92d53a1f792011e1029d7d68e19c6c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 29 Aug 2023 23:02:42 +0200 Subject: tests: fix everything broken by the pipe change god, those tests are a mess. so are esemaphores. --- src/cmd/tests/tests.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/cmd/tests/tests.c') diff --git a/src/cmd/tests/tests.c b/src/cmd/tests/tests.c index 5cba682..ce28eb3 100644 --- a/src/cmd/tests/tests.c +++ b/src/cmd/tests/tests.c @@ -1,21 +1,26 @@ #include "tests.h" #include +#include #include -__attribute__((visibility("hidden"))) -extern char __executable_start[]; - FILE *fail_trig; -void run_test(void (*fn)()) { - if (!fork()) { +void run_test_inner(void (*fn)(), const char *s) { + int pid = fork(); + if (pid == 0) { fn(); _sys_filicide(); exit(0); + } else if (pid < 0) { + /* working around macro stupidity */ + test_failf("%s", "in fork"); } else { /* successful tests must return 0 */ - if (_sys_await() != 0) { - test_failf("%p, base %p", (void*)((void*)fn - (void*)__executable_start), __executable_start); + int status; + if (waitpid(pid, &status, 0) != pid) { + test_failf("%s", "waitpid returned something weird"); + } else if (WEXITSTATUS(status) != 0) { + test_failf("%s exited with %d", s, WEXITSTATUS(status)); } } } -- cgit v1.2.3