[CRIU] [PATCH 1/7] zdtm: Add maps02 test

Andrew Vagin avagin at parallels.com
Wed May 16 06:43:23 EDT 2012


On Sat, May 12, 2012 at 07:47:49PM +0400, Cyrill Gorcunov wrote:
> 
> In a sake of nonlinear mapping.
> 
> Still the test is out of normal test-flow
> since it's "always fail" case (because we
> don't support nonlinear mapping yet, but
> this test code might be needed in future.
> After all I've been using it for testing
> proc-parsing procesure).
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm/live/static/Makefile |    1 +
>  test/zdtm/live/static/maps02.c |   58 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 59 insertions(+), 0 deletions(-)
>  create mode 100644 test/zdtm/live/static/maps02.c
> 

> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 5cf9445..53cc10e 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -44,6 +44,7 @@ TST_NOFILE	=				\
>  		file_fown			\
>  		eventfs00			\
>  		inotify00			\
> +		maps02				\
>  #		jobctl00			\
>  
>  TST_FILE	=				\
> diff --git a/test/zdtm/live/static/maps02.c b/test/zdtm/live/static/maps02.c
> new file mode 100644
> index 0000000..1657e28
> --- /dev/null
> +++ b/test/zdtm/live/static/maps02.c
> @@ -0,0 +1,58 @@
> +#define _GNU_SOURCE         /* See feature_test_macros(7) */
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <string.h>
> +#include <setjmp.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/mman.h>
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Create non-linear mapping\n";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
> +
> +#define MAPS_LEN	0x4000
> +
> +int main(int argc, char ** argv)
> +{
> +	const char fname[] = "maps02-test";

char *filename;
TEST_OPTION(filename, string, "file name", 1);


Look at write_read01.c for example
> +	void *map;
> +	int fd, i;
> +	long data;
> +
> +	test_init(argc, argv);
> +
> +	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC);
> +	if (fd < 0) {
> +		fail("Can't open %s\n", fname);
> +		exit(1);
> +	}
> +
> +	for (i = 0; i < MAPS_LEN / sizeof(long); i++)
> +		write(fd, &data, sizeof(data));
Where are you use fd?
> +
> +	map = mmap(NULL, MAPS_LEN, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
> +	if (map == MAP_FAILED) {
> +		fail("Can't map %s\n", fname);
> +		exit(1);
> +	}
> +
> +	for (i = 0; i < MAPS_LEN / sizeof(long) - 1; i++) {
> +		((long *)map)[i] = i;
> +	}
> +
> +	if (remap_file_pages(map + 0x1000, 0x1000, 0, 0, 0)) {
Where is remap_file_pages declared?
> +		fail("Can't remap file pages %s\n", fname);
> +		exit(1);
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
Probably we should check that all mappings restored.
> +
> +	pass();
> +	return 0;
> +}

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



More information about the CRIU mailing list