From f139fff6ae7063c1965fa3085bb2585d7d838d72 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 30 Oct 2024 13:34:18 +0200 Subject: rpc actually marks and unmarks stack regions + Processes won't be able to read previous stack frames etc --- tests/Makefile | 4 ++++ tests/create-exhaustion/source.mk | 3 +-- tests/create/source.mk | 3 +-- tests/detach/source.mk | 3 +-- tests/fork-exhaustion/source.mk | 3 +-- tests/fork/source.mk | 3 +-- tests/hello-world/source.mk | 3 +-- tests/ipc-notify/source.mk | 3 +-- tests/ipc-req/init.c | 28 +++++++++++++++++----------- tests/ipc-req/source.mk | 3 +-- tests/malloc/source.mk | 3 +-- tests/noop/source.mk | 3 +-- tests/scripts/gen-simple | 4 +++- tests/scripts/gen-tests | 29 +++++++++++++++++++++++++++++ 14 files changed, 63 insertions(+), 32 deletions(-) create mode 100755 tests/scripts/gen-tests (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 0a662f7..105b9bb 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -6,8 +6,12 @@ check: SOURCES != echo */source.mk DO != echo -n > tests.mk + +TESTS := include $(SOURCES) +DO != ./scripts/gen-tests $(TESTS) + RM ?= rm .PHONY: clean diff --git a/tests/create-exhaustion/source.mk b/tests/create-exhaustion/source.mk index d096746..5b90073 100644 --- a/tests/create-exhaustion/source.mk +++ b/tests/create-exhaustion/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n create-exhaustion -p init init.c -DO != ./scripts/gen-simple -n create-exhaustion -p init +TESTS += create-exhaustion diff --git a/tests/create/source.mk b/tests/create/source.mk index b9f8efe..7aa5eb7 100644 --- a/tests/create/source.mk +++ b/tests/create/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n create -p init init.c -DO != ./scripts/gen-simple -n create -p init +TESTS += create diff --git a/tests/detach/source.mk b/tests/detach/source.mk index 843562f..c248759 100644 --- a/tests/detach/source.mk +++ b/tests/detach/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n detach -p init init.c -DO != ./scripts/gen-simple -n detach -p init +TESTS += detach diff --git a/tests/fork-exhaustion/source.mk b/tests/fork-exhaustion/source.mk index 458973d..7dc7d36 100644 --- a/tests/fork-exhaustion/source.mk +++ b/tests/fork-exhaustion/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n fork-exhaustion -p init init.c -DO != ./scripts/gen-simple -n fork-exhaustion -p init +TESTS += fork-exhaustion diff --git a/tests/fork/source.mk b/tests/fork/source.mk index 47572e6..e78d467 100644 --- a/tests/fork/source.mk +++ b/tests/fork/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n fork -p init init.c -DO != ./scripts/gen-simple -n fork -p init +TEST += fork diff --git a/tests/hello-world/source.mk b/tests/hello-world/source.mk index 5fd60ff..a24092c 100644 --- a/tests/hello-world/source.mk +++ b/tests/hello-world/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n hello-world -p init init.c -DO != ./scripts/gen-simple -n hello-world -p init +TESTS += hello-world diff --git a/tests/ipc-notify/source.mk b/tests/ipc-notify/source.mk index e154996..635d335 100644 --- a/tests/ipc-notify/source.mk +++ b/tests/ipc-notify/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n ipc-notify -p init init.c -DO != ./scripts/gen-simple -n ipc-notify -p init +TESTS += ipc-notify diff --git a/tests/ipc-req/init.c b/tests/ipc-req/init.c index 3439335..90e04a7 100644 --- a/tests/ipc-req/init.c +++ b/tests/ipc-req/init.c @@ -4,19 +4,25 @@ START(pid, tid, d0, d1, d2, d3) { check(pid == 0 || pid == 1, "illegal pid for init"); if (pid == 0) { - /* send request to ourselves */ - printf("sending ipc req to ourselves\n"); - struct sys_ret r = sys_ipc_req4(1, 1, 2, 3, 4); - printf("returned ipc req to ourselves\n"); - check(r.s == OK, "not OK return\n"); - check(r.id == 1, "not OK response ID\n"); - check(r.a0 == 1, "not OK d0 response\n"); - check(r.a1 == 2, "not OK d1 response\n"); - check(r.a2 == 3, "not OK d2 response\n"); - check(r.a3 == 4, "not OK d3 response\n"); + printf("doing nonsense response\n"); + enum sys_status s = sys_ipc_resp0(); + check(s != OK, "OK return?\n"); + + for (size_t i = 0; i < 3; ++i) { + printf("sending ipc req %zd to ourselves\n", i); + struct sys_ret r = sys_ipc_req4(1, 1, 2, 3, 4); + + printf("returned ipc req to ourselves\n"); + check(r.s == OK, "not OK return\n"); + check(r.id == 1, "not OK response ID\n"); + check(r.a0 == 1, "not OK d0 response\n"); + check(r.a1 == 2, "not OK d1 response\n"); + check(r.a2 == 3, "not OK d2 response\n"); + check(r.a3 == 4, "not OK d3 response\n"); + } /* try to request to non-existing proc */ - r = sys_ipc_req0(200); + struct sys_ret r = sys_ipc_req0(200); check(r.s != OK, "got OK return for illegal pid\n"); } else if (pid == 1) { diff --git a/tests/ipc-req/source.mk b/tests/ipc-req/source.mk index 0e65407..4b77d99 100644 --- a/tests/ipc-req/source.mk +++ b/tests/ipc-req/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n ipc-req -p init init.c -DO != ./scripts/gen-simple -n ipc-req -p init +TESTS += ipc-req diff --git a/tests/malloc/source.mk b/tests/malloc/source.mk index 9498682..01b4d6e 100644 --- a/tests/malloc/source.mk +++ b/tests/malloc/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n malloc -p init init.c -DO != ./scripts/gen-simple -n malloc -p init +TESTS += malloc diff --git a/tests/noop/source.mk b/tests/noop/source.mk index cbb87b7..0663967 100644 --- a/tests/noop/source.mk +++ b/tests/noop/source.mk @@ -1,2 +1 @@ -DO != ./scripts/gen-prog -n noop -p init init.c -DO != ./scripts/gen-simple -n noop -p init +TESTS += noop diff --git a/tests/scripts/gen-simple b/tests/scripts/gen-simple index 418cc02..a942fb3 100755 --- a/tests/scripts/gen-simple +++ b/tests/scripts/gen-simple @@ -28,8 +28,10 @@ echo " timeout --foreground 30s \$(QEMU) \ echo "TESTS += $NAME" >> tests.mk echo ".PHONY: $NAME" >> tests.mk -echo "$NAME: reports/$NAME/log" >> tests.mk +echo "reports/$NAME/OK: reports/$NAME/log" >> tests.mk echo " grep 'BUG' reports/$NAME/log \\" >> tests.mk echo " && echo 'BUG' > reports/$NAME/log \\" >> tests.mk echo " || tail -n1 reports/$NAME/log | tr -d '\\\\r' \\" >> tests.mk echo " > reports/$NAME/OK" >> tests.mk + +echo "$NAME: reports/$NAME/OK" >> tests.mk diff --git a/tests/scripts/gen-tests b/tests/scripts/gen-tests new file mode 100755 index 0000000..7095e30 --- /dev/null +++ b/tests/scripts/gen-tests @@ -0,0 +1,29 @@ +#!/bin/sh + +mkdir -p $(for d in "${@}"; do echo $d; done | sed "s|^|build/|") +mkdir -p $(for d in "${@}"; do echo $d; done | sed "s|^|reports/|") + +for NAME in "${@}"; do + echo "build/$NAME/init.d:" >> tests.mk + echo "-include build/$NAME/init.d" >> tests.mk + + echo "build/$NAME/init: $NAME/init.c \$(COMMON) \$(KMI)" >> tests.mk + echo " \$(COMPILE_TEST) $NAME/init.c \$(COMMON) -o build/$NAME/init" >> tests.mk + + echo "build/$NAME/initrd: build/$NAME/init" >> tests.mk + echo " echo build/$NAME/init | \$(GEN_INITRD) build/$NAME/initrd" >> tests.mk + + echo "reports/$NAME/log: build/$NAME/initrd" >> tests.mk + echo " timeout --foreground 30s \$(QEMU) \ + build/$NAME/initrd > reports/$NAME/log" >> tests.mk + + echo "reports/$NAME/OK: reports/$NAME/log" >> tests.mk + echo " grep 'BUG' reports/$NAME/log \\" >> tests.mk + echo " && echo 'BUG' > reports/$NAME/log \\" >> tests.mk + echo " || tail -n1 reports/$NAME/log | tr -d '\\\\r' \\" >> tests.mk + echo " > reports/$NAME/OK" >> tests.mk + + echo "TESTS += $NAME" >> tests.mk + echo ".PHONY: $NAME" >> tests.mk + echo "$NAME: reports/$NAME/OK" >> tests.mk +done -- cgit v1.3