Introduce TEST_MACROS
cover Introduce TEST_MACROS
This is a RFC for a TEST_MACROS() implementation.
These macros are intended to simplify and unify syscall unit tests.
This patchset converts a few testcases to use TEST_MACROS it's intenteded to serve as an example since there is a lot of testcases that could use them as well.
Also the documentation for these macros is ommited at this point, I will add it in a case that we agree to include them in the test library.
Cyril Hrubis (10):
lib: Introduce more TEST_* macros
syscalls/uname: Make use of TEST_MACROS
syscalls/accept: Make use of TEST_MACROS
syscalls/access: Make use of TEST_MACROS
syscalls/bind: Make use of TEST_MACROS
syscalls/brk01: Make use of TEST_MACROS
syscalls/cacheflush: Make use of TEST_MACROS
syscalls/capget: Make use of TEST_MACROS
syscalls/capset: Make use of TEST_MACROS
syscalls/open: Make use of TEST_MACROS
include/tst_test.h | 28 +--- include/tst_test_macros.h | 131 ++++++++++++++++++ lib/newlib_tests/.gitignore | 3 + lib/newlib_tests/test_macros01.c | 40 ++++++ lib/newlib_tests/test_macros02.c | 42 ++++++ lib/newlib_tests/test_macros03.c | 40 ++++++ lib/tst_test.c | 1 + testcases/kernel/syscalls/accept/accept01.c | 17 +-- testcases/kernel/syscalls/access/access01.c | 43 +----- testcases/kernel/syscalls/access/access02.c | 8 +- testcases/kernel/syscalls/access/access03.c | 28 +--- testcases/kernel/syscalls/bind/bind01.c | 12 +- testcases/kernel/syscalls/bind/bind02.c | 11 +- testcases/kernel/syscalls/bind/bind03.c | 26 +--- testcases/kernel/syscalls/bind/bind04.c | 5 +- testcases/kernel/syscalls/bind/bind05.c | 5 +- testcases/kernel/syscalls/brk/brk01.c | 9 +- .../kernel/syscalls/cacheflush/cacheflush01.c | 8 +- testcases/kernel/syscalls/capget/capget01.c | 17 +-- testcases/kernel/syscalls/capget/capget02.c | 26 ++-- testcases/kernel/syscalls/capset/capset01.c | 14 +- testcases/kernel/syscalls/capset/capset02.c | 28 ++-- testcases/kernel/syscalls/capset/capset03.c | 10 +- testcases/kernel/syscalls/capset/capset04.c | 13 +- testcases/kernel/syscalls/open/open01.c | 11 +- testcases/kernel/syscalls/open/open02.c | 25 +--- testcases/kernel/syscalls/open/open11.c | 22 ++- testcases/kernel/syscalls/uname/uname01.c | 13 +- testcases/kernel/syscalls/uname/uname02.c | 17 +-- 29 files changed, 348 insertions(+), 305 deletions(-) create mode 100644 include/tst_test_macros.h create mode 100644 lib/newlib_tests/test_macros01.c create mode 100644 lib/newlib_tests/test_macros02.c create mode 100644 lib/newlib_tests/test_macros03.c
Signature · 1 line
2.26.2
PATCH 1/10 lib: Introduce more TEST_* macros
In order to simplify common return value checks.
--- include/tst_test.h | 28 +------ include/tst_test_macros.h | 131 +++++++++++++++++++++++++++++++ lib/newlib_tests/.gitignore | 3 + lib/newlib_tests/test_macros01.c | 40 ++++++++++ lib/newlib_tests/test_macros02.c | 42 ++++++++++ lib/newlib_tests/test_macros03.c | 40 ++++++++++ lib/tst_test.c | 1 + 7 files changed, 258 insertions(+), 27 deletions(-) create mode 100644 include/tst_test_macros.h create mode 100644 lib/newlib_tests/test_macros01.c create mode 100644 lib/newlib_tests/test_macros02.c create mode 100644 lib/newlib_tests/test_macros03.c
include/tst_test.h +1 -27
@@ -18,6 +18,7 @@#include "tst_common.h" #include "tst_res_flags.h" +#include "tst_test_macros.h" #include "tst_checkpoint.h" #include "tst_device.h" #include "tst_mkfs.h"
@@ -269,33 +270,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)*/ void tst_reinit (void ); -//TODO Clean? -#define TEST (SCALL ) \ - do { \ - errno = 0; \ - TST_RET = SCALL; \ - TST_ERR = errno; \ - } while (0) - -#define TEST_VOID (SCALL ) \ - do { \ - errno = 0; \ - SCALL; \ - TST_ERR = errno; \ - } while (0) - -extern long TST_RET ; -extern int TST_ERR ; - -extern void *TST_RET_PTR ; - -#define TESTPTR (SCALL ) \ - do { \ - errno = 0; \ - TST_RET_PTR = (void*)SCALL; \ - TST_ERR = errno; \ - } while (0) -/* * Functions to convert ERRNO to its name and SIGNAL to its name. */
include/tst_test_macros.h new file +131 -0
131 lines not on this page · raw message
lib/newlib_tests/.gitignore +3 -0
@@ -36,3 +36,6 @@ test_kconfig02 variant test_guarded_buf tst_bool_expr +test_macros01 +test_macros02 +test_macros03
lib/newlib_tests/test_macros01.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Cyril Hrubis <[email protected]> +*/ + +/* +* Test macros. +*/ + +#include "tst_test.h" + +static int fail_fd (void ) +{ + errno =EINVAL ; +return -1 ; +} + +static int pass_fd (void ) +{ +return 42 ; +} + +static int inval_val (void ) +{ +return -42 ; +} + +static void do_test (void ) +{ +TEST_FD (fail_fd (),"TEST DESCRIPTION" ); +tst_res (TINFO ,"TST_PASS = %i" ,TST_PASS ); +TEST_FD (pass_fd (),"%s" ,"TEST DESCRIPTION PARAM" ); +tst_res (TINFO ,"TST_PASS = %i" ,TST_PASS ); +TEST_FD (inval_val ()); +tst_res (TINFO ,"TST_PASS = %i" ,TST_PASS ); +} + +static struct tst_test test = { + .test_all = do_test, +};
lib/newlib_tests/test_macros02.c new file +42 -0
42 lines not on this page · raw message
lib/newlib_tests/test_macros03.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Cyril Hrubis <[email protected]> +*/ + +/* +* Test macros. +*/ + +#include "tst_test.h" + +static int fail_fn (void ) +{ + errno =EINVAL ; +return -1 ; +} + +static int pass_fn (void ) +{ +return 0 ; +} + +static int inval_ret_fn (void ) +{ +return 42 ; +} + +static void do_test (void ) +{ +TEST_PASS (fail_fn ()); +tst_res (TINFO ,"TST_PASS = %i" ,TST_PASS ); +TEST_PASS (pass_fn (),"TEST DESCRIPTION" ); +tst_res (TINFO ,"TST_PASS = %i" ,TST_PASS ); +TEST_PASS (inval_ret_fn ()); +tst_res (TINFO ,"TST_PASS = %i" ,TST_PASS ); +} + +static struct tst_test test = { + .test_all = do_test, +};
lib/tst_test.c +1 -0
@@ -74,6 +74,7 @@ const char *tst_ipc_path = ipc_path;static char shm_path[1024 ];int TST_ERR ; +int TST_PASS ;long TST_RET ;static void do_cleanup (void );
Signature · 1 line
2.26.2
PATCH 1/10 lib: Introduce more TEST_* macros
Quoted 1 line
In order to simplify common return value checks.
Great improvement, thanks!
The only concern I have is for tests which does not end 0
as it's not obvious from the output (without looking into the test source) that everything it's working, but not a big deal.
FYI I plan to send a patchset which runs tests in lib/newlib_tests/. First I thought simple check for 0 would be ok, but with non-zero results it might be good to not only check expected return value but maybe for whole output (the same approach we have unfinished in patchset from Christian Lanig).
Kind regards,
Petr
PATCH 1/10 lib: Introduce more TEST_* macros
Quoted 8 lines · Petr Vorel
Quoted 1 line
In order to simplify common return value checks.
Great improvement, thanks!
The only concern I have is for tests which does not end 0
as it's not obvious from the output (without looking into the test source) that everything it's working, but not a big deal.
+1
I agree to add an expected value check for TEST_PASS(), e.g
#define TEST_PASS(SCALL, EXPECTED, ...)
Quoted 14 lines
FYI I plan to send a patchset which runs tests in
lib/newlib_tests/. First I thought simple check for 0 would be ok, but with non-zero results it
might be good to not only check expected return value but maybe for whole output (the same approach we have unfinished in patchset from Christian Lanig).Kind regards,
Petr--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20201116/957aa64f/attachment.htm>
PATCH 1/10 lib: Introduce more TEST_* macros
Hi!
Quoted 3 lines
I agree to add an expected value check for
TEST_PASS(), e.g#define
TEST_PASS(SCALL, EXPECTED, ...)
I would rather keep this simple case as it is, since many function return zero on success and added more specialized functions if needed as it was done with TEST_FD()
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/10 lib: Introduce more TEST_* macros
Hi!
Quoted 7 lines
Quoted 3 lines
I agree to add an expected value check for
TEST_PASS(), e.g#define
TEST_PASS(SCALL, EXPECTED, ...)I would rather keep this simple case as it is, since many function return zero on success and added more specialized functions if needed as it was done with
TEST_FD()
Is anyone against pushing this initial patchset as it is?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/10 lib: Introduce more TEST_* macros
Quoted 9 lines · Cyril Hrubis
Hi!
Quoted 7 lines
Quoted 3 lines
I agree to add an expected value check for
TEST_PASS(), e.g#define
TEST_PASS(SCALL, EXPECTED, ...)I would rather keep this simple case as it is, since many function return zero on success and added more specialized functions if needed as it was done with
TEST_FD()
Ok.
Quoted 3 lines
Is anyone against pushing this initial patchset as it is?
Another bit of concern I have is the TEST_FAIL might cause confusion in code reading. It looks like the test will be failed here but in finish the test report pass, maybe we'd better tell people the failure is expected?
(that was just my feeling on TEST_FAIL at the first glance)
Or rename them to:
TEST_EXP_PASSTEST_EXP_FAILTEST_EXP_FD
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20201125/ac0c9a6d/attachment.htm>
PATCH 1/10 lib: Introduce more TEST_* macros
Hi!
Quoted 9 lines
Quoted 2 lines
Is anyone against pushing this initial patchset as it is?
Another bit of concern I have is the
TEST_FAILmight cause confusion in code reading. It looks like the test will be failed here but in finish the test report pass, maybe we'd better tell people the failure is expected?
(that was just my feeling onTEST_FAILat the first glance)
Quoted 5 lines
Or rename them to:
TEST_EXP_PASSTEST_EXP_FAILTEST_EXP_FD
Fair enough, let's rename them like this.
Any other concerns?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/10 lib: Introduce more TEST_* macros
Quoted 12 lines · Cyril Hrubis
Hi!
Quoted 11 lines
Quoted 2 lines
Is anyone against pushing this initial patchset as it is?
Another bit of concern I have is the
TEST_FAILmight cause confusion in code reading. It looks like the test will be failed here but in finish the test report pass, maybe we'd better tell people the failure is expected?
(that was just my feeling onTEST_FAILat the first glance)Or rename them to:
Quoted 8 lines
Quoted 3 lines
TEST_EXP_PASSTEST_EXP_FAILTEST_EXP_FDFair enough, let's rename them like this.
Any other concerns?
No more from me, thank you.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20201126/cdad67fd/attachment.htm>
PATCH 1/10 lib: Introduce more TEST_* macros
In reply to Petr VorelHi!
Quoted 4 lines
FYI I plan to send a patchset which runs tests in
lib/newlib_tests/. First I thought simple check for 0 would be ok, but with non-zero results it might be good to not only check expected return value but maybe for whole output (the same approach we have unfinished in patchset from Christian Lanig).
That has to be indeed done, since many of these tests have no way how to check if the call to test library had done what it should have.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/10 lib: Introduce more TEST_* macros
In reply to Cyril HrubisQuoted 62 lines · Cyril Hrubis
In order to simplify common return value checks.
Signed-off-by Cyril Hrubis <[email protected]>--- include/tst_test.h | 28 +------ include/tst_test_macros.h | 131 +++++++++++++++++++++++++++++++ lib/newlib_tests/.gitignore | 3 + lib/newlib_tests/test_macros01.c | 40 ++++++++++ lib/newlib_tests/test_macros02.c | 42 ++++++++++ lib/newlib_tests/test_macros03.c | 40 ++++++++++ lib/tst_test.c | 1 + 7 files changed, 258 insertions(+), 27 deletions(-) create mode 100644 include/tst_test_macros.h create mode 100644 lib/newlib_tests/test_macros01.c create mode 100644 lib/newlib_tests/test_macros02.c create mode 100644 lib/newlib_tests/test_macros03.cinclude/tst_test_macros.h new file +39
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2015-2020 Cyril Hrubis <[email protected]> +*/ + +#ifndef TST_TEST_MACROS_H__ +#define TST_TEST_MACROS_H__ + +#define TEST (SCALL ) \ + do { \ + errno = 0; \ + TST_RET = SCALL; \ + TST_ERR = errno; \ + } while (0) + +#define TEST_VOID (SCALL ) \ + do { \ + errno = 0; \ + SCALL; \ + TST_ERR = errno; \ + } while (0) + +extern long TST_RET ; +extern int TST_ERR ; +extern int TST_PASS ; + +extern void *TST_RET_PTR ; + +#define TESTPTR (SCALL ) \ + do { \ + errno = 0; \ + TST_RET_PTR = (void*)SCALL; \ + TST_ERR = errno; \ + } while (0) + + +#define TEST_2 (_1, _2, ...) _2 + +#define TEST_FMT_ (FMT , _1, ...) FMT, ##__VA_ARGS__
include/tst_test_macros.h line 49
Quoted 10 lines
include/tst_test_macros.h new file +10
-0+ +#define TEST_MSG (RES ,FMT ,SCALL , ...) \ + tst_res_(__FILE__, __LINE__, RES, \ + TEST_FMT_(TEST_2(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__)) + +#define TEST_MSGP (RES ,FMT ,PAR ,SCALL , ...) \ + tst_res_(__FILE__, __LINE__, RES, \ + TEST_FMT_(TEST_2(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR) + +#define TEST_FD (SCALL , ...) \
I'd recommend adding TEST_*_IMPL() variant with extra arguments that'll allow special handling of ENOSYS, ENOTSUP and possibly also a zero-terminated array of allowed errnos. TEST_FD() etc. would then call the respective IMPL macro with default arguments:
#define TEST_FD_IMPL(SCALL, NOSYS_RES, NOTSUP_RES, ERRNO_LIST, ...) \
...#define TEST_FD(SCALL, ...) \
TEST_FD_IMPL((SCALL), TFAIL, TFAIL, NULL, ##__VA_ARGS__)Signature · 7 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic
PATCH 1/10 lib: Introduce more TEST_* macros
Hi!
Quoted 10 lines
I'd recommend adding TEST_*_IMPL() variant with extra arguments that'll allow special handling of ENOSYS, ENOTSUP and possibly also a zero-terminated array of allowed errnos.
TEST_FD()etc. would then call the respective IMPL macro with default arguments:#define TEST_FD_IMPL(SCALL, NOSYS_RES, NOTSUP_RES, ERRNO_LIST, ...) \ ...#define TEST_FD(SCALL, ...) \ TEST_FD_IMPL((SCALL), TFAIL, TFAIL, NULL, ##__VA_ARGS__)
I do plan adding something like this later on once I run out of the simple cases to convert, then I would like to review what is left there and how to make best interface for the rest of the testcases.
So for now I would like to proceed with the patchset as it is in order not to make it overly complicated.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/10 lib: Introduce more TEST_* macros
Quoted 12 lines · Cyril Hrubis
Hi!
Quoted 10 lines
I'd recommend adding TEST_*_IMPL() variant with extra arguments that'll allow special handling of ENOSYS, ENOTSUP and possibly also a zero-terminated array of allowed errnos.
TEST_FD()etc. would then call the respective IMPL macro with default arguments:#define TEST_FD_IMPL(SCALL, NOSYS_RES, NOTSUP_RES, ERRNO_LIST, ...) \ ...#define TEST_FD(SCALL, ...) \ TEST_FD_IMPL((SCALL), TFAIL, TFAIL, NULL, ##__VA_ARGS__)
Quoted 6 lines
I do plan adding something like this later on once I run out of the simple cases to convert, then I would like to review what is left there and how to make best interface for the rest of the testcases.
So for now I would like to proceed with the patchset as it is in order not to make it overly complicated.
Great, looking forward to the follow-up patchset. I haven't reviewed everything so I won't add any signoff but consider my comments resolved. Feel free to push the patchset when you have enough reviews from others.
Signature · 7 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic
PATCH 2/10 syscalls/uname: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/uname/uname01.c | 13 +++---------- testcases/kernel/syscalls/uname/uname02.c | 17 +---------------- 2 files changed, 4 insertions(+), 26 deletions(-)
testcases/kernel/syscalls/uname/uname01.c +3 -10
@@ -18,24 +18,17 @@ static void verify_uname(void)memset (&un,0 ,sizeof (un)); -TEST (uname (&un)); -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO ,"uname() failed" ); -return ; - } +TEST_PASS (uname (&un)); -if (TST_RET !=0 ) { -tst_res (TFAIL |TTERRNO , -"uname() returned invalid value %ld" ,TST_RET ); +if (!TST_PASS )return ; - }if (strcmp (un.sysname,"Linux" )) {tst_res (TFAIL ,"sysname is not Linux" );return ; } -tst_res (TPASS ,"uname() succeeded" ); +tst_res (TPASS ,"sysname set to Linux" ); }static struct tst_test test = {
testcases/kernel/syscalls/uname/uname02.c +1 -16
@@ -16,22 +16,7 @@ static void *bad_addr;static void verify_uname (void ) { -TEST (uname (bad_addr)); -if (TST_RET ==0 ) { -tst_res (TFAIL ,"uname() succeed when failure expected" ); -return ; - } - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"Invalid uname() return value %ld" ,TST_RET ); -return ; - } - -if (TST_ERR ==EFAULT ) -tst_res (TPASS ,"uname() got EFAULT as expected" ); -else -tst_res (TFAIL |TTERRNO ,"uname() failed unexpectedly" ); - +TEST_FAIL (uname (bad_addr),EFAULT ); }static void setup (void )
Signature · 1 line
2.26.2
PATCH 3/10 syscalls/accept: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/accept/accept01.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/accept/accept01.c +2 -15
@@ -95,21 +95,8 @@ void verify_accept(unsigned int nr) {struct test_case *tcase = &tcases[nr]; -TEST (accept (*tcase->fd, tcase->sockaddr, &tcase->salen)); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"%s: returned %li, expected -1" , - tcase->desc,TST_RET ); -return ; - } - -if (TST_ERR != tcase->experrno) { -tst_res (TFAIL |TTERRNO ,"%s: expected errno %s, got " , - tcase->desc,tst_strerrno (tcase->experrno)); -return ; - } - -tst_res (TPASS |TTERRNO ,"%s successful" , tcase->desc); +TEST_FAIL (accept (*tcase->fd, tcase->sockaddr, &tcase->salen), + tcase->experrno,"%s" , tcase->desc); }static struct tst_test test = {
Signature · 1 line
2.26.2
PATCH 4/10 syscalls/access: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/access/access01.c | 43 ++++----------------- testcases/kernel/syscalls/access/access02.c | 8 ++-- testcases/kernel/syscalls/access/access03.c | 28 ++------------ 3 files changed, 14 insertions(+), 65 deletions(-)
testcases/kernel/syscalls/access/access01.c +7 -36
@@ -231,46 +231,17 @@ static struct tcase { {DNAME_WX"/"FNAME_X, W_OK, "W_OK", EACCES, 1} }; -static void verify_success (struct tcase *tc,const char *user) -{ -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO , -"access(%s, %s) as %s failed unexpectedly" , - tc->fname, tc->name, user); -return ; - } - -tst_res (TPASS ,"access(%s, %s) as %s" , tc->fname, tc->name, user); -} - -static void verify_failure (struct tcase *tc,const char *user) -{ -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"access(%s, %s) as %s succeded unexpectedly" , - tc->fname, tc->name, user); -return ; - } - -if (TST_ERR != tc->exp_errno) { -tst_res (TFAIL |TTERRNO , -"access(%s, %s) as %s should fail with %s" , - tc->fname, tc->name, user, -tst_strerrno (tc->exp_errno)); -return ; - } - -tst_res (TPASS |TTERRNO ,"access(%s, %s) as %s" , - tc->fname, tc->name, user); -} -static void access_test (struct tcase *tc,const char *user) {TEST (access (tc->fname, tc->mode)); -if (tc->exp_errno) -verify_failure (tc, user); -else -verify_success (tc, user); +if (tc->exp_errno) { +TEST_FAIL (access (tc->fname, tc->mode), tc->exp_errno, +"access(%s, %s) as %s" , tc->fname, tc->name, user); + }else { +TEST_PASS (access (tc->fname, tc->mode), +"access(%s, %s) as %s" , tc->fname, tc->name, user); + } }static void verify_access (unsigned int n)
testcases/kernel/syscalls/access/access02.c +3 -5
@@ -59,13 +59,11 @@ static void access_test(struct tcase *tc, const char *user)struct stat stat_buf;char command[64 ]; -TEST (access (tc->pathname, tc->mode)); +TEST_PASS (access (tc->pathname, tc->mode), +"access(%s, %s) as %s" , tc->pathname, tc->name, user); -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO ,"access(%s, %s) as %s failed" , - tc->pathname, tc->name, user); +if (!TST_PASS )return ; - }switch (tc->mode) {case F_OK :
testcases/kernel/syscalls/access/access03.c +4 -24
@@ -26,34 +26,13 @@ static struct tcase { {(void *)-1, X_OK, "X_OK"}, }; -static void access_test (struct tcase *tc,const char *user) -{ -TEST (access (tc->addr, tc->mode)); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"access(%p, %s) as %s succeeded unexpectedly" , - tc->addr, tc->name, user); -return ; - } - -if (TST_ERR !=EFAULT ) { -tst_res (TFAIL |TTERRNO , -"access(%p, %s) as %s should fail with EFAULT" , - tc->addr, tc->name, user); -return ; - } - -tst_res (TPASS |TTERRNO ,"access(%p, %s) as %s" , - tc->addr, tc->name, user); -} -static void verify_access (unsigned int n) {struct tcase *tc = &tcases[n];pid_t pid; -/* test as root */ -access_test (tc,"root" ); +TEST_FAIL (access (tc->addr, tc->mode),EFAULT , +"invalid address as root" );/* test as nobody */ pid =SAFE_FORK ();
@@ -61,7 +40,8 @@ static void verify_access(unsigned int n)SAFE_WAITPID (pid,NULL ,0 ); }else {SAFE_SETUID (uid); -access_test (tc,"nobody" ); +TEST_FAIL (access (tc->addr, tc->mode),EFAULT , +"invalid address as nobody" ); } }
Signature · 1 line
2.26.2
PATCH 5/10 syscalls/bind: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/bind/bind01.c | 12 +++++------- testcases/kernel/syscalls/bind/bind02.c | 11 ++--------- testcases/kernel/syscalls/bind/bind03.c | 26 ++++--------------------- testcases/kernel/syscalls/bind/bind04.c | 5 ++--- testcases/kernel/syscalls/bind/bind05.c | 5 ++--- 5 files changed, 15 insertions(+), 44 deletions(-)
testcases/kernel/syscalls/bind/bind01.c +5 -7
@@ -47,14 +47,12 @@ void verify_bind(unsigned int nr) {struct test_case *tcase = &tcases[nr]; -TEST (bind (*tcase->socket_fd, tcase->sockaddr, tcase->salen)); -if (TST_RET != tcase->retval &&TST_ERR != tcase->experrno) { -tst_res (TFAIL ,"%s ; returned" -" %ld (expected %d), errno %d (expected" -" %d)" , tcase->desc,TST_RET , tcase->retval, -TST_ERR , tcase->experrno); +if (tcase->experrno) { +TEST_FAIL (bind (*tcase->socket_fd, tcase->sockaddr, tcase->salen), + tcase->experrno,"%s" , tcase->desc); }else { -tst_res (TPASS ,"%s successful" , tcase->desc); +TEST_PASS (bind (*tcase->socket_fd, tcase->sockaddr, tcase->salen), +"%s" , tcase->desc); } }
testcases/kernel/syscalls/bind/bind02.c +2 -9
@@ -36,16 +36,9 @@ static void run(void) servaddr.sin_family =AF_INET ; servaddr.sin_port =htons (TCP_PRIVILEGED_PORT ); servaddr.sin_addr.s_addr =htonl (INADDR_ANY ); -TEST (bind (sockfd, (struct sockaddr *)&servaddr,sizeof (servaddr))); +TEST_FAIL (bind (sockfd, (struct sockaddr *)&servaddr,sizeof (servaddr)), +EACCES ,"bind()" );SAFE_CLOSE (sockfd); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"bind() returned %li, expected -1" ,TST_RET ); - }else if (TST_ERR ==EACCES ) { -tst_res (TPASS |TTERRNO ,"bind() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"Unexpected error" ); - } }static void setup (void )
testcases/kernel/syscalls/bind/bind03.c +4 -22
@@ -51,17 +51,8 @@ void run(void)* Once a STREAM UNIX domain socket has been bound, it can't be * rebound. */ -if (bind (sock1, (struct sockaddr *)&sun2,sizeof (sun2)) ==0 ) { -tst_res (TFAIL ,"re-binding of socket succeeded" ); -return ; - } - -if (errno !=EINVAL ) { -tst_res (TFAIL |TERRNO ,"expected EINVAL" ); -return ; - } - -tst_res (TPASS ,"bind() failed with EINVAL as expected" ); +TEST_FAIL (bind (sock1, (struct sockaddr *)&sun2,sizeof (sun2)), +EINVAL ,"re-bind() socket" ); sock2 =SAFE_SOCKET (PF_UNIX ,SOCK_STREAM ,0 );
@@ -69,17 +60,8 @@ void run(void)* Since a socket is already bound to the pathname, it can't be bound * to a second socket. Expected error is EADDRINUSE. */ -if (bind (sock2, (struct sockaddr *)&sun1,sizeof (sun1)) ==0 ) { -tst_res (TFAIL ,"bind() succeeded with already bound pathname!" ); -return ; - } - -if (errno !=EADDRINUSE ) { -tst_res (TFAIL |TERRNO ,"expected to fail with EADDRINUSE" ); -return ; - } - -tst_res (TPASS ,"bind() failed with EADDRINUSE as expected" ); +TEST_FAIL (bind (sock2, (struct sockaddr *)&sun1,sizeof (sun1)), +EADDRINUSE ,"bind() with bound pathname" ); }static void cleanup (void )
testcases/kernel/syscalls/bind/bind04.c +2 -3
@@ -118,10 +118,9 @@ static void test_bind(unsigned int n) listen_sock =SAFE_SOCKET (tc->address->sa_family, tc->type, tc->protocol); -TEST (bind (listen_sock, tc->address, tc->addrlen)); +TEST_PASS (bind (listen_sock, tc->address, tc->addrlen),"bind()" ); -if (TST_RET ) { -tst_res (TFAIL |TERRNO ,"bind() failed" ); +if (!TST_PASS ) {SAFE_CLOSE (listen_sock);return ; }
testcases/kernel/syscalls/bind/bind05.c +2 -3
@@ -131,10 +131,9 @@ static void test_bind(unsigned int n)tst_res (TINFO ,"Testing %s" , tc->description); sock =SAFE_SOCKET (tc->address->sa_family, tc->type, tc->protocol); -TEST (bind (sock, tc->address, tc->addrlen)); +TEST_PASS (bind (sock, tc->address, tc->addrlen),"bind()" ); -if (TST_RET ) { -tst_res (TFAIL |TERRNO ,"bind() failed" ); +if (!TST_PASS ) {SAFE_CLOSE (sock);return ; }
Signature · 1 line
2.26.2
PATCH 6/10 syscalls/brk01: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/brk/brk01.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
testcases/kernel/syscalls/brk/brk01.c +1 -8
@@ -31,12 +31,7 @@ void verify_brk(void)break ; } -TEST (brk ((void *)new_brk)); - -if (TST_RET ==-1 ) { -tst_res (TFAIL |TERRNO ,"brk() failed" ); -return ; - } +TEST_PASS (brk ((void *)new_brk),"brk()" ); cur_brk = (uintptr_t )sbrk (0 );
@@ -51,8 +46,6 @@ void verify_brk(void)if (i %3 ==0 ) *((char *)cur_brk) =0 ; } - -tst_res (TPASS ,"brk() works fine" ); }static struct tst_test test = {
Signature · 1 line
2.26.2
PATCH 7/10 syscalls/cacheflush: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/cacheflush/cacheflush01.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/cacheflush/cacheflush01.c +2 -6
@@ -45,12 +45,8 @@ static void test_cacheflush(unsigned int i) {struct test_case_t *tc = &test_cases[i]; -TEST (tst_syscall (__NR_cacheflush, addr,getpagesize (), tc->cache)); -if (TST_RET ==0 ) { -tst_res (TPASS ,"%s passed" , tc->desc); - }else { -tst_res (TFAIL |TTERRNO ,"%s failed" , tc->desc); - } +TEST_PASS (tst_syscall (__NR_cacheflush, addr,getpagesize (), tc->cache), +"%s" , tc->desc); }static struct tst_test test = {
Signature · 1 line
2.26.2
PATCH 8/10 syscalls/capget: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/capget/capget01.c | 17 +++++--------- testcases/kernel/syscalls/capget/capget02.c | 26 +++++++-------------- 2 files changed, 14 insertions(+), 29 deletions(-)
testcases/kernel/syscalls/capget/capget01.c +6 -11
@@ -20,25 +20,20 @@ static struct tcase {int version;char *message; } tcases[] = { - {0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"}, - {0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"}, - {0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"}, + {0x19980330, "LINUX_CAPABILITY_VERSION_1"}, + {0x20071026, "LINUX_CAPABILITY_VERSION_2"}, + {0x20080522, "LINUX_CAPABILITY_VERSION_3"}, }; static void verify_capget(unsigned int n) { struct tcase *tc = &tcases[n]; - tst_res(TINFO, "%s", tc->message); - hdr->version = tc->version; hdr->pid = pid; - TEST(tst_syscall(__NR_capget, hdr, data)); - if (TST_RET == 0) - tst_res(TPASS, "capget() returned %ld", TST_RET); - else - tst_res(TFAIL | TTERRNO, "Test Failed, capget() returned %ld", - TST_RET); + + TEST_PASS(tst_syscall(__NR_capget, hdr, data), + "capget() with %s", tc->message); if (data[0].effective & 1 << CAP_NET_RAW) tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");
testcases/kernel/syscalls/capget/capget02.c +8 -18
@@ -31,11 +31,11 @@ static struct tcase {int flag;char *message; } tcases[] = { - {0x20080522, 0, EFAULT, 1, "Test bad address header"}, - {0x20080522, 0, EFAULT, 2, "Test bad address data"}, - {0, 0, EINVAL, 0, "Test bad version"}, - {0x20080522, -1, EINVAL, 0, "Test bad pid"}, - {0x20080522, 1, ESRCH, 0, "Test unused pid"}, + {0x20080522, 0, EFAULT, 1, "bad address header"}, + {0x20080522, 0, EFAULT, 2, "bad address data"}, + {0, 0, EINVAL, 0, "bad version"}, + {0x20080522, -1, EINVAL, 0, "bad pid"}, + {0x20080522, 1, ESRCH, 0, "unused pid"}, }; static void verify_capget(unsigned int n)
@@ -48,25 +48,15 @@ static void verify_capget(unsigned int n)else header->pid = tc->pid; -tst_res (TINFO ,"%s" , tc->message); -/* * header must not be NULL. data may be NULL only when the user is * trying to determine the preferred capability version format * supported by the kernel. So use tst_get_bad_addr() to get * this error. */ -TEST (tst_syscall (__NR_capget, tc->flag -1 ? header :NULL , - tc->flag -2 ? data : bad_data)); -if (TST_RET ==0 ) { -tst_res (TFAIL ,"capget() succeed unexpectedly" ); -return ; - } -if (TST_ERR == tc->exp_err) -tst_res (TPASS |TTERRNO ,"capget() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"capget() expected %s got " , -tst_strerrno (tc->exp_err)); +TEST_FAIL (tst_syscall (__NR_capget, tc->flag -1 ? header :NULL , + tc->flag -2 ? data : bad_data), + tc->exp_err,"capget() with %s" , tc->message);/* * When an unsupported version value is specified, it will
Signature · 1 line
2.26.2
PATCH 9/10 syscalls/capset: Make use of TEST_MACROS
In reply to Cyril Hrubis--- testcases/kernel/syscalls/capset/capset01.c | 14 ++++------- testcases/kernel/syscalls/capset/capset02.c | 28 +++++++-------------- testcases/kernel/syscalls/capset/capset03.c | 10 +------- testcases/kernel/syscalls/capset/capset04.c | 13 +++------- 4 files changed, 18 insertions(+), 47 deletions(-)
testcases/kernel/syscalls/capset/capset01.c +5 -9
@@ -20,16 +20,15 @@ static struct tcase {int version;char *message; } tcases[] = { - {0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"}, - {0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"}, - {0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"}, + {0x19980330, "LINUX_CAPABILITY_VERSION_1"}, + {0x20071026, "LINUX_CAPABILITY_VERSION_2"}, + {0x20080522, "LINUX_CAPABILITY_VERSION_3"}, }; static void verify_capset(unsigned int n) { struct tcase *tc = &tcases[n]; - tst_res(TINFO, "%s", tc->message); header->version = tc->version; header->pid = pid;
@@ -38,11 +37,8 @@ static void verify_capset(unsigned int n)return ; } -TEST (tst_syscall (__NR_capset, header, data)); -if (TST_RET ==0 ) -tst_res (TPASS ,"capset() returned %ld" ,TST_RET ); -else -tst_res (TFAIL |TTERRNO ,"Test Failed, capset() returned %ld" ,TST_RET ); +TEST_PASS (tst_syscall (__NR_capset, header, data), +"capset() with %s" , tc->message); }static void setup (void )
testcases/kernel/syscalls/capset/capset02.c +9 -19
@@ -43,12 +43,12 @@ static struct tcase {int flag;char *message; } tcases[] = { - {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 1, "Test bad address header"}, - {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 2, "Test bad address data"}, - {0, 0, CAP1, CAP1, CAP1, EINVAL, 0, "Test bad version"}, - {0x20080522, 0, CAP2, CAP1, CAP1, EPERM, 0, "Test bad value data(when pE is not in pP)"}, - {0x20080522, 0, CAP1, CAP2, CAP1, EPERM, 0, "Test bad value data(when pP is not in old pP)"}, - {0x20080522, 0, CAP1, CAP1, CAP2, EPERM, 0, "Test bad value data(when pI is not in bounding set or old pI)"}, + {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 1, "bad address header"}, + {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 2, "bad address data"}, + {0, 0, CAP1, CAP1, CAP1, EINVAL, 0, "bad version"}, + {0x20080522, 0, CAP2, CAP1, CAP1, EPERM, 0, "bad value data(when pE is not in pP)"}, + {0x20080522, 0, CAP1, CAP2, CAP1, EPERM, 0, "bad value data(when pP is not in old pP)"}, + {0x20080522, 0, CAP1, CAP1, CAP2, EPERM, 0, "bad value data(when pI is not in bounding set or old pI)"}, }; static void verify_capset(unsigned int n)
@@ -62,19 +62,9 @@ static void verify_capset(unsigned int n) data->permitted = tc->permitted; data->inheritable = tc->inheritable; -tst_res (TINFO ,"%s" , tc->message); - -TEST (tst_syscall (__NR_capset, tc->flag -1 ? header : bad_addr, - tc->flag -2 ? data : bad_addr)); -if (TST_RET ==0 ) { -tst_res (TFAIL ,"capset() succeed unexpectedly" ); -return ; - } -if (TST_ERR == tc->exp_err) -tst_res (TPASS |TTERRNO ,"capset() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"capset() expected %s got " , -tst_strerrno (tc->exp_err)); +TEST_FAIL (tst_syscall (__NR_capset, tc->flag -1 ? header : bad_addr, + tc->flag -2 ? data : bad_addr), + tc->exp_err,"capset() with %s" , tc->message);/* * When an unsupported version value is specified, it will * return the kernel preferred value of _LINUX_CAPABILITY_VERSION_?.
testcases/kernel/syscalls/capset/capset03.c +1 -9
@@ -23,15 +23,7 @@ static void verify_capset(void) {tst_res (TINFO ,"Test bad value data(when pI is not old pP or old pI without CAP_SETPCAP)" ); data[0 ].inheritable =CAP2 ; -TEST (tst_syscall (__NR_capset, header, data)); -if (TST_RET ==0 ) { -tst_res (TFAIL ,"capset succeed unexpectedly" ); -return ; - } -if (TST_ERR ==EPERM ) -tst_res (TPASS |TTERRNO ,"capset() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"capset expected EPERM, bug got" ); +TEST_FAIL (tst_syscall (__NR_capset, header, data),EPERM ,"capset()" ); }static void setup (void )
testcases/kernel/syscalls/capset/capset04.c +3 -10
@@ -24,18 +24,11 @@ static void verify_capset(void)if (!child_pid)pause (); - header->pid = child_pid; +tst_res (TINFO ,"Test capset() for a different process" ); -TEST (tst_syscall (__NR_capset, header, data)); -if (TST_RET ==0 ) { -tst_res (TFAIL ,"capset succeed unexpectedly" ); -return ; - } + header->pid = child_pid; -if (TST_ERR ==EPERM ) -tst_res (TPASS ,"capset can't modify other process capabilities" ); -else -tst_res (TFAIL |TTERRNO ,"capset expected EPERM, bug got" ); +TEST_FAIL (tst_syscall (__NR_capset, header, data),EPERM ,"capset()" );SAFE_KILL (child_pid,SIGTERM );SAFE_WAIT (NULL );
Signature · 1 line
2.26.2
PATCH 10/10 syscalls/open: Make use of TEST_MACROS
In reply to Cyril HrubisIn the newlib testcases at least.
--- testcases/kernel/syscalls/open/open01.c | 11 ++++------- testcases/kernel/syscalls/open/open02.c | 25 ++++++------------------- testcases/kernel/syscalls/open/open11.c | 22 ++++++++++------------ 3 files changed, 20 insertions(+), 38 deletions(-)
testcases/kernel/syscalls/open/open01.c +4 -7
@@ -36,8 +36,8 @@ static struct tcase {unsigned short tst_bit;char *desc; } tcases[] = { - {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "Sticky bit"}, - {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "Directory bit"} + {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"}, + {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "sirectory bit"} }; static void verify_open(unsigned int n)
@@ -45,12 +45,9 @@ static void verify_open(unsigned int n)struct tcase *tc = &tcases[n];struct stat buf; -TEST (open (tc->filename, tc->flag, tc->mode)); +TEST_FD (open (tc->filename, tc->flag, tc->mode), +"open() with %s" , tc->desc); fd =TST_RET ; -if (fd ==-1 ) { -tst_res (TFAIL ,"Cannot open a file" ); -return ; - }SAFE_FSTAT (fd, &buf);if (!(buf.st_mode & tc->tst_bit))
testcases/kernel/syscalls/open/open02.c +6 -19
@@ -25,12 +25,13 @@#define TEST_FILE2 "test_file2"static struct tcase { -char *filename; +const char *filename;int flag;int exp_errno; +const char *desc; } tcases[] = { - {TEST_FILE ,O_RDWR ,ENOENT }, - {TEST_FILE2 ,O_RDONLY |O_NOATIME ,EPERM }, + {TEST_FILE ,O_RDWR ,ENOENT ,"new file without O_CREAT" }, + {TEST_FILE2 ,O_RDONLY |O_NOATIME ,EPERM ,"unpriviledget O_RDONLY | O_NOATIME" }, };void setup (void )
@@ -48,22 +49,8 @@ static void verify_open(unsigned int n) {struct tcase *tc = &tcases[n]; -TEST (open (tc->filename, tc->flag,0444 )); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"open(%s) succeeded unexpectedly" , - tc->filename); -return ; - } - -if (tc->exp_errno !=TST_ERR ) { -tst_res (TFAIL |TTERRNO , -"open() should fail with %s" , -tst_strerrno (tc->exp_errno)); -return ; - } - -tst_res (TPASS |TTERRNO ,"open() failed as expected" ); +TEST_FAIL (open (tc->filename, tc->flag,0444 ), + tc->exp_errno,"open() %s" , tc->desc); }void cleanup (void )
testcases/kernel/syscalls/open/open11.c +10 -12
@@ -277,21 +277,19 @@ static struct test_case {static void verify_open (unsigned int n) { -int fd; - -TEST (open (tc[n].path, tc[n].flags, tc[n].mode)); - fd =TST_RET ; - -if (fd >0 ) -SAFE_CLOSE (fd); - -if (tc[n].err ==-1 ||TST_ERR == tc[n].err) { +if (tc[n].err >0 ) { +TEST_FAIL (open (tc[n].path, tc[n].flags, tc[n].mode), + tc[n].err,"%s" , tc[n].desc); + }else if (tc[n].err ==0 ) { +TEST_FD (open (tc[n].path, tc[n].flags, tc[n].mode), +"%s" , tc[n].desc); + }else { +TEST (open (tc[n].path, tc[n].flags, tc[n].mode));tst_res (TPASS ,"%s" , tc[n].desc); -return ; } -tst_res (TFAIL |TTERRNO ,"%s - expected %s" , - tc[n].desc,tst_strerrno (tc[n].err)); +if (TST_RET >0 ) +SAFE_CLOSE (TST_RET ); }static void setup (void )
Signature · 1 line
2.26.2