aboutsummaryrefslogtreecommitdiff
path: root/tests/exec
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-11-02 15:28:23 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-11-02 15:28:23 +0200
commitd127146846f4d6561e15000d1469b715dafdb627 (patch)
tree2ee7d7512023df0dc25f0bd51da1c378ebb1a400 /tests/exec
parent4ce6aa975be40286465cd9ac6a669ff5a95fe5a1 (diff)
downloadkmi-d127146846f4d6561e15000d1469b715dafdb627.tar.gz
kmi-d127146846f4d6561e15000d1469b715dafdb627.zip
initial exec support
Diffstat (limited to 'tests/exec')
-rw-r--r--tests/exec/exec.c16
-rw-r--r--tests/exec/init.c38
-rw-r--r--tests/exec/source.mk1
3 files changed, 55 insertions, 0 deletions
diff --git a/tests/exec/exec.c b/tests/exec/exec.c
new file mode 100644
index 0000000..4f92b27
--- /dev/null
+++ b/tests/exec/exec.c
@@ -0,0 +1,16 @@
+#include <common/test.h>
+
+START(pid, tid, d0, d1, d2, d3)
+{
+ UNUSED(d2);
+ UNUSED(d3);
+
+ printf("pid = %ld, tid = %ld, d0 = %ld, d1 = %ld\n",
+ pid, tid, d0, d1);
+
+ check(pid == 0, "unexpected pid for exec\n");
+ check(tid == 2, "unexpected tid for exec\n");
+ check(d0 == SYS_USER_SPAWNED, "unexpected d0 for exec\n");
+ check(d1 == 2, "unexpected d1 for exec\n");
+ ok();
+}
diff --git a/tests/exec/init.c b/tests/exec/init.c
new file mode 100644
index 0000000..d56337d
--- /dev/null
+++ b/tests/exec/init.c
@@ -0,0 +1,38 @@
+#include <common/test.h>
+#include <common/cpio.h>
+
+START(pid, tid, d0, d1, d2, d3)
+{
+ UNUSED(pid);
+ UNUSED(tid);
+ UNUSED(d0);
+ UNUSED(d1);
+ UNUSED(d2);
+ UNUSED(d3);
+
+ check(pid == 0, "illegal pid for init\n");
+ id_t our_id = 0;
+ printf("forking\n");
+ id_t new_id = sys_fork(&our_id);
+ check(new_id >= 0, "error from fork\n");
+
+ if (new_id == 0) {
+ printf("hello from child with pid %ld\n", (long int)our_id);
+ printf("finding exec in cpio archive %lx...\n", d2);
+ struct cpio_header *cp = cpio_find_file((const void *)d2,
+ "exec", sizeof("exec") - 1);
+
+ check(cp, "couldn't find exec?\n");
+ long name_len = convnum(cp->c_namesize, 8, 16);
+ uintptr_t exec = (uintptr_t)(cp) + align_up(sizeof(struct cpio_header) + name_len, 4);
+ printf("found exec at %lx\n", exec);
+
+ printf("doing exec...\n");
+ sys_exec(exec, 0);
+ error("exec failed\n");
+ }
+
+ printf("hello from parent\n");
+ sys_swap(new_id);
+ check(0, "failed swapping to child\n");
+}
diff --git a/tests/exec/source.mk b/tests/exec/source.mk
new file mode 100644
index 0000000..fdd3d0e
--- /dev/null
+++ b/tests/exec/source.mk
@@ -0,0 +1 @@
+DO != ./scripts/gen-simple -n exec -p init -p exec