[CRIU] [PATCH 3/3] test: zdtm -- Add proc-self test

Andrew Vagin avagin at parallels.com
Mon Apr 29 16:48:47 EDT 2013


On Mon, Apr 29, 2013 at 08:19:59PM +0400, Cyrill Gorcunov wrote:
> Just open /proc/self/ns/net and check if
> it remains the same on restore.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm/live/static/Makefile    |  1 +
>  test/zdtm/live/static/proc-self.c | 73 +++++++++++++++++++++++++++++++++++++++

This test case should be added in the test list for regular execution.
Look at zdtm.sh

Do you try to execute zdtm.sh ns/static/proc-self?

>  2 files changed, 74 insertions(+)
>  create mode 100644 test/zdtm/live/static/proc-self.c
> 
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 9a0509d..56e7958 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -66,6 +66,7 @@ TST_NOFILE	=				\
>  		xids00				\
>  		groups				\
>  		file_fown			\
> +		proc-self			\
>  		eventfs00			\
>  		signalfd00			\
>  		inotify00			\
> diff --git a/test/zdtm/live/static/proc-self.c b/test/zdtm/live/static/proc-self.c
> new file mode 100644
> index 0000000..feefc44
> --- /dev/null
> +++ b/test/zdtm/live/static/proc-self.c
> @@ -0,0 +1,73 @@
> +#define _GNU_SOURCE         /* See feature_test_macros(7) */
> +#include <unistd.h>
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <string.h>
> +#include <utime.h>
> +
> +#include <sys/stat.h>
> +#include <sys/types.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Check for /proc/self/ns path restore";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
> +
> +const char nspath[] = "/proc/self/ns/net";
> +
> +int read_fd_link(int lfd, char *buf, size_t size)
> +{
> +	ssize_t ret;
> +	char t[32];
> +
> +	snprintf(t, sizeof(t), "/proc/self/fd/%d", lfd);
> +	ret = readlink(t, buf, size);

size -1, the last one is used for a null byte.

> +	if (ret < 0) {
> +		err("Can't read link of fd %d", lfd);
> +		return -1;
> +	}
> +	buf[ret] = 0;
> +
> +	return 0;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	char path_orig[64], path_new[64];
> +	int fd_self;
> +
> +	test_init(argc, argv);
> +
> +	memset(path_orig, 0, sizeof(path_orig));
> +	memset(path_new, 0, sizeof(path_new));
> +
> +	fd_self = open(nspath, O_RDONLY);
> +	if (fd_self < 0) {
> +		err("Can't open %s", nspath);
> +		return -1;
> +	}
> +
> +	if (read_fd_link(fd_self, path_orig, sizeof(path_orig))) {
> +		err("Can't fill original path");
> +		return -1;
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	if (read_fd_link(fd_self, path_new, sizeof(path_new))) {
> +		err("Can't fill new path");
> +		return -1;
> +	}
> +
> +	if (memcmp(path_orig, path_new, sizeof(path_orig))) {
> +		fail("Paths mismatch %s %s\n", path_orig, path_new);
> +		return -1;
> +	}
> +
> +	pass();
> +	return 0;
> +}
> -- 
> 1.8.1.4
> 


More information about the CRIU mailing list