public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 4/8] waitpid09: use the new API
Date: Mon, 18 Jul 2016 16:18:44 +0200	[thread overview]
Message-ID: <20160718141844.GD18221@rei.suse.cz> (raw)
In-Reply-To: <1468593589-30545-5-git-send-email-stanislav.kholmanskikh@oracle.com>

Hi!
> +static void case0(void)
> +{
> +	pid_t ret;
> +	int status;
> +	int fail = 0;
> +
> +	pid = SAFE_FORK();
> +	if (pid == 0)
> +		do_exit();
> +
> +	/*
> +	 *Check that waitpid with WNOHANG returns zero
> +	 */
> +	while (((ret = waitpid(pid, &status, WNOHANG))
> +		!= 0) || (errno == EINTR)) {
> +		if (ret == -1)
> +			continue;
> +
> +		tst_res(TFAIL, "return value for "
> +			 "WNOHANG expected 0 got %d",
> +			 ret);
> +		fail = 1;
> +	}
>  
> -				while (((ret = waitpid(pid, &status, WNOHANG))
> -					!= -1) || (errno == EINTR)) {
> -					if (ret == -1)
> -						continue;
> +	TST_CHECKPOINT_WAKE(0);
>  
> -					if (ret != pid) {
> -						tst_resm(TFAIL, "proc id %d "
> -							 "and retval %d do not "
> -							 "match", pid, ret);
> -						fail = 1;
> -					}
> +	while (((ret = waitpid(pid, &status, 0)) != -1)
> +	       || (errno == EINTR)) {
> +		if (ret == -1)
> +			continue;
>  
> -					if (status != 0) {
> -						tst_resm(TFAIL, "non zero "
> -							 "status received %d",
> -							 status);
> -						fail = 1;
> -					}
> -				}
> -			}
> +		if (ret != pid) {
> +			tst_res(TFAIL, "Expected %d "
> +				 "got %d as proc id of "
> +				 "child", pid, ret);
> +			fail = 1;
> +		}
>  
> -			if (fail)
> -				tst_resm(TFAIL, "case 1 FAILED");
> -			else
> -				tst_resm(TPASS, "case 1 PASSED");
> +		if (status != 0) {
> +			tst_res(TFAIL, "status value "
> +				 "got %d expected 0",
> +				 status);
> +			fail = 1;
> +		}
> +	}
>  
> -			fail = 0;
> -			ret = waitpid(pid, &status, 0);
> +	pid = 0;
>  
> -			if (ret != -1) {
> -				tst_resm(TFAIL, "Expected -1 got %d", ret);
> -				fail = 1;
> -			}
> -			if (errno != ECHILD) {
> -				tst_resm(TFAIL, "Expected ECHILD got %d",
> -					 errno);
> -				fail = 1;
> -			}
> +	pid = SAFE_FORK();
> +	if (pid == 0)
> +		exit(0);
>  
> -			ret = waitpid(pid, &status, WNOHANG);
> -			if (ret != -1) {
> -				tst_resm(TFAIL, "WNOHANG: Expected -1 got %d",
> -					 ret);
> -				fail = 1;
> -			}
> -			if (errno != ECHILD) {
> -				tst_resm(TFAIL, "WNOHANG: Expected ECHILD got "
> -					 "%d", errno);
> -				fail = 1;
> -			}
> +	while (((ret = waitpid(pid, &status, WNOHANG))
> +		!= -1) || (errno == EINTR)) {
> +		if (ret == -1)
> +			continue;
> +		if (ret == 0)
> +			continue;
>  
> -			if (fail)
> -				tst_resm(TFAIL, "case 2 FAILED");
> -			else
> -				tst_resm(TPASS, "case 2 PASSED");
> +		if (ret != pid) {
> +			tst_res(TFAIL, "proc id %d "
> +				 "and retval %d do not "
> +				 "match", pid, ret);
> +			fail = 1;
>  		}
>  
> -		cleanup();
> -	} else {
> -		/* wait for the child to return */
> -		waitpid(pid, &status, 0);
> -		if (WEXITSTATUS(status) != 0) {
> -			tst_brkm(TBROK, cleanup, "child returned bad "
> -				 "status");
> +		if (status != 0) {
> +			tst_res(TFAIL, "non zero "
> +				 "status received %d",
> +				 status);
> +			fail = 1;
>  		}
>  	}
>  
> -	tst_exit();
> +	pid = 0;
> +
> +	if (fail)
> +		tst_res(TFAIL, "case 0 FAILED");
> +	else
> +		tst_res(TPASS, "case 0 PASSED");
>  }

Both of the case0 and case1 can be easily further split into two
testcases, then we can get rid of the fail flag as well (do a return in
case of a failure and do TPASS on the last line of the test function).

> -/*
> - * setup_sigint()
> - *	sets up a SIGINT handler
> - */
> -static void setup_sigint(void)
> +static void case1(void)
>  {
> -	if ((sig_t) signal(SIGINT, inthandlr) == SIG_ERR) {
> -		tst_brkm(TFAIL, cleanup, "signal SIGINT failed, errno = %d",
> +	pid_t ret;
> +	int status;
> +	int fail = 0;
> +
> +	ret = waitpid(-1, &status, 0);
> +
> +	if (ret != -1) {
> +		tst_res(TFAIL, "Expected -1 got %d", ret);
> +		fail = 1;
> +	}
> +	if (errno != ECHILD) {
> +		tst_res(TFAIL, "Expected ECHILD got %d",
>  			 errno);
> +		fail = 1;
>  	}
> -}
> -
> -static void setup(void)
> -{
> -	TEST_PAUSE;
> -}
>  
> -static void cleanup(void)
> -{
> -}
> +	ret = waitpid(-1, &status, WNOHANG);
> +	if (ret != -1) {
> +		tst_res(TFAIL, "WNOHANG: Expected -1 got %d",
> +			 ret);
> +		fail = 1;
> +	}
> +	if (errno != ECHILD) {
> +		tst_res(TFAIL, "WNOHANG: Expected ECHILD got "
> +			 "%d", errno);
> +		fail = 1;
> +	}
>  
> -static void inthandlr(void)
> -{
> -	intintr++;
> +	if (fail)
> +		tst_res(TFAIL, "case 1 FAILED");
> +	else
> +		tst_res(TPASS, "case 1 PASSED");
>  }
>  
> -static void wait_for_parent(void)
> +static void waitpid09_test(unsigned int id)
>  {
> -	int testvar;
> -	while (!intintr)
> -		testvar = 0;
> +	switch (id) {
> +	case 0:
> +		case0();
> +		break;
> +	case 1:
> +		case1();
> +		break;
> +	default:
> +		tst_brk(TBROK, "Unknown %d", id);
> +	}
>  }
>  
>  static void do_exit(void)
>  {
> -	wait_for_parent();
> +	TST_CHECKPOINT_WAIT(0);
> +
>  	exit(0);
>  }

Since UCLINUX support was removed it does not make any sense to keep
this code in a function anymore...

> -#ifdef UCLINUX
> -/*
> - * do_exit_uclinux()
> - *	Sets up SIGINT handler again, then calls do_exit
> - */
> -static void do_exit_uclinux(void)
> -{
> -	setup_sigint();
> -	do_exit();
> -}
> -#endif
> +static struct tst_test test = {
> +	.tid = "waitpid09",
> +	.forks_child = 1,
> +	.needs_checkpoints = 1,
> +	.cleanup = cleanup,
> +	.test = waitpid09_test,
> +	.tcnt = 2,
> +};

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2016-07-18 14:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-15 14:39 [LTP] waitpid: new API Stanislav Kholmanskikh
2016-07-15 14:39 ` [LTP] [PATCH 1/8] tst_safe_macros: SAFE_GETPGID Stanislav Kholmanskikh
2016-07-15 14:39 ` [LTP] [PATCH 2/8] waitpid06: use the new API Stanislav Kholmanskikh
2016-07-18 13:05   ` Cyril Hrubis
2016-07-19 14:55     ` [LTP] [PATCH V2 1/4] " Stanislav Kholmanskikh
2016-07-19 14:55       ` [LTP] [PATCH V2 2/4] waitpid07: " Stanislav Kholmanskikh
2016-07-19 14:55         ` [LTP] [PATCH V2 3/4] waitpid08: " Stanislav Kholmanskikh
2016-07-19 14:55           ` [LTP] [PATCH V2 4/4] waitpid11: " Stanislav Kholmanskikh
2016-08-03 16:12         ` [LTP] [PATCH V2 2/4] waitpid07: " Cyril Hrubis
2016-08-03 16:01       ` [LTP] [PATCH V2 1/4] waitpid06: " Cyril Hrubis
2016-08-03 10:19     ` [LTP] [PATCH 2/8] " Stanislav Kholmanskikh
2016-08-03 12:01       ` Cyril Hrubis
2016-07-15 14:39 ` [LTP] [PATCH 3/8] waitpid07: " Stanislav Kholmanskikh
2016-07-15 14:39 ` [LTP] [PATCH 4/8] waitpid09: " Stanislav Kholmanskikh
2016-07-18 14:18   ` Cyril Hrubis [this message]
2016-07-19 10:34     ` [LTP] [PATCH V2 " Stanislav Kholmanskikh
2016-07-19 12:41       ` Cyril Hrubis
2016-07-19 14:57         ` Stanislav Kholmanskikh
2016-07-15 14:39 ` [LTP] [PATCH 5/8] waitpid11: " Stanislav Kholmanskikh
2016-07-18 15:01   ` Cyril Hrubis
2016-07-15 14:39 ` [LTP] [PATCH 6/8] waitpid12: " Stanislav Kholmanskikh
2016-07-18 15:07   ` Cyril Hrubis
2016-07-15 14:39 ` [LTP] [PATCH 7/8] waitpid13: " Stanislav Kholmanskikh
2016-07-15 14:39 ` [LTP] [PATCH 8/8] waitpid08: " Stanislav Kholmanskikh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160718141844.GD18221@rei.suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox