From 462a92cf1a26a4bc576ef163de308be4ab249c2c Mon Sep 17 00:00:00 2001 From: Emil Tsalapatis Date: Tue, 3 Oct 2023 00:28:38 -0400 Subject: [PATCH] adjust wait tests to test for pid and return value --- tests/spawnanytest.c | 25 +++++++++++++++++++------ tests/spawnmultipletest.c | 35 ++++++++++++++++++++++++++--------- tests/spawnsingletest.c | 34 ++++++++++++++++++++++++++-------- 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/tests/spawnanytest.c b/tests/spawnanytest.c index 1e78719..af8d1f9 100644 --- a/tests/spawnanytest.c +++ b/tests/spawnanytest.c @@ -1,26 +1,39 @@ - #include #include #include #include // Castor Only +#include #include int main(int argc, const char *argv[]) { - int status[10]; + char *program; + int pid[10]; + int status; printf("Spawn parallel test wait any: "); for (int i = 0; i < 10; i++) { - status[i] = OSSpawn("/bin/echo", &argv[0]); - printf("spawn: %lx\n", status[i]); + program = (i % 2) ? "/bin/false" : "/bin/true"; + pid[i] = OSSpawn(program, &argv[0]); + printf("spawn: %lx\n", pid[i]); } + for (int i = 0; i < 10; i++) { - status[i] = OSWait(0); - printf("wait: %lx\n", status[i]); + wait(&status); + if (!WIFEXITED(status)) { + printf("wait: process did not exit\n"); + return 0; + } + + if (WEXITSTATUS(status) != (i % 2)) { + printf("wait: unexpected return %lx\n", status); + return 0; + } } + printf("Success!\n"); return 0; diff --git a/tests/spawnmultipletest.c b/tests/spawnmultipletest.c index bc6888c..8ac5da5 100644 --- a/tests/spawnmultipletest.c +++ b/tests/spawnmultipletest.c @@ -1,28 +1,45 @@ - #include #include #include #include // Castor Only +#include #include int main(int argc, const char *argv[]) { - int status[10]; + int origpid[10], pid[10]; + char *program; + int status; printf("Spawn parallel test wait any: "); - for (int i = 0; i < 10; i++) { - status[i] = OSSpawn("/bin/echo", &argv[0]); - printf("spawn: %lx\n", status[i]); + for (int i = 0; i < 10; i ++) { + program = (i % 2) ? "/bin/false" : "/bin/true"; + origpid[i] = OSSpawn(program, &argv[0]); + printf("spawn: %lx\n", pid[i]); } - for (int i = 0; i < 10; i++) { - status[i] = OSWait(status[i]); - printf("wait: %lx\n", status[i]); + + for (int i = 0; i < 10; i ++) { + pid[i] = wait(&status); + if (!WIFEXITED(status)) { + printf("wait: process did not exit\n"); + return 0; + } + + if (pid[i] != origpid[i]) { + printf("wait: expected pid %d found %d\n", origpid, pid); + return 0; + } + + if (WEXITSTATUS(status) != (i % 2)) { + printf("wait: unexpected return %lx\n", status); + return 0; + } } + printf("Success!\n"); return 0; } - diff --git a/tests/spawnsingletest.c b/tests/spawnsingletest.c index 01f5938..f4dc097 100644 --- a/tests/spawnsingletest.c +++ b/tests/spawnsingletest.c @@ -1,24 +1,42 @@ - #include #include #include #include // Castor Only +#include #include int main(int argc, const char *argv[]) { - int status[10]; + int origpid, pid; + char *program; + int status; - printf("Spawn test: "); - for (int i = 0; i < 100; i++) { - status[0] = OSSpawn("/bin/echo", &argv[0]); - printf("spawn: %lx\n", status[0]); - status[0] = OSWait(status[0]); - printf("wait: %lx\n", status[0]); + printf("Spawn parallel test wait any: "); + for (int i = 0; i < 10; i ++) { + program = (i % 2) ? "/bin/false" : "/bin/true"; + origpid = OSSpawn(program, &argv[0]); + printf("spawn: %lx\n", origpid); + + pid = wait(&status); + if (!WIFEXITED(status)) { + printf("wait: process did not exit\n"); + return 0; + } + + if (pid != origpid) { + printf("wait: expected pid %d found %d\n", origpid, pid); + return 0; + } + + if (WEXITSTATUS(status) != (i % 2)) { + printf("wait: unexpected return %lx\n", status); + return 0; + } } + printf("Success!\n"); return 0;