[LTP] [PATCH v3 1/4] test macros: Fix TST_EXP_FD_OR_FAIL()

Petr Vorel pvorel@suse.cz
Tue Aug 11 17:51:59 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_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>
Reviewed-by: Li Wang <li.wang@linux.dev>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Please double check if TST_MSGP_() in TST_EXP_FD_() should really use
SSCALL instead of #SCALL.

 include/tst_test_macros.h | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index f06c8aeb77..65ec873444 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,13 +155,16 @@ 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__);              \
+		TST_EXP_POSITIVE__(SCALL, SSCALL, ##__VA_ARGS__);              \
 		                                                               \
 		if (TST_PASS)                                                  \
 			TST_MSGP_(TPASS, " returned fd %ld", TST_RET,          \
-				#SCALL, ##__VA_ARGS__);                        \
+				SSCALL, ##__VA_ARGS__);                        \
 		                                                               \
 		TST_RET;                                                       \
 	})
@@ -174,11 +183,11 @@ extern int TST_PASS;
  * Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
  */
 #define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                  \
-	({                                                                     \
+	({                                                                 \
 		if (ERRNO)                                                     \
-			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
+			TST_EXP_FAIL_(SCALL, #SCALL, ERRNO, ##__VA_ARGS__);    \
 		else                                                           \
-			TST_EXP_FD(SCALL, ##__VA_ARGS__);                      \
+			TST_EXP_FD_(SCALL, #SCALL, ##__VA_ARGS__);             \
 		                                                               \
 		TST_RET;                                                       \
 	})
@@ -488,10 +497,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.55.0



More information about the ltp mailing list