diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-11-02 16:02:41 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-11-02 16:02:41 +0200 |
| commit | 21efbba39340300a7ba9d5f4f94017f5ff956833 (patch) | |
| tree | c9116d4e38a574a8edae7cdcebcd7569af9cb5a7 /tests | |
| parent | d127146846f4d6561e15000d1469b715dafdb627 (diff) | |
| download | kmi-21efbba39340300a7ba9d5f4f94017f5ff956833.tar.gz kmi-21efbba39340300a7ba9d5f4f94017f5ff956833.zip | |
intial working sys_spawn
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/common/sys.h | 2 | ||||
| -rw-r--r-- | tests/spawn/init.c | 34 | ||||
| -rw-r--r-- | tests/spawn/source.mk | 1 | ||||
| -rw-r--r-- | tests/spawn/spawn.c | 18 |
4 files changed, 54 insertions, 1 deletions
diff --git a/tests/common/sys.h b/tests/common/sys.h index 3e98abf..0bee8bd 100644 --- a/tests/common/sys.h +++ b/tests/common/sys.h @@ -240,7 +240,7 @@ static inline enum sys_status sys_exec(uintptr_t bin, uintptr_t interp) /* negative IDs mean errors */ static inline id_t sys_spawn(uintptr_t bin, uintptr_t interp) { - struct sys_ret r = syscall2(SYS_EXEC, bin, interp); + struct sys_ret r = syscall2(SYS_SPAWN, bin, interp); return r.s; } diff --git a/tests/spawn/init.c b/tests/spawn/init.c new file mode 100644 index 0000000..8c25615 --- /dev/null +++ b/tests/spawn/init.c @@ -0,0 +1,34 @@ +#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"); + printf("finding spawn in cpio archive %lx...\n", d2); + struct cpio_header *cp = cpio_find_file((const void *)d2, + "spawn", sizeof("spawn") - 1); + + check(cp, "couldn't find spawn?\n"); + long name_len = convnum(cp->c_namesize, 8, 16); + uintptr_t spawn = (uintptr_t)(cp) + align_up(sizeof(struct cpio_header) + name_len, 4); + printf("found spawn at %lx\n", spawn); + + printf("doing spawn...\n"); + id_t new = sys_spawn(spawn, 0); + check(new > 1, "spawn failed?\n"); + + printf("giving spawn CAP_POWER\n"); + enum sys_status s = sys_set_cap(new, CAP_POWER); + check(s == OK, "CAP_POWER failed?\n"); + + printf("swapping to spawn\n"); + s = sys_swap(new); + check(s == OK, "swap to spawn failed?\n"); +} diff --git a/tests/spawn/source.mk b/tests/spawn/source.mk new file mode 100644 index 0000000..9a1f676 --- /dev/null +++ b/tests/spawn/source.mk @@ -0,0 +1 @@ +DO != ./scripts/gen-simple -n spawn -p init -p spawn diff --git a/tests/spawn/spawn.c b/tests/spawn/spawn.c new file mode 100644 index 0000000..67d64f8 --- /dev/null +++ b/tests/spawn/spawn.c @@ -0,0 +1,18 @@ +#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 spawn\n"); + check(tid == 2, "unexpected tid for spawn\n"); + check(d0 == SYS_USER_SPAWNED, "unexpected d0 for spawn\n"); + check(d1 == 2, "unexpected d1 for spawn\n"); + + printf("causing shutdown, assuming init gave us CAP_POWER\n"); + ok(); +} |
