getitimer02: Skipped EFAULT tests for libc variant.
PATCH 1/7 getitimer02: Skipped EFAULT tests for libc variant.
Tested EFAULT cases only for "__NR_getitimer" syscall.
--- .../kernel/syscalls/getitimer/getitimer02.c | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +45 -9
@@ -30,6 +30,7 @@#include <errno.h> #include <sys/time.h> +#include "lapi/syscalls.h" char *TCID ="getitimer02" ;int TST_TOTAL =1 ;
@@ -39,9 +40,35 @@ int TST_TOTAL = 1;static void cleanup (void );static void setup (void ); +static int libc_getitimer (int which,void *curr_value) +{ +return getitimer (which, curr_value); +} + +static int sys_getitimer (int which,void *curr_value) +{ +return ltp_syscall (__NR_getitimer, which, curr_value); +} + +static struct test_variants +{ +int (*getitimer)(int which,void *curr_value); +char *desc; +} variants[] = { + { .getitimer = libc_getitimer, .desc ="libc getitimer()" }, + +#if (__NR_getitimer != __LTP__NR_INVALID_SYSCALL) + { .getitimer = sys_getitimer, .desc ="__NR_getitimer syscall" }, +#endif +}; + +unsigned int tst_variant_t; +int TST_VARIANTS =ARRAY_SIZE (variants); +int main (int ac,char **av) { -int lc; +int lc, i; +struct test_variants *tv = &variants[tst_variant_t];tst_parse_opts (ac, av,NULL ,NULL );
@@ -50,16 +77,25 @@ int main(int ac, char **av)for (lc =0 ;TEST_LOOPING (lc); lc++) { tst_count =0 ; -/* call with a bad address */ -TEST (getitimer (ITIMER_REAL , (struct itimerval *)-1 )); +for (i =0 ; i <TST_VARIANTS ; i++) { +tst_resm (TINFO ,"Testing variant: %s" , tv->desc); -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -continue ; - } +/* call with a bad address */ +if (tv->getitimer == libc_getitimer) { +tst_resm (TCONF ,"EFAULT skipped for libc variant" ); + tv++; +continue ; + } +TEST (tv->getitimer (ITIMER_REAL , (struct itimerval *)-1 )); + +if (TEST_RETURN ==0 ) { +tst_resm (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TEST_ERRNO ,strerror (TEST_ERRNO )); +continue ; + } + }switch (TEST_ERRNO ) {case EFAULT : tst_resm(TPASS, "expected failure - errno = %d - %s",
Signature · 1 line
2.17.1
PATCH 2/7 getrusage02: Skipped EFAULT tests for libc variant.
Tested EFAULT cases only for "__NR_getrusage" syscall.
--- .../kernel/syscalls/getrusage/getrusage02.c | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/getrusage/getrusage02.c +45 -8
@@ -71,6 +71,7 @@#include <sched.h> #include <sys/resource.h> #include "test.h" +#include "lapi/syscalls.h" #ifndef RUSAGE_BOTH /* Removed from user space on RHEL4 */ #define RUSAGE_BOTH (-2)/* still works on SuSE */
@@ -83,6 +84,16 @@ char *TCID = "getrusage02";static struct rusage usage; +static int libc_getrusage (int who,void *usage) +{ +return getrusage (who, usage); +} + +static int sys_getrusage (int who,void *usage) +{ +return ltp_syscall (__NR_getrusage, who, usage); +} +struct test_cases_t {int who;struct rusage *usage;
@@ -96,12 +107,26 @@ struct test_cases_t {#endif }; +static struct test_variants +{ +int (*getrusage)(int who,void *usage); +char *desc; +} variants[] = { + { .getrusage = libc_getrusage, .desc ="libc getrusage()" }, + +#if (__NR_getrusage != __LTP__NR_INVALID_SYSCALL) + { .getrusage = sys_getrusage, .desc ="__NR_getrusage syscall" }, +#endif +}; + +unsigned int tst_variant_t; +int TST_VARIANTS =ARRAY_SIZE (variants);int TST_TOTAL =ARRAY_SIZE (test_cases);int main (int ac,char **av) { - -int lc, i; +struct test_variants *tv = &variants[tst_variant_t]; +int lc, i, j;tst_parse_opts (ac, av,NULL ,NULL );
@@ -111,18 +136,30 @@ int main(int ac, char **av) tst_count =0 ; -for (i =0 ; i <TST_TOTAL ; i++) { -TEST (getrusage (test_cases[i].who, test_cases[i].usage)); +for (j =0 ; j <TST_VARIANTS ; j++) { + +tst_resm (TINFO ,"Testing variant: %s" , tv->desc); +for (i =0 ; i <TST_TOTAL ; i++) { + +if (test_cases[i].exp_errno ==EFAULT && + tv->getrusage == libc_getrusage) { +tst_resm (TCONF ,"EFAULT is skipped for libc variant" ); + tv++; +continue ; + } + +TEST (tv->getrusage (test_cases[i].who, test_cases[i].usage));if (TEST_RETURN ==-1 && -TEST_ERRNO == test_cases[i].exp_errno) +TEST_ERRNO == test_cases[i].exp_errno)tst_resm (TPASS |TTERRNO , -"getrusage failed as expected" ); +"getrusage failed as expected" );else tst_resm (TFAIL |TTERRNO , -"getrusage failed unexpectedly" ); +"getrusage failed unexpectedly" ); + } + } } - }cleanup ();
Signature · 1 line
2.17.1
PATCH 3/7 msgctl04: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_msgctl" syscall.
--- .../kernel/syscalls/ipc/msgctl/msgctl04.c | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/msgctl/msgctl04.c +37 -1
@@ -15,6 +15,7 @@#include "tst_test.h" #include "tst_safe_sysv_ipc.h" #include "libnewipc.h" +#include "lapi/syscalls.h" static int msg_id1 =-1 ;static int msg_id2 =-1 ;
@@ -23,6 +24,16 @@ static int bad_q = -1;struct msqid_ds q_buf; +static int libc_msgctl (int msqid,int cmd,void *buf) +{ +return msgctl (msqid, cmd, buf); +} + +static int sys_msgctl (int msqid,int cmd,void *buf) +{ +return tst_syscall (__NR_msgctl, msqid, cmd, buf); +} +struct tcase {int *msg_id;int cmd;
@@ -45,9 +56,29 @@ struct tcase { {&msg_id3, IPC_RMID, NULL, EPERM}, }; +static struct test_variants +{ +int (*msgctl)(int msqid,int cmd,void *buf); +char *desc; +} variants[] = { + { .msgctl = libc_msgctl, .desc ="libc msgctl()" }, + +#if (__NR_msgctl != __LTP__NR_INVALID_SYSCALL) + { .msgctl = sys_msgctl, .desc ="__NR_msgctl syscall" }, +#endif +}; +static void verify_msgctl (unsigned int i) { -TEST (msgctl (*(tc[i].msg_id), tc[i].cmd, tc[i].buf)); +struct test_variants *tv = &variants[tst_variant]; + +if (tc[i].error ==EFAULT && + tv->msgctl == libc_msgctl) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } + +TEST (tv->msgctl (*(tc[i].msg_id), tc[i].cmd, tc[i].buf));if (TST_RET !=-1 ) {tst_res (TFAIL ,"msgctl() returned %li" ,TST_RET );
@@ -66,6 +97,8 @@ static void verify_msgctl(unsigned int i)static void setup (void ) { +struct test_variants *tv = &variants[tst_variant]; +key_t msgkey1, msgkey2;struct passwd *ltpuser;
@@ -79,6 +112,8 @@ static void setup(void) msg_id1 =SAFE_MSGGET (msgkey1,IPC_CREAT |IPC_EXCL ); msg_id2 =SAFE_MSGGET (msgkey2,IPC_CREAT |IPC_EXCL |MSG_RD |MSG_WR ); + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); }static void cleanup (void )
@@ -100,6 +135,7 @@ static struct tst_test test = { .cleanup = cleanup, .test = verify_msgctl, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .needs_tmpdir = 1, .needs_root = 1, };
Signature · 1 line
2.17.1
PATCH 4/7 semctl03: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_semctl" syscall.
--- .../kernel/syscalls/ipc/semctl/semctl03.c | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/semctl/semctl03.c +37 -2
@@ -15,6 +15,7 @@#include "tst_test.h" #include "lapi/sem.h" #include "libnewipc.h" +#include "lapi/syscalls.h" static int sem_id =-1 ;static int bad_id =-1 ;
@@ -23,6 +24,17 @@ static struct semid_ds sem_ds;static union semun sem_un = {.buf = &sem_ds};static void *semds_ptr = &sem_un;static void *bad_ptr; +static union semun arg = {0 }; + +static int libc_semctl (int semid,int semnum,int cmd, ...) +{ +return semctl (semid, semnum, cmd, arg); +} + +static int sys_semctl (int semid,int semnum,int cmd, ...) +{ +return tst_syscall (__NR_semctl, semid, semnum, cmd, arg); +} static struct tcases { int *sem_id;
@@ -37,17 +49,39 @@ static struct tcases { {&sem_id, IPC_SET, &bad_ptr, EFAULT, "invalid union arg"} }; +static struct test_variants +{ +int (*semctl)(int semid,int semnum,int cmd, ...); +char *desc; +} variants[] = { + { .semctl = libc_semctl, .desc ="libc semctl()" }, + +#if (__NR_sys_semctl != __LTP__NR_INVALID_SYSCALL) + { .semctl = sys_semctl, .desc ="__NR_semctl syscall" }, +#endif +}; +static void verify_semctl (unsigned int n) {struct tcases *tc = &tests[n]; +struct test_variants *tv = &variants[tst_variant]; + +if (tc->error ==EFAULT + && tv->semctl == libc_semctl) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } -TST_EXP_FAIL (semctl (*(tc->sem_id),0 , tc->ipc_cmd, *(tc->buf)), - tc->error,"semctl() with %s" , tc->message); +TST_EXP_FAIL (sys_semctl (*(tc->sem_id),0 , tc->ipc_cmd, *(tc->buf)), + tc->error,"semctl() with %s" , tc->message); }static void setup (void ) {static key_t semkey; +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); semkey =GETIPCKEY ();
@@ -67,4 +101,5 @@ static struct tst_test test = { .cleanup = cleanup, .test = verify_semctl, .tcnt = ARRAY_SIZE(tests), + .test_variants = ARRAY_SIZE(variants), };
Signature · 1 line
2.17.1
PATCH 5/7 shmctl02: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_shmctl"
--- .../kernel/syscalls/ipc/shmctl/shmctl02.c | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +38 -2
@@ -32,6 +32,7 @@#include "tst_test.h" #include "tst_safe_sysv_ipc.h" #include "libnewipc.h" +#include "lapi/syscalls.h" #define SHM_SIZE 2048
@@ -43,6 +44,16 @@ static int shm_rem;static struct shmid_ds buf; +static int libc_shmctl (int shmid,int cmd,void *buf) +{ +return shmctl (shmid, cmd, buf); +} + +static int sys_shmctl (int shmid,int cmd,void *buf) +{ +return tst_syscall (__NR_shmctl, shmid, cmd, buf); +} + static struct tcase { int *shm_id; int cmd;
@@ -63,9 +74,29 @@ static struct tcase { {&shm_id3, SHM_UNLOCK, &buf, EPERM} }; +static struct test_variants +{ +int (*shmctl)(int shmid,int cmd,void *buf); +char *desc; +} variants[] = { + { .shmctl = libc_shmctl, .desc ="libc shmctl()" }, + +#if (__NR_shmctl != __LTP__NR_INVALID_SYSCALL) + { .shmctl = sys_shmctl, .desc ="__NR_shmctl syscall" }, +#endif +}; +static void verify_shmctl (unsigned int i) { -TEST (shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf)); +struct test_variants *tv = &variants[tst_variant]; + +if (tc[i].error ==EFAULT + && tv->shmctl == libc_shmctl) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } + +TEST (tv->shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf));if (TST_RET !=-1 ) {tst_res (TFAIL ,"shmctl() returned %li" ,TST_RET );
@@ -74,7 +105,7 @@ static void verify_shmctl(unsigned int i)if (TST_ERR == tc[i].error) {tst_res (TPASS |TTERRNO ,"shmctl(%i, %i, %p)" , - *tc[i].shm_id, tc[i].cmd, tc[i].buf); + *tc[i].shm_id, tc[i].cmd, tc[i].buf);return ; }
@@ -84,10 +115,14 @@ static void verify_shmctl(unsigned int i)static void setup (void ) { +struct test_variants *tv = &variants[tst_variant]; +key_t shmkey1, shmkey2;struct passwd *ltpuser;int tmp; +tst_res (TINFO ,"Testing variant: %s" , tv->desc); + shm_id3 =SAFE_SHMGET (IPC_PRIVATE ,SHM_SIZE ,IPC_CREAT |SHM_RW ); ltpuser =SAFE_GETPWNAM ("nobody" );
@@ -121,6 +156,7 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test = verify_shmctl, + .test_variants = ARRAY_SIZE(variants), .tcnt = ARRAY_SIZE(tc), .needs_root = 1, };
Signature · 1 line
2.17.1
PATCH 6/7 sched_rr_get_interval03: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_sched_rr_get_interval" and "__NR_sched_rr_get_interval_time64"
--- .../sched_rr_get_interval/sched_rr_get_interval03.c | 6 ++++++ 1 file changed, 6 insertions(+)
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c +6 -0
@@ -67,6 +67,12 @@ static void run(unsigned int i)struct test_cases_t *tc = &test_cases[i];struct timerspec *ts; +if (tc->exp_errno ==EFAULT + && tv->sched_rr_get_interval == libc_sched_rr_get_interval) { +tst_res (TCONF ,"EFAULT skipped for libc_variant" ); +return ; + } +if (tc->exp_errno ==EFAULT ) ts = bad_addr;else
Signature · 1 line
2.17.1
PATCH 7/7 setitimer02: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_setitimer"
--- .../kernel/syscalls/setitimer/setitimer02.c | 82 +++++++++++++------ 1 file changed, 59 insertions(+), 23 deletions(-)
testcases/kernel/syscalls/setitimer/setitimer02.c +59 -23
@@ -56,6 +56,7 @@#include <errno.h> #include <sys/time.h> +#include "lapi/syscalls.h" void cleanup (void );void setup (void );
@@ -63,12 +64,38 @@ void setup(void);char *TCID ="setitimer02" ;int TST_TOTAL =1 ; +static int libc_setitimer (int which,void *new_value,void *old_value) +{ +return setitimer (which, new_value, old_value); +} + +static int sys_setitimer (int which,void *new_value,void *old_value) +{ +return ltp_syscall (__NR_setitimer, which, new_value, old_value); +} + +static struct test_variants +{ +int (*setitimer)(int which,void *new_value,void *old_value); +char *desc; +} variants[] = { + { .setitimer = libc_setitimer, .desc ="libc setitimer()" }, + +#if (__NR_setitimer != __LTP__NR_INVALID_SYSCALL) + { .setitimer = sys_setitimer, .desc ="__NR_setitimer syscall" }, +#endif +}; + +unsigned int tst_variant_t; +int TST_VARIANTS =ARRAY_SIZE (variants); +#if !defined(UCLINUX )int main (int ac,char **av) { -int lc; +int lc, i;struct itimerval *value; +struct test_variants *tv = &variants[tst_variant_t];tst_parse_opts (ac, av,NULL ,NULL );
@@ -87,7 +114,6 @@ int main(int ac, char **av) }/* set up some reasonable values */ - value->it_value.tv_sec =30 ; value->it_value.tv_usec =0 ; value->it_interval.tv_sec =0 ;
@@ -97,27 +123,37 @@ int main(int ac, char **av)* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 */ -/* call with a bad address */ -TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); - -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); -continue ; +for (i =0 ; i <TST_VARIANTS ; i++) { + +tst_resm (TINFO ,"Testing variant: %s" , tv->desc); + +/* call with a bad address */ +if (tv->setitimer == libc_setitimer) { +tst_resm (TCONF ,"EFAULT is skipped for libc variant" ); + tv++; +continue ; + } + +TEST (tv->setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); + +if (TEST_RETURN ==0 ) { +tst_resm (TFAIL ,"call failed to produce EFAULT error " +"- errno = %d - %s" ,TEST_ERRNO , +strerror (TEST_ERRNO )); +continue ; + } + +switch (TEST_ERRNO ) { +case EFAULT : +tst_resm (TPASS ,"expected failure - errno = %d - %s" , +TEST_ERRNO ,strerror (TEST_ERRNO )); +break ; +default : +tst_resm (TFAIL ,"call failed to produce EFAULT error " +"- errno = %d - %s" ,TEST_ERRNO , +strerror (TEST_ERRNO )); + } } - -switch (TEST_ERRNO ) { -case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - } -/* * clean up things in case we are looping */
@@ -153,7 +189,7 @@ void setup(void)/* * cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. +* or premature exit. */ void cleanup (void ) {
Signature · 1 line
2.17.1
PATCH 1/7 getitimer02: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarHi Vinay,
Quoted 1 line
Tested EFAULT cases only for "
__NR_getitimer" syscall.
Well, you added testing raw syscall via test variant. That's IMHO the most important thing to mention.
In the text after blank line I'd mention EFAULT skipped on raw syscall. It'd would deserve to mention why.
Also, as test it's quite simple, it'd be nice, if you first convert it to new API and in second commit added test variants.
During rewrite you should remove #if !defined(UCLINUX) check as getitimer() is supported on uclibc-ng.
This apply to whole patchset (some tests are already ported to new API).
Kind regards,
Petr
PATCH v2 1/10 getitimer02 : Convert getitimer02 to new API
--- .../kernel/syscalls/getitimer/getitimer02.c | 103 ++++-------------- 1 file changed, 24 insertions(+), 79 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +24 -79
@@ -1,99 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* 03/2001 - Written by Wayne Boyer */ -/* -HISTORY -03/2001 - Written by Wayne Boyer - -TEST ITEMS: -Check that a getitimer() call fails as expected -with an incorrect second argument. -*/ - - -#include "test.h" +/*\ +*[Description] +* +* Check that a getitimer() call fails as expected +* with an incorrect second argument. +*/ #include <errno.h> #include <sys/time.h> +#include "tst_test.h" -char *TCID ="getitimer02" ; -int TST_TOTAL =1 ; - -#if !defined(UCLINUX ) - -static void cleanup (void ); -static void setup (void ); - -int main (int ac,char **av) +static void verify_getitimer (void ) { -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -/* call with a bad address */ TEST (getitimer (ITIMER_REAL , (struct itimerval *)-1 )); -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -continue ; +if (TST_RET ==0 ) { +tst_res (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); } -switch (TEST_ERRNO ) { +switch (TST_ERR ) {case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); +tst_res (TPASS ,"expected failure - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR ));break ;default : -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); +tst_res (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); } - } - -cleanup (); - -tst_exit (); -} - -static void setup (void ) -{ -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} - -static void cleanup (void ) -{ -} - -#else - -int main (void ) -{ -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); } -#endif /* if !defined(UCLINUX) */ +static struct tst_test test = { + .test_all = verify_getitimer, + .needs_root =1 , +};
Signature · 1 line
2.17.1
PATCH v2 2/10 getitimer02: Skipped EFAULT tests for libc variant.
Tested EFAULT cases only for "__NR_getitimer" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/getitimer/getitimer02.c | 81 ++++++++++++++----- 1 file changed, 60 insertions(+), 21 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +60 -21
@@ -14,31 +14,70 @@#include <errno.h> #include <sys/time.h> #include "tst_test.h" +#include "lapi/syscalls.h" + +static int libc_getitimer (int which,void *curr_value) +{ +return getitimer (which, curr_value); +} + +static int sys_getitimer (int which,void *curr_value) +{ +return tst_syscall (__NR_getitimer, which, curr_value); +} + +static struct test_variants +{ +int (*getitimer)(int which,void *curr_value); +char *desc; +} variants[] = { +{ .getitimer = libc_getitimer, .desc ="libc getitimer()" }, + +#if (__NR_getitimer != __LTP__NR_INVALID_SYSCALL) +{ .getitimer = sys_getitimer, .desc ="__NR_getitimer syscall" }, +#endif +};static void verify_getitimer (void ) { -/* call with a bad address */ -TEST (getitimer (ITIMER_REAL , (struct itimerval *)-1 )); - -if (TST_RET ==0 ) { -tst_res (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TST_ERR ,strerror (TST_ERR )); - } - -switch (TST_ERR ) { -case EFAULT : -tst_res (TPASS ,"expected failure - errno = %d - %s" , -TST_ERR ,strerror (TST_ERR )); -break ; -default : -tst_res (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TST_ERR ,strerror (TST_ERR )); - } +struct test_variants *tv = &variants[tst_variant]; + +if (tv->getitimer == libc_getitimer) { +tst_res (TCONF ,"EFAULT skipped for libc variant" ); +return ; + } + +/* call with a bad address */ +TEST (tv->getitimer (ITIMER_REAL , (struct itimerval *)-1 )); + +if (TST_RET ==0 ) { +tst_res (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); + } + +switch (TST_ERR ) { +case EFAULT : +tst_res (TPASS ,"expected failure - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); +break ; +default : +tst_res (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); + } +} + +static void setup (void ) +{ +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); }static struct tst_test test = { - .test_all = verify_getitimer, - .needs_root =1 , + .test_all = verify_getitimer, + .setup = setup, + .test_variants =ARRAY_SIZE (variants), + .needs_root =1 , };
Signature · 1 line
2.17.1
PATCH v2 2/10 getitimer02: Skipped EFAULT tests for libc variant.
Hi!
What is the point of adding test variants when the test does only EFAULT test that ends up being skipped on the libc variant?
Can't we simply just switch to the syscall here instead?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 getitimer02: Skipped EFAULT tests for libc variant.
Tested EFAULT cases only for "__NR_getitimer" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- testcases/kernel/syscalls/getitimer/getitimer02.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +9 -1
@@ -14,12 +14,20 @@#include <errno.h> #include <sys/time.h> #include "tst_test.h" +#include "lapi/syscalls.h" + +static int sys_getitimer (int which,void *curr_value) +{ +return tst_syscall (__NR_getitimer, which, curr_value); +}static void verify_getitimer (void ) {/* call with a bad address */ -TST_EXP_FAIL (getitimer (ITIMER_REAL , (struct itimerval *)-1 ), +TST_EXP_FAIL (sys_getitimer (ITIMER_REAL , (struct itimerval *)-1 ),EFAULT ,"expected failure - errno = %d - %s" ,TST_ERR ,strerror (TST_ERR )); + +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); }static struct tst_test test = {
Signature · 1 line
2.17.1
PATCH v3 1/1 getitimer02: Skipped EFAULT tests for libc variant.
Hi!
Adjusted this patch and pushed as well, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 3/10 getrusage02: Convert getrusage02 to new API
In reply to Vinay Kumar--- .../kernel/syscalls/getrusage/getrusage02.c | 142 ++++-------------- 1 file changed, 27 insertions(+), 115 deletions(-)
testcases/kernel/syscalls/getrusage/getrusage02.c +27 -115
@@ -1,86 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* +* AUTHOR : Saji Kumar.V.R <[email protected]> */ -/********************************************************** -* -* TEST IDENTIFIER : getrusage02 -* -* EXECUTED BY : anyone -* -* TEST TITLE : Tests for error conditions -* -* TEST CASE TOTAL : 2 -* -* AUTHOR : Saji Kumar.V.R <[email protected]> -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* DESCRIPTION -* Verify that -* 1) getrusage() fails with errno EINVAL when an invalid value -* is given for who -* 2) getrusage() fails with errno EFAULT when an invalid address -* is given for usage -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* if call failed with expected errno, -* Test Passed -* else -* Test Failed -* -* Cleanup: -* Print errno log and/or timing stats if options given + +/*\ +*[Description] * -* USAGE: <for command-line> -* getrusage02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] -* [-p] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -h : Show help screen -* -f : Turn off functional testing -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -p : Pause for SIGUSR1 before starting -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +* Verify that +* 1) getrusage() fails with errno EINVAL when an invalid value +* is given for who +* 2) getrusage() fails with errno EFAULT when an invalid address +* is given for usage * -****************************************************************/ +*/ #include <errno.h> #include <sched.h> #include <sys/resource.h> -#include "test.h" +#include "tst_test.h" #ifndef RUSAGE_BOTH /* Removed from user space on RHEL4 */ #define RUSAGE_BOTH (-2)/* still works on SuSE */ #endif /* so this is a work around */ -static void setup (); -static void cleanup (); - -char *TCID ="getrusage02" ; -static struct rusage usage;struct test_cases_t {
@@ -90,56 +33,25 @@ struct test_cases_t { } test_cases[] = { { RUSAGE_BOTH, &usage, EINVAL}, -#ifndef UCLINUX { RUSAGE_SELF, (struct rusage *)-1, EFAULT} -#endif }; -int TST_TOTAL =ARRAY_SIZE (test_cases); - -int main (int ac,char **av) +static void verify_getrusage (unsigned int i) { - -int lc, i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; i++) { -TEST (getrusage (test_cases[i].who, test_cases[i].usage)); - -if (TEST_RETURN ==-1 && -TEST_ERRNO == test_cases[i].exp_errno) -tst_resm (TPASS |TTERRNO , -"getrusage failed as expected" ); -else -tst_resm (TFAIL |TTERRNO , -"getrusage failed unexpectedly" ); - } - } - -cleanup (); - -tst_exit (); - +TEST (getrusage (test_cases[i].who, test_cases[i].usage)); + +if (TST_RET ==-1 && +TST_ERR == test_cases[i].exp_errno) +tst_res (TPASS |TTERRNO , +"getrusage failed as expected" ); +else +tst_res (TFAIL |TTERRNO , +"getrusage failed unexpectedly" ); } -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -} - -void cleanup (void ) -{ - -} +static struct tst_test test = { + .test = verify_getrusage, + .tcnt =ARRAY_SIZE (test_cases), + .needs_root =1 , +};
Signature · 1 line
2.17.1
PATCH v2 3/10 getrusage02: Convert getrusage02 to new API
Hi!
Quoted 3 lines
#ifndef
RUSAGE_BOTH/* Removed from user space on RHEL4 */
#defineRUSAGE_BOTH(-2) /* still works on SuSE */
#endif /* so this is a work around */
This is used as invalid value here, so this whole part looks wrong.
Can we just place -2 in the testcases structure instead?
Quoted 50 lines
testcases/kernel/syscalls/getrusage/getrusage02.c +1
-37-static void setup (); -static void cleanup (); - -char *TCID ="getrusage02" ; -static struct rusage usage;struct test_cases_t {@@ -90,56 +33,25 @@ struct test_cases_t { } test_cases[] = { { RUSAGE_BOTH, &usage, EINVAL}, -#ifndef UCLINUX { RUSAGE_SELF, (struct rusage *)-1, EFAULT} -#endif }; -int TST_TOTAL =ARRAY_SIZE (test_cases); - -int main (int ac,char **av) +static void verify_getrusage (unsigned int i) { - -int lc, i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; i++) { -TEST (getrusage (test_cases[i].who, test_cases[i].usage)); - -if (TEST_RETURN ==-1 && -TEST_ERRNO == test_cases[i].exp_errno) -tst_resm (TPASS |TTERRNO , -"getrusage failed as expected" ); -else -tst_resm (TFAIL |TTERRNO , -"getrusage failed unexpectedly" ); - } - } - -cleanup (); - -tst_exit ();
testcases/kernel/syscalls/getrusage/getrusage02.c struct test_cases_t { · line 50
Quoted 10 lines
testcases/kernel/syscalls/getrusage/getrusage02.c +9
-1- +TEST (getrusage (test_cases[i].who, test_cases[i].usage)); + +if (TST_RET ==-1 && +TST_ERR == test_cases[i].exp_errno) +tst_res (TPASS |TTERRNO , +"getrusage failed as expected" ); +else +tst_res (TFAIL |TTERRNO , +"getrusage failed unexpectedly" );
Here as well, can we please switch to TST_EXP_FAIL()?
Quoted 9 lines
testcases/kernel/syscalls/getrusage/getrusage02.c +0
-7} -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -
testcases/kernel/syscalls/getrusage/getrusage02.c struct test_cases_t { · line 56
Quoted 10 lines
testcases/kernel/syscalls/getrusage/getrusage02.c +4
-6-} - -void cleanup (void ) -{ - -} +static struct tst_test test = { + .test = verify_getrusage, + .tcnt =ARRAY_SIZE (test_cases), + .needs_root =1 ,
Do we really need root for this test?
The original test works fine when executed as a user.
Quoted 7 lines
testcases/kernel/syscalls/getrusage/getrusage02.c +1
-0+};Signature · 5 lines
2.17.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 getrusage02: Convert getrusage02 to new API
--- .../kernel/syscalls/getrusage/getrusage02.c | 140 +++--------------- 1 file changed, 20 insertions(+), 120 deletions(-)
testcases/kernel/syscalls/getrusage/getrusage02.c +20 -120
@@ -1,85 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -* +* AUTHOR : Saji Kumar.V.R <[email protected]> */ -/********************************************************** -* -* TEST IDENTIFIER : getrusage02 -* -* EXECUTED BY : anyone -* -* TEST TITLE : Tests for error conditions -* -* TEST CASE TOTAL : 2 -* -* AUTHOR : Saji Kumar.V.R <[email protected]> -* -* SIGNALS -* Uses SIGUSR1 to pause before test if option set. -* (See the parse_opts(3) man page). -* -* DESCRIPTION -* Verify that -* 1) getrusage() fails with errno EINVAL when an invalid value -* is given for who -* 2) getrusage() fails with errno EFAULT when an invalid address -* is given for usage -* -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* if call failed with expected errno, -* Test Passed -* else -* Test Failed -* -* Cleanup: -* Print errno log and/or timing stats if options given + +/*\ +*[Description] * -* USAGE: <for command-line> -* getrusage02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] -* [-p] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -h : Show help screen -* -f : Turn off functional testing -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -p : Pause for SIGUSR1 before starting -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +* Verify that +* 1) getrusage() fails with errno EINVAL when an invalid value +* is given for who +* 2) getrusage() fails with errno EFAULT when an invalid address +* is given for usage * -****************************************************************/ +*/ #include <errno.h> #include <sched.h> #include <sys/resource.h> -#include "test.h" - -#ifndef RUSAGE_BOTH /* Removed from user space on RHEL4 */ -#define RUSAGE_BOTH (-2)/* still works on SuSE */ -#endif /* so this is a work around */ - -static void setup (); -static void cleanup (); - -char *TCID ="getrusage02" ; +#include "tst_test.h" static struct rusage usage;
@@ -89,57 +28,18 @@ struct test_cases_t {int exp_errno; } test_cases[] = { { - RUSAGE_BOTH, &usage, EINVAL}, -#ifndef UCLINUX + -2, &usage, EINVAL}, { RUSAGE_SELF, (struct rusage *)-1, EFAULT} -#endif }; -int TST_TOTAL =ARRAY_SIZE (test_cases); - -int main (int ac,char **av) +static void verify_getrusage (unsigned int i) { - -int lc, i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; i++) { -TEST (getrusage (test_cases[i].who, test_cases[i].usage)); - -if (TEST_RETURN ==-1 && -TEST_ERRNO == test_cases[i].exp_errno) -tst_resm (TPASS |TTERRNO , -"getrusage failed as expected" ); -else -tst_resm (TFAIL |TTERRNO , -"getrusage failed unexpectedly" ); - } - } - -cleanup (); - -tst_exit (); - +TST_EXP_FAIL (getrusage (test_cases[i].who, test_cases[i].usage), + test_cases[i].exp_errno,"getrusage failed as expected" ); } -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -} - -void cleanup (void ) -{ - -} +static struct tst_test test = { + .test = verify_getrusage, + .tcnt =ARRAY_SIZE (test_cases), +};
Signature · 1 line
2.17.1
PATCH v2 4/10 getrusage02: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_getrusage" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/getrusage/getrusage02.c | 58 ++++++++++++++++--- 1 file changed, 49 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/getrusage/getrusage02.c +49 -9
@@ -19,6 +19,7 @@#include <sched.h> #include <sys/resource.h> #include "tst_test.h" +#include "lapi/syscalls.h" #ifndef RUSAGE_BOTH /* Removed from user space on RHEL4 */ #define RUSAGE_BOTH (-2)/* still works on SuSE */
@@ -26,6 +27,16 @@static struct rusage usage; +static int libc_getrusage (int who,void *usage) +{ +return getrusage (who, usage); +} + +static int sys_getrusage (int who,void *usage) +{ +return tst_syscall (__NR_getrusage, who, usage); +} +struct test_cases_t {int who;struct rusage *usage;
@@ -37,21 +48,50 @@ struct test_cases_t { RUSAGE_SELF, (struct rusage *)-1, EFAULT} }; +static struct test_variants +{ +int (*getrusage)(int who,void *usage); +char *desc; +} variants[] = { +{ .getrusage = libc_getrusage, .desc ="libc getrusage()" }, + +#if (__NR_getrusage != __LTP__NR_INVALID_SYSCALL) +{ .getrusage = sys_getrusage, .desc ="__NR_getrusage syscall" }, +#endif +}; +static void verify_getrusage (unsigned int i) { -TEST (getrusage (test_cases[i].who, test_cases[i].usage)); - -if (TST_RET ==-1 && -TST_ERR == test_cases[i].exp_errno) -tst_res (TPASS |TTERRNO , -"getrusage failed as expected" ); -else -tst_res (TFAIL |TTERRNO , -"getrusage failed unexpectedly" ); +struct test_variants *tv = &variants[tst_variant]; + +if (test_cases[i].exp_errno ==EFAULT && + tv->getrusage == libc_getrusage) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } + +TEST (tv->getrusage (test_cases[i].who, test_cases[i].usage)); + +if (TST_RET ==-1 && +TST_ERR == test_cases[i].exp_errno) +tst_res (TPASS |TTERRNO , +"getrusage failed as expected" ); +else +tst_res (TFAIL |TTERRNO , +"getrusage failed unexpectedly" ); +} + +static void setup (void ) +{ +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); }static struct tst_test test = { .test = verify_getrusage, + .setup = setup, .tcnt =ARRAY_SIZE (test_cases), + .test_variants =ARRAY_SIZE (variants), .needs_root =1 , };
Signature · 1 line
2.17.1
PATCH v2 4/10 getrusage02: Skipped EFAULT tests for libc variant.
Hi!
This looks good, but the patch it builds on needs changes.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 getrusage02: Skipped EFAULT tests for libc variant.
Tested EFAULT cases only for "__NR_getrusage" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/getrusage/getrusage02.c | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/getrusage/getrusage02.c +41 -1
@@ -19,9 +19,20 @@#include <sched.h> #include <sys/resource.h> #include "tst_test.h" +#include "lapi/syscalls.h" static struct rusage usage; +static int libc_getrusage (int who,void *usage) +{ +return getrusage (who, usage); +} + +static int sys_getrusage (int who,void *usage) +{ +return tst_syscall (__NR_getrusage, who, usage); +} +struct test_cases_t {int who;struct rusage *usage;
@@ -33,13 +44,42 @@ struct test_cases_t { RUSAGE_SELF, (struct rusage *)-1, EFAULT} }; +static struct test_variants +{ +int (*getrusage)(int who,void *usage); +char *desc; +} variants[] = { +{ .getrusage = libc_getrusage, .desc ="libc getrusage()" }, + +#if (__NR_getrusage != __LTP__NR_INVALID_SYSCALL) +{ .getrusage = sys_getrusage, .desc ="__NR_getrusage syscall" }, +#endif +}; +static void verify_getrusage (unsigned int i) { -TST_EXP_FAIL (getrusage (test_cases[i].who, test_cases[i].usage), +struct test_variants *tv = &variants[tst_variant]; + +if (test_cases[i].exp_errno ==EFAULT && + tv->getrusage == libc_getrusage) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } + +TST_EXP_FAIL (tv->getrusage (test_cases[i].who, test_cases[i].usage), test_cases[i].exp_errno,"getrusage failed as expected" ); } +static void setup (void ) +{ +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); +} +static struct tst_test test = { .test = verify_getrusage, + .setup = setup, .tcnt =ARRAY_SIZE (test_cases), + .test_variants =ARRAY_SIZE (variants), };
Signature · 1 line
2.17.1
PATCH v3 1/1 getrusage02: Skipped EFAULT tests for libc variant.
Hi!
Slightly adjusted and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 getrusage02: Skipped EFAULT tests for libc variant.
Hi Cyril,
Thanks for your review.
In your corrections for getrusage02.c need below change.
============================
(quoted diff) +0 -0
b/testcases/kernel/syscalls/getrusage/getrusage02.c index 24777687c..767663090 100644
testcases/kernel/syscalls/getrusage/getrusage02.c +1 -1
@@ -61,7 +61,7 @@ static void verify_getrusage(unsigned int i)return ; } -TST_EXP_FAIL (getrusage (tc[i].who, tc[i].usage), tc[i].exp_errno, +TST_EXP_FAIL (tv->getrusage (tc[i].who, tc[i].usage), tc[i].exp_errno,"getrusage(%i, %p)" , tc[i].who, tc[i].usage); }
============================
Regards,
Vinay
Quoted 7 lines · Cyril Hrubis
Hi!
Slightly adjusted and pushed, thanks.--
Cyril Hrubis
[email protected]
PATCH v3 1/1 getrusage02: Skipped EFAULT tests for libc variant.
Hi!
Quoted 2 lines
Thanks for your review.
In your corrections forgetrusage02.cneed below change.
Sorry for missing that, fix pushed.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 5/10 setitimer02: Convert setitimer02 to new API
In reply to Vinay Kumar--- .../kernel/syscalls/setitimer/setitimer02.c | 192 +++++------------- 1 file changed, 51 insertions(+), 141 deletions(-)
testcases/kernel/syscalls/setitimer/setitimer02.c +51 -141
@@ -1,161 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2001 +* 03/2001 - Written by Wayne Boyer * -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* -* NAME -* setitimer02.c -* -* DESCRIPTION -* setitimer02 - check that a setitimer() call fails as expected -* with incorrect values. +/*\ +* [Description] * -* ALGORITHM -* loop if that option was specified -* allocate needed space and set up needed values -* issue the system call -* check the errno value -* issue a PASS message if we get EFAULT -* otherwise, the tests fails -* issue a FAIL message -* break any remaining tests -* call cleanup -* -* USAGE: <for command-line> -* setitimer02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 03/2001 - Written by Wayne Boyer -* -* RESTRICTIONS -* none +* setitimer02 - check that a setitimer() call fails as expected +* with incorrect values. */ -#include "test.h" -#include <errno.h> #include <sys/time.h> +#include <stdlib.h> +#include "tst_test.h" -void cleanup (void ); -void setup (void ); - -char *TCID ="setitimer02" ; -int TST_TOTAL =1 ; - -#if !defined(UCLINUX ) - -int main (int ac,char **av) +static void verify_setitimer (void ) { -int lc;struct itimerval *value; -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* allocate some space for a timer structure */ -if ((value =malloc ((size_t )sizeof (struct itimerval ))) == -NULL ) { -tst_brkm (TBROK , cleanup,"value malloc failed" ); - } - -/* set up some reasonable values */ - - value->it_value.tv_sec =30 ; - value->it_value.tv_usec =0 ; - value->it_interval.tv_sec =0 ; - value->it_interval.tv_usec =0 ; -/* -* issue the system call with the TEST() macro -* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 -*/ - -/* call with a bad address */ -TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); - -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); -continue ; - } - -switch (TEST_ERRNO ) { -case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - } - -/* -* clean up things in case we are looping -*/ -free (value); - value =NULL ; +/* allocate some space for a timer structure */ +if ((value =malloc ((size_t )sizeof (struct itimerval ))) == +NULL ) { +tst_brk (TBROK ,"value malloc failed" ); } -cleanup (); -tst_exit (); - -} - -#else - -int main (void ) -{ -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); -} - -#endif /* if !defined(UCLINUX) */ - -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) -{ +/* set up some reasonable values */ + value->it_value.tv_sec =30 ; + value->it_value.tv_usec =0 ; + value->it_interval.tv_sec =0 ; + value->it_interval.tv_usec =0 ; +/* +* issue the system call with the TEST() macro +* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 +*/ + +/* call with a bad address */ +TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); + +if (TST_RET ==0 ) { +tst_res (TFAIL ,"call failed to produce EFAULT error " +"- errno = %d - %s" ,TST_ERR , +strerror (TST_ERR )); + } -tst_sig (NOFORK ,DEF_HANDLER , cleanup); +switch (TST_ERR ) { +case EFAULT : +tst_res (TPASS ,"expected failure - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); +break ; +default : +tst_res (TFAIL ,"call failed to produce EFAULT error " +"- errno = %d - %s" ,TST_ERR , +strerror (TST_ERR )); + } -TEST_PAUSE ; +/* +* clean up things in case we are looping +*/ +free (value); + value =NULL ; } -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) -{ +static struct tst_test test = { + .test_all = verify_setitimer, + .needs_root =1 , +}; -}
Signature · 1 line
2.17.1
PATCH v2 5/10 setitimer02: Convert setitimer02 to new API
Hi!
Quoted 53 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +1
-49+static void verify_setitimer (void ) { -int lc;struct itimerval *value; -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* allocate some space for a timer structure */ -if ((value =malloc ((size_t )sizeof (struct itimerval ))) == -NULL ) { -tst_brkm (TBROK , cleanup,"value malloc failed" ); - } - -/* set up some reasonable values */ - - value->it_value.tv_sec =30 ; - value->it_value.tv_usec =0 ; - value->it_interval.tv_sec =0 ; - value->it_interval.tv_usec =0 ; -/* -* issue the system call with the TEST() macro -* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 -*/ - -/* call with a bad address */ -TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); - -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); -continue ; - } - -switch (TEST_ERRNO ) { -case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - } -
testcases/kernel/syscalls/setitimer/setitimer02.c line 28
Quoted 10 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +4
-5-/* -* clean up things in case we are looping -*/ -free (value); - value =NULL ; +/* allocate some space for a timer structure */ +if ((value =malloc ((size_t )sizeof (struct itimerval ))) == +NULL ) { +tst_brk (TBROK ,"value malloc failed" ); }
This should be allocated as a guarded buffer and initialized once in the test setup, see:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#131-guarded-buffers
Quoted 47 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +25
-21-cleanup (); - tst_exit(); - -} - -#else - -int main (void ) -{ -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); -} - -#endif /* if !defined(UCLINUX) */ - -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) -{ +/* set up some reasonable values */ + value->it_value.tv_sec =30 ; + value->it_value.tv_usec =0 ; + value->it_interval.tv_sec =0 ; + value->it_interval.tv_usec =0 ; +/* +* issue the system call with the TEST() macro +* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 +*/ + +/* call with a bad address */ +TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); + +if (TST_RET ==0 ) { +tst_res (TFAIL ,"call failed to produce EFAULT error " +"- errno = %d - %s" ,TST_ERR , +strerror (TST_ERR )); + } -tst_sig (NOFORK ,DEF_HANDLER , cleanup); +switch (TST_ERR ) { +case EFAULT : +tst_res (TPASS ,"expected failure - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); +break ; +default : + tst_res(TFAIL, "call failed to produce EFAULT error "
testcases/kernel/syscalls/setitimer/setitimer02.c line 64
Quoted 10 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +8
-1+"- errno = %d - %s" ,TST_ERR , + strerror(TST_ERR)); + } -TEST_PAUSE ; +/* +* clean up things in case we are looping +*/ +free (value); + value =NULL ;
Here as well, we should switch to TST_EXP_FAIL()
testcases/kernel/syscalls/setitimer/setitimer02.c line 69
Quoted 11 lines
}
testcases/kernel/syscalls/setitimer/setitimer02.c +3
-6-/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) -{ +static struct tst_test test = { + .test_all = verify_setitimer, + .needs_root =1 ,
Here as well, no need for the root.
Quoted 9 lines
testcases/kernel/syscalls/setitimer/setitimer02.c +1
-1+}; -}Signature · 5 lines
2.17.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 setitimer02: Convert setitimer02 to new API
--- .../kernel/syscalls/setitimer/setitimer02.c | 167 +++--------------- 1 file changed, 24 insertions(+), 143 deletions(-)
testcases/kernel/syscalls/setitimer/setitimer02.c +24 -143
@@ -1,161 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2001 +* 03/2001 - Written by Wayne Boyer * -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* -* NAME -* setitimer02.c -* -* DESCRIPTION -* setitimer02 - check that a setitimer() call fails as expected -* with incorrect values. +/*\ +* [Description] * -* ALGORITHM -* loop if that option was specified -* allocate needed space and set up needed values -* issue the system call -* check the errno value -* issue a PASS message if we get EFAULT -* otherwise, the tests fails -* issue a FAIL message -* break any remaining tests -* call cleanup -* -* USAGE: <for command-line> -* setitimer02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 03/2001 - Written by Wayne Boyer -* -* RESTRICTIONS -* none +* setitimer02 - check that a setitimer() call fails as expected +* with incorrect values. */ -#include "test.h" -#include <errno.h> #include <sys/time.h> +#include <stdlib.h> +#include "tst_test.h" -void cleanup (void ); -void setup (void ); - -char *TCID ="setitimer02" ; -int TST_TOTAL =1 ; +struct itimerval *value; -#if !defined(UCLINUX ) - -int main (int ac,char **av) +static void verify_setitimer (void ) { -int lc; -struct itimerval *value; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup */ - -/* The following loop checks looping state if -i option given */ - -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - -/* allocate some space for a timer structure */ -if ((value =malloc ((size_t )sizeof (struct itimerval ))) == -NULL ) { -tst_brkm (TBROK , cleanup,"value malloc failed" ); - } - -/* set up some reasonable values */ - - value->it_value.tv_sec =30 ; - value->it_value.tv_usec =0 ; - value->it_interval.tv_sec =0 ; - value->it_interval.tv_usec =0 ; -/* -* issue the system call with the TEST() macro -* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 -*/ - -/* call with a bad address */ -TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); - -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); -continue ; - } - -switch (TEST_ERRNO ) { -case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed to produce EFAULT error " -"- errno = %d - %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - } - -/* -* clean up things in case we are looping -*/ -free (value); - value =NULL ; - } - -cleanup (); -tst_exit (); - -} - -#else - -int main (void ) -{ -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); +/* call with a bad address */ +TST_EXP_FAIL (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 ), +EFAULT ,"expected failure - errno = %d - %s" ,TST_ERR ,strerror (TST_ERR )); } -#endif /* if !defined(UCLINUX) */ - -/* -* setup() - performs all the ONE TIME setup for this test. -*/ -void setup (void ) +static void setup (void ) { + value =tst_alloc ((size_t )sizeof (struct itimerval )); -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; + value->it_value.tv_sec =30 ; + value->it_value.tv_usec =0 ; + value->it_interval.tv_sec =0 ; + value->it_interval.tv_usec =0 ; } -/* -* cleanup() - performs all the ONE TIME cleanup for this test at completion -* or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .test_all = verify_setitimer, + .setup = setup, +};
Signature · 1 line
2.17.1
PATCH v3 1/1 setitimer02: Convert setitimer02 to new API
Hi!
Pushed with small changes, thanks.
* Slightly adjusted the docparse comment
* Switched from malloc to .bufs static declaration in test structure
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 6/10 setitimer02: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_setitimer" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/setitimer/setitimer02.c | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/setitimer/setitimer02.c +39 -2
@@ -16,10 +16,34 @@#include <sys/time.h> #include <stdlib.h> #include "tst_test.h" +#include "lapi/syscalls.h" + +static int libc_setitimer (int which,void *new_value,void *old_value) +{ +return setitimer (which, new_value, old_value); +} + +static int sys_setitimer (int which,void *new_value,void *old_value) +{ +return tst_syscall (__NR_setitimer, which, new_value, old_value); +} + +static struct test_variants +{ +int (*setitimer)(int which,void *new_value,void *old_value); +char *desc; +} variants[] = { +{ .setitimer = libc_setitimer, .desc ="libc setitimer()" }, + +#if (__NR_setitimer != __LTP__NR_INVALID_SYSCALL) +{ .setitimer = sys_setitimer, .desc ="__NR_setitimer syscall" }, +#endif +};static void verify_setitimer (void ) {struct itimerval *value; +struct test_variants *tv = &variants[tst_variant];/* allocate some space for a timer structure */ if ((value = malloc((size_t)sizeof(struct itimerval))) ==
@@ -37,8 +61,13 @@ static void verify_setitimer(void)* ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2 */ +if (tv->setitimer == libc_setitimer) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } +/* call with a bad address */ -TEST (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 )); +TEST (tv->setitimer (ITIMER_REAL , value, (struct itimerval *)-1 ));if (TST_RET ==0 ) { tst_res(TFAIL, "call failed to produce EFAULT error "
@@ -64,8 +93,16 @@ static void verify_setitimer(void) value =NULL ; } +static void setup (void ) +{ +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); +} +static struct tst_test test = { .test_all = verify_setitimer, + .setup = setup, + .test_variants =ARRAY_SIZE (variants), .needs_root =1 , }; -
Signature · 1 line
2.17.1
PATCH v2 6/10 setitimer02: Skipped EFAULT tests for libc variant.
Hi!
Here as well, no need for the variant if the test checks only the EFAULT error. We can simply switch to the syscall variant instead.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 setitimer02: Skipped EFAULT tests for libc variant.
Tested EFAULT cases only for "__NR_setitimer" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- testcases/kernel/syscalls/setitimer/setitimer02.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/setitimer/setitimer02.c +9 -1
@@ -16,14 +16,22 @@#include <sys/time.h> #include <stdlib.h> #include "tst_test.h" +#include "lapi/syscalls.h" struct itimerval *value; +static int sys_setitimer (int which,void *new_value,void *old_value) +{ +return tst_syscall (__NR_setitimer, which, new_value, old_value); +} +static void verify_setitimer (void ) {/* call with a bad address */ -TST_EXP_FAIL (setitimer (ITIMER_REAL , value, (struct itimerval *)-1 ), +TST_EXP_FAIL (sys_setitimer (ITIMER_REAL , value, (struct itimerval *)-1 ),EFAULT ,"expected failure - errno = %d - %s" ,TST_ERR ,strerror (TST_ERR )); + +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); }static void setup (void )
Signature · 1 line
2.17.1
PATCH v3 1/1 setitimer02: Skipped EFAULT tests for libc variant.
Hi!
Slightly adjusted and fixed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 7/10 msgctl04: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_msgctl" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/ipc/msgctl/msgctl04.c | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/msgctl/msgctl04.c +37 -1
@@ -15,6 +15,7 @@#include "tst_test.h" #include "tst_safe_sysv_ipc.h" #include "libnewipc.h" +#include "lapi/syscalls.h" static int msg_id1 =-1 ;static int msg_id2 =-1 ;
@@ -23,6 +24,16 @@ static int bad_q = -1;struct msqid_ds q_buf; +static int libc_msgctl (int msqid,int cmd,void *buf) +{ +return msgctl (msqid, cmd, buf); +} + +static int sys_msgctl (int msqid,int cmd,void *buf) +{ +return tst_syscall (__NR_msgctl, msqid, cmd, buf); +} +struct tcase {int *msg_id;int cmd;
@@ -45,9 +56,29 @@ struct tcase { {&msg_id3, IPC_RMID, NULL, EPERM}, }; +static struct test_variants +{ +int (*msgctl)(int msqid,int cmd,void *buf); +char *desc; +} variants[] = { + { .msgctl = libc_msgctl, .desc ="libc msgctl()" }, + +#if (__NR_msgctl != __LTP__NR_INVALID_SYSCALL) + { .msgctl = sys_msgctl, .desc ="__NR_msgctl syscall" }, +#endif +}; +static void verify_msgctl (unsigned int i) { -TEST (msgctl (*(tc[i].msg_id), tc[i].cmd, tc[i].buf)); +struct test_variants *tv = &variants[tst_variant]; + +if (tc[i].error ==EFAULT && + tv->msgctl == libc_msgctl) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } + +TEST (tv->msgctl (*(tc[i].msg_id), tc[i].cmd, tc[i].buf));if (TST_RET !=-1 ) {tst_res (TFAIL ,"msgctl() returned %li" ,TST_RET );
@@ -66,6 +97,8 @@ static void verify_msgctl(unsigned int i)static void setup (void ) { +struct test_variants *tv = &variants[tst_variant]; +key_t msgkey1, msgkey2;struct passwd *ltpuser;
@@ -79,6 +112,8 @@ static void setup(void) msg_id1 =SAFE_MSGGET (msgkey1,IPC_CREAT |IPC_EXCL ); msg_id2 =SAFE_MSGGET (msgkey2,IPC_CREAT |IPC_EXCL |MSG_RD |MSG_WR ); + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); }static void cleanup (void )
@@ -100,6 +135,7 @@ static struct tst_test test = { .cleanup = cleanup, .test = verify_msgctl, .tcnt = ARRAY_SIZE(tc), + .test_variants = ARRAY_SIZE(variants), .needs_tmpdir = 1, .needs_root = 1, };
Signature · 1 line
2.17.1
PATCH v2 7/10 msgctl04: Skipped EFAULT tests for libc variant.
Hi!
Pushed with a minor whitespace adjustement, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 8/10 semctl03 :Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_semctl" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/ipc/semctl/semctl03.c | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/semctl/semctl03.c +37 -2
@@ -15,6 +15,7 @@#include "tst_test.h" #include "lapi/sem.h" #include "libnewipc.h" +#include "lapi/syscalls.h" static int sem_id =-1 ;static int bad_id =-1 ;
@@ -23,6 +24,17 @@ static struct semid_ds sem_ds;static union semun sem_un = {.buf = &sem_ds};static void *semds_ptr = &sem_un;static void *bad_ptr; +static union semun arg = {0 }; + +static int libc_semctl (int semid,int semnum,int cmd, ...) +{ +return semctl (semid, semnum, cmd, arg); +} + +static int sys_semctl (int semid,int semnum,int cmd, ...) +{ +return tst_syscall (__NR_semctl, semid, semnum, cmd, arg); +} static struct tcases { int *sem_id;
@@ -37,17 +49,39 @@ static struct tcases { {&sem_id, IPC_SET, &bad_ptr, EFAULT, "invalid union arg"} }; +static struct test_variants +{ +int (*semctl)(int semid,int semnum,int cmd, ...); +char *desc; +} variants[] = { + { .semctl = libc_semctl, .desc ="libc semctl()" }, + +#if (__NR_sys_semctl != __LTP__NR_INVALID_SYSCALL) + { .semctl = sys_semctl, .desc ="__NR_semctl syscall" }, +#endif +}; +static void verify_semctl (unsigned int n) {struct tcases *tc = &tests[n]; +struct test_variants *tv = &variants[tst_variant]; + +if (tc->error ==EFAULT + && tv->semctl == libc_semctl) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } -TST_EXP_FAIL (semctl (*(tc->sem_id),0 , tc->ipc_cmd, *(tc->buf)), - tc->error,"semctl() with %s" , tc->message); +TST_EXP_FAIL (sys_semctl (*(tc->sem_id),0 , tc->ipc_cmd, *(tc->buf)), + tc->error,"semctl() with %s" , tc->message); }static void setup (void ) {static key_t semkey; +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); semkey =GETIPCKEY ();
@@ -67,4 +101,5 @@ static struct tst_test test = { .cleanup = cleanup, .test = verify_semctl, .tcnt = ARRAY_SIZE(tests), + .test_variants = ARRAY_SIZE(variants), };
Signature · 1 line
2.17.1
PATCH v2 8/10 semctl03 :Skipped EFAULT tests for libc variant.
Hi!
testcases/kernel/syscalls/ipc/semctl/semctl03.c static struct tcases { · line 75
Quoted 1 line
testcases/kernel/syscalls/ipc/semctl/semctl03.c +1
-0+ TST_EXP_FAIL(sys_semctl(*(tc->sem_id), 0, tc->ipc_cmd, *(tc->buf)),
^ Fixed this to tv->semctl
And adjusted a few whitespaces and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 9/10 sched_rr_get_interval03: Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_sched_rr_get_interval" and "__NR_sched_rr_get_interval_time64" syscalls.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../sched_rr_get_interval/sched_rr_get_interval03.c | 6 ++++++ 1 file changed, 6 insertions(+)
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c +6 -0
@@ -67,6 +67,12 @@ static void run(unsigned int i)struct test_cases_t *tc = &test_cases[i];struct timerspec *ts; +if (tc->exp_errno ==EFAULT + && tv->sched_rr_get_interval == libc_sched_rr_get_interval) { +tst_res (TCONF ,"EFAULT skipped for libc_variant" ); +return ; + } +if (tc->exp_errno ==EFAULT ) ts = bad_addr;else
Signature · 1 line
2.17.1
PATCH v2 9/10 sched_rr_get_interval03: Skipped EFAULT tests for libc variant.
Hi!
Applied, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 10/10 shmctl02 :Skipped EFAULT tests for libc variant.
In reply to Vinay KumarTested EFAULT cases only for "__NR_shmctl" syscall.
Tests for bad addresses in LTP cases trigger segment fault in libc on a 32bit system.
--- .../kernel/syscalls/ipc/shmctl/shmctl02.c | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +38 -2
@@ -32,6 +32,7 @@#include "tst_test.h" #include "tst_safe_sysv_ipc.h" #include "libnewipc.h" +#include "lapi/syscalls.h" #define SHM_SIZE 2048
@@ -43,6 +44,16 @@ static int shm_rem;static struct shmid_ds buf; +static int libc_shmctl (int shmid,int cmd,void *buf) +{ +return shmctl (shmid, cmd, buf); +} + +static int sys_shmctl (int shmid,int cmd,void *buf) +{ +return tst_syscall (__NR_shmctl, shmid, cmd, buf); +} + static struct tcase { int *shm_id; int cmd;
@@ -63,9 +74,29 @@ static struct tcase { {&shm_id3, SHM_UNLOCK, &buf, EPERM} }; +static struct test_variants +{ +int (*shmctl)(int shmid,int cmd,void *buf); +char *desc; +} variants[] = { + { .shmctl = libc_shmctl, .desc ="libc shmctl()" }, + +#if (__NR_shmctl != __LTP__NR_INVALID_SYSCALL) + { .shmctl = sys_shmctl, .desc ="__NR_shmctl syscall" }, +#endif +}; +static void verify_shmctl (unsigned int i) { -TEST (shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf)); +struct test_variants *tv = &variants[tst_variant]; + +if (tc[i].error ==EFAULT + && tv->shmctl == libc_shmctl) { +tst_res (TCONF ,"EFAULT is skipped for libc variant" ); +return ; + } + +TEST (tv->shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf));if (TST_RET !=-1 ) {tst_res (TFAIL ,"shmctl() returned %li" ,TST_RET );
@@ -74,7 +105,7 @@ static void verify_shmctl(unsigned int i)if (TST_ERR == tc[i].error) {tst_res (TPASS |TTERRNO ,"shmctl(%i, %i, %p)" , - *tc[i].shm_id, tc[i].cmd, tc[i].buf); + *tc[i].shm_id, tc[i].cmd, tc[i].buf);return ; }
@@ -84,10 +115,14 @@ static void verify_shmctl(unsigned int i)static void setup (void ) { +struct test_variants *tv = &variants[tst_variant]; +key_t shmkey1, shmkey2;struct passwd *ltpuser;int tmp; +tst_res (TINFO ,"Testing variant: %s" , tv->desc); + shm_id3 =SAFE_SHMGET (IPC_PRIVATE ,SHM_SIZE ,IPC_CREAT |SHM_RW ); ltpuser =SAFE_GETPWNAM ("nobody" );
@@ -121,6 +156,7 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test = verify_shmctl, + .test_variants = ARRAY_SIZE(variants), .tcnt = ARRAY_SIZE(tc), .needs_root = 1, };
Signature · 1 line
2.17.1
PATCH v3 1/1 ipc/shmctl02: Make use of TST_EXP_FAIL()
In order to simplify the code a bit.
--- testcases/kernel/syscalls/ipc/shmctl/shmctl02.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +2 -15
@@ -96,21 +96,8 @@ static void verify_shmctl(unsigned int i)return ; } -TEST (tv->shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf)); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"shmctl() returned %li" ,TST_RET ); -return ; - } - -if (TST_ERR == tc[i].error) { -tst_res (TPASS |TTERRNO ,"shmctl(%i, %i, %p)" , - *tc[i].shm_id, tc[i].cmd, tc[i].buf); -return ; - } - -tst_res (TFAIL |TTERRNO ,"shmctl(%i, %i, %p) expected %s" , - *tc[i].shm_id, tc[i].cmd, tc[i].buf,tst_strerrno (tc[i].error)); +TST_EXP_FAIL (tv->shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf), + tc[i].error,"shmctl(%i, %i, %p)" , *(tc[i].shm_id), tc[i].cmd, tc[i].buf); }static void setup (void )
Signature · 1 line
2.17.1
PATCH v3 1/1 ipc/shmctl02: Make use of TST_EXP_FAIL()
Hi Cyril,
Could you please review below test cases changes also,
semctl03.c
https://lists.linux.it/pipermail/ltp/2021-June/023116.html
shmctl02.c
https://lists.linux.it/pipermail/ltp/2021-June/023118.html
https://lists.linux.it/pipermail/ltp/2021-June/023166.html
Regards,
Vinay
Quoted 39 lines · Vinay Kumar
In order to simplify the code a bit.
Signed-off-by Vinay Kumar <[email protected]>--- testcases/kernel/syscalls/ipc/shmctl/shmctl02.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +2
-16@@ -96,21 +96,8 @@ static void verify_shmctl(unsigned int i)return ; } -TEST (tv->shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf)); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"shmctl() returned %li" ,TST_RET ); -return ; - } - -if (TST_ERR == tc[i].error) { -tst_res (TPASS |TTERRNO ,"shmctl(%i, %i, %p)" , - *tc[i].shm_id, tc[i].cmd, tc[i].buf); -return ; - } - -tst_res (TFAIL |TTERRNO ,"shmctl(%i, %i, %p) expected %s" , - *tc[i].shm_id, tc[i].cmd, tc[i].buf,tst_strerrno (tc[i].error)); +TST_EXP_FAIL (tv->shmctl (*(tc[i].shm_id), tc[i].cmd, tc[i].buf), + tc[i].error,"shmctl(%i, %i, %p)" , *(tc[i].shm_id), tc[i].cmd, tc[i].buf); }static void setup (void ) --2.17.1
PATCH v3 1/1 ipc/shmctl02: Make use of TST_EXP_FAIL()
In reply to Vinay KumarHi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 10/10 shmctl02 :Skipped EFAULT tests for libc variant.
In reply to Vinay KumarHi!
Adjusted a few whitespaces and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/10 getitimer02 : Convert getitimer02 to new API
In reply to Vinay KumarHi!
testcases/kernel/syscalls/getitimer/getitimer02.c line 21
Quoted 3 lines
testcases/kernel/syscalls/getitimer/getitimer02.c +0
-0/* call with a bad address */ TEST (getitimer (ITIMER_REAL , (struct itimerval *)-1 ));
Can we please make use of TST_EXP_FAIL() here instead?
Quoted 16 lines
testcases/kernel/syscalls/getitimer/getitimer02.c +5
-8-if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -continue ; +if (TST_RET ==0 ) { +tst_res (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR )); } -switch (TEST_ERRNO ) { +switch (TST_ERR ) {case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO ));
testcases/kernel/syscalls/getitimer/getitimer02.c line 37
Quoted 10 lines
testcases/kernel/syscalls/getitimer/getitimer02.c +5
-3+tst_res (TPASS ,"expected failure - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR ));break ;default : -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); +tst_res (TFAIL ,"call failed to produce " +"expected error - errno = %d - %s" , +TST_ERR ,strerror (TST_ERR ));
And can we please have a proper indentation here from the start instead of fixing that in subsequent patches?
testcases/kernel/syscalls/getitimer/getitimer02.c line 43
Quoted 4 lines
testcases/kernel/syscalls/getitimer/getitimer02.c +3
-1-#endif /* if !defined(UCLINUX) */ +static struct tst_test test = { + .test_all = verify_getitimer, + .needs_root =1 ,
And here as well.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 getitimer02: Convert getitimer02 to new API
--- .../kernel/syscalls/getitimer/getitimer02.c | 104 +++--------------- 1 file changed, 16 insertions(+), 88 deletions(-)
testcases/kernel/syscalls/getitimer/getitimer02.c +16 -88
@@ -1,99 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* 03/2001 - Written by Wayne Boyer */ -/* -HISTORY -03/2001 - Written by Wayne Boyer - -TEST ITEMS: -Check that a getitimer() call fails as expected -with an incorrect second argument. -*/ - - -#include "test.h" +/*\ +*[Description] +* +* Check that a getitimer() call fails as expected +* with an incorrect second argument. +*/ #include <errno.h> #include <sys/time.h> +#include "tst_test.h" -char *TCID ="getitimer02" ; -int TST_TOTAL =1 ; - -#if !defined(UCLINUX ) - -static void cleanup (void ); -static void setup (void ); - -int main (int ac,char **av) -{ -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -/* call with a bad address */ -TEST (getitimer (ITIMER_REAL , (struct itimerval *)-1 )); - -if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -continue ; - } - -switch (TEST_ERRNO ) { -case EFAULT : -tst_resm (TPASS ,"expected failure - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -break ; -default : -tst_resm (TFAIL ,"call failed to produce " -"expected error - errno = %d - %s" , -TEST_ERRNO ,strerror (TEST_ERRNO )); - } - } - -cleanup (); - -tst_exit (); -} - -static void setup (void ) -{ -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} - -static void cleanup (void ) -{ -} - -#else - -int main (void ) +static void verify_getitimer (void ) { -tst_resm (TINFO ,"test is not available on uClinux" ); -tst_exit (); +/* call with a bad address */ +TST_EXP_FAIL (getitimer (ITIMER_REAL , (struct itimerval *)-1 ), +EFAULT ,"expected failure - errno = %d - %s" ,TST_ERR ,strerror (TST_ERR )); } -#endif /* if !defined(UCLINUX) */ +static struct tst_test test = { + .test_all = verify_getitimer, +};
Signature · 1 line
2.17.1
PATCH v3 1/1 getitimer02: Convert getitimer02 to new API
Hi!
Pushed with small changes, thanks.
* Adjusted the docparse comment to be more clear
* I've removed the printf format from TST_EXP_FAIL() since in this case the automatic message will be nicer
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/7 getitimer02: Skipped EFAULT tests for libc variant.
In reply to Petr VorelHi Petr,
Sent v2 patches for review with suggested corrections.
Quoted 2 lines
Quoted 2 lines
In the text after blank line I'd mention EFAULT skipped on raw syscall. It'd would deserve to mention why.
Yes, added the reason in the commit log of each test case.
Quoted 2 lines
Quoted 2 lines
Also, as test it's quite simple, it'd be nice, if you first convert it to new API and in second commit added test variants.
getitimer02.c, getrusage02.c and setitimer02.c are updated to the new API. Then added test variants. Remaining test cases are already updated with the new API.
Quoted 2 lines
Quoted 2 lines
During rewrite you should remove #if !defined(UCLINUX) check as
getitimer()is supported on uclibc-ng.
Removed the same.
Regards,
Vinay
Quoted 19 lines · Petr Vorel
Hi Vinay,
Quoted 1 line
Tested EFAULT cases only for "
__NR_getitimer" syscall.Well, you added testing raw syscall via test variant. That's IMHO the most important thing to mention.
In the text after blank line I'd mention EFAULT skipped on raw syscall. It'd would deserve to mention why.
Also, as test it's quite simple, it'd be nice, if you first convert it to new API and in second commit added test variants.
During rewrite you should remove #if !defined(UCLINUX) check asgetitimer()is supported on uclibc-ng.This apply to whole patchset (some tests are already ported to new API).
Kind regards,
Petr