[CRIU] [PATCH 2/2] zdtm: Add maps05 test

Andrew Vagin avagin at parallels.com
Wed May 7 05:15:33 PDT 2014


On Mon, May 05, 2014 at 07:48:29PM +0400, Cyrill Gorcunov wrote:
> To test a flood of small VMAs.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm.sh                   |  1 +
>  test/zdtm/live/static/Makefile |  1 +
>  test/zdtm/live/static/maps05.c | 51 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 53 insertions(+)
>  create mode 100644 test/zdtm/live/static/maps05.c
> 
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 4de131d0b47c..1df1d969bdb6 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -12,6 +12,7 @@ static/maps00
>  static/maps01
>  static/maps02
>  static/maps04
> +static/maps05
>  static/maps_file_prot
>  static/mprotect00
>  static/mtime_mmap
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index b0f7807f9732..bf53ab6ecac4 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -66,6 +66,7 @@ TST_NOFILE	=				\
>  		maps02				\
>  		maps03				\
>  		maps04				\
> +		maps05				\
>  		xids00				\
>  		groups				\
>  		file_fown			\
> diff --git a/test/zdtm/live/static/maps05.c b/test/zdtm/live/static/maps05.c
> new file mode 100644
> index 000000000000..2ef178598405
> --- /dev/null
> +++ b/test/zdtm/live/static/maps05.c
> @@ -0,0 +1,51 @@
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <string.h>
> +#include <sys/mman.h>
> +#include <setjmp.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Create a bunch of small VMAs and test they survive transferring\n";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
> +
> +#define NR_MAPS 4096
> +
> +int main(int argc, char ** argv)
> +{
> +	void *map[NR_MAPS] = { };
> +	size_t i;
> +
> +	test_init(argc, argv);
> +
> +	for (i = 0; i < NR_MAPS; i++) {
> +		map[i] = mmap(i > 0 ? map[i - 1] + 8192 : NULL, 4096, PROT_READ | PROT_WRITE,
> +			      MAP_ANONYMOUS | MAP_PRIVATE | (i > 0 ? MAP_FIXED : 0), -1, 0);

It's dangerous, because you can overlap with other vmas.

> +		if (map[i] == MAP_FAILED) {
> +			err("Can't mmap");
> +			return 1;
> +		} else {
> +			/* Dirtify it */
> +			int *v = (void *)map[i];
> +			*v = i;
> +		}
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	for (i = 0; i < NR_MAPS; i++) {
> +		int *v = (void *)map[i];
> +
> +		if (*v != i) {
> +			fail("Data corrupted at page %lu", (unsigned long)i);
> +			return 1;
> +		}
> +	}
> +	pass();
> +	return 0;
> +}
> -- 
> 1.8.3.1
> 


More information about the CRIU mailing list