summaryrefslogtreecommitdiff
path: root/src/cmd/tests
diff options
context:
space:
mode:
authordzwdz2023-08-29 23:02:42 +0200
committerdzwdz2023-08-29 23:02:42 +0200
commitdd385a413c92d53a1f792011e1029d7d68e19c6c (patch)
tree134fa61d71f6894e37a1b890004cfcb2d96ea17b /src/cmd/tests
parente43939bcc6123e02314aa403eef94d5ace441f7f (diff)
tests: fix everything broken by the pipe change
god, those tests are a mess. so are esemaphores.
Diffstat (limited to 'src/cmd/tests')
-rw-r--r--src/cmd/tests/kernel/miscsyscall.c32
-rw-r--r--src/cmd/tests/tests.c19
-rw-r--r--src/cmd/tests/tests.h4
3 files changed, 21 insertions, 34 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)