aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-26 18:51:10 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-26 18:51:10 +0300
commitb25156373cd89792b1c457b77699bb7f9beb430d (patch)
tree56816903fcedc9fe35786b9baf43499d4ec3d19f /tests
parent260fc4c790ca25ee1ffab4edd9c6488d3bcb441c (diff)
downloadkmi-b25156373cd89792b1c457b77699bb7f9beb430d.tar.gz
kmi-b25156373cd89792b1c457b77699bb7f9beb430d.zip
improve killing processes/threads, test
+ Remove sys_kill() as we should be using a two-stage process where a thread is first orphaned by sys_detach(), and then the thread itself calls sys_exit() after it has done all necessary cleanup in init.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/test.h10
-rw-r--r--tests/detach/init.c52
-rw-r--r--tests/detach/source.mk2
3 files changed, 56 insertions, 8 deletions
diff --git a/tests/common/test.h b/tests/common/test.h
index 18ac388..0b53b52 100644
--- a/tests/common/test.h
+++ b/tests/common/test.h
@@ -249,12 +249,6 @@ static inline id_t sys_spawn(uintptr_t bin, uintptr_t interp)
return r.s;
}
-static inline enum sys_status sys_kill(id_t pid)
-{
- struct sys_ret r = syscall1(SYS_KILL, pid);
- return r.s;
-}
-
static inline enum sys_status sys_swap(id_t tid)
{
struct sys_ret r = syscall1(SYS_SWAP, tid);
@@ -323,9 +317,9 @@ static inline enum sys_status sys_detach(id_t tid)
return r.s;
}
-static inline enum sys_status sys_exit()
+static inline enum sys_status sys_exit(id_t tid)
{
- struct sys_ret r = syscall0(SYS_EXIT);
+ struct sys_ret r = syscall1(SYS_EXIT, tid);
return r.s;
}
diff --git a/tests/detach/init.c b/tests/detach/init.c
new file mode 100644
index 0000000..d3f282e
--- /dev/null
+++ b/tests/detach/init.c
@@ -0,0 +1,52 @@
+#include <common/test.h>
+
+START(pid, tid, d0, d1, d2, d3)
+{
+ UNUSED(pid);
+ UNUSED(tid);
+ UNUSED(d1);
+ UNUSED(d2);
+ UNUSED(d3);
+
+ if (d0 == SYS_USER_SPAWNED) {
+ size_t prev_ram = sys_conf_get(CONF_RAM_USAGE, 0);
+ printf("ram usage before new process: %zx\n", prev_ram);
+
+ printf("forking\n");
+ id_t our_tid = 0;
+ id_t new_id = sys_fork(&our_tid);
+ check(new_id > 0, "error from fork\n");
+
+ /* not in general but in this case */
+ check(new_id != 0, "in child, should never be in child\n");
+
+ printf("checking detach of nonsense id\n");
+ enum sys_status r = sys_detach(200);
+ check(r != OK, "nonsense id succeeded?\n");
+
+ printf("detaching child\n");
+ r = sys_detach(new_id);
+ check(r == OK, "detaching child failed\n");
+
+ printf("swapping to detached/orphaned thread\n");
+ r = sys_swap(new_id);
+ check(r == OK, "swapping to detached thread failed\n");
+
+ size_t new_ram = sys_conf_get(CONF_RAM_USAGE, 0);
+ printf("ram usage after new process: %zx\n", new_ram);
+
+ check(new_ram == prev_ram, "fork/detach leaked memory\n");
+ ok();
+ }
+ else if (d0 == SYS_USER_ORPHANED) {
+ printf("exiting with nonsense swap id\n");
+ enum sys_status r = sys_exit(200);
+ check(r != OK, "nonsense exit succeeded (but returned...?)\n");
+
+ printf("exiting with sensible swap id\n");
+ r = sys_exit(1);
+ check(0, "exit with sensible id returned\n");
+ }
+
+ check(0, "missed SYS_USER_ORPHANED\n");
+}
diff --git a/tests/detach/source.mk b/tests/detach/source.mk
new file mode 100644
index 0000000..843562f
--- /dev/null
+++ b/tests/detach/source.mk
@@ -0,0 +1,2 @@
+DO != ./scripts/gen-prog -n detach -p init init.c
+DO != ./scripts/gen-simple -n detach -p init