[LTP] [PATCH] waitpid01: Test all standard deadly signals

Martin Doucha mdoucha@suse.cz
Tue Jan 30 17:28:12 CET 2024


Extend waitpid01 to test all standard signals that kill the target
process unless caught. Also remove waitpid02 since testing SIGFPE
in waitpid01 makes it redundant.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 runtest/syscalls                              |   1 -
 testcases/kernel/syscalls/waitpid/.gitignore  |   1 -
 testcases/kernel/syscalls/waitpid/waitpid01.c |  60 +++++--
 testcases/kernel/syscalls/waitpid/waitpid02.c | 167 ------------------
 4 files changed, 47 insertions(+), 182 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/waitpid/waitpid02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 6e2407879..98f31c1ee 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1708,7 +1708,6 @@ wait402 wait402
 wait403 wait403
 
 waitpid01 waitpid01
-waitpid02 waitpid02
 waitpid03 waitpid03
 waitpid04 waitpid04
 waitpid05 waitpid05
diff --git a/testcases/kernel/syscalls/waitpid/.gitignore b/testcases/kernel/syscalls/waitpid/.gitignore
index cf9ddf6fa..2fac142c7 100644
--- a/testcases/kernel/syscalls/waitpid/.gitignore
+++ b/testcases/kernel/syscalls/waitpid/.gitignore
@@ -1,5 +1,4 @@
 /waitpid01
-/waitpid02
 /waitpid03
 /waitpid04
 /waitpid05
diff --git a/testcases/kernel/syscalls/waitpid/waitpid01.c b/testcases/kernel/syscalls/waitpid/waitpid01.c
index 5a39a1107..b6d8f6078 100644
--- a/testcases/kernel/syscalls/waitpid/waitpid01.c
+++ b/testcases/kernel/syscalls/waitpid/waitpid01.c
@@ -5,25 +5,57 @@
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
 
-/*
- * Check that when a child kills itself by SIGALRM the waiting parent is
- * correctly notified.
+/*\
+ * [Description]
+ *
+ * Check that when a child kills itself with one of the standard signals,
+ * the waiting parent is correctly notified.
  *
- * Fork a child that raises(SIGALRM), the parent checks that SIGALRM was
- * returned.
+ * Fork a child that raise()s given signal, the parent checks that the signal
+ * was returned.
  */
 #include <stdlib.h>
 #include <sys/wait.h>
 #include "tst_test.h"
 
-static void run(void)
+static int testcase_list[] = {
+	SIGABRT,
+	SIGALRM,
+	SIGBUS,
+	SIGFPE,
+	SIGHUP,
+	SIGILL,
+	SIGINT,
+	SIGKILL,
+	SIGPIPE,
+	SIGPOLL,
+	SIGPROF,
+	SIGQUIT,
+	SIGSEGV,
+	SIGSYS,
+	SIGTERM,
+	SIGTRAP,
+	SIGVTALRM,
+	SIGXCPU,
+	SIGXFSZ
+};
+
+static void setup(void)
+{
+	struct rlimit lim = { 0 };
+
+	/* Disable core dumps */
+	SAFE_SETRLIMIT(RLIMIT_CORE, &lim);
+}
+
+static void run(unsigned int n)
 {
 	pid_t pid;
-	int status;
+	int status, sig = testcase_list[n];
 
 	pid = SAFE_FORK();
 	if (!pid) {
-		raise(SIGALRM);
+		raise(sig);
 		exit(0);
 	}
 
@@ -46,16 +78,18 @@ static void run(void)
 
 	tst_res(TPASS, "WIFSIGNALED() set in status");
 
-	if (WTERMSIG(status) != SIGALRM) {
-		tst_res(TFAIL, "WTERMSIG() != SIGALRM but %s",
-		        tst_strsig(WTERMSIG(status)));
+	if (WTERMSIG(status) != sig) {
+		tst_res(TFAIL, "WTERMSIG() != %s but %s", tst_strsig(sig),
+			tst_strsig(WTERMSIG(status)));
 		return;
 	}
 
-	tst_res(TPASS, "WTERMSIG() == SIGALRM");
+	tst_res(TPASS, "WTERMSIG() == %s", tst_strsig(sig));
 }
 
 static struct tst_test test = {
 	.forks_child = 1,
-	.test_all = run,
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(testcase_list)
 };
diff --git a/testcases/kernel/syscalls/waitpid/waitpid02.c b/testcases/kernel/syscalls/waitpid/waitpid02.c
deleted file mode 100644
index 1164a7834..000000000
--- a/testcases/kernel/syscalls/waitpid/waitpid02.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   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
- */
-
-/*
- * NAME
- *	waitpid02.c
- *
- * DESCRIPTION
- *	Check that when a child gets killed by an integer zero
- *	divide exception, the waiting parent is correctly notified.
- *
- * ALGORITHM
- *	Fork a child and send a SIGFPE to it. The parent waits for the
- *	death of the child and checks that SIGFPE was returned.
- *
- * USAGE:  <for command-line>
- *      waitpid02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *      where,  -c n : Run n copies concurrently.
- *              -e   : Turn on errno logging.
- *              -i n : Execute test n times.
- *              -I x : Execute test for x seconds.
- *              -P x : Pause for x seconds between iterations.
- *              -t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *	10/2002 Paul Larson
- *		Div by zero doesn't cause SIGFPE on some archs, fixed
- *		to send the signal with kill
- *
- * Restrictions
- *	None
- */
-
-#include <sys/file.h>
-#include <sys/resource.h>
-#include <sys/signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include "test.h"
-
-static void do_child(void);
-static void setup(void);
-
-char *TCID = "waitpid02";
-int TST_TOTAL = 1;
-
-int main(int argc, char **argv)
-{
-	int lc;
-
-	int pid, npid, sig, nsig;
-	int nexno, status;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-#ifdef UCLINUX
-	maybe_run_child(&do_child, "");
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		sig = SIGFPE;
-
-		pid = FORK_OR_VFORK();
-
-		if (pid < 0)
-			tst_brkm(TBROK|TERRNO, NULL, "fork failed");
-
-		if (pid == 0) {
-#ifdef UCLINUX
-			self_exec(argv[0], "");
-			/* No fork() error check is done so don't check here */
-#else
-			do_child();
-#endif
-		} else {
-			kill(pid, sig);
-			errno = 0;
-			while (((npid = waitpid(pid, &status, 0)) != -1) ||
-			       (errno == EINTR)) {
-				if (errno == EINTR)
-					continue;
-
-				if (npid != pid) {
-					tst_resm(TFAIL, "waitpid error: "
-						 "unexpected pid returned");
-				} else {
-					tst_resm(TPASS,
-						 "received expected pid");
-				}
-
-				nsig = WTERMSIG(status);
-
-				/*
-				 * nsig is the signal number returned by
-				 * waitpid
-				 */
-				if (nsig != sig) {
-					tst_resm(TFAIL, "waitpid error: "
-						 "unexpected signal returned");
-				} else {
-					tst_resm(TPASS, "received expected "
-						 "signal");
-				}
-
-				/*
-				 * nexno is the exit number returned by
-				 * waitpid
-				 */
-				nexno = WEXITSTATUS(status);
-				if (nexno != 0) {
-					tst_resm(TFAIL, "signal error: "
-						 "unexpected exit number "
-						 "returned");
-				} else {
-					tst_resm(TPASS, "received expected "
-						 "exit value");
-				}
-			}
-		}
-	}
-
-	tst_exit();
-}
-
-static void do_child(void)
-{
-	int exno = 1;
-
-	while (1)
-		usleep(10);
-
-	exit(exno);
-}
-
-static void setup(void)
-{
-	/* SIGFPE is expected signal, so avoid creating any corefile.
-	 * '1' is a special value, that will also avoid dumping via pipe. */
-	struct rlimit r;
-	r.rlim_cur = 1;
-	r.rlim_max = 1;
-	setrlimit(RLIMIT_CORE, &r);
-
-	TEST_PAUSE;
-}
-- 
2.42.1



More information about the ltp mailing list