[CRIU] [PATCH] zdtm: Make thread-bomb be bomb

Andrew Vagin avagin at virtuozzo.com
Thu Nov 19 06:50:55 PST 2015


On Wed, Nov 11, 2015 at 07:23:45PM +0300, Pavel Emelyanov wrote:
> In current implementation of thread bomb effectively only one
> thread runs, the rest sit in the read from pipe.
> 
> Fix this by making threads constantly creating new ones and 
> just exiting.
>

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

> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
> 
> ---
> 
> diff --git a/test/zdtm.py b/test/zdtm.py
> index 87051ac..a3af1ef 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -258,7 +258,7 @@ class zdtm_test:
>  
>  		print "Start test"
>  
> -		env['ZDTM_THREAD_BOMB'] = "100"
> +		env['ZDTM_THREAD_BOMB'] = "5"
>  		if not test_flag(self.__desc, 'suid'):
>  			env['ZDTM_UID'] = "18943"
>  			env['ZDTM_GID'] = "58467"
> diff --git a/test/zdtm/live/transition/thread-bomb.c b/test/zdtm/live/transition/thread-bomb.c
> index a21320f..0b794ef 100644
> --- a/test/zdtm/live/transition/thread-bomb.c
> +++ b/test/zdtm/live/transition/thread-bomb.c
> @@ -8,61 +8,46 @@
>  
>  #include "zdtmtst.h"
>  
> -static int p[2];
> -static char *buf;
> -static int buf_size = 1024;
> -
>  #define exit_group(code)	\
>  	syscall(__NR_exit_group, code)
>  
>  static void *thread_fn(void *arg)
>  {
> -	pthread_t t;
> -	char c = 0;
> -	int ret;
> +	pthread_t t, p, *self;
>  
> -	while (test_go()) {
> -		ret = read(p[0], &c, 1);
> -		if (ret == -1 && errno == EAGAIN)
> -			return NULL;
> -		if (ret != 1)
> -			goto err;
> -		if (pthread_create(&t, NULL, thread_fn, NULL))
> -			goto err;
> -		pthread_join(t, NULL);
> -		if (write(p[1], &c, 1) != 1)
> -			goto err;
> +	if (arg) {
> +		p = *(pthread_t *)arg;
> +		pthread_join(p, NULL);
> +		free(arg);
>  	}
>  
> -	return NULL;
> -err:
> -	exit_group(1);
> +	self = malloc(sizeof(*self));
> +	*self = pthread_self();
> +
> +	pthread_create(&t, NULL, thread_fn, self);
>  	return NULL;
>  }
>  
>  int main(int argc, char **argv)
>  {
>  	char *val;
> +	int max_nr = 1024, i;
>  
>  	val = getenv("ZDTM_THREAD_BOMB");
>  	if (val)
> -		buf_size = atoi(val);
> -	test_msg("%d\n", buf_size);
> -	buf = malloc(buf_size);
> -	if (!buf)
> -		return 1;
> -
> -	if (pipe(p))
> -		return 1;
> -	fcntl(p[0], F_SETFL, O_NONBLOCK);
> +		max_nr = atoi(val);
>  
> -	if (write(p[1], buf, buf_size) != buf_size)
> -		return 1;
> +	test_msg("%d\n", max_nr);
>  
>  	test_init(argc, argv);
> -	test_daemon();
>  
> -	thread_fn(NULL);
> +	for (i = 0; i < max_nr; i++) {
> +		pthread_t p;
> +		pthread_create(&p, NULL, thread_fn, NULL);
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
>  
>  	pass();
>  


More information about the CRIU mailing list