@@ -42,7 +42,7 @@
|
||||
#include "test.h"
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_badpid(pid_t pid, const char *desc)
|
||||
{
|
||||
pid_t rv;
|
||||
@@ -59,23 +59,24 @@ wait_badpid(pid_t pid, const char *desc)
|
||||
else if (err == ENOSYS) {
|
||||
report_saw_enosys();
|
||||
}
|
||||
report_check2(rv, err, ESRCH, ECHILD);
|
||||
return report_check2(rv, err, ESRCH, ECHILD);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_nullstatus(void)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
int result;
|
||||
|
||||
report_begin("wait with NULL status");
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
@@ -83,50 +84,54 @@ wait_nullstatus(void)
|
||||
|
||||
/* POSIX explicitly says passing NULL for status is allowed */
|
||||
rv = waitpid(pid, NULL, 0);
|
||||
report_check(rv, errno, 0);
|
||||
result = report_check(rv, errno, 0);
|
||||
waitpid(pid, &x, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_badstatus(void *ptr, const char *desc)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
int result;
|
||||
|
||||
report_begin(desc);
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
rv = waitpid(pid, ptr, 0);
|
||||
report_check(rv, errno, EFAULT);
|
||||
result = report_check(rv, errno, EFAULT);
|
||||
waitpid(pid, &x, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_unaligned(void)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
int status[2]; /* will have integer alignment */
|
||||
char *ptr;
|
||||
int result;
|
||||
|
||||
report_begin("wait with unaligned status");
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
@@ -139,55 +144,61 @@ wait_unaligned(void)
|
||||
ptr++;
|
||||
|
||||
rv = waitpid(pid, (int *)ptr, 0);
|
||||
report_survival(rv, errno);
|
||||
report_survival(rv, errno, &result);
|
||||
if (rv<0) {
|
||||
waitpid(pid, &x, 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_badflags(void)
|
||||
{
|
||||
pid_t pid, rv;
|
||||
int x;
|
||||
int result;
|
||||
|
||||
report_begin("wait with bad flags");
|
||||
|
||||
pid = fork();
|
||||
if (pid<0) {
|
||||
report_warn("fork failed");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
if (pid==0) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
rv = waitpid(pid, &x, 309429);
|
||||
report_check(rv, errno, EINVAL);
|
||||
result = report_check(rv, errno, EINVAL);
|
||||
waitpid(pid, &x, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_self(void)
|
||||
{
|
||||
pid_t rv;
|
||||
int x;
|
||||
int result;
|
||||
|
||||
report_begin("wait for self");
|
||||
|
||||
rv = waitpid(getpid(), &x, 0);
|
||||
report_survival(rv, errno);
|
||||
report_survival(rv, errno, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_parent(void)
|
||||
{
|
||||
pid_t mypid, childpid, rv;
|
||||
int x;
|
||||
int result;
|
||||
|
||||
report_begin("wait for parent");
|
||||
report_hassubs();
|
||||
@@ -196,30 +207,32 @@ wait_parent(void)
|
||||
childpid = fork();
|
||||
if (childpid<0) {
|
||||
report_warn("can't fork");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
if (childpid==0) {
|
||||
/* Child. Wait for parent. */
|
||||
rv = waitpid(mypid, &x, 0);
|
||||
report_beginsub("from child:");
|
||||
report_survival(rv, errno);
|
||||
report_survival(rv, errno, &result);
|
||||
_exit(0);
|
||||
}
|
||||
rv = waitpid(childpid, &x, 0);
|
||||
rv = waitpid(mypid, &x, 0);
|
||||
report_beginsub("from parent:");
|
||||
report_survival(rv, errno);
|
||||
report_survival(rv, errno, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_siblings_child(const char *semname)
|
||||
{
|
||||
pid_t pids[2], mypid, otherpid;
|
||||
int rv, fd, semfd, x;
|
||||
char c;
|
||||
int result;
|
||||
|
||||
mypid = getpid();
|
||||
|
||||
@@ -244,7 +257,7 @@ wait_siblings_child(const char *semname)
|
||||
if (fd<0) {
|
||||
report_warn("child process (pid %d) can't open %s",
|
||||
mypid, TESTFILE);
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -257,13 +270,13 @@ wait_siblings_child(const char *semname)
|
||||
if (rv<0) {
|
||||
report_warn("child process (pid %d) lseek error",
|
||||
mypid);
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
rv = read(fd, pids, sizeof(pids));
|
||||
if (rv<0) {
|
||||
report_warn("child process (pid %d) read error",
|
||||
mypid);
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
} while (rv < (int)sizeof(pids));
|
||||
|
||||
@@ -276,23 +289,25 @@ wait_siblings_child(const char *semname)
|
||||
else {
|
||||
report_warn("child process (pid %d) got garbage in comm file",
|
||||
mypid);
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
rv = waitpid(otherpid, &x, 0);
|
||||
report_beginsub("sibling (pid %d)", mypid);
|
||||
report_survival(rv, errno);
|
||||
report_survival(rv, errno, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
wait_siblings(void)
|
||||
{
|
||||
pid_t pids[2];
|
||||
int rv, fd, semfd, x;
|
||||
int bad = 0;
|
||||
char semname[32];
|
||||
int result;
|
||||
|
||||
/* This test may also blow up if FS synchronization is substandard */
|
||||
|
||||
@@ -303,26 +318,26 @@ wait_siblings(void)
|
||||
semfd = open(semname, O_WRONLY|O_CREAT|O_TRUNC, 0664);
|
||||
if (semfd < 0) {
|
||||
report_warn("can't make semaphore");
|
||||
report_aborted();
|
||||
return;
|
||||
report_aborted(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
fd = open_testfile(NULL);
|
||||
if (fd<0) {
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
pids[0] = fork();
|
||||
if (pids[0]<0) {
|
||||
report_warn("can't fork");
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
if (pids[0]==0) {
|
||||
close(fd);
|
||||
@@ -334,12 +349,12 @@ wait_siblings(void)
|
||||
pids[1] = fork();
|
||||
if (pids[1]<0) {
|
||||
report_warn("can't fork");
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
/* abandon the other child process :( */
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
if (pids[1]==0) {
|
||||
close(fd);
|
||||
@@ -351,21 +366,21 @@ wait_siblings(void)
|
||||
rv = write(fd, pids, sizeof(pids));
|
||||
if (rv < 0) {
|
||||
report_warn("write error on %s", TESTFILE);
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
/* abandon child procs :( */
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
if (rv != (int)sizeof(pids)) {
|
||||
report_warnx("write error on %s: short count", TESTFILE);
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
/* abandon child procs :( */
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* gate the child procs */
|
||||
@@ -388,15 +403,17 @@ wait_siblings(void)
|
||||
}
|
||||
if (bad) {
|
||||
/* XXX: aborted, or failure, or what? */
|
||||
report_aborted();
|
||||
report_aborted(&result);
|
||||
}
|
||||
else {
|
||||
report_passed();
|
||||
report_passed(&result);
|
||||
}
|
||||
close(fd);
|
||||
close(semfd);
|
||||
remove(semname);
|
||||
remove(TESTFILE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -404,20 +421,61 @@ wait_siblings(void)
|
||||
void
|
||||
test_waitpid(void)
|
||||
{
|
||||
wait_badpid(-8, "wait for pid -8");
|
||||
wait_badpid(-1, "wait for pid -1");
|
||||
wait_badpid(0, "pid zero");
|
||||
wait_badpid(NONEXIST_PID, "nonexistent pid");
|
||||
int ntests = 0, lost_points = 0;
|
||||
int result;
|
||||
|
||||
wait_nullstatus();
|
||||
wait_badstatus(INVAL_PTR, "wait with invalid pointer status");
|
||||
wait_badstatus(KERN_PTR, "wait with kernel pointer status");
|
||||
ntests++;
|
||||
result = wait_badpid(-8, "wait for pid -8");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
wait_unaligned();
|
||||
ntests++;
|
||||
result = wait_badpid(-1, "wait for pid -1");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
wait_badflags();
|
||||
ntests++;
|
||||
result = wait_badpid(0, "pid zero");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
wait_self();
|
||||
wait_parent();
|
||||
wait_siblings();
|
||||
ntests++;
|
||||
result = wait_badpid(NONEXIST_PID, "nonexistent pid");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
|
||||
ntests++;
|
||||
result = wait_nullstatus();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = wait_badstatus(INVAL_PTR, "wait with invalid pointer status");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = wait_badstatus(KERN_PTR, "wait with kernel pointer status");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
|
||||
ntests++;
|
||||
result = wait_unaligned();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
|
||||
ntests++;
|
||||
result = wait_badflags();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
|
||||
ntests++;
|
||||
result = wait_self();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = wait_parent();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = wait_siblings();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
if(!lost_points)
|
||||
success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
|
||||
}
|
||||
|
Reference in New Issue
Block a user