[CRIU] [PATCH] zdtm: check a test result for static/different_creds

Tycho Andersen tycho.andersen at canonical.com
Thu Oct 1 07:06:49 PDT 2015


On Thu, Oct 01, 2015 at 02:50:52PM +0300, Andrey Vagin wrote:
> From: Andrew Vagin <avagin at openvz.org>
> 
> CRIU should not affect process states when it can't dump them.
> 
> Cc: Tycho Andersen <tycho.andersen at canonical.com>

Acked-by: Tycho Andersen <tycho.andersen at canonical.com>

> Signed-off-by: Andrew Vagin <avagin at openvz.org>
> ---
>  test/zdtm.sh                            | 14 +++++----
>  test/zdtm/live/static/different_creds.c | 55 +++++++++++++++++++++------------
>  2 files changed, 43 insertions(+), 26 deletions(-)
> 
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index a0c3520..6e265a8 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -801,12 +801,15 @@ EOF
>  		# Here we may have two cases: either checkpoint is failed
>  		# with some error code, or checkpoint is complete but return
>  		# code is non-zero because of post dump action.
> -		if [ "$retcode" -ne 0 ] && [[ "$retcode" -ne 32 || -z "$dump_only" ]]; then
> -			if echo $TEST_EXPECTED_FAILURE | grep -q $tname; then
> -				echo "Got expected dump failure"
> -				return 0
> +		if echo $TEST_EXPECTED_FAILURE | grep -q $tname; then
> +			echo "Expect dump falure: $retcode"
> +			if [ "$retcode" -eq 0 ]; then
> +				return 1
>  			fi
> -
> +			dump_only=1
> +			retcode=32
> +		fi
> +		if [ "$retcode" -ne 0 ] && [[ "$retcode" -ne 32 || -z "$dump_only" ]]; then
>  			if [ $BATCH_TEST -eq 0 ]; then
>  				echo WARNING: $tname returned $retcode and left running for debug needs
>  			else
> @@ -814,7 +817,6 @@ EOF
>  			fi
>  			return 1
>  		fi
> -		cat $ddump/dump.log* | grep Error
>  
>  		if [ -n "$SNAPSHOT" ]; then
>  			snappdir=../`basename $ddump`
> diff --git a/test/zdtm/live/static/different_creds.c b/test/zdtm/live/static/different_creds.c
> index e2ffe23..c18216a 100644
> --- a/test/zdtm/live/static/different_creds.c
> +++ b/test/zdtm/live/static/different_creds.c
> @@ -8,19 +8,19 @@
>  #include <linux/limits.h>
>  #include <pthread.h>
>  #include <syscall.h>
> +#include <sys/socket.h>
>  
>  #include "zdtmtst.h"
>  
>  const char *test_doc	= "Check that threads with different creds aren't checkpointed";
>  const char *test_author	= "Tycho Andersen <tycho.andersen at canonical.com>";
>  
> -#define exit_group(code)	\
> -	syscall(__NR_exit_group, code)
> -
>  void *drop_caps_and_wait(void *arg)
>  {
> +	int fd = *((int *) arg);
> +	void *retcode = (void *)0xdeadbeaf;
>  	cap_t caps;
> -	int *pipe = arg;
> +	char c;
>  
>          caps = cap_get_proc();
>          if (!caps) {
> @@ -38,41 +38,45 @@ void *drop_caps_and_wait(void *arg)
>                  goto die;
>          }
>  
> -	close(*pipe);
> +	if (write(fd, "a", 1) != 1) {
> +		err("Unable to send a status");
> +		goto die;
> +	}
> +
> +	if (read(fd, &c, 1) != 1) {
> +		err("Unable to read a status");
> +		goto die;
> +	}
>  
> -	while(1)
> -		sleep(1000);
> +	retcode = NULL;
>  die:
>          cap_free(caps);
> -        return NULL;
> +	return retcode;
>  }
>  
>  int main(int argc, char ** argv)
>  {
> -	int ret, pipefd[2];
> +	int pipefd[2];
>  	pthread_t thr;
> -
> -	char buf;
> +	char c;
> +	void *retcode;
>  
>  	test_init(argc, argv);
>  
> -	if (pipe(pipefd) < 0) {
> +	if (socketpair(AF_FILE, SOCK_SEQPACKET, 0, pipefd)) {
>  		err("pipe");
>  		return -1;
>  	}
>  
> -	if (pthread_create(&thr, NULL, drop_caps_and_wait, pipefd)) {
> +	if (pthread_create(&thr, NULL, drop_caps_and_wait, &pipefd[0])) {
>  		err("Unable to create thread");
>  		return -1;
>  	}
> -	close(pipefd[1]);
>  
>  	/*
>  	 * Wait for child to signal us that it has droped caps.
>  	 */
> -	ret = read(pipefd[0], &buf, 1);
> -	close(pipefd[0]);
> -	if (ret < 0) {
> +	if (read(pipefd[1], &c, 1) != 1) {
>  		err("read");
>  		return 1;
>  	}
> @@ -80,8 +84,19 @@ int main(int argc, char ** argv)
>  	test_daemon();
>  	test_waitsig();
>  
> -	fail("shouldn't dump successfully");
> +	if (write(pipefd[1], &c, 1) != 1) {
> +		err("write");
> +		return 1;
> +	}
> +
> +	if (pthread_join(thr, &retcode)) {
> +		err("Unable to jount a thread");
> +		return 1;
> +	}
> +	if (retcode != NULL)
> +		return 1;
> +
> +	pass();
>  
> -	exit_group(ret);
> -	return 1;
> +	return 0;
>  }
> -- 
> 2.4.3
> 


More information about the CRIU mailing list