public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] fix the bug of sched_getaffinity in cpuset_syscall_test
@ 2010-01-14  7:53 Miao Xie
  0 siblings, 0 replies; only message in thread
From: Miao Xie @ 2010-01-14  7:53 UTC (permalink / raw)
  To: Subrata Modak; +Cc: LTP-ML

The 5th and 6th testcases of cpuset05 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:
cpuset05    5  TFAIL  :  Test task exited abnormally.(expect return value is 0)
cpuset05    6  TFAIL  :  Test task exited abnormally.(expect return value is 0)

After using this patch, the test result is following:
cpuset05    5  TPASS  :  Cpuset vs systemcall test succeeded.
cpuset05    6  TPASS  :  Cpuset vs systemcall test succeeded.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 .../cpuset_syscall_test/cpuset_syscall_test.c      |   58 ++++++++++++++++++--
 1 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c b/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c
index 77bb7d7..c0aada7 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c
@@ -57,6 +57,10 @@ int test = -1;
 int flag_exit;
 int ret;
 
+#if !(__GLIBC_PREREQ(2, 7))
+#define CPU_FREE(ptr) free(ptr)
+#endif
+
 /* Policies for set_mempolicy() */
 #define MPOL_DEFAULT     0
 #define MPOL_PREFERRED   1
@@ -161,14 +165,56 @@ void test_setaffinity(void)
 
 void test_getaffinity(void)
 {
-	cpu_set_t tmask;
-	int i;
-	CPU_ZERO(&tmask);
-	ret = sched_getaffinity(0, sizeof(tmask), &tmask);
-	for (i = 0; i < 8 * sizeof(mask); i++) {
-		if (CPU_ISSET(i, &tmask))
+	cpu_set_t *tmask;
+	int i, nrcpus = 1024;
+	size_t size;
+
+#if __GLIBC_PREREQ(2, 7)
+realloc:
+	tmask = CPU_ALLOC(nrcpus);
+#else
+	tmask = malloc(sizeof(cpu_set_t));
+#endif
+	if (tmask == NULL) {
+		warn("CPU_ALLOC:errno:%d", errno);
+		ret = -1;
+		return;
+	}
+
+#if __GLIBC_PREREQ(2, 7)
+	size = CPU_ALLOC_SIZE(nrcpus);
+	CPU_ZERO_S(size, tmask);
+#else
+	size = sizeof(cpu_set_t);
+	CPU_ZERO(tmask);
+#endif
+
+	ret = sched_getaffinity(0, size, tmask);
+	if (ret < 0) {
+		CPU_FREE(tmask);
+#if __GLIBC_PREREQ(2, 7)
+		if (errno == EINVAL && nrcpus < (1024 << 8)) {
+			nrcpus = nrcpus << 2;
+			ret = 0;
+			goto realloc;
+		}
+#else
+		if (errno == EINVAL)
+			warn("NR_CPUS of the kernel is more than 1024, so we'd better use a newer glibc(>= 2.7)");
+		else
+#endif
+			warn("sched_getaffinity:errno:%d", errno);
+		return;
+	}
+	for (i = 0; i < 8 * size; i++) {
+#if __GLIBC_PREREQ(2, 7)
+		if (CPU_ISSET_S(i, size, tmask))
+#else
+		if (CPU_ISSET(i, tmask))
+#endif
 			printf("%d,", i);
 	}
+	CPU_FREE(tmask);
 }
 
 void test_mbind(void)
-- 
1.6.5.2



------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-01-14  7:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-14  7:53 [LTP] [PATCH] fix the bug of sched_getaffinity in cpuset_syscall_test Miao Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox