2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00

zdtm: Test for zombie tasks

Test that 2 different exit()-ed zombies and 2 killed with different
signals are handled properly.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
Pavel Emelyanov
2012-01-22 20:29:15 +04:00
committed by Cyrill Gorcunov
parent 5c2083ee87
commit 2e070f114c
2 changed files with 68 additions and 22 deletions

View File

@@ -23,6 +23,7 @@ $ZP/streaming/pipe_loop00
$ZP/streaming/pipe_shared00
$ZP/transition/file_read
$ZP/transition/fork
$ZP/static/zombie00
$ZP/static/socket_listen"
CRTOOLS=`pwd`/`dirname $0`/../crtools

View File

@@ -11,40 +11,85 @@
const char *test_doc = "See if we can wait() for a zombified child after migration";
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 ret;
pid_t pid;
int i, status;
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);
pid = fork();
if (pid < 0) {
err("fork failed: %m\n");
for (i = 0; i < NR_ZOMBIES; i++) {
zombie[i].pid = fork();
if (zombie[i].pid < 0) {
err("Fork failed %m\n");
exit(1);
}
if (pid == 0)
_exit(0);
if (zombie[i].pid == 0) {
if (zombie[i].exited)
_exit(zombie[i].exitcode);
else if (zombie[i].exitcode == SIGSEGV)
*(int *)NULL = 0;
else
kill(getpid(), zombie[i].exitcode);
_exit(13); /* just in case */
}
test_msg("kid %d will %d/%d\n", zombie[i].pid,
zombie[i].exited, zombie[i].exitcode);
}
test_daemon();
test_waitsig();
if (wait(&ret) != pid) {
fail("wait() returned wrong pid: %m\n");
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);
}
if (WIFEXITED(ret)) {
ret = WEXITSTATUS(ret);
if (ret) {
fail("child exited with nonzero code %d (%s)\n", ret, strerror(ret));
if (zombie[i].exited) {
if (!WIFEXITED(status)) {
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);
}
}
if (WIFSIGNALED(ret)) {
fail("child exited on unexpected signal %d\n", WTERMSIG(ret));
exit(1);
}
pass();