public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] waitpid04: Convert to new API
Date: Wed, 31 Jan 2024 18:21:48 +0100	[thread overview]
Message-ID: <20240131172148.GA5570@pevik> (raw)
In-Reply-To: <20240131135026.1562-1-mdoucha@suse.cz>

> Convert waitpid() error state checks to new API, fix bugs in the original
> test and add ESRCH subtest.

Very nice cleanup.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

BTW what were these bugs? It looks like old test uses pid O for the first ECHILD
test (not sure how it got defined to 0).

>  #include <sys/signal.h>
nit: this should be <signal.h>
warning: #warning redirecting incorrect #include <sys/signal.h> to <signal.h> [-Wcpp]

Can be fixed before merge.

>  #include <sys/types.h>
>  #include <sys/wait.h>
...
> +#include "tst_test.h"
> +
> +#define TCFMT "waipid(%d, NULL, 0x%x)"
> +#define TCFMTARGS(tc) (tc)->pid, (tc)->flags

checkpatch.pl complains:
waitpid04.c:19: ERROR: Macros with complex values should be enclosed in parentheses

I guess we can ignore this unless you see a quick fix (I guess macro which runs
tst_res() inside would be needed.

> +static struct testcase {
> +	pid_t pid;
> +	int flags;
> +	int err;
> +} testcase_list[] = {
> +	{-1, 0, ECHILD},	/* Wait for any child when none exist */
> +	{1, 0, ECHILD},		/* Wait for non-child process */
> +	{-1, -1, EINVAL},	/* Invalid flags */
> +	{INT_MIN, 0, ESRCH},	/* Wait for invalid process group */
> +};
> +
> +void run(unsigned int n)
>  {
...
> +	const struct testcase *tc = testcase_list + n;

> -		if (FORK_OR_VFORK() == 0)
> -			exit(0);
> +	TEST(waitpid(tc->pid, NULL, tc->flags));
How about using TST_EXP_FAIL2() to avoid code below? It would also help to avoid
macros, right?  Or you want to explicitly state what failed?

Kind regards,
Petr

> +	if (TST_RET == -1 && TST_ERR == tc->err) {
> +		tst_res(TPASS | TTERRNO, TCFMT " failed as expected",
> +			TCFMTARGS(tc));
> +		return;
> +	}

> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TTERRNO, TCFMT ": expected error %s, got",
> +			TCFMTARGS(tc), tst_strerrno(tc->err));
> +		return;
>  	}

> +	if (TST_RET < 0) {
> +		tst_res(TFAIL | TTERRNO, TCFMT ": invalid return value %ld",
> +			TCFMTARGS(tc), TST_RET);
> +		return;
> +	}

> +	tst_res(TFAIL, TCFMT " returned unexpected PID %ld", TCFMTARGS(tc),
> +		TST_RET);
>  }

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-01-31 17:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 13:50 [LTP] [PATCH] waitpid04: Convert to new API Martin Doucha
2024-01-31 17:21 ` Petr Vorel [this message]
2024-02-01 11:10   ` Martin Doucha
2024-02-01 11:51     ` Petr Vorel

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=20240131172148.GA5570@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=mdoucha@suse.cz \
    /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