[CRIU] [PATCH] zdtm/stopped: fix stopped test

Andrew Vagin avagin at parallels.com
Tue Oct 7 05:51:02 PDT 2014


On Tue, Oct 07, 2014 at 03:28:30PM +0400, Konstantin Neumoin wrote:
> The main problem with the
> test that it's never 'fail'.
> Test can only 'pass' or hangs.
> 
> Signed-off-by: Konstantin Neumoin <kneumoin at parallels.com>
> ---
>  test/zdtm/live/static/stopped.c | 29 ++++++++++++++++++-----------
>  1 file changed, 18 insertions(+), 11 deletions(-)
> 
> diff --git a/test/zdtm/live/static/stopped.c b/test/zdtm/live/static/stopped.c
> index 6194d6b..b74b7ff 100644
> --- a/test/zdtm/live/static/stopped.c
> +++ b/test/zdtm/live/static/stopped.c
> @@ -33,35 +33,42 @@ int main(int argc, char **argv)
>  			return 1;
>  		}
>  
> -		ret = read(p[0], &c, 1);
> -		if (ret != 0) {
> -			err("Unable to read: %d", ret);
> -			return 1;
> -		}
> -
>  		return 0;
>  	}
>  	close(p[0]);
>  
>  	kill(pid, SIGSTOP);
> +
>  	write(p[1], "0", 1);
> +	close(p[1]);
>  
>  	test_daemon();
>  	test_waitsig();
>  
> +	// Return immediately if child run or stopped(by SIGSTOP)
> +	if (waitpid(pid, &status, WUNTRACED | WCONTINUED) == -1) {

it doesn't return if a child is running.

import os, time, sys, signal

pid = os.fork()
if pid == 0:
	time.sleep(5)
	sys.exit(0)
pid, status = os.waitpid(pid, os.WCONTINUED | os.WUNTRACED)
os.kill(pid, signal.SIGKILL);
print pid, status


> +		err("Unable to wait child");
> +		goto out;
> +	}
> +
> +	if (WIFSTOPPED(status))
> +		test_msg("The procces stopped\n");
> +	else{
> +		fail("The process doesn't stopped");
> +		goto out;
> +	}
> +
>  	kill(pid, SIGCONT);
> -	if (waitpid(pid, &status, WCONTINUED) == -1) {
> +
> +	if (waitpid(pid, &status, 0) == -1) {
>  		err("Unable to wait child");
>  		goto out;
>  	}
>  
> -	if (WIFCONTINUED(status))
> +	if (WIFEXITED(status))
>  		pass();
>  	else
>  		fail("The process doesn't continue");
>  out:
> -	close(p[1]);
> -	waitpid(pid, &status, 0);
> -
>  	return 0;
>  }
> -- 
> 1.7.11.7
> 


More information about the CRIU mailing list