From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 2/2] test_macros: Add TST_EXP_PASS_OR_FAIL()
Date: Fri, 10 Jul 2026 15:12:56 +0200 [thread overview]
Message-ID: <alDv2LPAshw48WBE@rei> (raw)
In-Reply-To: <20260710130303.1210731-2-pvorel@suse.cz>
Hi!
> #define TST_EXP_PASS(SCALL, ...) \
> + TST_EXP_PASS_(SCALL, #SCALL, ##__VA_ARGS__)
> +
> +#define TST_EXP_PASS_(SCALL, SSCALL, ...) \
> do { \
> TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__); \
^
Here as well SSCALL
> @@ -366,6 +369,32 @@ extern int TST_PASS;
> TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
> } while (0)
>
> +/**
> + * TST_EXP_PASS_OR_FAIL() - Test syscall and expect it to pass or fail with
> + * expected errno.
> + *
> + * @SCALL: Tested syscall.
> + * @ERRNO: Expected errno or 0.
> + * @...: A printf-like parameters.
> + *
> + * Expect to pass if ERRNO is 0 otherwise expect a failure with
> + * expected errno.
> + *
> + * Internally it uses TST_EXP_FAIL() and TST_EXP_PASS().
> + */
> +#define TST_EXP_PASS_OR_FAIL(SCALL, ERRNO, ...) \
> + TST_EXP_PASS_OR_FAIL_(SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
> +
> +#define TST_EXP_PASS_OR_FAIL_(SCALL, SSCALL, ERRNO, ...) \
And here as well, no need for the indirection until we need to use
TST_EXP_PASS_OR_FAIL_ in another macro.
> + ({ \
> + if (ERRNO) \
> + TST_EXP_FAIL_(SCALL, SSCALL, ERRNO, ##__VA_ARGS__); \
> + else \
> + TST_EXP_PASS_(SCALL, SSCALL, ##__VA_ARGS__); \
> + \
> + TST_RET; \
> + })
> +
> /**
> * TST_EXP_PASS_PTR_VOID() - Test syscall to return a valid pointer.
> *
> diff --git a/lib/newlib_tests/test_macros03.c b/lib/newlib_tests/test_macros03.c
> index 19a0ad6fd3..2a281bafcd 100644
> --- a/lib/newlib_tests/test_macros03.c
> +++ b/lib/newlib_tests/test_macros03.c
> @@ -9,9 +9,11 @@
>
> #include "tst_test.h"
>
> +#define ERR_ERRNO EINVAL
> +
> static int fail_fn(void)
> {
> - errno = EINVAL;
> + errno = ERR_ERRNO;
> return -1;
> }
>
> @@ -42,6 +44,11 @@ static void do_test(void)
> tst_res(TINFO, "TST_PASS = %i from TST_EXP_PASS_SILENT(pass_fn, ...)", TST_PASS);
> TST_EXP_PASS_SILENT(inval_ret_fn(), "inval_ret_fn()");
> tst_res(TINFO, "TST_PASS = %i", TST_PASS);
> +
> + tst_res(TINFO, "Testing TST_EXP_PASS_OR_FAIL() macro (pass)");
> + TST_EXP_PASS_OR_FAIL(pass_fn(), 0, "pass_fn()");
> + tst_res(TINFO, "Testing TST_EXP_PASS_OR_FAIL() macro (fail)");
> + TST_EXP_PASS_OR_FAIL(fail_fn(), ERR_ERRNO, "fail_fn()");
> }
>
> static struct tst_test test = {
> --
> 2.54.0
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-07-10 13:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 13:03 [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL() Petr Vorel
2026-07-10 13:03 ` [LTP] [PATCH v2 2/2] test_macros: Add TST_EXP_PASS_OR_FAIL() Petr Vorel
2026-07-10 13:12 ` Cyril Hrubis [this message]
2026-07-10 13:09 ` [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL() Cyril Hrubis
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=alDv2LPAshw48WBE@rei \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@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 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.