Commit 2e070f11 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Cyrill Gorcunov

zdtm: Test for zombie tasks

Test that 2 different exit()-ed zombies and 2 killed with different
signals are handled properly.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 5c2083ee
...@@ -23,6 +23,7 @@ $ZP/streaming/pipe_loop00 ...@@ -23,6 +23,7 @@ $ZP/streaming/pipe_loop00
$ZP/streaming/pipe_shared00 $ZP/streaming/pipe_shared00
$ZP/transition/file_read $ZP/transition/file_read
$ZP/transition/fork $ZP/transition/fork
$ZP/static/zombie00
$ZP/static/socket_listen" $ZP/static/socket_listen"
CRTOOLS=`pwd`/`dirname $0`/../crtools CRTOOLS=`pwd`/`dirname $0`/../crtools
......
...@@ -11,40 +11,85 @@ ...@@ -11,40 +11,85 @@
const char *test_doc = "See if we can wait() for a zombified child after migration"; const char *test_doc = "See if we can wait() for a zombified child after migration";
const char *test_author = "Roman Kagan <rkagan@parallels.com>"; const char *test_author = "Roman Kagan <rkagan@parallels.com>";
struct zombie {
int pid;
int exited;
int exitcode;
};
#define NR_ZOMBIES 4
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
int ret; int i, status;
pid_t pid; struct zombie zombie[NR_ZOMBIES];
zombie[0].exited = 1;
zombie[0].exitcode = 0;
zombie[1].exited = 1;
zombie[1].exitcode = 3;
zombie[2].exited = 0;
zombie[2].exitcode = SIGKILL;
zombie[3].exited = 0;
zombie[3].exitcode = SIGSEGV;
test_init(argc, argv); test_init(argc, argv);
pid = fork(); for (i = 0; i < NR_ZOMBIES; i++) {
if (pid < 0) { zombie[i].pid = fork();
err("fork failed: %m\n"); if (zombie[i].pid < 0) {
exit(1); err("Fork failed %m\n");
} exit(1);
}
if (pid == 0) if (zombie[i].pid == 0) {
_exit(0); if (zombie[i].exited)
_exit(zombie[i].exitcode);
else if (zombie[i].exitcode == SIGSEGV)
*(int *)NULL = 0;
else
kill(getpid(), zombie[i].exitcode);
test_daemon(); _exit(13); /* just in case */
test_waitsig(); }
if (wait(&ret) != pid) { test_msg("kid %d will %d/%d\n", zombie[i].pid,
fail("wait() returned wrong pid: %m\n"); zombie[i].exited, zombie[i].exitcode);
exit(1);
} }
if (WIFEXITED(ret)) { test_daemon();
ret = WEXITSTATUS(ret); test_waitsig();
if (ret) {
fail("child exited with nonzero code %d (%s)\n", ret, strerror(ret)); for (i = 0; i < NR_ZOMBIES; i++) {
if (waitpid(zombie[i].pid, &status, 0) != zombie[i].pid) {
fail("Exit with wrong pid\n");
exit(1); exit(1);
} }
}
if (WIFSIGNALED(ret)) { if (zombie[i].exited) {
fail("child exited on unexpected signal %d\n", WTERMSIG(ret)); if (!WIFEXITED(status)) {
exit(1); fail("Not exited, but should (%d)\n", zombie[i].pid);
exit(1);
}
if (WEXITSTATUS(status) != zombie[i].exitcode) {
fail("Exit with wrong status (%d)\n", zombie[i].pid);
exit(1);
}
} else {
if (!WIFSIGNALED(status)) {
fail("Not killed, but should (%d)\n", zombie[i].pid);
exit(1);
}
if (WTERMSIG(status) != zombie[i].exitcode) {
fail("Killed with wrong signal (%d)\n", zombie[i].pid);
exit(1);
}
}
} }
pass(); pass();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment