mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +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:
committed by
Cyrill Gorcunov
parent
5c2083ee87
commit
2e070f114c
@@ -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 @@
|
|||||||
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);
|
||||||
|
|
||||||
|
_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_daemon();
|
||||||
test_waitsig();
|
test_waitsig();
|
||||||
|
|
||||||
if (wait(&ret) != pid) {
|
for (i = 0; i < NR_ZOMBIES; i++) {
|
||||||
fail("wait() returned wrong pid: %m\n");
|
if (waitpid(zombie[i].pid, &status, 0) != zombie[i].pid) {
|
||||||
exit(1);
|
fail("Exit with wrong pid\n");
|
||||||
}
|
|
||||||
|
|
||||||
if (WIFEXITED(ret)) {
|
|
||||||
ret = WEXITSTATUS(ret);
|
|
||||||
if (ret) {
|
|
||||||
fail("child exited with nonzero code %d (%s)\n", ret, strerror(ret));
|
|
||||||
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();
|
||||||
|
Reference in New Issue
Block a user