* [LTP] [PATCH 1/1] test_macros: Add TST_EXP_PASS_OR_FAIL()
@ 2026-07-10 8:33 Petr Vorel
2026-07-10 9:30 ` Cyril Hrubis
2026-07-10 11:55 ` [LTP] " linuxtestproject.agent
0 siblings, 2 replies; 3+ messages in thread
From: Petr Vorel @ 2026-07-10 8:33 UTC (permalink / raw)
To: ltp
This allows instead of:
if (err) {
TST_EXP_FAIL(epoll_ctl(efd, EPOLL_CTL_ADD,
fd.fd, &ev), err,
"epoll_ctl() on %s", tst_fd_desc(&fd));
} else {
TST_EXP_PASS(epoll_ctl(efd, EPOLL_CTL_ADD,
fd.fd, &ev),
"epoll_ctl() on %s", tst_fd_desc(&fd));
}
to simplify to just:
TST_EXP_PASS_OR_FAIL(epoll_ctl(efd, EPOLL_CTL_ADD,
fd.fd, &ev), err,
"epoll_ctl() on %s", tst_fd_desc(&fd));
+ Fix macro parameter name in TST_EXP_FD_OR_FAIL() (upper case).
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
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; \
+ })
+
/**
* TST_EXP_PASS_PTR_VOID() - Test syscall to return a valid pointer.
*
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [LTP] [PATCH 1/1] test_macros: Add TST_EXP_PASS_OR_FAIL()
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
2026-07-10 11:55 ` [LTP] " linuxtestproject.agent
1 sibling, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2026-07-10 9:30 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [LTP] test_macros: Add TST_EXP_PASS_OR_FAIL()
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
@ 2026-07-10 11:55 ` linuxtestproject.agent
1 sibling, 0 replies; 3+ messages in thread
From: linuxtestproject.agent @ 2026-07-10 11:55 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi Petr,
On Fri, Jul 10, 2026, Petr Vorel wrote:
> test_macros: Add TST_EXP_PASS_OR_FAIL()
> + Fix macro parameter name in TST_EXP_FD_OR_FAIL() (upper case).
This is a second, independent logical change bundled into the same
patch. Ground Rule 7 requires exactly one logical change per patch.
The doc-comment fix in TST_EXP_FD_OR_FAIL() should go in a separate
preparatory patch.
> + * TST_EXP_PASS_OR_FAIL() - Test syscall to and expect to pass or fail with
> + * expected errno.
"to and expect" reads as ungrammatical here. Something like:
TST_EXP_PASS_OR_FAIL() - Test syscall to pass or fail with expected errno.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-10 11:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-07-10 11:55 ` [LTP] " linuxtestproject.agent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox