* [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL()
@ 2026-07-10 13:03 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:09 ` [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL() Cyril Hrubis
0 siblings, 2 replies; 4+ messages in thread
From: Petr Vorel @ 2026-07-10 13:03 UTC (permalink / raw)
To: ltp
SCALL in first macro needs to be stringified otherwise constants in
syscalls will be evaluated (e.g. O_RDONLY becomes 0).
That required to add TST_EXP_FD_OR_FAIL_() and TST_EXP_FAIL_().
While at it, document this reason in the header.
Fixes: a2a5730f34 ("tst_test_macros: Add TST_EXP_FD_OR_FAIL() macro")
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes in v2:
* Use underscore variant TST_EXP_PASS_ and TST_EXP_FAIL_() (Cyril)
* Add a test (can be done in a separate commit)
* Fix grammar "to and expect" (agent)
Link to v1:
https://lore.kernel.org/ltp/20260710083337.1185184-1-pvorel@suse.cz/
include/tst_test_macros.h | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index f06c8aeb77..e18f1d33f3 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -8,6 +8,12 @@
* DOC: tst_test_macros.h -- helpers for testing syscalls
*/
+/*
+ * NOTE: for all TST_EXP_*() macros SCALL in first macro needs to be stringified
+ * otherwise constants in syscalls will be evaluated (e.g. O_RDONLY becomes 0).
+ * That is the reason for underscore variants (e.g. TST_EXP_FAIL_()).
+ */
+
#ifndef TST_TEST_MACROS_H__
#define TST_TEST_MACROS_H__
@@ -149,7 +155,10 @@ extern int TST_PASS;
* This is a variant of the TST_EXP_POSITIVE() for a more specific case that
* the returned value is a file descriptor.
*/
-#define TST_EXP_FD(SCALL, ...) \
+#define TST_EXP_FD(SCALL, ...) \
+ TST_EXP_FD_(SCALL, #SCALL, ##__VA_ARGS__)
+
+#define TST_EXP_FD_(SCALL, SSCALL, ...) \
({ \
TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__); \
\
@@ -174,11 +183,14 @@ extern int TST_PASS;
* Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
*/
#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...) \
- ({ \
+ TST_EXP_FD_OR_FAIL_(SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_FD_OR_FAIL_(SCALL, SSCALL, ERRNO, ...) \
+ ({ \
if (ERRNO) \
- TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__); \
+ TST_EXP_FAIL_(SCALL, SSCALL, ERRNO, ##__VA_ARGS__); \
else \
- TST_EXP_FD(SCALL, ##__VA_ARGS__); \
+ TST_EXP_FD_(SCALL, SSCALL, ##__VA_ARGS__); \
\
TST_RET; \
})
@@ -488,10 +500,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(SCALL, EXP_ERR, ...) \
+ TST_EXP_FAIL_(SCALL, #SCALL, EXP_ERR, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL_(SCALL, SSCALL, 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)
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread* [LTP] [PATCH v2 2/2] test_macros: Add TST_EXP_PASS_OR_FAIL()
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 ` Petr Vorel
2026-07-10 13:12 ` Cyril Hrubis
2026-07-10 13:09 ` [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL() Cyril Hrubis
1 sibling, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2026-07-10 13:03 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));
That required to add TST_EXP_PASS_().
Add test into test_macros03.c.
+ Fix macro parameter name in TST_EXP_FD_OR_FAIL() (upper case).
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes in v2:
* Use underscore variant TST_EXP_PASS_ and TST_EXP_FAIL_() (Cyril)
* Add a test (can be done in a separate commit)
Link to v1:
https://lore.kernel.org/ltp/20260710083337.1185184-1-pvorel@suse.cz/
include/tst_test_macros.h | 31 ++++++++++++++++++++++++++++++-
lib/newlib_tests/test_macros03.c | 9 ++++++++-
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index e18f1d33f3..3932687904 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -177,7 +177,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().
@@ -350,6 +350,9 @@ extern int TST_PASS;
* is converted to a string and used instead.
*/
#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__); \
\
@@ -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, ...) \
+ ({ \
+ 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [LTP] [PATCH v2 2/2] test_macros: Add TST_EXP_PASS_OR_FAIL()
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
0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2026-07-10 13:12 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL()
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:09 ` Cyril Hrubis
1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2026-07-10 13:09 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index f06c8aeb77..e18f1d33f3 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -8,6 +8,12 @@
> * DOC: tst_test_macros.h -- helpers for testing syscalls
> */
>
> +/*
> + * NOTE: for all TST_EXP_*() macros SCALL in first macro needs to be stringified
> + * otherwise constants in syscalls will be evaluated (e.g. O_RDONLY becomes 0).
> + * That is the reason for underscore variants (e.g. TST_EXP_FAIL_()).
> + */
> +
> #ifndef TST_TEST_MACROS_H__
> #define TST_TEST_MACROS_H__
>
> @@ -149,7 +155,10 @@ extern int TST_PASS;
> * This is a variant of the TST_EXP_POSITIVE() for a more specific case that
> * the returned value is a file descriptor.
> */
> -#define TST_EXP_FD(SCALL, ...) \
> +#define TST_EXP_FD(SCALL, ...) \
> + TST_EXP_FD_(SCALL, #SCALL, ##__VA_ARGS__)
> +
> +#define TST_EXP_FD_(SCALL, SSCALL, ...) \
> ({ \
> TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__); \
^
SSCALL
> @@ -174,11 +183,14 @@ extern int TST_PASS;
> * Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
> */
> #define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...) \
> - ({ \
> + TST_EXP_FD_OR_FAIL_(SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
> +
> +#define TST_EXP_FD_OR_FAIL_(SCALL, SSCALL, ERRNO, ...) \
> + ({ \
This indirection is not needed as long as TST_EXP_FD_OR_FAIL() is not
called from other macros.
> if (ERRNO) \
> - TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__); \
> + TST_EXP_FAIL_(SCALL, SSCALL, ERRNO, ##__VA_ARGS__); \
> else \
> - TST_EXP_FD(SCALL, ##__VA_ARGS__); \
> + TST_EXP_FD_(SCALL, SSCALL, ##__VA_ARGS__); \
> \
> TST_RET; \
> })
> @@ -488,10 +500,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(SCALL, EXP_ERR, ...) \
> + TST_EXP_FAIL_(SCALL, #SCALL, EXP_ERR, ##__VA_ARGS__)
> +
> +#define TST_EXP_FAIL_(SCALL, SSCALL, 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)
>
> --
> 2.54.0
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-10 13:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-07-10 13:09 ` [LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL() Cyril Hrubis
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.