[LTP] [PATCH 1/1] test_macros: Add TST_EXP_PASS_OR_FAIL()
Petr Vorel
pvorel@suse.cz
Fri Jul 10 10:33:37 CEST 2026
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
More information about the ltp
mailing list