fix the bug of the smaller cpu_set_t's length in sched_getaffinity01
PATCH 1/1 fix the bug of the smaller cpu_set_t's length in sched_getaffinity01
sched_getaffinity01 test failed because the len of cpu_set_t in the glibc is smaller than the length of the cpumask in the kernel. So we must use the dynamically sized CPU sets instead of the standard cpu_set_t.
This patch fix this problem.
Before using this patch, the test result is following:
sched_getaffinity01 0 TINFO : system has 4 processor(s). sched_getaffinity01 1 TPASS : sched_getaffinity(0, len, (cpu_set_t *)-1): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 2 TPASS : sched_getaffinity(0, 0, &mask): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 3 TPASS : sched_getaffinity(getpid() + 1, len, &mask): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 4 TFAIL : could not get cpu affinity: TEST_ERRNO=EINVAL(22): Invalid argument
The subcases1-3 of this test also failed though they were successful according to the log. Becuase the errnos returned were wrong.
After using this patch, the test result is following:
sched_getaffinity01 0 TINFO : system has 4 processor(s). sched_getaffinity01 0 TINFO : cpusetsize is 512 sched_getaffinity01 0 TINFO : mask.__bits[0] = 15 sched_getaffinity01 1 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 0 sched_getaffinity01 2 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 1 sched_getaffinity01 3 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 2 sched_getaffinity01 4 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 3 sched_getaffinity01 5 TPASS : sched_getaffinity(0, len, (cpu_set_t *)-1): TEST_ERRNO=EFAULT(14): Bad address sched_getaffinity01 6 TPASS : sched_getaffinity(0, 0, mask): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 7 TPASS : sched_getaffinity(getpid() + 1, len, mask): TEST_ERRNO=ESRCH(3): No such process
--- .../sched_getaffinity/sched_getaffinity01.c | 81 +++++++++++++++----- 1 files changed, 61 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +61 -20
@@ -119,11 +119,15 @@ do { \ tst_resm((TEST_RETURN == -1 ? TPASS : TFAIL) | TTERRNO, #t); \ } while (0) +#if !(__GLIBC_PREREQ (2 ,7 )) +#define CPU_FREE (ptr) free(ptr) +#endif int main (int ac,char **av) {int lc,num,i;/* loop counter */ char *msg;/* message returned from parse_opts */ -cpu_set_t mask; -unsigned int len =sizeof (cpu_set_t); +cpu_set_t *mask; +int nrcpus =1024 ; +unsigned int len;/* parse standard options */ if ((msg =parse_opts (ac, av, (option_t *)NULL ,NULL )) != (char *)NULL ){
@@ -140,30 +144,67 @@ int main(int ac, char **av) {for (lc =0 ;TEST_LOOPING (lc); ++lc) { Tst_count =0 ;for (testno =0 ; testno <TST_TOTAL ; ++testno) { -QUICK_TEST (sched_getaffinity (0 , len, (cpu_set_t *)-1 )); -QUICK_TEST (sched_getaffinity (0 ,0 , &mask)); -QUICK_TEST (sched_getaffinity (getpid () +1 , len, &mask)); - -CPU_ZERO (&mask);//clear -TEST (sched_getaffinity (0 ,len,&mask));//call sched_getaffinity() +#if __GLIBC_PREREQ (2 ,7 ) +realloc: + mask =CPU_ALLOC (nrcpus); +# else + mask =malloc (sizeof (cpu_set_t)); +#endif +if (mask ==NULL ) { +tst_resm (TFAIL |TTERRNO ,"cann't get enough memory" ); +cleanup (); +tst_exit (); + } + +#if __GLIBC_PREREQ (2 ,7 ) + len =CPU_ALLOC_SIZE (nrcpus); +CPU_ZERO_S (len, mask);//clear +#else + len =sizeof (cpu_set_t); +CPU_ZERO (mask);//clear +#endif +TEST (sched_getaffinity (0 , len, mask));//call sched_getaffinity() if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL |TTERRNO ,"could not get cpu affinity" ); -cleanup (); -tst_exit (); +CPU_FREE (mask); +#if __GLIBC_PREREQ (2 ,7 ) +if (errno ==EINVAL && nrcpus < (1024 <<8 )) { + nrcpus = nrcpus <<2 ; + goto realloc; + } +#else +if (errno ==EINVAL ) +tst_resm (TFAIL ,"NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)" ); + else +#endif +tst_resm (TFAIL |TTERRNO ,"could not get cpu affinity" ); +cleanup (); +tst_exit (); }else {tst_resm (TINFO ,"cpusetsize is %d" , len); -tst_resm (TINFO ,"mask.__bits[0] = %lu " ,mask.__bits[0 ]); +tst_resm (TINFO ,"mask.__bits[0] = %lu " ,mask->__bits[0 ]);for (i=0 ;i<num;i++){// check the processor -TEST (CPU_ISSET (i,&mask)); +#if __GLIBC_PREREQ (2 ,7 ) +TEST (CPU_ISSET_S (i, len, mask)); +#else +TEST (CPU_ISSET (i, mask)); +#endif if (TEST_RETURN !=-1 ){tst_resm (TPASS ,"sched_getaffinity() succeed ,this process %d is running processor: %d" ,getpid (), i); - } - } - } - - - } - } + } + } + } + +#if __GLIBC_PREREQ (2 ,7 ) +CPU_ZERO_S (len, mask);//clear +#else +CPU_ZERO (mask);//clear +#endif +QUICK_TEST (sched_getaffinity (0 , len, (cpu_set_t *)-1 )); +QUICK_TEST (sched_getaffinity (0 ,0 , mask)); +QUICK_TEST (sched_getaffinity (getpid () +1 , len, mask)); +CPU_FREE (mask); + } + }cleanup ();tst_exit (); }
Signature · 13 lines
1.6.5.2 ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 27 lines · Miao Xie
sched_getaffinity01test failed because the len ofcpu_set_tin the glibc is smaller than the length of the cpumask in the kernel. So we must use the dynamically sized CPU sets instead of the standardcpu_set_t.This patch fix this problem.
Before using this patch, the test result is following:sched_getaffinity01 0 TINFO : system has 4 processor(s). sched_getaffinity01 1 TPASS : sched_getaffinity(0, len, (cpu_set_t *)-1): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 2 TPASS : sched_getaffinity(0, 0, &mask): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 3 TPASS : sched_getaffinity(getpid() + 1, len, &mask): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 4 TFAIL : could not get cpu affinity: TEST_ERRNO=EINVAL(22): Invalid argumentThe subcases1-3 of this test also failed though they were successful according to the log. Becuase the errnos returned were wrong.
After using this patch, the test result is following:
sched_getaffinity01 0 TINFO : system has 4 processor(s). sched_getaffinity01 0 TINFO : cpusetsize is 512 sched_getaffinity01 0 TINFO : mask.__bits[0] = 15 sched_getaffinity01 1 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 0 sched_getaffinity01 2 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 1 sched_getaffinity01 3 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 2 sched_getaffinity01 4 TPASS : sched_getaffinity() succeed ,this process 2239 is running processor: 3 sched_getaffinity01 5 TPASS : sched_getaffinity(0, len, (cpu_set_t *)-1): TEST_ERRNO=EFAULT(14): Bad address sched_getaffinity01 6 TPASS : sched_getaffinity(0, 0, mask): TEST_ERRNO=EINVAL(22): Invalid argument sched_getaffinity01 7 TPASS : sched_getaffinity(getpid() + 1, len, mask): TEST_ERRNO=ESRCH(3): No such process
Quoted 1 line
Signed-off-by Miao Xie <[email protected]>
Thanks.
Regards--
Subrata
Quoted 102 lines
--- .../sched_getaffinity/sched_getaffinity01.c | 81 +++++++++++++++----- 1 files changed, 61 insertions(+), 20 deletions(-)testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +54
-20@@ -119,11 +119,15 @@ do { \ tst_resm((TEST_RETURN == -1 ? TPASS : TFAIL) | TTERRNO, #t); \ } while (0) +#if !(__GLIBC_PREREQ (2 ,7 )) +#define CPU_FREE (ptr) free(ptr) +#endif int main (int ac,char **av) {int lc,num,i;/* loop counter */ char *msg;/* message returned from parse_opts */ -cpu_set_t mask; -unsigned int len =sizeof (cpu_set_t); +cpu_set_t *mask; +int nrcpus =1024 ; +unsigned int len;/* parse standard options */ if ((msg =parse_opts (ac, av, (option_t *)NULL ,NULL )) != (char *)NULL ){@@ -140,30 +144,67 @@ int main(int ac, char **av) {for (lc =0 ;TEST_LOOPING (lc); ++lc) { Tst_count =0 ;for (testno =0 ; testno <TST_TOTAL ; ++testno) { -QUICK_TEST (sched_getaffinity (0 , len, (cpu_set_t *)-1 )); -QUICK_TEST (sched_getaffinity (0 ,0 , &mask)); -QUICK_TEST (sched_getaffinity (getpid () +1 , len, &mask)); - -CPU_ZERO (&mask);//clear -TEST (sched_getaffinity (0 ,len,&mask));//call sched_getaffinity() +#if __GLIBC_PREREQ (2 ,7 ) +realloc: + mask =CPU_ALLOC (nrcpus); +# else + mask =malloc (sizeof (cpu_set_t)); +#endif +if (mask ==NULL ) { +tst_resm (TFAIL |TTERRNO ,"cann't get enough memory" ); +cleanup (); +tst_exit (); + } + +#if __GLIBC_PREREQ (2 ,7 ) + len =CPU_ALLOC_SIZE (nrcpus); +CPU_ZERO_S (len, mask);//clear +#else + len =sizeof (cpu_set_t); +CPU_ZERO (mask);//clear +#endif +TEST (sched_getaffinity (0 , len, mask));//call sched_getaffinity() if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL |TTERRNO ,"could not get cpu affinity" ); -cleanup (); -tst_exit (); +CPU_FREE (mask); +#if __GLIBC_PREREQ (2 ,7 ) +if (errno ==EINVAL && nrcpus < (1024 <<8 )) { + nrcpus = nrcpus <<2 ; + goto realloc; + } +#else +if (errno ==EINVAL ) +tst_resm (TFAIL ,"NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)" ); + else +#endif +tst_resm (TFAIL |TTERRNO ,"could not get cpu affinity" ); +cleanup (); +tst_exit (); }else {tst_resm (TINFO ,"cpusetsize is %d" , len); -tst_resm (TINFO ,"mask.__bits[0] = %lu " ,mask.__bits[0 ]); +tst_resm (TINFO ,"mask.__bits[0] = %lu " ,mask->__bits[0 ]);for (i=0 ;i<num;i++){// check the processor -TEST (CPU_ISSET (i,&mask)); +#if __GLIBC_PREREQ (2 ,7 ) +TEST (CPU_ISSET_S (i, len, mask)); +#else +TEST (CPU_ISSET (i, mask)); +#endif if (TEST_RETURN !=-1 ){tst_resm (TPASS ,"sched_getaffinity() succeed ,this process %d is running processor: %d" ,getpid (), i); - } - } - } - - - } - } + } + } + } + +#if __GLIBC_PREREQ (2 ,7 ) +CPU_ZERO_S (len, mask);//clear +#else +CPU_ZERO (mask);//clear
testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c int main(int ac, char **av) { · line 210
Quoted 10 lines
testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +7
-0+#endif +QUICK_TEST (sched_getaffinity (0 , len, (cpu_set_t *)-1 )); +QUICK_TEST (sched_getaffinity (0 ,0 , mask)); +QUICK_TEST (sched_getaffinity (getpid () +1 , len, mask)); +CPU_FREE (mask); + } + }cleanup ();tst_exit (); }
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list