getrandom01: Convert to the new library.
PATCH 1/4 getrandom01: Convert to the new library.
Signed-off-by Cyril Hrubis <[email protected]>
--- testcases/kernel/syscalls/getrandom/getrandom01.c | 40 +++++++++-------------- 1 file changed, 16 insertions(+), 24 deletions(-)
testcases/kernel/syscalls/getrandom/getrandom01.c +16 -24
@@ -28,33 +28,25 @@#include "lapi/getrandom.h" #include "linux_syscall_numbers.h" -#include "test.h" +#include "tst_test.h" -char *TCID ="getrandom01" ; -static int modes[] = {0 ,GRND_RANDOM ,GRND_NONBLOCK , -GRND_RANDOM |GRND_NONBLOCK }; +static int modes[] = {0 ,GRND_RANDOM ,GRND_NONBLOCK , +GRND_RANDOM |GRND_NONBLOCK }; -int TST_TOTAL =ARRAY_SIZE (modes); - -int main (int ac,char **av) +static void verify_getrandom (unsigned int n) { -int lc, i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { +TEST (tst_syscall (__NR_getrandom,NULL ,100 , modes[n])); - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; i++) { -TEST (ltp_syscall (__NR_getrandom,NULL ,100 , modes[i])); -if (TEST_RETURN ==-1 ) { -tst_resm (TPASS ,"getrandom returned %ld" , -TEST_RETURN ); - }else { -tst_resm (TFAIL |TTERRNO ,"getrandom failed" ); - } - } +if (TEST_RETURN ==-1 ) { +tst_res (TPASS |TTERRNO ,"getrandom returned %ld" , +TEST_RETURN ); + }else { +tst_res (TFAIL |TTERRNO ,"getrandom failed" ); } -tst_exit (); } + +static struct tst_test test = { + .tid ="getrandom01" , + .tcnt =ARRAY_SIZE (modes), + .test = verify_getrandom, +};
Signature · 1 line
2.10.2
PATCH 2/4 getrandom02: Convert to the new library.
Signed-off-by Cyril Hrubis <[email protected]>
--- testcases/kernel/syscalls/getrandom/getrandom02.c | 69 ++++++++--------------- 1 file changed, 25 insertions(+), 44 deletions(-)
testcases/kernel/syscalls/getrandom/getrandom02.c +25 -44
@@ -29,54 +29,12 @@#include "lapi/getrandom.h" #include "linux_syscall_numbers.h" -#include "test.h" +#include "tst_test.h" -char *TCID ="getrandom02" ;static int modes[] = {0 ,GRND_RANDOM ,GRND_NONBLOCK ,GRND_RANDOM |GRND_NONBLOCK }; -int TST_TOTAL =ARRAY_SIZE (modes); - -static unsigned char buf[256 ]; -static size_t size =256 ; - -static void fill (void ); -static int check_content (int nb); - -int main (int ac,char **av) -{ -int lc, i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; i++) { -fill (); - -do { -TEST (ltp_syscall (__NR_getrandom, buf, size, - modes[i])); - }while ((modes[i] &GRND_NONBLOCK ) &&TEST_RETURN ==-1 - &&TEST_ERRNO ==EAGAIN ); - -if (!check_content (TEST_RETURN )) -tst_resm (TFAIL |TTERRNO ,"getrandom failed" ); -else -tst_resm (TPASS ,"getrandom returned %ld" , -TEST_RETURN ); - } - } -tst_exit (); -} - -static void fill (void ) -{ -memset (buf,'\0' ,sizeof (buf)); -} - -static int check_content (int nb) +static int check_content (unsigned char *buf,int nb) {int table[256 ];int i, index, max;
@@ -96,3 +54,26 @@ static int check_content(int nb) }return 1 ; } + +static void verify_getrandom (unsigned int n) +{ +unsigned char buf[256 ]; + +memset (buf,0 ,sizeof (buf)); + +do { +TEST (tst_syscall (__NR_getrandom, buf,sizeof (buf), modes[n])); + }while ((modes[n] &GRND_NONBLOCK ) &&TEST_RETURN ==-1 + &&TEST_ERRNO ==EAGAIN ); + +if (!check_content (buf,TEST_RETURN )) +tst_res (TFAIL |TTERRNO ,"getrandom failed" ); +else +tst_res (TPASS ,"getrandom returned %ld" ,TEST_RETURN ); +} + +static struct tst_test test = { + .tid ="getrandom02" , + .tcnt =ARRAY_SIZE (modes), + .test = verify_getrandom, +};
Signature · 1 line
2.10.2
PATCH 3/4 getrandom03: Convert to the new library.
In reply to Cyril HrubisAlso use hardcoded table of sizes instead of random().
Signed-off-by Cyril Hrubis <[email protected]>
--- testcases/kernel/syscalls/getrandom/getrandom03.c | 47 +++++++++++++---------- 1 file changed, 26 insertions(+), 21 deletions(-)
testcases/kernel/syscalls/getrandom/getrandom03.c +26 -21
@@ -32,33 +32,38 @@#include "lapi/getrandom.h" #include "linux_syscall_numbers.h" -#include "test.h" +#include "tst_test.h" #define MAX_SIZE 256 -char *TCID ="getrandom03" ; -int TST_TOTAL =5 ; +static unsigned int sizes[] = { +1 , +2 , +3 , +7 , +8 , +15 , +22 , +64 , +127 , +}; -static char buf[256 ]; - -int main (int ac,char **av) +static void verify_getrandom (unsigned int n) { -int lc, i; -long size; +char buf[MAX_SIZE ]; -tst_parse_opts (ac, av,NULL ,NULL ); +TEST (tst_syscall (__NR_getrandom, buf, sizes[n],0 )); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -for (i =0 ; i <TST_TOTAL ; i++) { - size =random () %MAX_SIZE ; -TEST (ltp_syscall (__NR_getrandom, buf, size,0 )); -if (TEST_RETURN != size) -tst_resm (TFAIL |TTERRNO ,"getrandom failed" ); -else -tst_resm (TPASS ,"getrandom returned %ld" , -TEST_RETURN ); - } +if (TEST_RETURN != sizes[n]) { +tst_res (TFAIL |TTERRNO ,"getrandom returned %li, expected %u" , +TEST_RETURN , sizes[n]); + }else { +tst_res (TPASS ,"getrandom returned %ld" ,TEST_RETURN ); } -tst_exit (); } + +static struct tst_test test = { + .tid ="getrandom03" , + .tcnt =ARRAY_SIZE (sizes), + .test = verify_getrandom, +};
Signature · 1 line
2.10.2
PATCH 4/4 getrandom04: Convert to the new library.
In reply to Cyril HrubisSigned-off-by Cyril Hrubis <[email protected]>
--- testcases/kernel/syscalls/getrandom/getrandom04.c | 36 +++++++++++------------ 1 file changed, 17 insertions(+), 19 deletions(-)
testcases/kernel/syscalls/getrandom/getrandom04.c +17 -19
@@ -33,30 +33,28 @@#include <sys/resource.h> #include "lapi/getrandom.h" #include "linux_syscall_numbers.h" -#include "test.h" +#include "tst_test.h" -char *TCID ="getrandom04" ; -int TST_TOTAL =1 ; -static char buf[128 ]; - -int main (int ac,char **av) +static void verify_getrandom (void ) { -tst_parse_opts (ac, av,NULL ,NULL ); - -int r; - -struct rlimit lim = {3 ,3 }; +char buf[128 ]; +struct rlimit lold, lnew; - r =setrlimit (RLIMIT_NOFILE , &lim); +SAFE_GETRLIMIT (RLIMIT_NOFILE , &lold); + lnew.rlim_max = lold.rlim_max; + lnew.rlim_cur =3 ; +SAFE_SETRLIMIT (RLIMIT_NOFILE , &lnew); -if (r ==-1 ) -tst_brkm (TBROK |TTERRNO ,NULL ,"setrlimit failed" ); - -TEST (ltp_syscall (__NR_getrandom, buf,100 ,0 )); +TEST (tst_syscall (__NR_getrandom, buf,100 ,0 ));if (TEST_RETURN ==-1 ) -tst_resm (TFAIL |TTERRNO ,"getrandom failed" ); +tst_res (TFAIL |TTERRNO ,"getrandom failed" );else -tst_resm (TPASS ,"getrandom returned %ld" ,TEST_RETURN ); +tst_res (TPASS ,"getrandom returned %ld" ,TEST_RETURN ); -tst_exit (); +SAFE_SETRLIMIT (RLIMIT_NOFILE , &lold); } + +static struct tst_test test = { + .tid ="getrandom04" , + .test_all = verify_getrandom, +};
Signature · 1 line
2.10.2