[CRIU] [PATCH 4/4] test: add a test for remap_dead_pid
Andrew Vagin
avagin at parallels.com
Mon Sep 15 07:05:35 PDT 2014
On Fri, Sep 12, 2014 at 07:43:31PM -0500, Tycho Andersen wrote:
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> ---
> test/zdtm.sh | 1 +
> test/zdtm/.gitignore | 1 +
> test/zdtm/live/static/Makefile | 1 +
> test/zdtm/live/static/remap_dead_pid.c | 74 ++++++++++++++++++++++++++++++++++
> 4 files changed, 77 insertions(+)
> create mode 100644 test/zdtm/live/static/remap_dead_pid.c
>
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index f6011ea..09cb1bf 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -179,6 +179,7 @@ static/cgroup00
> static/cgroup01
> static/cgroup02
> ns/static/clean_mntns
> +ns/static/remap_dead_pid
Why can it not be executed in a current set of namespaces?
> "
>
> TEST_CR_KERNEL="
> diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
> index a8f60b9..fef561d 100644
> --- a/test/zdtm/.gitignore
> +++ b/test/zdtm/.gitignore
> @@ -90,6 +90,7 @@
> /live/static/pty02
> /live/static/pty03
> /live/static/pty04
> +/live/static/remap_dead_pid
> /live/static/rlimits00
> /live/static/rmdir_open
> /live/static/rtc
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index e079201..e44bf6a 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -113,6 +113,7 @@ TST_NOFILE = \
> clean_mntns \
> dumpable01 \
> dumpable02 \
> + remap_dead_pid \
> # jobctl00 \
>
> TST_FILE = \
> diff --git a/test/zdtm/live/static/remap_dead_pid.c b/test/zdtm/live/static/remap_dead_pid.c
> new file mode 100644
> index 0000000..4e3953a
> --- /dev/null
> +++ b/test/zdtm/live/static/remap_dead_pid.c
> @@ -0,0 +1,74 @@
> +#define _GNU_SOURCE
> +#include <string.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <stdio.h>
> +#include <limits.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +
> +#include "zdtmtst.h"
> +
> +#ifndef CLONE_NEWNS
> +#define CLONE_NEWNS 0x00020000
> +#endif
> +
> +const char *test_doc = "Check that dead pid's /proc entries are remapped correctly";
> +const char *test_author = "Tycho Andersen <tycho.andersen at canonical.com>";
> +
> +int main(int argc, char **argv)
> +{
> + pid_t pid;
> +
> + test_init(argc, argv);
> +
> + pid = fork();
> + if (pid < 0) {
> + fail("fork() failed");
> + return -1;
> + }
> +
> + if (pid == 0) {
> + test_msg("child is %d\n", pid);
> + /* Child process just sleeps until it is killed. All we need
> + * here is a process to open the mountinfo of. */
> + while(1)
> + sleep(10);
> + } else {
> + int fd, ret;
> + char path[PATH_MAX];
> + pid_t result;
> +
> + sprintf(path, "/proc/%d/mountinfo", pid);
> +
> + fd = open(path, O_RDONLY);
> +
> + /* no matter what, we should kill the child */
> + kill(pid, SIGINT);
> + result = waitpid(pid, NULL, 0);
> + if (result < 0) {
> + fail("failed waitpid()");
> + return -1;
> + }
> +
> + if (fd < 0) {
> + fail("failed opening %s", path);
> + return -1;
> + }
> +
> + test_daemon();
> + test_waitsig();
> +
> + ret = fcntl(fd, F_GETFD);
> + close(fd);
> +
> + if (ret) {
> + fail("bad fd after restore");
> + return -1;
> + }
> + }
> +
> + pass();
> + return 0;
> +}
> --
> 1.9.1
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list