[LTP] [PATCH v2] Support return value in TST_* macros

Andrea Cervesato andrea.cervesato@suse.de
Wed Apr 26 11:08:03 CEST 2023


From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Removed return value from TST_EXP_PASS_* and TST_EXP_FAIL_*
Add TST_EXP_POSITIVE__

 include/tst_test_macros.h | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 231c04951..bd0c491c1 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -51,7 +51,7 @@ extern void *TST_RET_PTR;
 	tst_res_(__FILE__, __LINE__, RES, \
 		TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR, PAR2)
 
-#define TST_EXP_POSITIVE_(SCALL, SSCALL, ...)                                  \
+#define TST_EXP_POSITIVE__(SCALL, SSCALL, ...)                                 \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -73,46 +73,59 @@ extern void *TST_RET_PTR;
                                                                                \
 	} while (0)
 
+#define TST_EXP_POSITIVE_(SCALL, ...)                                          \
+	({                                                                     \
+		TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__);              \
+		TST_RET;                                                       \
+	})
+
 #define TST_EXP_POSITIVE(SCALL, ...)                                           \
-	do {                                                                   \
-		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
+	({                                                                     \
+		TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__);              \
 		                                                               \
 		if (TST_PASS) {                                                \
 			TST_MSGP_(TPASS, " returned %ld",                      \
 			          TST_RET, #SCALL, ##__VA_ARGS__);             \
 		}                                                              \
-	} while (0)
+		                                                               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_FD_SILENT(SCALL, ...)	TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
 
 #define TST_EXP_FD(SCALL, ...)                                                 \
-	do {                                                                   \
-		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
+	({                                                                     \
+		TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__);              \
 		                                                               \
 		if (TST_PASS)                                                  \
 			TST_MSGP_(TPASS, " returned fd %ld", TST_RET,          \
 				#SCALL, ##__VA_ARGS__);                        \
-	} while (0)
+		                                                               \
+		TST_RET;                                                       \
+	})
 
-#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                    \
-	do {                                                                   \
+#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                  \
+	({                                                                     \
 		if (ERRNO)                                                     \
 			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
 		else                                                           \
 			TST_EXP_FD(SCALL, ##__VA_ARGS__);                      \
 		                                                               \
-	} while (0)
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_PID_SILENT(SCALL, ...)	TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
 
 #define TST_EXP_PID(SCALL, ...)                                                \
-	do {                                                                   \
-		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
+	({                                                                     \
+		TST_EXP_POSITIVE__(SCALL, #SCALL, ##__VA_ARGS__);              \
 									       \
 		if (TST_PASS)                                                  \
 			TST_MSGP_(TPASS, " returned pid %ld", TST_RET,         \
 				#SCALL, ##__VA_ARGS__);                        \
-	} while (0)
+		                                                               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_VAL_SILENT_(SCALL, VAL, SSCALL, ...)                           \
 	do {                                                                   \
-- 
2.35.3



More information about the ltp mailing list