[LTP] [PATCH v1] lib: Add TST_EXP_PASS_PTR_{NULL,VOID} macros
Wei Gao
wegao@suse.com
Mon Apr 15 04:51:00 CEST 2024
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_test_macros.h | 41 +++++++++++++++++++++++++
testcases/kernel/syscalls/sbrk/sbrk01.c | 7 +----
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 22b39fb14..2668758fb 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -178,6 +178,28 @@ extern void *TST_RET_PTR;
\
} while (0)
+#define TST_EXP_PASS_SILENT_PTR_(SCALL, SSCALL, FAIL_PTR_VAL, ...) \
+ do { \
+ TESTPTR(SCALL); \
+ \
+ TST_PASS = 0; \
+ \
+ if (TST_RET_PTR == FAIL_PTR_VAL) { \
+ TST_MSG_(TFAIL | TTERRNO, " failed", \
+ SSCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ if (TST_RET != 0) { \
+ TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld", \
+ TST_RET, SSCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ TST_PASS = 1; \
+ \
+ } while (0)
+
#define TST_EXP_PASS_SILENT(SCALL, ...) TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__)
#define TST_EXP_PASS(SCALL, ...) \
@@ -188,6 +210,25 @@ extern void *TST_RET_PTR;
TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
} while (0) \
+#define TST_EXP_PASS_PTR_(SCALL, SSCALL, FAIL_PTR_VAL, ...) \
+ do { \
+ TST_EXP_PASS_SILENT_PTR_(SCALL, SSCALL, \
+ FAIL_PTR_VAL, ##__VA_ARGS__); \
+ \
+ if (TST_PASS) \
+ TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
+ } while (0)
+
+#define TST_EXP_PASS_PTR_NULL(SCALL, ...) \
+ do { \
+ TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__); \
+ } while (0)
+
+#define TST_EXP_PASS_PTR_VOID(SCALL, ...) \
+ do { \
+ TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__); \
+ } while (0)
+
/*
* Returns true if err is in the exp_err array.
*/
diff --git a/testcases/kernel/syscalls/sbrk/sbrk01.c b/testcases/kernel/syscalls/sbrk/sbrk01.c
index bb78d9a7b..2d2244a35 100644
--- a/testcases/kernel/syscalls/sbrk/sbrk01.c
+++ b/testcases/kernel/syscalls/sbrk/sbrk01.c
@@ -26,12 +26,7 @@ static void run(unsigned int i)
{
struct tcase *tc = &tcases[i];
- TESTPTR(sbrk(tc->increment));
-
- if (TST_RET_PTR == (void *) -1)
- tst_res(TFAIL | TTERRNO, "sbrk(%ld) failed", tc->increment);
- else
- tst_res(TPASS, "sbrk(%ld) returned %p", tc->increment, TST_RET_PTR);
+ TST_EXP_PASS_PTR_VOID(sbrk(tc->increment), "sbrk(%ld) returned %p", tc->increment, TST_RET_PTR);
}
static struct tst_test test = {
--
2.35.3
More information about the ltp
mailing list