diff mbox series

[v2] Split waitid01.c test into multiple tests

Message ID 20220223091349.30833-1-andrea.cervesato@suse.de
State Accepted
Headers show
Series [v2] Split waitid01.c test into multiple tests | expand

Commit Message

Andrea Cervesato Feb. 23, 2022, 9:13 a.m. UTC
Introduced LTP API usage and splitted waitid01.c into three tests:
waitid01, waitid10 and waitid11.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/waitid/.gitignore |   2 +
 testcases/kernel/syscalls/waitid/waitid01.c | 151 +++++---------------
 testcases/kernel/syscalls/waitid/waitid10.c |  47 ++++++
 testcases/kernel/syscalls/waitid/waitid11.c |  48 +++++++
 5 files changed, 133 insertions(+), 117 deletions(-)
 create mode 100644 testcases/kernel/syscalls/waitid/waitid10.c
 create mode 100644 testcases/kernel/syscalls/waitid/waitid11.c

Comments

Cyril Hrubis Feb. 23, 2022, 10:46 a.m. UTC | #1
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)},
+		{},
+	},
 };
diff mbox series

Patch

diff --git a/runtest/syscalls b/runtest/syscalls
index d48216a15..59e495193 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1706,6 +1706,8 @@  waitid06 waitid06
 waitid07 waitid07
 waitid08 waitid08
 waitid09 waitid09
+waitid10 waitid10
+waitid11 waitid11
 
 write01 write01
 write02 write02
diff --git a/testcases/kernel/syscalls/waitid/.gitignore b/testcases/kernel/syscalls/waitid/.gitignore
index 315af1690..089d860c7 100644
--- a/testcases/kernel/syscalls/waitid/.gitignore
+++ b/testcases/kernel/syscalls/waitid/.gitignore
@@ -7,3 +7,5 @@ 
 /waitid07
 /waitid08
 /waitid09
+/waitid10
+/waitid11
diff --git a/testcases/kernel/syscalls/waitid/waitid01.c b/testcases/kernel/syscalls/waitid/waitid01.c
index b6579d91d..60ecf9022 100644
--- a/testcases/kernel/syscalls/waitid/waitid01.c
+++ b/testcases/kernel/syscalls/waitid/waitid01.c
@@ -1,126 +1,43 @@ 
-/******************************************************************************/
-/* Copyright (c) Crackerjack Project., 2007                                   */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software Foundation,   */
-/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* Description: This tests the waitid() syscall                               */
-/*                                                                            */
-/* Test Name:   waitid01                                                      */
-/* History:     Porting from Crackerjack to LTP is done by                    */
-/*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test is checking if waitid() syscall does wait for WEXITED and check for
+ * the return value.
+ */
 
-#include <stdio.h>
-#include <errno.h>
 #include <stdlib.h>
 #include <sys/wait.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/stat.h>
+#include "tst_test.h"
 
-#include "test.h"
+static siginfo_t *infop;
 
-char *TCID = "waitid01";
-int testno;
-int TST_TOTAL = 3;
-
-void setup(void)
-{
-	TEST_PAUSE;
-}
-
-void display_status(siginfo_t * infop)
+static void run(void)
 {
-	tst_resm(TINFO, "Process %d terminated:", infop->si_pid);
-	tst_resm(TINFO, "code = %d", infop->si_code);
-	if (infop->si_code == CLD_EXITED)
-		tst_resm(TINFO, "exit value = %d", infop->si_status);
-	else
-		tst_resm(TINFO, "signal = %d", infop->si_status);
-}
-
-int main(int ac, char **av)
-{
-	id_t pid;
-	siginfo_t infop;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
+	pid_t pidchild;
 
-	setup();
+	pidchild = SAFE_FORK();
+	if (!pidchild)
+		exit(123);
 
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-
-			TEST(fork());
-			if (TEST_RETURN < 0)
-				tst_brkm(TBROK | TTERRNO, NULL,
-					"fork() failed");
-
-			if (TEST_RETURN == 0) {
-				exit(123);
-			} else {
-				TEST(waitid(P_ALL, getpid(), &infop, WEXITED));
-				if (TEST_RETURN == -1) {
-					tst_brkm(TFAIL | TTERRNO,
-						 NULL,
-						 "waitid(getpid()) failed");
-				} else
-					display_status(&infop);	//CLD_EXITED = 1
-			}
-
-			TEST(fork());
-			if (TEST_RETURN < 0)
-				tst_brkm(TBROK | TTERRNO, NULL,
-					"fork() failed");
-
-			if (TEST_RETURN == 0) {
-				int a, b = 0;
-				a = 1 / b;
-				tst_exit();
-			} else {
-				TEST(waitid(P_ALL, 0, &infop, WEXITED));
-				if (TEST_RETURN == -1) {
-					tst_brkm(TFAIL | TTERRNO,
-						 NULL, "waitid(0) failed");
-				} else
-					display_status(&infop);	//CLD_DUMPED = 3 ; SIGFPE = 8
-			}
-
-			TEST(pid = fork());
-			if (TEST_RETURN < 0)
-				tst_brkm(TBROK | TTERRNO, NULL,
-					"fork() failed");
-
-			if (TEST_RETURN == 0) {
-				TEST(sleep(10));
-				tst_exit();
-			}
-			TEST(kill(pid, SIGHUP));
-			TEST(waitid(P_ALL, 0, &infop, WEXITED));
-			if (TEST_RETURN == -1) {
-				tst_brkm(TFAIL | TTERRNO, NULL,
-					 "waitid(0) failed");
-			} else
-				display_status(&infop);	//CLD_KILLED = 2 ; SIGHUP = 1
-		}
-	}
-	tst_resm(TPASS, "waitid(): system call passed");
-	tst_exit();
+	TST_EXP_PASS(waitid(P_ALL, getpid(), 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);
+	TST_EXP_EQ_LI(infop->si_code, CLD_EXITED);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs =
+		(struct tst_buffers[]){
+			{ &infop, .size = sizeof(*infop) },
+			{},
+		},
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid10.c b/testcases/kernel/syscalls/waitid/waitid10.c
new file mode 100644
index 000000000..3b2b0fae9
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid10.c
@@ -0,0 +1,47 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test is checking if waitid() syscall recognizes a process that ended
+ * with division by zero error.
+ */
+
+#include <stdlib.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pidchild;
+
+	pidchild = SAFE_FORK();
+	if (!pidchild) {
+		volatile int a, zero = 0;
+
+		a = 1 / zero;
+		exit(0);
+	}
+
+	TST_EXP_PASS(waitid(P_ALL, pidchild, 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);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs =
+		(struct tst_buffers[]){
+			{ &infop, .size = sizeof(*infop) },
+			{},
+		},
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid11.c b/testcases/kernel/syscalls/waitid/waitid11.c
new file mode 100644
index 000000000..8f2b847ea
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid11.c
@@ -0,0 +1,48 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test is checking if waitid() syscall recognizes a process that has been
+ * killed with SIGKILL.
+ */
+
+#include <time.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pidchild;
+
+	pidchild = SAFE_FORK();
+	if (!pidchild) {
+		sleep(10);
+		return;
+	}
+
+	SAFE_KILL(pidchild, SIGKILL);
+
+	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
+	TST_EXP_EQ_LI(infop->si_pid, pidchild);
+	TST_EXP_EQ_LI(infop->si_status, SIGKILL);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs =
+		(struct tst_buffers[]){
+			{ &infop, .size = sizeof(*infop) },
+			{},
+		},
+};