[LTP] [PATCH] waitpid04: Convert to new API
Petr Vorel
pvorel@suse.cz
Wed Jan 31 18:21:48 CET 2024
> 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);
> }
More information about the ltp
mailing list