Skip to contentSkip to conversation

tst_test_macros.h: Add TST_EXP_VAL macro

PATCH Superseded zhanglianjie 2 participants 3 messages Aug 31, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tst_test_macros.h: Add TST_EXP_VAL macro

Add TST_EXP_VAL to determine whether the return value is equal to the given value.

include/tst_test_macros.h +28 -0
index 50598aa15..f8e08e134 100644
@@ -132,6 +132,34 @@ extern void *TST_RET_PTR;
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)                                                            \
 
+
+#define TST_EXP_VAL_SILENT_(SCALL, VAL, SSCALL, ...)                           \
+	do {                                                                   \
+		TEST(SCALL);                                                   \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET != VAL) {                                          \
+			TST_MSGP_(TFAIL | TTERRNO, " retval not %ld",          \
+			          (long )VAL, SSCALL, ##__VA_ARGS__);          \
+			break;                                                 \
+		}                                                              \
+		                                                               \
+		TST_PASS = 1;                                                  \
+		                                                               \
+	} 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)
+
 #define TST_EXP_FAIL_(PASS_COND, SCALL, SSCALL, ERRNO, ...)                    \
 	do {                                                                   \
 		TEST(SCALL);                                                   \

--
2.20.1

#1 lore raw

PATCH v3 1/1 tst_test_macros.h: Add TST_EXP_VAL macro

Hi Lianjie, Cyril,

I have revised the order of the macros and pushed them.
(put them on the top of TST_EXP_PASS_* to make the whole more readable)

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210831/a2bec591/attachment.htm>
#2 lore raw

PATCH v3 1/1 tst_test_macros.h: Add TST_EXP_VAL macro

Hi,
thank you.

Quoted 8 lines · Li Wang

Hi Lianjie, Cyril,

I have revised the order of the macros and pushed them.
(put them on the top of TST_EXP_PASS_* to make the whole more readable)

Signature · 2 lines
Regards,
Li Wang
Signature · 2 lines
Regards,
Zhang Lianjie