Message ID | 20240415025100.2103-1-wegao@suse.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [v1] lib: Add TST_EXP_PASS_PTR_{NULL,VOID} macros | expand |
Hi Wei, > Signed-off-by: Wei Gao <wegao@suse.com> > --- > include/tst_test_macros.h | 41 +++++++++++++++++++++++++ > testcases/kernel/syscalls/sbrk/sbrk01.c | 7 +---- I would split sbrk01 change into separate commit (generally it's better to separate library change). And you can add also sbrk02. I tried to find test which could use TST_EXP_PASS_PTR_NULL(), but haven't found any. Do we need it? > 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) do { } while is not needed, maybe just (not an error, just code simplification): #define TST_EXP_PASS_PTR_NULL(SCALL, ...) \ TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__) #define TST_EXP_PASS_PTR_VOID(SCALL, ...) \ TST_EXP_PASS_PTR_(SCALL, #SCALL, (void *)-1, ##__VA_ARGS__) Also, the same applies to TST_EXP_FAIL_PTR_NULL_ARR() and TST_EXP_FAIL_PTR_VOID_ARR(). > + > /* > * 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); Too long line, it's be better to split. Kind regards, Petr
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 = {
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(-)