[LTP] [PATCH v2] Split waitid01.c test into multiple tests

Cyril Hrubis chrubis@suse.cz
Wed Feb 23 11:46:10 CET 2022


Hi!
Pushed with a few changes, thanks.

Apart from formatting changes there were two functional changes I did.

- with P_ALL the the id parameter is ignored so I've changed it to 0

- the CLD_DUMPED case is a bit more complicated, since have to make sure
  that core dumps are enabled, so I did add a setup fucntion that
  attempts to raise rlimit(RLIMIT_CORE) and if that fails we expect
  CLD_KILLED instead of CLD_DUMPED

Full diff:


diff --git a/testcases/kernel/syscalls/waitid/waitid01.c b/testcases/kernel/syscalls/waitid/waitid01.c
index 60ecf9022..136eec8a6 100644
--- a/testcases/kernel/syscalls/waitid/waitid01.c
+++ b/testcases/kernel/syscalls/waitid/waitid01.c
@@ -25,7 +25,7 @@ static void run(void)
 	if (!pidchild)
 		exit(123);
 
-	TST_EXP_PASS(waitid(P_ALL, getpid(), infop, WEXITED));
+	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
 	TST_EXP_EQ_LI(infop->si_pid, pidchild);
 	TST_EXP_EQ_LI(infop->si_status, 123);
 	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
@@ -35,9 +35,8 @@ static void run(void)
 static struct tst_test test = {
 	.test_all = run,
 	.forks_child = 1,
-	.bufs =
-		(struct tst_buffers[]){
-			{ &infop, .size = sizeof(*infop) },
-			{},
-		},
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{},
+	},
 };
diff --git a/testcases/kernel/syscalls/waitid/waitid10.c b/testcases/kernel/syscalls/waitid/waitid10.c
index 3b2b0fae9..869ef18bd 100644
--- a/testcases/kernel/syscalls/waitid/waitid10.c
+++ b/testcases/kernel/syscalls/waitid/waitid10.c
@@ -13,9 +13,11 @@
 
 #include <stdlib.h>
 #include <sys/wait.h>
+#include <sys/prctl.h>
 #include "tst_test.h"
 
 static siginfo_t *infop;
+static int core_dumps = 1;
 
 static void run(void)
 {
@@ -26,22 +28,47 @@ static void run(void)
 		volatile int a, zero = 0;
 
 		a = 1 / zero;
-		exit(0);
+		exit(a);
 	}
 
-	TST_EXP_PASS(waitid(P_ALL, pidchild, infop, WEXITED));
+	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
 	TST_EXP_EQ_LI(infop->si_pid, pidchild);
 	TST_EXP_EQ_LI(infop->si_status, SIGFPE);
 	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
-	TST_EXP_EQ_LI(infop->si_code, CLD_DUMPED);
+
+	if (core_dumps)
+		TST_EXP_EQ_LI(infop->si_code, CLD_DUMPED);
+	else
+		TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
+}
+
+static void setup(void)
+{
+	struct rlimit rlim;
+
+	SAFE_GETRLIMIT(RLIMIT_CORE, &rlim);
+
+	if (rlim.rlim_cur)
+		return;
+
+	if (!rlim.rlim_max) {
+		core_dumps = 0;
+		return;
+	}
+
+	tst_res(TINFO, "Raising RLIMIT_CORE rlim_cur=%li -> %li",
+	        rlim.rlim_cur, rlim.rlim_max);
+
+	rlim.rlim_cur = rlim.rlim_max;
+	SAFE_SETRLIMIT(RLIMIT_CORE, &rlim);
 }
 
 static struct tst_test test = {
 	.test_all = run,
 	.forks_child = 1,
-	.bufs =
-		(struct tst_buffers[]){
-			{ &infop, .size = sizeof(*infop) },
-			{},
-		},
+	.setup = setup,
+	.bufs =	(struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{},
+	},
 };
diff --git a/testcases/kernel/syscalls/waitid/waitid11.c b/testcases/kernel/syscalls/waitid/waitid11.c
index 8f2b847ea..e3754bb1d 100644
--- a/testcases/kernel/syscalls/waitid/waitid11.c
+++ b/testcases/kernel/syscalls/waitid/waitid11.c
@@ -24,7 +24,7 @@ static void run(void)
 
 	pidchild = SAFE_FORK();
 	if (!pidchild) {
-		sleep(10);
+		pause();
 		return;
 	}
 
@@ -40,9 +40,8 @@ static void run(void)
 static struct tst_test test = {
 	.test_all = run,
 	.forks_child = 1,
-	.bufs =
-		(struct tst_buffers[]){
-			{ &infop, .size = sizeof(*infop) },
-			{},
-		},
+	.bufs =	(struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{},
+	},
 };

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list