adjust wait tests to test for pid and return value
This commit is contained in:
parent
32cd3ba42b
commit
462a92cf1a
@ -1,26 +1,39 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
// Castor Only
|
// Castor Only
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int status[10];
|
char *program;
|
||||||
|
int pid[10];
|
||||||
|
int status;
|
||||||
|
|
||||||
printf("Spawn parallel test wait any: ");
|
printf("Spawn parallel test wait any: ");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
status[i] = OSSpawn("/bin/echo", &argv[0]);
|
program = (i % 2) ? "/bin/false" : "/bin/true";
|
||||||
printf("spawn: %lx\n", status[i]);
|
pid[i] = OSSpawn(program, &argv[0]);
|
||||||
|
printf("spawn: %lx\n", pid[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
status[i] = OSWait(0);
|
wait(&status);
|
||||||
printf("wait: %lx\n", status[i]);
|
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");
|
printf("Success!\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,28 +1,45 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
// Castor Only
|
// Castor Only
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int status[10];
|
int origpid[10], pid[10];
|
||||||
|
char *program;
|
||||||
|
int status;
|
||||||
|
|
||||||
printf("Spawn parallel test wait any: ");
|
printf("Spawn parallel test wait any: ");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i ++) {
|
||||||
status[i] = OSSpawn("/bin/echo", &argv[0]);
|
program = (i % 2) ? "/bin/false" : "/bin/true";
|
||||||
printf("spawn: %lx\n", status[i]);
|
origpid[i] = OSSpawn(program, &argv[0]);
|
||||||
|
printf("spawn: %lx\n", pid[i]);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
status[i] = OSWait(status[i]);
|
for (int i = 0; i < 10; 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");
|
printf("Success!\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,42 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
// Castor Only
|
// Castor Only
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int status[10];
|
int origpid, pid;
|
||||||
|
char *program;
|
||||||
|
int status;
|
||||||
|
|
||||||
printf("Spawn test: ");
|
printf("Spawn parallel test wait any: ");
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 10; i ++) {
|
||||||
status[0] = OSSpawn("/bin/echo", &argv[0]);
|
program = (i % 2) ? "/bin/false" : "/bin/true";
|
||||||
printf("spawn: %lx\n", status[0]);
|
origpid = OSSpawn(program, &argv[0]);
|
||||||
status[0] = OSWait(status[0]);
|
printf("spawn: %lx\n", origpid);
|
||||||
printf("wait: %lx\n", status[0]);
|
|
||||||
|
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");
|
printf("Success!\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user