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 <[email protected]>
---
 .../sched_getaffinity/sched_getaffinity01.c        |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

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
------------------------------------------------------------------------------
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/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to