All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/8] waitpid09: use the new API
Date: Mon, 15 Aug 2016 15:55:24 +0200	[thread overview]
Message-ID: <20160815135523.GE20680@rei.lan> (raw)
In-Reply-To: <1470818466-28109-2-git-send-email-stanislav.kholmanskikh@oracle.com>

Hi!
> +static void case1(void)
>  {
> -	intintr++;
> +	pid_t pid, ret;
> +	int status;
> +
> +	pid = SAFE_FORK();
> +	if (pid == 0)
> +		exit(0);
> +
> +	for (;;) {
> +		ret = waitpid(pid, &status, WNOHANG);
> +
> +		if ((ret == -1) && (errno == EINTR))
> +			continue;
> +		if (ret == 0)
> +			continue;
> +
> +		if (ret == pid)
> +			break;
> +
> +		tst_res(TFAIL, "waitpid(WNOHANG) returned %d, expected %d",
> +			ret, pid);
> +		cleanup_pid(pid);
> +		return;
> +	}
> +
> +	if (!WIFEXITED(status)) {
> +		tst_res(TFAIL, "Child exited abnormally");
> +		return;
> +	}
> +
> +	if (WEXITSTATUS(status) != 0) {
> +		tst_res(TFAIL, "Child exited with %d, expected 0",
> +			WEXITSTATUS(status));
> +		return;
> +	}
> +
> +	tst_res(TPASS, "Case 1 PASSED");
>  }

Isn't this one the same as the second part of case0() ?

I guess that we can just do:

	TST_CHECKPOINT_WAKE(0);
	SAFE_WAITPID(pid, NULL, 0);

In the case0() since the rest of the assertions is covered in case1().


Also we may print something little more informative than "Case 1
PASSED". I would do something as:

tst_res(TPASS | TERRNO, "waitpid(-1, ..., WNOHANG)");

But that is very minor.

> +static void waitpid09_test(unsigned int id)
>  {
> -	setup_sigint();
> -	do_exit();
> +	switch (id) {
> +	case 0:
> +		case0();
> +		break;
> +	case 1:
> +		case1();
> +		break;
> +	case 2:
> +		case2();
> +		break;
> +	case 3:
> +		case3();
> +		break;
> +	default:
> +		tst_brk(TBROK, "Unknown %d", id);
> +	}
>  }

This maybe could be a little shorter with an array of fucnctions.

Something as:

static void (*tests[])(void) = {case0, case1, case2, case3};

static void do_test(unsigned int i)
{
	tests[i]();
}


...

static struct test = {
	...
	.tcnt = ARRAY_SIZE(tests);
};




And we may even add a tests pointer to the struct test structure and
teach the test library to use it if set so that we can pass an array of
functions directly.

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2016-08-15 13:55 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10  8:40 [LTP] waitpid: new API (part 2) Stanislav Kholmanskikh
2016-08-10  8:40 ` [LTP] [PATCH 1/8] waitpid09: use the new API Stanislav Kholmanskikh
2016-08-10  8:41   ` [LTP] [PATCH 2/8] waitpid10: " Stanislav Kholmanskikh
2016-08-10  8:41     ` [LTP] [PATCH 3/8] syscalls/waitpid: implement waitpid_ret_test() Stanislav Kholmanskikh
2016-08-10  8:41       ` [LTP] [PATCH 4/8] syscalls/waitpid: make reap_children() fail if errno is not ECHILD Stanislav Kholmanskikh
2016-08-10  8:41         ` [LTP] [PATCH 5/8] waitpid11: update the description Stanislav Kholmanskikh
2016-08-10  8:41           ` [LTP] [PATCH 6/8] waitpid12: use the new API Stanislav Kholmanskikh
2016-08-10  8:41             ` [LTP] [PATCH 7/8] waitpid13: " Stanislav Kholmanskikh
2016-08-10  8:41               ` [LTP] [PATCH 8/8] waitpid08: test stopped children Stanislav Kholmanskikh
2016-08-16 13:03                 ` Cyril Hrubis
2016-08-18 10:12                   ` Stanislav Kholmanskikh
2016-08-18 10:48                     ` Cyril Hrubis
2016-08-18 11:37                       ` Stanislav Kholmanskikh
2016-08-16 13:24               ` [LTP] [PATCH 7/8] waitpid13: use the new API Cyril Hrubis
2016-08-16 13:20             ` [LTP] [PATCH 6/8] waitpid12: " Cyril Hrubis
2016-08-15 15:51           ` [LTP] [PATCH 5/8] waitpid11: update the description Cyril Hrubis
2016-08-15 15:49         ` [LTP] [PATCH 4/8] syscalls/waitpid: make reap_children() fail if errno is not ECHILD Cyril Hrubis
2016-08-15 15:27       ` [LTP] [PATCH 3/8] syscalls/waitpid: implement waitpid_ret_test() Cyril Hrubis
2016-08-18  9:54         ` Stanislav Kholmanskikh
2016-08-18 10:42           ` Cyril Hrubis
2016-08-18 15:15             ` Stanislav Kholmanskikh
2016-08-18 15:43               ` Cyril Hrubis
2016-08-18 15:54               ` Cyril Hrubis
2016-08-19  9:47                 ` Stanislav Kholmanskikh
2016-08-22 17:38                   ` Cyril Hrubis
2016-08-15 14:36     ` [LTP] [PATCH 2/8] waitpid10: use the new API Cyril Hrubis
2016-08-18  8:25       ` Stanislav Kholmanskikh
2016-08-18  8:33         ` Stanislav Kholmanskikh
2016-08-18  9:19           ` Cyril Hrubis
2016-08-15 13:55   ` Cyril Hrubis [this message]
2016-08-18  7:40     ` [LTP] [PATCH 1/8 V2] waitpid09: " 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=20160815135523.GE20680@rei.lan \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.