From 76b8ab3500f2c47826e5dd83fc3bf252ed7e2bc8 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Thu, 28 Dec 2017 13:51:03 +0300 Subject: [PATCH] zdtm: Add zombie01 test Create a zombie with specific pgid and check that pgid remains the same after restore. This test hangs criu restore without any of two previous patches: 1)without "restore: Call prepare_fds() in restore_one_zombie()" in 100% cases; 2)without "restore: Split restore_one_helper() and wait exiting zombie children" fail is racy, but you can add something like criu/cr-restore.c: ## -1130,6 +1130,8 @@ static int restore_one_zombie(CoreEntry *core) if (task_entries != NULL) { restore_finish_stage(task_entries, CR_STATE_RESTORE); + if (current->parent->pid->state == TASK_ALIVE) + sleep(2); zombie_prepare_signals(); } and it will fail with almost 100% probability. Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- test/zdtm/static/Makefile | 1 + test/zdtm/static/zombie01.c | 80 ++++++++++++++++++++++++++++++++++ test/zdtm/static/zombie01.desc | 1 + 3 files changed, 82 insertions(+) create mode 100644 test/zdtm/static/zombie01.c create mode 100644 test/zdtm/static/zombie01.desc diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index 16ea0f042..ff2473125 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -10,6 +10,7 @@ TST_NOFILE := \ caps00 \ wait00 \ zombie00 \ + zombie01 \ fpu00 \ fpu01 \ arm-neon00 \ diff --git a/test/zdtm/static/zombie01.c b/test/zdtm/static/zombie01.c new file mode 100644 index 000000000..6e904c047 --- /dev/null +++ b/test/zdtm/static/zombie01.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Check that zombie pgid is restored"; +const char *test_author = "Kirill Tkhai "; + +int main(int argc, char **argv) +{ + pid_t pid, pgrp; + siginfo_t info; + int status; + + test_init(argc, argv); + + pid = fork(); + if (pid < 0) { + fail("fork"); + exit(1); + } + + if (!pid) { + /* Child */ + if (setpgid(0, 0) < 0) { + fail("setpgid"); + exit(1); + } + pid = sys_clone_unified(CLONE_PARENT|SIGCHLD, NULL, NULL, NULL, 0); + if (pid < 0) { + fail("fork"); + exit(1); + } + + exit(0); + } + + if (waitpid(pid, &status, 0) < 0) { + fail("waitpid"); + exit(1); + } + if (!WIFEXITED(status) || WEXITSTATUS(status)) { + pr_err("Exited with problems: status=%d\n", status); + fail("fail"); + exit(1); + } + + if (waitid(P_ALL, 0, &info, WEXITED|WNOWAIT) < 0) { + fail("waitpid"); + exit(1); + } + + test_daemon(); + test_waitsig(); + + if (waitid(P_ALL, 0, &info, WEXITED|WNOWAIT) < 0) { + fail("waitpid"); + exit(1); + } + + pgrp = getpgid(info.si_pid); + if (pgrp < 0) { + fail("getpgrp"); + exit(1); + } + + if (pgrp != pid) { + pr_err("Wrong pgrp: %d != %d\n", pgrp, pid); + fail("fail"); + exit(1); + } + + pass(); + return 0; +} diff --git a/test/zdtm/static/zombie01.desc b/test/zdtm/static/zombie01.desc new file mode 100644 index 000000000..2eac7e654 --- /dev/null +++ b/test/zdtm/static/zombie01.desc @@ -0,0 +1 @@ +{'flags': 'suid'}