From: Miao Xie <miaox@cn.fujitsu.com>
To: Subrata Modak <subrata@linux.vnet.ibm.com>
Cc: LTP-ML <ltp-list@lists.sourceforge.net>
Subject: [LTP] [PATCH] fix the bug of the smaller cpu_set_t's length in sched_getaffinity01
Date: Wed, 06 Jan 2010 11:29:44 +0800 [thread overview]
Message-ID: <4B4403A8.2040502@cn.fujitsu.com> (raw)
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
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
.../sched_getaffinity/sched_getaffinity01.c | 81 +++++++++++++++-----
1 files changed, 61 insertions(+), 20 deletions(-)
diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
index 7c4a254..7dfb0ec 100644
--- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
+++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
@@ -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();
}
--
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next reply other threads:[~2010-01-06 3:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-06 3:29 Miao Xie [this message]
2010-01-07 11:06 ` [LTP] [PATCH] fix the bug of the smaller cpu_set_t's length in sched_getaffinity01 Subrata Modak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B4403A8.2040502@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=subrata@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox