[LTP] [PATCH v6 3/3] realpath01.c: use TST_EXP_FAIL_PTR_NULL

Wei Gao wegao@suse.com
Wed Apr 3 05:28:59 CEST 2024


Signed-off-by: Wei Gao <wegao@suse.com>
---
 include/tst_test_macros.h                       |  8 ++++----
 lib/newlib_tests/test_macros07.c                |  8 ++++----
 testcases/kernel/syscalls/realpath/realpath01.c | 11 +----------
 3 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index eff3aef69..88c329333 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -300,10 +300,10 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
 	} while (0)
 
-#define TST_EXP_FAIL_PTR_ARR_NULL(SCALL, EXP_ERRS, ...)                        \
+#define TST_EXP_FAIL_PTR_ARR_NULL(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_PTR_(SCALL, #SCALL, NULL,                         \
-			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);        \
+			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);                \
 	} while (0)
 
 #define TST_EXP_FAIL_PTR_VOID(SCALL, EXP_ERR, ...)                             \
@@ -313,10 +313,10 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
 	} while (0)
 
-#define TST_EXP_FAIL_PTR_ARR_VOID(SCALL, EXP_ERRS, ...)                        \
+#define TST_EXP_FAIL_PTR_ARR_VOID(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)          \
 	do {                                                                   \
 		TST_EXP_FAIL_PTR_(SCALL, #SCALL, (void *)-1,                   \
-			EXP_ERRS, ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);        \
+			EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__);                \
 	} while (0)
 
 #define TST_EXP_FAIL2(SCALL, EXP_ERR, ...)                                     \
diff --git a/lib/newlib_tests/test_macros07.c b/lib/newlib_tests/test_macros07.c
index ac361fd8e..6015988cf 100644
--- a/lib/newlib_tests/test_macros07.c
+++ b/lib/newlib_tests/test_macros07.c
@@ -38,9 +38,9 @@ static void do_test(void)
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 	TST_EXP_FAIL_PTR_NULL(pass_fn(), ENOTTY, "pass_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_pass, "fail_fn_null()");
+	TST_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_pass, ARRAY_SIZE(exp_errs_pass), "fail_fn_null()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_fail, "fail_fn()_null");
+	TST_EXP_FAIL_PTR_ARR_NULL(fail_fn_null(), exp_errs_fail, ARRAY_SIZE(exp_errs_fail), "fail_fn()_null");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 
 	tst_res(TINFO, "Testing TST_EXP_FAIL_PTR_VOID macro");
@@ -50,9 +50,9 @@ static void do_test(void)
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 	TST_EXP_FAIL_PTR_VOID(pass_fn(), ENOTTY, "pass_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_pass, "fail_fn_void()");
+	TST_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_pass, ARRAY_SIZE(exp_errs_pass), "fail_fn_void()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_fail, "fail_fn()_void");
+	TST_EXP_FAIL_PTR_ARR_VOID(fail_fn_void(), exp_errs_fail, ARRAY_SIZE(exp_errs_fail), "fail_fn()_void");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 }
 
diff --git a/testcases/kernel/syscalls/realpath/realpath01.c b/testcases/kernel/syscalls/realpath/realpath01.c
index c0381e9cb..c4c603609 100644
--- a/testcases/kernel/syscalls/realpath/realpath01.c
+++ b/testcases/kernel/syscalls/realpath/realpath01.c
@@ -24,16 +24,7 @@ static void setup(void)
 
 static void run(void)
 {
-	TESTPTR(realpath(".", NULL));
-
-	if (TST_ERR != ENOENT) {
-		tst_res(TFAIL | TTERRNO, "returned unexpected errno");
-	} else	if (TST_RET_PTR != NULL) {
-		tst_res(TFAIL, "syscall didn't return NULL: '%s'",
-				(char *)TST_RET_PTR);
-	} else {
-		tst_res(TPASS, "bug not reproduced");
-	}
+	TST_EXP_FAIL_PTR_NULL(realpath(".", NULL), ENOENT);
 }
 
 static struct tst_test test = {
-- 
2.35.3



More information about the ltp mailing list