[LTP] [PATCH v2 3/7] lib: add TST_EXP_PASS_PTR_NULL() macro

Andrea Cervesato andrea.cervesato@suse.de
Thu Apr 16 16:33:37 CEST 2026


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

Add a variant of TST_EXP_PASS_PTR_VOID() that checks the return
value against NULL instead of (void *)-1. This is useful for libc
functions such as fopen() that return NULL on failure, allowing
tests to report TFAIL instead of TBROK when the call fails.

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

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 3d2287753b0419c82b1a878e8779def99d4bb4ca..2cfbdb5869af5c871e7086236a17b3a76e34b5d3 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -370,7 +370,20 @@ extern int TST_PASS;
  * is converted to a string and used instead.
  */
 #define TST_EXP_PASS_PTR_VOID(SCALL, ...)                                      \
-               TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__);
+	TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__);
+
+/**
+ * TST_EXP_PASS_PTR_NULL() - Test call to return a non-NULL pointer.
+ *
+ * @SCALL: Tested call.
+ * @...: A printf-like parameters.
+ *
+ * This macro works like TST_EXP_PASS_PTR_VOID() but checks the return
+ * value against NULL instead of (void *)-1. Use this for libc functions
+ * such as fopen() that return NULL on failure.
+ */
+#define TST_EXP_PASS_PTR_NULL(SCALL, ...)                                      \
+	TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__)
 
 /*
  * Returns true if err is in the exp_err array.

-- 
2.51.0



More information about the ltp mailing list