public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
@ 2012-03-09  5:28 Caspar Zhang
  2012-03-09  5:48 ` Caspar Zhang
  2012-03-09  7:19 ` Garrett Cooper
  0 siblings, 2 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-03-09  5:28 UTC (permalink / raw)
  To: LTP List

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]


in negative case:

    QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));

sometimes getpid()+1 will exist if there're other processes running.
This patch uses a different way to make sure the required pid doesn't
exist by forking a child and terminating it. The pid of the terminated
child will not be used for a short time and it's enough for the test to
continue.

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 .../sched_getaffinity/sched_getaffinity01.c        |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-sched_getaffinity-fix-possible-fail-in-negative-case.patch --]
[-- Type: text/x-patch; name="0001-sched_getaffinity-fix-possible-fail-in-negative-case.patch", Size: 1125 bytes --]

diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
index 97cf90f..80dea9a 100644
--- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
+++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
@@ -94,7 +94,7 @@ int main(int ac, char **av)
 
 static void do_test(void)
 {
-	int i;
+	int i, status;
 	cpu_set_t *mask;
 	int nrcpus = 1024;
 	pid_t pid;
@@ -153,10 +153,24 @@ realloc:
 #else
 	CPU_ZERO(mask);
 #endif
+
 	/* negative tests */
+
 	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));
+
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK|TERRNO, cleanup, "fork");
+	case 0:
+		exit(0);
+	default:
+		if (waitpid(pid, &status, WUNTRACED|WCONTINUED) == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+	}
+	QUICK_TEST(sched_getaffinity(pid, len, mask));
+
 	/*
 	 * pid_t -> int -- the actual kernel limit is lower
 	 * though, but this is a negative test, not a positive

[-- Attachment #3: Type: text/plain, Size: 317 bytes --]

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-05-02 12:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-09  5:28 [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case Caspar Zhang
2012-03-09  5:48 ` Caspar Zhang
2012-03-09  5:53   ` Wanlong Gao
2012-03-09  7:19 ` Garrett Cooper
2012-03-09  8:59   ` Caspar Zhang
2012-05-02 12:27   ` Cyril Hrubis

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