[LTP] [PATCH v3 2/3] tst_test_macros.h: Require to pass array size in TST_EXP_FAIL*_ARR()

Petr Vorel pvorel@suse.cz
Tue Mar 26 15:41:44 CET 2024


Although having to pass ARRAY_SIZE() of the expected errnos is not
ideal, it gives more flexibility to the tests allowing to use just
portion of the array (will be used in fanotify14 in the next commit).

It looks to be better than keep introduce yet another functions.

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_test_macros.h                         | 8 ++++----
 lib/newlib_tests/test_macros02.c                  | 8 ++++----
 testcases/kernel/syscalls/readahead/readahead01.c | 2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index d2e50a219..6a7bcdce5 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -242,9 +242,9 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
                                   ##__VA_ARGS__);                              \
 	} while (0)
 
-#define TST_EXP_FAIL_ARR(SCALL, EXP_ERRS, ...)                                 \
+#define TST_EXP_FAIL_ARR(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)                   \
 		TST_EXP_FAIL_ARR_(SCALL, #SCALL, EXP_ERRS,                     \
-				  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
+				  EXP_ERRS_CNT, ##__VA_ARGS__);
 
 #define TST_EXP_FAIL2_ARR_(SCALL, SSCALL, EXP_ERRS, EXP_ERRS_CNT, ...)         \
 	do {                                                                   \
@@ -254,9 +254,9 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 			TST_MSG_(TPASS | TTERRNO, " ", SSCALL, ##__VA_ARGS__); \
 	} while (0)
 
-#define TST_EXP_FAIL2_ARR(SCALL, EXP_ERRS, ...)                                \
+#define TST_EXP_FAIL2_ARR(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)                \
 		TST_EXP_FAIL2_ARR_(SCALL, #SCALL, EXP_ERRS,                    \
-		                  ARRAY_SIZE(EXP_ERRS), ##__VA_ARGS__);
+		                  EXP_ERRS_CNT, ##__VA_ARGS__);
 
 #define TST_EXP_FAIL2(SCALL, EXP_ERR, ...)                                     \
 	do {                                                                   \
diff --git a/lib/newlib_tests/test_macros02.c b/lib/newlib_tests/test_macros02.c
index 6c1ca7a8a..8e5a83346 100644
--- a/lib/newlib_tests/test_macros02.c
+++ b/lib/newlib_tests/test_macros02.c
@@ -39,9 +39,9 @@ static void do_test(void)
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 	TST_EXP_FAIL(inval_ret_fn(), ENOTTY, "inval_ret_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL_ARR(fail_fn(), exp_errs_pass, "fail_fn()");
+	TST_EXP_FAIL_ARR(fail_fn(), exp_errs_pass, ARRAY_SIZE(exp_errs_pass), "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL_ARR(fail_fn(), exp_errs_fail, "fail_fn()");
+	TST_EXP_FAIL_ARR(fail_fn(), exp_errs_fail, ARRAY_SIZE(exp_errs_fail), "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 
 	tst_res(TINFO, "Testing TST_EXP_FAIL2 macro");
@@ -53,9 +53,9 @@ static void do_test(void)
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 	TST_EXP_FAIL2(inval_ret_fn(), ENOTTY, "inval_ret_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL2_ARR(fail_fn(), exp_errs_pass, "fail_fn()");
+	TST_EXP_FAIL2_ARR(fail_fn(), exp_errs_pass, ARRAY_SIZE(exp_errs_pass), "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL2_ARR(fail_fn(), exp_errs_fail, "fail_fn()");
+	TST_EXP_FAIL2_ARR(fail_fn(), exp_errs_fail, ARRAY_SIZE(exp_errs_fail), "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 }
 
diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c
index 0f610daf8..d4b3f306f 100644
--- a/testcases/kernel/syscalls/readahead/readahead01.c
+++ b/testcases/kernel/syscalls/readahead/readahead01.c
@@ -61,7 +61,7 @@ static void test_invalid_fd(struct tst_fd *fd)
 	int exp_errnos[] = {EBADF, EINVAL, ESPIPE};
 
 	TST_EXP_FAIL_ARR(readahead(fd->fd, 0, getpagesize()), exp_errnos,
-			"readahead() on %s", tst_fd_desc(fd));
+			ARRAY_SIZE(exp_errnos), "readahead() on %s", tst_fd_desc(fd));
 }
 
 static void test_readahead(void)
-- 
2.43.0



More information about the ltp mailing list