[CRIU] [PATCH v2] test: add processes tree restoring test

Andrew Vagin avagin at parallels.com
Thu Nov 1 05:32:27 EDT 2012


Acked-by: Andrew Vagin <avagin at parallels.com>

On Thu, Nov 01, 2012 at 12:01:16PM +0400, Kinsbursky Stanislav wrote:
> From: Stanislav Kinsbursky <skinsbursky at openvz.org>
> 
> This test makes sure, that processes tree is restored before opened files.
> This is guaranteed by holding child's "/proc/<pid>/stat" file opened by parent.
> 
> It was inspired by OpenVZ bug:
> http://bugzilla.openvz.org/show_bug.cgi?id=2404
> 
> IOW, OpenVZ can't restore container with such test inside.
> 
> v2:
> 1) Test renamed + carefull cleanup + minor updates.
> 
> Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
> ---
>  test/zdtm.sh                              |    1 
>  test/zdtm/live/static/Makefile            |    1 
>  test/zdtm/live/static/child_opened_proc.c |   63 +++++++++++++++++++++++++++++
>  3 files changed, 65 insertions(+), 0 deletions(-)
>  create mode 100644 test/zdtm/live/static/child_opened_proc.c

> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index e7d8128..41cedeb 100644
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -65,6 +65,7 @@ transition/fork
>  static/pty00
>  static/pty01
>  static/pty04
> +static/child_opened_proc
>  "
>  # Duplicate list with ns/ prefix
>  TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#')
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 03e40fe..18ce2eb 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -72,6 +72,7 @@ TST_NOFILE	=				\
>  		socket-ext			\
>  		unhashed_proc			\
>  		cow00				\
> +		child_opened_proc		\
>  		posix_timers			\
>  #		jobctl00			\
>  
> diff --git a/test/zdtm/live/static/child_opened_proc.c b/test/zdtm/live/static/child_opened_proc.c
> new file mode 100644
> index 0000000..06f37cf
> --- /dev/null
> +++ b/test/zdtm/live/static/child_opened_proc.c
> @@ -0,0 +1,63 @@
> +#include <unistd.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <signal.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Check that tree prior to files opening";
> +const char *test_author	= "Stanislav Kinsbursky <skinsbursky at paralles.com";
> +
> +int main(int argc, char ** argv)
> +{
> +	int pid, err = 0;
> +	int proc_fd;
> +	char name[64];
> +
> +	test_init(argc, argv);
> +
> +	pid = test_fork();
> +	if (pid < 0) {
> +		err("Can't fork");
> +		exit(1);
> +	}
> +
> +	if (!pid) {
> +		test_waitsig();
> +		return 0;
> +	}
> +
> +	sprintf(name, "/proc/%d/stat", pid);
> +	proc_fd = open(name, O_RDONLY);
> +	if (proc_fd == -1) {
> +		err("can't open %s: %m\n", name);
> +		err++;
> +		goto out;
> +	}
> +	test_daemon();
> +	test_waitsig();
> +
> +	if (close(proc_fd) == -1) {
> +		err("Failed to close %s\n", name);
> +		err++;
> +	}
> +out:
> +	if (kill(pid, SIGTERM) == -1) {
> +		err("Failed to terminate child\n");
> +		err++;
> +	} else {
> +		if (waitpid(pid, NULL, 0) != pid) {
> +			err("Failed to collect killed child\n");
> +			err++;
> +		}
> +	}
> +
> +	if (!err)
> +		pass();
> +
> +	return err;
> +}

> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://openvz.org/mailman/listinfo/criu



More information about the CRIU mailing list