From c8b55b3fd4924abcdf919458b0d8adb0ec00b0f2 Mon Sep 17 00:00:00 2001
From: dzwdz
Date: Tue, 26 Jul 2022 23:23:50 +0200
Subject: user: break out the shell and tests into separate binaries

---
 src/user/app/init/init.c            |  66 +++++++++
 src/user/app/init/main.c            |  73 ----------
 src/user/app/init/shell.c           | 220 ------------------------------
 src/user/app/init/shell.h           |   3 -
 src/user/app/init/tests/main.c      | 258 ------------------------------------
 src/user/app/init/tests/pipe.c      | 117 ----------------
 src/user/app/init/tests/semaphore.c |  91 -------------
 src/user/app/init/tests/stress.c    |  28 ----
 src/user/app/init/tests/tests.h     |  20 ---
 9 files changed, 66 insertions(+), 810 deletions(-)
 create mode 100644 src/user/app/init/init.c
 delete mode 100644 src/user/app/init/main.c
 delete mode 100644 src/user/app/init/shell.c
 delete mode 100644 src/user/app/init/shell.h
 delete mode 100644 src/user/app/init/tests/main.c
 delete mode 100644 src/user/app/init/tests/pipe.c
 delete mode 100644 src/user/app/init/tests/semaphore.c
 delete mode 100644 src/user/app/init/tests/stress.c
 delete mode 100644 src/user/app/init/tests/tests.h

(limited to 'src/user/app/init')

diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c
new file mode 100644
index 0000000..0e90d1f
--- /dev/null
+++ b/src/user/app/init/init.c
@@ -0,0 +1,66 @@
+#include "driver/driver.h"
+#include <camellia/flags.h>
+#include <camellia/syscalls.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <user/lib/fs/misc.h>
+
+int main(void) {
+	freopen("/kdev/com1", "a+", stdout);
+	printf("in init (stage 2), main at 0x%x\n", &main);
+
+	MOUNT("/tmp/", tmpfs_drv());
+	MOUNT("/keyboard", ps2_drv());
+	MOUNT("/vga_tty", ansiterm_drv());
+	MOUNT("/bin/", fs_passthru("/init/bin"));
+
+	if (fork()) {
+		/* (used to) expose a bug in the kernel
+		 * the program will flow like this:
+		 * 1. we launch the forked init
+		 * 2. the forked init launches both shells
+		 * 3. one of the shells quit
+		 * 4. the forked init picks it up and quits
+		 *
+		 * then, in process_kill, the other shell will be deathbedded
+		 *
+		 * before i implement(ed) reparenting, it was a lingering running child
+		 * of a dead process, which is invalid state
+		 */
+		_syscall_await();
+		exit(1);
+	}
+
+	if (!fork()) {
+		if (!freopen("/kdev/com1", "a+", stdout)) {
+			printf("couldn't open /kdev/com1\n"); // TODO borked
+			exit(1);
+		}
+		if (!freopen("/kdev/com1", "r", stdin)) {
+			printf("couldn't open /kdev/com1\n");
+			exit(1);
+		}
+		termcook();
+		execv("/bin/shell", NULL);
+		exit(1);
+	}
+
+	if (!fork()) {
+		if (!freopen("/vga_tty", "a+", stdout)) {
+			printf("couldn't open /vga_tty\n"); // TODO borked
+			exit(1);
+		}
+		if (!freopen("/keyboard", "r", stdin)) {
+			printf("couldn't open /keyboard\n");
+			exit(1);
+		}
+		termcook();
+		execv("/bin/shell", NULL);
+		exit(1);
+	}
+
+	_syscall_await();
+	printf("init: quitting\n");
+	return 0;
+}
diff --git a/src/user/app/init/main.c b/src/user/app/init/main.c
deleted file mode 100644
index 4637703..0000000
--- a/src/user/app/init/main.c
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "driver/driver.h"
-#include "shell.h"
-#include <camellia/flags.h>
-#include <camellia/syscalls.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <user/lib/elfload.h>
-#include <user/lib/fs/misc.h>
-
-__attribute__((visibility("hidden")))
-extern char _image_base[];
-
-int main(void) {
-	freopen("/kdev/com1", "a+", stdout);
-	printf("in init (stage 2), loaded at 0x%x\n", &_image_base);
-
-	MOUNT("/tmp/", tmpfs_drv());
-	MOUNT("/keyboard", ps2_drv());
-	MOUNT("/vga_tty", ansiterm_drv());
-	MOUNT("/bin/", fs_passthru("/init/bin"));
-
-	if (fork()) {
-		/* (used to) expose a bug in the kernel
-		 * the program will flow like this:
-		 * 1. we launch the forked init
-		 * 2. the forked init launches both shells
-		 * 3. one of the shells quit
-		 * 4. the forked init picks it up and quits
-		 *
-		 * then, in process_kill, the other shell will be deathbedded
-		 *
-		 * before i implement(ed) reparenting, it was a lingering running child
-		 * of a dead process, which is invalid state
-		 */
-		_syscall_await();
-		exit(1);
-	}
-
-	if (!fork()) {
-		if (!freopen("/kdev/com1", "a+", stdout)) {
-			printf("couldn't open /kdev/com1\n"); // TODO borked
-			exit(1);
-		}
-		if (!freopen("/kdev/com1", "r", stdin)) {
-			printf("couldn't open /kdev/com1\n");
-			exit(1);
-		}
-		termcook();
-
-		shell_loop();
-		exit(1);
-	}
-
-	if (!fork()) {
-		if (!freopen("/vga_tty", "a+", stdout)) {
-			printf("couldn't open /vga_tty\n"); // TODO borked
-			exit(1);
-		}
-		if (!freopen("/keyboard", "r", stdin)) {
-			printf("couldn't open /keyboard\n");
-			exit(1);
-		}
-		termcook();
-
-		shell_loop();
-		exit(1);
-	}
-
-	_syscall_await();
-	printf("init: quitting\n");
-	return 0;
-}
diff --git a/src/user/app/init/shell.c b/src/user/app/init/shell.c
deleted file mode 100644
index a6b9965..0000000
--- a/src/user/app/init/shell.c
+++ /dev/null
@@ -1,220 +0,0 @@
-#include "shell.h"
-#include "tests/tests.h"
-#include <camellia/syscalls.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static bool isspace(char c) {
-	return c == ' ' || c == '\t' || c == '\n';
-}
-
-static char *strsplit(char *base, char delim) {
-	if (!base) return NULL;
-	while (*base) {
-		if (delim ? *base == delim : isspace(*base)) {
-			*base++ = '\0';
-			return base;
-		}
-		base++;
-	}
-	return NULL;
-}
-
-static char *strtrim(char *s) {
-	char *end;
-	if (!s) return NULL;
-	while (isspace(*s)) s++;
-	end = s + strlen(s);
-	while (end > s && isspace(end[-1])) end--;
-	*end = '\0';
-	return s;
-}
-
-
-// TODO fgets
-static int readline(char *buf, size_t max) {
-	char c = '\0';
-	size_t pos = 0;
-	while (pos < (max-1) && c != '\n' && fread(&c, 1, 1, stdin))
-		buf[pos++] = c;
-	buf[pos++] = '\0';
-	return pos;
-}
-
-static void cmd_cat_ls(const char *args, bool ls) {
-	FILE *file;
-	static char buf[512];
-	int len; // first used for strlen(args), then length of buffer
-
-	if (args) {
-		len = strlen(args);
-		memcpy(buf, args, len + 1); // no overflow check - the shell is just a PoC
-
-		if (ls) { // paths to directories always have a trailing slash
-			if (buf[len-1] != '/') {
-				buf[len] = '/';
-				buf[len+1] = '\0';
-			}
-		}
-
-		file = fopen(buf, "r");
-	} else if (ls) { /* ls default argument */
-		file = fopen("/", "r");
-	} else { /* cat default argument */
-		file = file_clone(stdin);
-	}
-
-	if (!file) {
-		printf("couldn't open.\n");
-		return;
-	}
-
-	while (!feof(file)) {
-		int len = fread(buf, 1, sizeof buf, file);
-		if (len <= 0) break;
-
-		if (ls) {
-			for (int i = 0; i < len; i++)
-				if (buf[i] == '\0') buf[i] = '\n';
-		}
-		fwrite(buf, 1, len, stdout);
-	}
-	fclose(file);
-}
-
-static void cmd_hexdump(const char *args) {
-	static uint8_t buf[512];
-	int fd, len;
-
-	fd = _syscall_open(args, strlen(args), 0);
-	if (fd < 0) {
-		printf("couldn't open.\n");
-		return;
-	}
-
-	len = _syscall_read(fd, buf, sizeof buf, 0);
-	for (int i = 0; i < len; i += 16) {
-		printf("%08x  ", i);
-
-		for (int j = i; j < i + 8 && j < len; j++)
-			printf("%02x ", buf[j]);
-		printf(" ");
-		for (int j = i + 8; j < i + 16 && j < len; j++)
-			printf("%02x ", buf[j]);
-		printf(" |");
-
-		for (int j = i; j < i + 16 && j < len; j++) {
-			char c = '.';
-			if (0x20 <= buf[j] && buf[j] < 0x7f) c = buf[j];
-			printf("%c", c);
-		}
-		printf("|\n");
-	}
-
-	close(fd);
-}
-
-static void cmd_touch(const char *args) {
-	int fd = _syscall_open(args, strlen(args), OPEN_CREATE);
-	if (fd < 0) {
-		printf("couldn't create file.\n");
-		return;
-	}
-	close(fd);
-}
-
-void shell_loop(void) {
-	static char buf[256];
-	int level = 0;
-	char *cmd, *args, *redir;
-
-	for (;;) {
-		printf("%x$ ", level);
-
-		readline(buf, 256);
-		if (feof(stdin))
-			exit(0);
-
-		cmd = strtrim(buf);
-		if (!*cmd) continue;
-
-		redir = strtrim(strsplit(cmd, '>'));
-		cmd = strtrim(cmd);
-		args = strtrim(strsplit(cmd, 0));
-
-		/* "special" commands that can't be handled in a subprocess */
-		if (!strcmp(cmd, "shadow")) {
-			_syscall_mount(-1, args, strlen(args));
-			continue;
-		} else if (!strcmp(cmd, "exit")) {
-			exit(0);
-			continue;
-		} else if (!strcmp(cmd, "fork")) {
-			if (!fork()) level++;
-			else _syscall_await();
-			continue;
-		}
-
-		if (!fork()) {
-			if (redir && !freopen(redir, "w", stdout)) {
-				// TODO stderr
-				exit(0);
-			}
-
-			if (!strcmp(cmd, "echo")) {
-				printf("%s\n", args);
-			} else if (!strcmp(cmd, "cat")) {
-				cmd_cat_ls(args, false);
-			} else if (!strcmp(cmd, "ls")) {
-				cmd_cat_ls(args, true);
-			} else if (!strcmp(cmd, "hexdump")) {
-				cmd_hexdump(args);
-			} else if (!strcmp(cmd, "catall")) {
-				const char *files[] = {
-					"/init/fake.txt",
-					"/init/1.txt", "/init/2.txt",
-					"/init/dir/3.txt", NULL};
-				for (int i = 0; files[i]; i++) {
-					printf("%s:\n", files[i]);
-					cmd_cat_ls(files[i], false);
-					printf("\n");
-				}
-			} else if (!strcmp(cmd, "touch")) {
-				cmd_touch(args);
-			} else if (!strcmp(cmd, "run_tests")) {
-				test_all();
-			} else if (!strcmp(cmd, "stress")) {
-				stress_all();
-			} else {
-				char *binname = cmd;
-				if (*cmd != '/') {
-					size_t cmdlen = strlen(cmd);
-					binname = malloc(cmdlen);
-					if (!binname) {
-						printf("sh: out of memory.\n");
-						exit(1);
-					}
-					memcpy(binname, "/bin/", 5);
-					memcpy(binname + 5, cmd, cmdlen + 1);
-				}
-
-				execv(binname, NULL);
-				if (errno == EINVAL) {
-					printf("%s isn't a valid executable\n", cmd);
-				} else {
-					printf("unknown command: %s\n", cmd);
-				}
-
-				if (binname != cmd)
-					free(binname);
-			}
-			exit(0);
-		} else {
-			_syscall_await();
-		}
-	}
-}
diff --git a/src/user/app/init/shell.h b/src/user/app/init/shell.h
deleted file mode 100644
index fb27410..0000000
--- a/src/user/app/init/shell.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-void shell_loop(void);
diff --git a/src/user/app/init/tests/main.c b/src/user/app/init/tests/main.c
deleted file mode 100644
index 7036965..0000000
--- a/src/user/app/init/tests/main.c
+++ /dev/null
@@ -1,258 +0,0 @@
-#define TEST_MACROS
-#include "tests.h"
-#include <camellia/errno.h>
-#include <camellia/execbuf.h>
-#include <camellia/flags.h>
-#include <camellia/syscalls.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-static void run_forked(void (*fn)()) {
-	if (!fork()) {
-		fn();
-		exit(0);
-	} else {
-		/* successful tests must return 0
-		 * TODO add a better fail msg */
-		if (_syscall_await() != 0) test_fail();
-	}
-}
-
-
-const char *tmpfilepath = "/tmp/.test_internal";
-
-static void test_await(void) {
-	/* creates 16 child processes, each returning a different value. then checks
-	 * if await() returns every value exactly once */
-	int ret;
-	int counts[16] = {0};
-
-	for (int i = 0; i < 16; i++)
-		if (!fork())
-			exit(i);
-
-	while ((ret = _syscall_await()) != ~0) {
-		assert(0 <= ret && ret < 16);
-		counts[ret]++;
-	}
-
-	for (int i = 0; i < 16; i++)
-		assert(counts[i] == 1);
-}
-
-static void test_faults(void) {
-	/* tests what happens when child processes fault.
-	 * expected behavior: parent processes still manages to finish, and it can
-	 * reap all its children */
-	int await_cnt = 0;
-
-	if (!fork()) { // invalid memory access
-		asm volatile("movb $69, 0" ::: "memory");
-		printf("this shouldn't happen");
-		exit(-1);
-	}
-	if (!fork()) { // #GP
-		asm volatile("hlt" ::: "memory");
-		printf("this shouldn't happen");
-		exit(-1);
-	}
-
-	while (_syscall_await() != ~0) await_cnt++;
-	assert(await_cnt == 2);
-}
-
-static void test_interrupted_fs(void) {
-	handle_t h;
-	if (_syscall_fork(FORK_NEWFS, &h)) { /* child */
-		// TODO make a similar test with all 0s passed to fs_wait
-		struct fs_wait_response res;
-		_syscall_fs_wait(NULL, 0, &res);
-		exit(0);
-	} else { /* parent */
-		_syscall_mount(h, "/", 1);
-		int ret = _syscall_open("/", 1, 0);
-		// the handler quits while handling that call - but this syscall should return anyways
-		exit(ret < 0 ? 0 : -1);
-	}
-}
-
-static void test_orphaned_fs(void) {
-	handle_t h;
-	if (_syscall_fork(FORK_NEWFS, &h)) { /* child */
-		exit(0);
-	} else { /* parent */
-		_syscall_mount(h, "/", 1);
-		int ret = _syscall_open("/", 1, 0);
-		// no handler will ever be available to handle this call - the syscall should instantly return
-		exit(ret < 0 ? 0 : -1);
-	}
-}
-
-static void test_memflag(void) {
-	void *page = (void*)0x77777000;
-	_syscall_memflag(page, 4096, MEMFLAG_PRESENT); // allocate page
-	memset(page, 77, 4096); // write to it
-	_syscall_memflag(page, 4096, 0); // free it
-
-	if (!fork()) {
-		memset(page, 11, 4096); // should segfault
-		exit(0);
-	} else {
-		assert(_syscall_await() != 0); // test if the process crashed
-	}
-
-	char *pages[4];
-	for (size_t i = 0; i < 4; i++) {
-		pages[i] = _syscall_memflag(NULL, 4096, MEMFLAG_FINDFREE);
-		printf("[test_memflag] findfree: 0x%x\n", pages[i]);
-
-		assert(pages[i] == _syscall_memflag(NULL, 4096, MEMFLAG_FINDFREE | MEMFLAG_PRESENT));
-		if (i > 0) assert(pages[i] != pages[i-1]);
-		*pages[i] = 0x77;
-	}
-
-	for (size_t i = 0; i < 4; i++)
-		_syscall_memflag(pages, 4096, MEMFLAG_PRESENT);
-
-	// TODO check if reclaims
-}
-
-static void test_dup(void) {
-	handle_t pipe[2];
-	handle_t h1, h2;
-	assert(_syscall_pipe(pipe, 0) >= 0);
-
-	if (!fork()) {
-		close(pipe[0]);
-
-		h1 = _syscall_dup(pipe[1], -1, 0);
-		assert(h1 >= 0);
-		assert(h1 != pipe[1]);
-		h2 = _syscall_dup(h1, -1, 0);
-		assert(h2 >= 0);
-		assert(h2 != pipe[1] && h2 != h1);
-
-		_syscall_write(pipe[1], "og", 2, 0);
-		_syscall_write(h1, "h1", 2, 0);
-		_syscall_write(h2, "h2", 2, 0);
-
-		close(pipe[1]);
-		_syscall_write(h1, "h1", 2, 0);
-		_syscall_write(h2, "h2", 2, 0);
-
-		assert(_syscall_dup(h1, pipe[1], 0) == pipe[1]);
-		assert(_syscall_dup(h2, pipe[1], 0) == pipe[1]);
-		assert(_syscall_dup(h1, pipe[1], 0) == pipe[1]);
-		assert(_syscall_dup(h2, pipe[1], 0) == pipe[1]);
-		close(h1);
-		close(h2);
-
-		assert(_syscall_dup(pipe[1], h2, 0) == h2);
-		_syscall_write(h2, "h2", 2, 0);
-		close(h2);
-
-		assert(_syscall_dup(pipe[1], h1, 0) == h1);
-		_syscall_write(h1, "h1", 2, 0);
-		close(h1);
-
-		exit(0);
-	} else {
-		char buf[16];
-		size_t count = 0;
-		close(pipe[1]);
-		while (_syscall_read(pipe[0], buf, sizeof buf, 0) >= 0)
-			count++;
-		assert(count == 7);
-		_syscall_await();
-	}
-
-
-	close(pipe[0]);
-}
-
-static void test_malloc(void) {
-	// not really a test
-	void *p1, *p2;
-
-	p1 = malloc(420);
-	printf("p1 = 0x%x\n", p1);
-
-	p2 = malloc(1024);
-	printf("p2 = 0x%x\n", p2);
-	free(p2);
-	p2 = malloc(256);
-	printf("p2 = 0x%x\n", p2);
-	free(p2);
-	p2 = malloc(4096);
-	printf("p2 = 0x%x\n", p2);
-	free(p2);
-
-	free(p1);
-}
-
-static void test_efault(void) {
-	const char *str = "o, 16 characters";
-	char str2[16];
-	char *invalid = (void*)0x1000;
-	handle_t h;
-
-	memcpy(str2, str, 16);
-
-	assert((h = _syscall_open(tmpfilepath, strlen(tmpfilepath), OPEN_CREATE)));
-	assert(_syscall_write(h, str, 16, 0) == 16);
-	assert(_syscall_write(h, str2, 16, 0) == 16);
-
-	assert(_syscall_write(h, invalid, 16, 0) == -EFAULT);
-
-	/* x64 canonical pointers */
-	assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x8000000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x1000000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0100000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0010000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0001000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0000800000000000), 16, 0) == -EFAULT);
-
-	assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x8000000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x1000000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0100000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0010000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0001000000000000), 16, 0) == -EFAULT);
-	assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0000800000000000), 16, 0) == -EFAULT);
-
-	assert(_syscall_write(h, str, 16, 0) == 16);
-	close(h);
-}
-
-static void test_execbuf(void) {
-	// not really a test, TODO
-	const char str1[] = "test_execbuf: string 1\n";
-	const char str2[] = "test_execbuf: and 2\n";
-	uint64_t buf[] = {
-		EXECBUF_SYSCALL, _SYSCALL_WRITE, 1, (uintptr_t)str1, sizeof(str1) - 1, -1,
-		EXECBUF_SYSCALL, _SYSCALL_WRITE, 1, (uintptr_t)str2, sizeof(str2) - 1, -1,
-		EXECBUF_SYSCALL, _SYSCALL_EXIT, 0, 0, 0, 0,
-	};
-	_syscall_execbuf(buf, sizeof buf);
-	test_fail();
-}
-
-static void test_misc(void) {
-	assert(_syscall(~0, 0, 0, 0, 0) < 0); /* try making an invalid syscall */
-}
-
-
-void test_all(void) {
-	run_forked(test_await);
-	run_forked(test_faults);
-	run_forked(test_interrupted_fs);
-	run_forked(test_orphaned_fs);
-	run_forked(test_memflag);
-	run_forked(test_dup);
-	run_forked(test_malloc);
-	run_forked(test_pipe);
-	run_forked(test_semaphore);
-	run_forked(test_efault);
-	run_forked(test_execbuf);
-	run_forked(test_misc);
-}
diff --git a/src/user/app/init/tests/pipe.c b/src/user/app/init/tests/pipe.c
deleted file mode 100644
index d6e954a..0000000
--- a/src/user/app/init/tests/pipe.c
+++ /dev/null
@@ -1,117 +0,0 @@
-#define TEST_MACROS
-#include "tests.h"
-#include <camellia/flags.h>
-#include <camellia/syscalls.h>
-#include <string.h>
-#include <unistd.h>
-
-static const char *pipe_msgs[2] = {"hello", "world"};
-
-void test_pipe(void) {
-	handle_t ends[2];
-	char buf[16];
-	int ret;
-
-	/* test regular reads / writes */
-	assert(_syscall_pipe(ends, 0) >= 0);
-	if (!fork()) {
-		/* those repeated asserts ensure that you can't read/write to the wrong ends */
-		assert(_syscall_read(ends[1], buf, 16, 0) < 0);
-		assert(_syscall_write(ends[0], buf, 16, 0) < 0);
-
-		ret = _syscall_write(ends[1], pipe_msgs[0], 5, -1);
-		assert(ret == 5);
-
-		assert(_syscall_read(ends[1], buf, 16, 0) < 0);
-		assert(_syscall_write(ends[0], buf, 16, 0) < 0);
-
-		ret = _syscall_write(ends[1], pipe_msgs[1], 5, -1);
-		assert(ret == 5);
-
-		exit(0);
-	} else {
-		assert(_syscall_read(ends[1], buf, 16, 0) < 0);
-		assert(_syscall_write(ends[0], buf, 16, 0) < 0);
-
-		ret = _syscall_read(ends[0], buf, 16, 0);
-		assert(ret == 5);
-		assert(!memcmp(buf, pipe_msgs[0], 5));
-
-		assert(_syscall_read(ends[1], buf, 16, 0) < 0);
-		assert(_syscall_write(ends[0], buf, 16, 0) < 0);
-
-		_syscall_read(ends[0], buf, 16, 0);
-		assert(ret == 5);
-		assert(!memcmp(buf, pipe_msgs[1], 5));
-
-		_syscall_await();
-	}
-	close(ends[0]);
-	close(ends[1]);
-
-
-	/* writing to pipes with one end closed */
-	assert(_syscall_pipe(ends, 0) >= 0);
-	for (int i = 0; i < 16; i++) {
-		if (!fork()) {
-			close(ends[1]);
-			assert(_syscall_read(ends[0], buf, 16, 0) < 0);
-			exit(0);
-		}
-	}
-	close(ends[1]);
-	for (int i = 0; i < 16; i++)
-		_syscall_await();
-	close(ends[0]);
-
-	assert(_syscall_pipe(ends, 0) >= 0);
-	for (int i = 0; i < 16; i++) {
-		if (!fork()) {
-			close(ends[0]);
-			assert(_syscall_write(ends[1], buf, 16, 0) < 0);
-			exit(0);
-		}
-	}
-	close(ends[0]);
-	for (int i = 0; i < 16; i++)
-		_syscall_await();
-	close(ends[1]);
-
-
-	/* queueing */
-	assert(_syscall_pipe(ends, 0) >= 0);
-	for (int i = 0; i < 16; i++) {
-		if (!fork()) {
-			assert(_syscall_write(ends[1], pipe_msgs[0], 5, -1) == 5);
-			exit(0);
-		}
-	}
-	close(ends[1]);
-	for (int i = 0; i < 16; i++) {
-		assert(_syscall_read(ends[0], buf, sizeof buf, 0) == 5);
-		_syscall_await();
-	}
-	assert(_syscall_read(ends[0], buf, sizeof buf, 0) < 0);
-	close(ends[0]);
-
-	assert(_syscall_pipe(ends, 0) >= 0);
-	for (int i = 0; i < 16; i++) {
-		if (!fork()) {
-			memset(buf, 0, sizeof buf);
-			assert(_syscall_read(ends[0], buf, 5, -1) == 5);
-			assert(!memcmp(buf, pipe_msgs[1], 5));
-			exit(0);
-		}
-	}
-	close(ends[0]);
-	for (int i = 0; i < 16; i++) {
-		assert(_syscall_write(ends[1], pipe_msgs[1], 5, -1) == 5);
-		_syscall_await();
-	}
-	assert(_syscall_write(ends[1], pipe_msgs[1], 5, -1) < 0);
-	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.
-}
diff --git a/src/user/app/init/tests/semaphore.c b/src/user/app/init/tests/semaphore.c
deleted file mode 100644
index e05f2f9..0000000
--- a/src/user/app/init/tests/semaphore.c
+++ /dev/null
@@ -1,91 +0,0 @@
-#define TEST_MACROS
-#include "tests.h"
-#include <camellia/flags.h>
-#include <camellia/syscalls.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <user/lib/esemaphore.h>
-
-static void odd(handle_t out, struct evil_sem *sem1, struct evil_sem *sem2) {
-	_syscall_write(out, "1", 1, -1);
-	esem_signal(sem1);
-
-	esem_wait(sem2);
-	_syscall_write(out, "3", 1, -1);
-	esem_signal(sem1);
-
-	esem_wait(sem2);
-	_syscall_write(out, "5", 1, -1);
-	esem_signal(sem1);
-}
-
-static void even(handle_t out, struct evil_sem *sem1, struct evil_sem *sem2) {
-	esem_wait(sem1);
-	_syscall_write(out, "2", 1, -1);
-	esem_signal(sem2);
-
-	esem_wait(sem1);
-	_syscall_write(out, "4", 1, -1);
-	esem_signal(sem2);
-
-	esem_wait(sem1);
-	_syscall_write(out, "6", 1, -1);
-	esem_signal(sem2);
-}
-
-void test_semaphore(void) {
-	struct evil_sem *sem1, *sem2;
-	handle_t pipe[2];
-	assert(_syscall_pipe(pipe, 0) >= 0);
-
-	if (!fork()) {
-		sem1 = esem_new(0);
-		sem2 = esem_new(0);
-		assert(sem1 && sem2);
-		if (!fork()) {
-			odd(pipe[1], sem1, sem2);
-			exit(69);
-		} else {
-			even(pipe[1], sem1, sem2);
-			assert(_syscall_await() == 69);
-		}
-		esem_free(sem1);
-		esem_free(sem2);
-
-		_syscall_write(pipe[1], "|", 1, -1);
-
-		sem1 = esem_new(0);
-		sem2 = esem_new(0);
-		assert(sem1 && sem2);
-		if (!fork()) {
-			even(pipe[1], sem1, sem2);
-			exit(69);
-		} else {
-			odd(pipe[1], sem1, sem2);
-			assert(_syscall_await() == 69);
-			_syscall_await();
-		}
-		esem_free(sem1);
-		esem_free(sem2);
-
-		exit(0);
-	} else {
-		close(pipe[1]);
-
-		char buf[16];
-		size_t pos = 0;
-		for (;;) {
-			int ret = _syscall_read(pipe[0], buf + pos, sizeof(buf) - pos, 0);
-			if (ret < 0) break;
-			pos += ret;
-		}
-		buf[pos] = '\0'; // idc about the "potential" overflow
-		if (strcmp(buf, "123456|123456")) {
-			printf("%s\n", buf);
-			test_fail();
-		}
-
-		_syscall_await();
-	}
-}
diff --git a/src/user/app/init/tests/stress.c b/src/user/app/init/tests/stress.c
deleted file mode 100644
index 9be88d7..0000000
--- a/src/user/app/init/tests/stress.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#define TEST_MACROS
-#include "tests.h"
-#include <camellia/flags.h>
-#include <camellia/syscalls.h>
-#include <unistd.h>
-
-static void run_forked(void (*fn)()) {
-	if (!fork()) {
-		fn();
-		exit(0);
-	} else {
-		/* successful tests must return 0
-		 * TODO add a better fail msg */
-		if (_syscall_await() != 0) test_fail();
-	}
-}
-
-
-static void stress_fork(void) {
-	for (size_t i = 0; i < 2048; i++) {
-		if (!fork()) exit(0);
-		_syscall_await();
-	}
-}
-
-void stress_all(void) {
-	run_forked(stress_fork);
-}
diff --git a/src/user/app/init/tests/tests.h b/src/user/app/init/tests/tests.h
deleted file mode 100644
index 39294eb..0000000
--- a/src/user/app/init/tests/tests.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-#include <camellia/syscalls.h>
-#include <stdio.h>
-
-void stress_all(void);
-void test_all(void);
-
-void test_pipe(void);
-void test_semaphore(void);
-
-#ifdef TEST_MACROS
-
-#define argify(str) str, sizeof(str) - 1
-#define test_fail() do { \
-	printf("\033[31m" "TEST FAILED: %s:%xh\n" "\033[0m", __func__, __LINE__); \
-	exit(0); \
-} while (0)
-#define assert(cond) if (!(cond)) test_fail();
-
-#endif
-- 
cgit v1.2.3