[LTP] [PATCH v2 1/2] test macros: Fix TST_EXP_FD_OR_FAIL()
Petr Vorel
pvorel@suse.cz
Fri Jul 10 15:03:02 CEST 2026
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
More information about the ltp
mailing list