aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2026-01-25 15:07:04 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2026-01-25 15:07:04 +0200
commite8a7fe3bd5c40168d531a6a4f00a7417a278d58c (patch)
treeddbbead310cd8951ea277eb4e1a13dff7d1a3dd9 /tests
parent783e615ca031045eaa979532fc2c2b762ed8593f (diff)
downloadkmi-e8a7fe3bd5c40168d531a6a4f00a7417a278d58c.tar.gz
kmi-e8a7fe3bd5c40168d531a6a4f00a7417a278d58c.zip
allow reading fdt in tests
Diffstat (limited to 'tests')
-rw-r--r--tests/common/test.h13
-rw-r--r--tests/exec/init.c2
-rw-r--r--tests/fdt/init.c29
-rw-r--r--tests/fdt/source.mk1
-rw-r--r--tests/ipc-fwd/init.c6
-rw-r--r--tests/ipc-kick/init.c6
-rw-r--r--tests/ipc-root/init.c2
-rw-r--r--tests/ipc-tail/init.c6
-rw-r--r--tests/scripts/makefile22
9 files changed, 68 insertions, 19 deletions
diff --git a/tests/common/test.h b/tests/common/test.h
index 1476fdf..f819ad8 100644
--- a/tests/common/test.h
+++ b/tests/common/test.h
@@ -8,18 +8,17 @@
#include "start.h"
#include "printf.h"
-#define error(x, ...)\
- printf("ERROR: " x, ## __VA_ARGS__)
+#define fail(x, ...)\
+ printf("FAIL: " x, ## __VA_ARGS__)
#define check(x, y, ...)\
if (!(x)) {\
- error(y, ##__VA_ARGS__);\
+ fail(y, ##__VA_ARGS__);\
sys_poweroff(SYS_SHUTDOWN);\
}
-static inline void ok() {
- printf("OK\n");
- sys_poweroff(SYS_SHUTDOWN);
-}
+#define ok()\
+ printf("OK\n");\
+ sys_poweroff(SYS_SHUTDOWN)
#endif /* KMI_TESTS_H */
diff --git a/tests/exec/init.c b/tests/exec/init.c
index d56337d..6ae46c0 100644
--- a/tests/exec/init.c
+++ b/tests/exec/init.c
@@ -29,7 +29,7 @@ START(pid, tid, d0, d1, d2, d3)
printf("doing exec...\n");
sys_exec(exec, 0);
- error("exec failed\n");
+ fail("exec failed\n");
}
printf("hello from parent\n");
diff --git a/tests/fdt/init.c b/tests/fdt/init.c
new file mode 100644
index 0000000..c6c35dd
--- /dev/null
+++ b/tests/fdt/init.c
@@ -0,0 +1,29 @@
+#include <common/test.h>
+#include <libfdt.h>
+
+START(pid, tid, d0, d1, d2, d3)
+{
+ UNUSED(d2);
+ UNUSED(d3);
+
+ check(pid == 0, "wrong src process ID");
+ check(tid == 1, "wrong root thread ID");
+ check(d0 == SYS_USER_SPAWNED, "wrong op");
+ printf("fdt at %lx\n", d1);
+
+ void *fdt = (void *)d1;
+
+ int chosen_offset = fdt_path_offset(fdt, "/chosen");
+ check(chosen_offset > 0, "couldn't find /chosen");
+
+ const char *stdout =
+ fdt_getprop(fdt, chosen_offset, "stdout-path", NULL);
+
+ check(stdout != NULL, "couldn't find stdout-path");
+
+ /* ideally we would also parse the stdout node and check that it is some
+ * reasonable value, but I'm not sure if we can trust the Qemu fdt to be
+ * stable. The above is suspicious enough I suppose */
+ printf("found stdout at: %s\n", stdout);
+ ok();
+}
diff --git a/tests/fdt/source.mk b/tests/fdt/source.mk
new file mode 100644
index 0000000..9336472
--- /dev/null
+++ b/tests/fdt/source.mk
@@ -0,0 +1 @@
+TESTS += fdt
diff --git a/tests/ipc-fwd/init.c b/tests/ipc-fwd/init.c
index 2f04f3f..ceb5927 100644
--- a/tests/ipc-fwd/init.c
+++ b/tests/ipc-fwd/init.c
@@ -40,7 +40,7 @@ START(pid, tid, d0, d1, d2, d3)
printf("pid 2 responding\n");
sys_ipc_resp4(1, 2, 3, 4);
- error("pid 2 ipc_resp failed\n");
+ fail("pid 2 ipc_resp failed\n");
}
else if (pid == 1 && d0 == 5) {
printf("pid 3 caught ipc fwd\n");
@@ -53,10 +53,10 @@ START(pid, tid, d0, d1, d2, d3)
printf("pid 3 responding\n");
sys_ipc_resp4(5, 6, 7, 8);
- error("pid 3 ipc_resp failed\n");
+ fail("pid 3 ipc_resp failed\n");
}
else {
- error("weird pid: %ld\n", pid);
+ fail("weird pid: %ld\n", pid);
}
ok();
diff --git a/tests/ipc-kick/init.c b/tests/ipc-kick/init.c
index 3be4dee..b7a50fe 100644
--- a/tests/ipc-kick/init.c
+++ b/tests/ipc-kick/init.c
@@ -31,7 +31,7 @@ START(pid, tid, d0, d1, d2, d3)
printf("pid 2 kicking\n");
sys_ipc_kick4(3, 5, 6, 7, 8);
- error("pid 2 ipc_tail failed\n");
+ fail("pid 2 ipc_tail failed\n");
}
else if (pid == 1 && d0 == 5) {
printf("pid 3 caught ipc kick\n");
@@ -44,10 +44,10 @@ START(pid, tid, d0, d1, d2, d3)
printf("pid 3 responding\n");
sys_ipc_resp4(5, 6, 7, 8);
- error("pid 3 ipc_resp failed\n");
+ fail("pid 3 ipc_resp failed\n");
}
else {
- error("weird pid: %ld\n", pid);
+ fail("weird pid: %ld\n", pid);
}
ok();
diff --git a/tests/ipc-root/init.c b/tests/ipc-root/init.c
index 8b43b4f..cb7568d 100644
--- a/tests/ipc-root/init.c
+++ b/tests/ipc-root/init.c
@@ -44,7 +44,7 @@ START(pid, tid, d0, d1, d2, d3)
printf("sending response\n");
sys_ipc_resp4(1, 2, 3, 4);
- error("ipc resp failed\n");
+ fail("ipc resp failed\n");
}
ok();
diff --git a/tests/ipc-tail/init.c b/tests/ipc-tail/init.c
index 8f3efdd..3336945 100644
--- a/tests/ipc-tail/init.c
+++ b/tests/ipc-tail/init.c
@@ -31,7 +31,7 @@ START(pid, tid, d0, d1, d2, d3)
printf("pid 2 tailing\n");
sys_ipc_tail4(3, 5, 6, 7, 8);
- error("pid 2 ipc_tail failed\n");
+ fail("pid 2 ipc_tail failed\n");
}
else if (pid == 2) {
printf("pid 3 caught ipc tail\n");
@@ -44,10 +44,10 @@ START(pid, tid, d0, d1, d2, d3)
printf("pid 3 responding\n");
sys_ipc_resp4(5, 6, 7, 8);
- error("pid 3 ipc_resp failed\n");
+ fail("pid 3 ipc_resp failed\n");
}
else {
- error("weird pid: %ld\n", pid);
+ fail("weird pid: %ld\n", pid);
}
ok();
diff --git a/tests/scripts/makefile b/tests/scripts/makefile
index 2161427..1ba7615 100644
--- a/tests/scripts/makefile
+++ b/tests/scripts/makefile
@@ -28,7 +28,27 @@ QEMU := qemu-system-$(ARCH) -machine virt -kernel ../kmi.bin \
-initrd
KMI := ../kmi.bin
-COMMON := build/printf.o build/string.o
+
+# common tools available for tests, printf/fdt/initrd handling and common memory
+# ops like memset and memcpy. Note that printf uses in-kernel printing at least
+# for now, so testsuite must be run on kernels compiled with -DDEBUG=1
+COMMON := build/printf.o \
+ build/string.o \
+ build/fdt.o \
+ build/fdt_ro.o \
+ build/bits.o
+
+# reuse some common parts from source tree. Could maybe split these into a
+# common directory to make it a bit easier to work with, but this is not too bad
+# for now
+build/bits.o: ../src/bits.c $(KMI)
+ $(COMPILE_TEST) -c ../src/bits.c -o build/bits.o
+
+build/fdt.o: ../lib/fdt.c $(KMI)
+ $(COMPILE_TEST) -c ../lib/fdt.c -o build/fdt.o
+
+build/fdt_ro.o: ../lib/fdt_ro.c $(KMI)
+ $(COMPILE_TEST) -c ../lib/fdt_ro.c -o build/fdt_ro.o
build/printf.o: common/printf.c $(KMI)
$(COMPILE_TEST) -c common/printf.c -o build/printf.o