Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/1] test_macros: Add TST_EXP_PASS_OR_FAIL()
Date: Fri, 10 Jul 2026 11:30:21 +0200	[thread overview]
Message-ID: <alC7rUcJTSvI3r61@rei> (raw)
In-Reply-To: <20260710083337.1185184-1-pvorel@suse.cz>

Hi!
>  include/tst_test_macros.h | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index f06c8aeb77..e980cc6022 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -168,7 +168,7 @@ extern int TST_PASS;
>   * @ERRNO: Expected errno or 0.
>   * @...: A printf-like parameters.
>   *
> - * Expect a file descriptor if errno is 0 otherwise expect a failure with
> + * Expect a file descriptor if ERRNO is 0 otherwise expect a failure with
>   * expected errno.
>   *
>   * Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
> @@ -354,6 +354,29 @@ extern int TST_PASS;
>  			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>  	} while (0)
>  
> +/**
> + * TST_EXP_PASS_OR_FAIL() - Test syscall to and expect 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, ...)                                \
> +	({                                                                     \
> +		if (ERRNO)                                                     \
> +			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
> +		else                                                           \
> +			TST_EXP_PASS(SCALL, ##__VA_ARGS__);                      \
> +		                                                               \
> +		TST_RET;                                                       \
> +	})

I do not think that this is working as expected. If I remmeber correctly
we have to stringify the SCALL in the first macro is passed into
otherwise it may get expanded and produce unexpected results.

E.g. if we pass something with macro constants such as open() with
O_RDONLY the O_RDONLY will be replaced with 0. This is the reason why
the rest of the macros pass #SCALL to any macros it uses.

We need to change the TST_EXP_FAIL() and TST_EXP_PASS() so that they
have underscore variant first, e.g.:

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index f06c8aeb7..d391bdb9e 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -488,10 +488,13 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
  * printed by the pass or fail tst_res() calls. If omitted the first parameter
  * is converted to a string and used instead.
  */
-#define TST_EXP_FAIL(SCALL, EXP_ERR, ...)                                      \
+#define TST_EXP_FAIL(SCAL, EXP_ERR, ...) \
+       TST_EXP_FAIL_(SCAL, #SCAL, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL_(SCALL, SSCAL, EXP_ERR, ...)                                      \
        do {                                                                   \
                int tst_exp_err__ = EXP_ERR;                                   \
-               TST_EXP_FAIL_ARR_(SCALL, #SCALL, &tst_exp_err__, 1,            \
+               TST_EXP_FAIL_ARR_(SCALL, SSCALL, &tst_exp_err__, 1,            \
                                   ##__VA_ARGS__);                              \
        } while (0)


Then we can build the _OR_FAIL() macros on the top of that. And the
TST_EXP_FD_OR_FAIL() should be fixed too.

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2026-07-10  9:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  8:33 [LTP] [PATCH 1/1] test_macros: Add TST_EXP_PASS_OR_FAIL() Petr Vorel
2026-07-10  9:30 ` Cyril Hrubis [this message]
2026-07-10 11:55 ` [LTP] " linuxtestproject.agent

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=alC7rUcJTSvI3r61@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox