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

Andrea Cervesato andrea.cervesato@suse.de
Wed Apr 26 09:49:50 CEST 2023


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

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tst_test_macros.h | 69 +++++++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 21 deletions(-)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 231c04951..acc2d1bff 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -74,45 +74,60 @@ extern void *TST_RET_PTR;
 	} while (0)
 
 #define TST_EXP_POSITIVE(SCALL, ...)                                           \
-	do {                                                                   \
+	({                                                                     \
 		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_SILENT(SCALL, ...)                                          \
+	({                                                                     \
+		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_FD(SCALL, ...)                                                 \
-	do {                                                                   \
+	({                                                                     \
 		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_SILENT(SCALL, ...)                                         \
+	({                                                                     \
+		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_PID(SCALL, ...)                                                \
-	do {                                                                   \
+	({                                                                     \
 		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 {                                                                   \
@@ -128,18 +143,20 @@ extern void *TST_RET_PTR;
 		                                                               \
 		TST_PASS = 1;                                                  \
 		                                                               \
+		TST_RET;                                                       \
 	} while (0)
 
 #define TST_EXP_VAL_SILENT(SCALL, VAL, ...) TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__)
 
 #define TST_EXP_VAL(SCALL, VAL, ...)                                           \
-	do {                                                                   \
+	({                                                                     \
 		TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__);        \
 		                                                               \
 		if (TST_PASS)                                                  \
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
-			                                                       \
-	} while(0)
+		                                                               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_PASS_SILENT_(SCALL, SSCALL, ...)                               \
 	do {                                                                   \
@@ -163,15 +180,21 @@ extern void *TST_RET_PTR;
                                                                                \
 	} while (0)
 
-#define TST_EXP_PASS_SILENT(SCALL, ...) TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__)
+#define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
+	({                                                                     \
+		TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__);            \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_PASS(SCALL, ...)                                               \
-	do {                                                                   \
+	({                                                                     \
 		TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__);            \
 		                                                               \
 		if (TST_PASS)                                                  \
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
-	} while (0)                                                            \
+		                                                               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_FAIL_SILENT_(PASS_COND, SCALL, SSCALL, ERRNO, ...)             \
 	do {                                                                   \
@@ -200,20 +223,24 @@ extern void *TST_RET_PTR;
 	} while (0)
 
 #define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
-	do {                                                                   \
+	({                                                                     \
 		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL,              \
 			ERRNO, ##__VA_ARGS__);                                 \
 		if (TST_PASS)                                                  \
 			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
-	} while (0)
+		                                                               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_FAIL2(SCALL, ERRNO, ...)                                       \
-	do {                                                                   \
+	({                                                                     \
 		TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL,              \
 			ERRNO, ##__VA_ARGS__);                                 \
 		if (TST_PASS)                                                  \
 			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
-	} while (0)
+		                                                               \
+		TST_RET;                                                       \
+	})
 
 #define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) \
 	TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
-- 
2.35.3



More information about the ltp mailing list