diff options
author | dzwdz | 2023-08-29 23:02:42 +0200 |
---|---|---|
committer | dzwdz | 2023-08-29 23:02:42 +0200 |
commit | dd385a413c92d53a1f792011e1029d7d68e19c6c (patch) | |
tree | 134fa61d71f6894e37a1b890004cfcb2d96ea17b /src | |
parent | e43939bcc6123e02314aa403eef94d5ace441f7f (diff) |
tests: fix everything broken by the pipe change
god, those tests are a mess. so are esemaphores.
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/tests/kernel/miscsyscall.c | 32 | ||||
-rw-r--r-- | src/cmd/tests/tests.c | 19 | ||||
-rw-r--r-- | src/cmd/tests/tests.h | 4 | ||||
-rw-r--r-- | src/libc/esemaphore.c | 7 |
4 files changed, 25 insertions, 37 deletions
diff --git a/src/cmd/tests/kernel/miscsyscall.c b/src/cmd/tests/kernel/miscsyscall.c index 459da2a..90da0e4 100644 --- a/src/cmd/tests/kernel/miscsyscall.c +++ b/src/cmd/tests/kernel/miscsyscall.c @@ -93,29 +93,13 @@ static void test_pipe(void) { /* writing to pipes with one end closed */ test(_sys_pipe(ends, 0) >= 0); - for (int i = 0; i < 16; i++) { - if (!fork()) { - close(ends[1]); - test(_sys_read(ends[0], buf, 16, 0) < 0); - exit(0); - } - } close(ends[1]); - for (int i = 0; i < 16; i++) - _sys_await(); + test(_sys_read(ends[0], buf, 16, 0) == 0); close(ends[0]); test(_sys_pipe(ends, 0) >= 0); - for (int i = 0; i < 16; i++) { - if (!fork()) { - close(ends[0]); - test(_sys_write(ends[1], buf, 16, 0, 0) < 0); - exit(0); - } - } close(ends[0]); - for (int i = 0; i < 16; i++) - _sys_await(); + test(_sys_write(ends[1], buf, 16, 0, 0) == -EPIPE); close(ends[1]); @@ -132,7 +116,7 @@ static void test_pipe(void) { test(_sys_read(ends[0], buf, sizeof buf, 0) == 5); _sys_await(); } - test(_sys_read(ends[0], buf, sizeof buf, 0) < 0); + test(_sys_read(ends[0], buf, sizeof buf, 0) == 0); close(ends[0]); test(_sys_pipe(ends, 0) >= 0); @@ -149,12 +133,8 @@ static void test_pipe(void) { test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) == 5); _sys_await(); } - test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) < 0); + test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) == -EPIPE); close(ends[1]); - - - // not a to.do detect when all processes that can read are stuck on writing to the pipe and vice versa - // it seems like linux just lets the process hang endlessly. } static void test_memflag(void) { @@ -225,7 +205,7 @@ static void test_dup(void) { char buf[16]; size_t count = 0; close(pipe[1]); - while (_sys_read(pipe[0], buf, sizeof buf, 0) >= 0) + while (_sys_read(pipe[0], buf, sizeof buf, 0) > 0) count++; test(count == 7); _sys_await(); @@ -288,7 +268,7 @@ static void test_sleep(void) { for (;;) { char buf[128]; long ret = _sys_read(reader, buf, sizeof buf, 0); - if (ret < 0) break; + if (ret == 0) break; test(pos + ret <= target); test(memcmp(buf, expected + pos, ret) == 0); pos += ret; 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 <camellia/syscalls.h> +#include <sys/wait.h> #include <unistd.h> -__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)); } } } diff --git a/src/cmd/tests/tests.h b/src/cmd/tests/tests.h index 5037e1a..bbf5309 100644 --- a/src/cmd/tests/tests.h +++ b/src/cmd/tests/tests.h @@ -5,7 +5,7 @@ #define TMPFILEPATH "/tmp/.test_internal" -void run_test(void (*fn)()); +void run_test_inner(void (*fn)(), const char *s); void r_k_fdlimit(void); void r_k_fs(void); @@ -35,3 +35,5 @@ int forkpipe(FILE **f, hid_t *h); exit(0); \ } while (0) #define test(cond) if (!(cond)) test_fail(); + +#define run_test(fn) run_test_inner(fn, #fn) diff --git a/src/libc/esemaphore.c b/src/libc/esemaphore.c index 2707d11..8e1d7b8 100644 --- a/src/libc/esemaphore.c +++ b/src/libc/esemaphore.c @@ -5,7 +5,7 @@ #include <esemaphore.h> void esem_signal(struct evil_sem *sem) { - _sys_write(sem->signal, NULL, 0, 0, 0); + _sys_write(sem->signal, "", 1, 0, 0); } void esem_wait(struct evil_sem *sem) { @@ -15,6 +15,7 @@ void esem_wait(struct evil_sem *sem) { struct evil_sem *esem_new(int value) { hid_t ends_wait[2], ends_signal[2]; struct evil_sem *sem; + char dummy; if (value < 0) return NULL; if (_sys_pipe(ends_wait, 0) < 0) return NULL; @@ -23,9 +24,9 @@ struct evil_sem *esem_new(int value) { if (!_sys_fork(FORK_NOREAP, NULL)) { close(ends_signal[1]); - while (_sys_read(ends_signal[0], NULL, 0, 0) >= 0) { + while (_sys_read(ends_signal[0], &dummy, 1, 0) > 0) { if (!_sys_fork(FORK_NOREAP, NULL)) { - _sys_write(ends_wait[1], NULL, 0, 0, 0); + _sys_write(ends_wait[1], "", 1, 0, 0); exit(0); } } |