[CRIU] Re: [PATCH] zdtm: shm test update

Andrew Vagin avagin at parallels.com
Mon Feb 6 09:00:49 EST 2012


On Fri, Feb 03, 2012 at 05:20:52PM +0300, Kinsbursky Stanislav wrote:
> What's new:
> 1) cloning to new IPC ns depends on built option.
> 2) Check for lookup shared segment by key added.
> 3) Check for creation new segnent after migration added.
> 4) Few check for syscalls results added.
> 
> Signed-off-by: Stanislav Kinsbursky <skinsbursky at parallels.com>
> 
> ---
>  test/zdtm.sh                   |    4 -
>  test/zdtm/live/static/Makefile |    1 
>  test/zdtm/live/static/shm.c    |  167 +++++++++++++++++++++++++++++++++-------
>  3 files changed, 141 insertions(+), 31 deletions(-)
> 
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 8bfb03e..4c56f9c 100644
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -7,7 +7,6 @@ $ZP/static/pipe00
>  $ZP/static/busyloop00
>  $ZP/static/cwd00
>  $ZP/static/env00
> -$ZP/static/shm
>  $ZP/static/maps00
>  $ZP/static/mprotect00
>  $ZP/static/mtime_mmap
> @@ -34,7 +33,8 @@ $ZP/static/socket_listen"
>  UTS_TEST_LIST="\
>  $ZP/static/utsname"
>  IPC_TEST_LIST="\
> -$ZP/static/ipc_namespace"
> +$ZP/static/ipc_namespace \
> +$ZP/static/shm"
>  
>  CRTOOLS=`pwd`/`dirname $0`/../crtools
>  
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 490f504..4c4b934 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -145,6 +145,7 @@ socket_aio:		override LDLIBS += -lrt
>  unlink_largefile:	override CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
>  inotify_system_nodel:	override CFLAGS += -DNODEL
>  pthread00:		override LDLIBS += -pthread
> +shm:			override CFLAGS += -DNEW_IPC_NS
>  
>  $(LIB):	force
>  	$(MAKE) -C $(LIBDIR)
> diff --git a/test/zdtm/live/static/shm.c b/test/zdtm/live/static/shm.c
> index fd20251..16c8b8f 100644
> --- a/test/zdtm/live/static/shm.c
> +++ b/test/zdtm/live/static/shm.c
> @@ -11,6 +11,8 @@
>  
>  #include "zdtmtst.h"
>  
> +#define IPC_PRESET 00040000
I can't find where do you use IPC_PRESET?
> +
>  const char *test_doc="Tests detached shmems migrate fine";
>  const char *test_author="Andrew Vagin <avagin at parallels.com>";
You rewrite this test case, so you are the author.
>  
> @@ -20,69 +22,176 @@ TEST_OPTION(shmem_size, uint, "Size of shared memory segment", 0);
>  
>  #define INIT_CRC	(~0)
>  
> -int main(int argc, char **argv)
> +#if defined (__GLIBC__) && __GLIBC__ >= 2
> +#define KEY __key
> +#else
> +#define KEY key
> +#endif
What is it ^^^?
> +
> +#define SHM_SET        15
nobody uses SHM_SET
> +
> +#define CLONE_NEWIPC		0x08000000
#define _GNU_SOURCE
#include <sched.h>
> +
> +char *filename;
> +
> +static int fill_shm_seg(int id, size_t size)
> +{
> +	uint8_t *mem;
> +	uint32_t crc = INIT_CRC;
> +
> +	mem = shmat(id, NULL, 0);
> +	if (mem == (void *)-1) {
> +		err("Can't attach shm: %d\n", -errno);
> +		return -1;
> +	}
> +
> +	datagen(mem, size, &crc);
> +
> +	if (shmdt(mem) < 0) {
> +		err("Can't detach shm: %d\n", -errno);
> +		return -1;
> +	}
> +	return 0;
> +}
> +
> +static int get_shm_seg(int key, size_t size, unsigned int flags)
> +{
> +	int id;
> +
> +	id = shmget(key, size, 0777 | flags);
> +	if (id == -1) {
> +		err("Can't get shm: %d\n", -errno);
> +		return -1;
> +	}
> +	return id;
> +}
> +
> +static int prepare_shm(int key, size_t size)
> +{
> +	int id;
> +
> +	id = get_shm_seg(key, shmem_size, IPC_CREAT | IPC_EXCL);
> +	if (id == -1) {
> +		return -1;
> +	}
> +	if (fill_shm_seg(id, shmem_size) < 0)
> +		return -1;
> +	return id;
> +}
> +
> +static int check_shm_id(int id, size_t size)
> +{
> +	uint8_t *mem;
> +	uint32_t crc = INIT_CRC;
> +
> +	mem = shmat(id, NULL, 0);
> +	if (mem == (void *)-1) {
> +		err("Can't attach shm: %d\n", -errno);
> +		return -1;
> +	}
> +	crc = INIT_CRC;
> +	if (datachk(mem, size, &crc)) {
> +		fail("shmem data are corrupted");
> +		return -1;
> +	}
> +	if (shmdt(mem) < 0) {
> +		err("Can't detach shm: %d\n", -errno);
> +		return -1;
> +	}
> +	return 0;
> +}
> +
> +static int check_shm_key(int key, size_t size)
> +{
> +	int id;
> +
> +	id = get_shm_seg(key, size, 0);
> +	if (id < 0)
> +		return -1;
> +	return check_shm_id(id, size);
> +}
> +
> +static void test_fn(void)
>  {
>  	key_t key;
>  	int shm;
>  	int fail_count = 0;
> -	uint8_t *mem;
> -	uint32_t crc;
>  	int ret;
>  
> -	test_init(argc, argv);
> -
> -	key = ftok(argv[0], 822155666);
> +	key = ftok(filename, 822155666);
>  	if (key == -1) {
>  		err("Can't make key");
>  		goto out;
>  	}
>  
> -	shm = shmget(key, shmem_size, 0777 | IPC_CREAT | IPC_EXCL);
> +	shm = prepare_shm(key, shmem_size);
>  	if (shm == -1) {
> -		err("Can't get shm");
>  		fail_count++;
>  		goto out;
>  	}
>  
> -	mem = shmat(shm, NULL, 0);
> -	if (mem == (void *)-1) {
> -		err("Can't attach shm");
> +	test_daemon();
> +	test_waitsig();
> +
> +	ret = check_shm_id(shm, shmem_size);
> +	if (ret < 0) {
> +		fail("ID check (1) failed\n");
>  		fail_count++;
>  		goto out_shm;
>  	}
>  
> -
> -	test_daemon();
> -
> -	crc = INIT_CRC;
> -	datagen(mem, shmem_size, &crc);
> -	ret = shmdt(mem);
> -	if (ret) {
> -		err("Can't detach shm");
> +	ret = check_shm_key(key, shmem_size);
> +	if (ret < 0) {
> +		fail("KEY check failed\n");
>  		fail_count++;
>  		goto out_shm;
>  	}
>  
> -	test_waitsig();
> -
> -	mem = shmat(shm, NULL, 0);
> -	if (mem == (void *)-1) {
> -		err("Can't attach shm");
> +	ret = shmctl(shm, IPC_RMID, NULL);
> +	if (ret < 0) {
> +		fail("Failed (1) to destroy segment: %d\n", -errno);
>  		fail_count++;
>  		goto out_shm;
>  	}
> +	/*
> +	 * Code below checks that it's still possible to create new IPC SHM
> +	 * segments
> +	 */
> +	shm = prepare_shm(key, shmem_size);
> +	if (shm == -1) {
> +		fail_count++;
> +		goto out;
> +	}
>  
> -	crc = INIT_CRC;
> -	if (datachk(mem, shmem_size, &crc)) {
> +	ret = check_shm_id(shm, shmem_size);
> +	if (ret < 0) {
> +		fail("ID check (2) failed\n");
>  		fail_count++;
> -		fail("shmem data are corrupted");
> +		goto out_shm;
>  	}
>  
> -	shmdt(mem);
>  out_shm:
> -	shmctl(shm, IPC_RMID, NULL);
> +	ret = shmctl(shm, IPC_RMID, NULL);
> +	if (ret < 0) {
> +		fail("Failed (2) to destroy segment: %d\n", -errno);
> +		fail_count++;
> +		goto out_shm;
> +	}
>  	if (fail_count == 0)
>  		pass();
>  out:
> +	return;
> +}
> +
> +
> +int main(int argc, char **argv)
> +{
> +	filename = argv[0];
> +#ifdef NEW_IPC_NS
> +	test_init_ns(argc, argv, CLONE_NEWIPC, test_fn);
> +#else
> +	test_init(argc, argv);
> +	test_fn();
> +#endif
>  	return 0;
>  }
> 


More information about the CRIU mailing list