[LTP] [PATCH v2 1/2] tst_test_macros: add TST_EXP_FAIL_SILENT

Jan Stancek jstancek@redhat.com
Fri Feb 4 14:14:01 CET 2022


This variant does not print TPASS messages when
SCALL fails as expected.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 doc/c-test-api.txt        |  3 +++
 include/tst_test_macros.h | 15 ++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
index 6f4de3f80f95..9119e094dbfd 100644
--- a/doc/c-test-api.txt
+++ b/doc/c-test-api.txt
@@ -298,6 +298,9 @@ The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()' except the return value is
 expected to be non-negative integer if call passes. These macros build upon the
 +TEST()+ macro and associated variables.
 
+'TST_EXP_FAIL_SILENT()' and 'TST_EXP_FAIL2_SILENT()' variants are less verbose
+and do not print TPASS messages when SCALL fails as expected.
+
 [source,c]
 -------------------------------------------------------------------------------
 TEST(socket(AF_INET, SOCK_RAW, 1));
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index ec8c38523344..f7de8d00a666 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -163,7 +163,7 @@ extern void *TST_RET_PTR;
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)                                                            \
 
-#define TST_EXP_FAIL_(PASS_COND, SCALL, SSCALL, ERRNO, ...)                    \
+#define TST_EXP_FAIL_(SILENT, PASS_COND, SCALL, SSCALL, ERRNO, ...)            \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -181,8 +181,9 @@ extern void *TST_RET_PTR;
 		}                                                              \
 		                                                               \
 		if (TST_ERR == (ERRNO)) {                                      \
-			TST_MSG_(TPASS | TTERRNO, " ",                         \
-				 SSCALL, ##__VA_ARGS__);                       \
+			if (!SILENT)                                           \
+				TST_MSG_(TPASS | TTERRNO, " ",                 \
+				        SSCALL, ##__VA_ARGS__);                \
 			TST_PASS = 1;                                          \
 		} else {                                                       \
 			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
@@ -191,9 +192,13 @@ extern void *TST_RET_PTR;
 		}                                                              \
 	} while (0)
 
-#define TST_EXP_FAIL(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#define TST_EXP_FAIL(SCALL, ERRNO, ...) TST_EXP_FAIL_(0, TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
 
-#define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+#define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(0, TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) TST_EXP_FAIL_(1, TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL2_SILENT(SCALL, ERRNO, ...) TST_EXP_FAIL_(1, TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
 
 #define TST_EXP_EXPR(EXPR, FMT, ...)						\
 	tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: " FMT, ##__VA_ARGS__);
-- 
2.27.0



More information about the ltp mailing list