adjust wait tests to test for pid and return value

This commit is contained in:
Emil Tsalapatis 2023-10-03 00:28:38 -04:00
parent 32cd3ba42b
commit 462a92cf1a
3 changed files with 71 additions and 23 deletions

View File

@ -1,26 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Castor Only
#include <sys/wait.h>
#include <syscall.h>
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;

View File

@ -1,28 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Castor Only
#include <sys/wait.h>
#include <syscall.h>
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]);
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]);
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;
}

View File

@ -1,24 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Castor Only
#include <sys/wait.h>
#include <syscall.h>
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;