public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/5] signal:Rewrite using new LTP API
@ 2022-10-17  1:43 Luo xiaoyu via ltp
  2022-10-17  1:43 ` [LTP] [PATCH 1/5] signal01.c: Rewrite " Luo xiaoyu via ltp
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Luo xiaoyu via ltp @ 2022-10-17  1:43 UTC (permalink / raw)
  To: ltp

Rewrite the first five signal cases.

Luo xiaoyu (5):
  signal01.c: Rewrite using new LTP API
  signal02.c: Rewrite using new LTP API
  signal03.c: Rewrite using new LTP API
  signal04.c: Rewrite using new LTP API
  signal05.c: Rewrite using new LTP API

 testcases/kernel/syscalls/signal/signal01.c | 197 +++++---------------
 testcases/kernel/syscalls/signal/signal02.c | 144 ++------------
 testcases/kernel/syscalls/signal/signal03.c | 161 ++--------------
 testcases/kernel/syscalls/signal/signal04.c | 179 +++---------------
 testcases/kernel/syscalls/signal/signal05.c | 159 ++--------------
 5 files changed, 121 insertions(+), 719 deletions(-)

--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH 1/5] signal01.c: Rewrite using new LTP API
  2022-10-17  1:43 [LTP] [PATCH 0/5] signal:Rewrite using new LTP API Luo xiaoyu via ltp
@ 2022-10-17  1:43 ` Luo xiaoyu via ltp
  2022-10-24 12:29   ` Richard Palethorpe
  2022-10-17  1:43 ` [LTP] [PATCH 2/5] signal02.c: " Luo xiaoyu via ltp
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Luo xiaoyu via ltp @ 2022-10-17  1:43 UTC (permalink / raw)
  To: ltp

Rewrite using new LTP API and remove the UCLinux support.

Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>
---
 testcases/kernel/syscalls/signal/signal01.c | 197 +++++---------------
 1 file changed, 43 insertions(+), 154 deletions(-)

diff --git a/testcases/kernel/syscalls/signal/signal01.c b/testcases/kernel/syscalls/signal/signal01.c
index d99e35cb7..c39190a73 100644
--- a/testcases/kernel/syscalls/signal/signal01.c
+++ b/testcases/kernel/syscalls/signal/signal01.c
@@ -1,67 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *  AUTHOR           :  Dave Baumgartner
- *                   :  Rewrote 12/92 by Richard Logan
- *  CO-PILOT         :  Barrie Kletscher
- *  DATE STARTED     :  10/17/85
  * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ * AUTHOR	: Dave Baumgartner
+ * CO-PILOT	: Barrie Kletscher
  */
-/*
- * TEST ITEMS
+
+/*\
+ * [Description]
  *
- *	1. SIGKILL can not be set to be caught, errno:EINVAL (POSIX).
- *	2. SIGKILL can not be caught.
- *	3. SIGKILL can not be set to be ignored, errno:EINVAL (POSIX).
+ * Test SIGKILL for these items:
+ *	1. SIGKILL can not be set to be ignored, errno:EINVAL (POSIX).
+ *	2. SIGKILL can not be reset to default, errno:EINVAL (POSIX).
+ *	3. SIGKILL can not be set to be caught, errno:EINVAL (POSIX).
  *	4. SIGKILL can not be ignored.
- *	5. SIGKILL can not be reset to default, errno:EINVAL (POSIX).
+ *	5. SIGKILL is reset to default failed but processed by default.
+ *	6. SIGKILL can not be caught.
  */
-#include <signal.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/wait.h>

-#include "test.h"
-#include "safe_macros.h"
+#include <stdlib.h>
+#include "tst_test.h"

-static void setup(void);
-static void do_test(int tc);
-static void do_child(void);
 static void catchsig(int sig);

 static struct tcase {
-	void (*sighandler)(int);
+	void (*sighandler)(int i);
 	int kill;
 } tcases[] = {
 	{SIG_IGN, 0},
@@ -72,71 +35,37 @@ static struct tcase {
 	{catchsig, 1},
 };

-char *TCID = "signal01";
-int TST_TOTAL = ARRAY_SIZE(tcases);
-
-static int tcase;
-
-int main(int argc, char *argv[])
-{
-	int lc, i;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-#ifdef UCLINUX
-	maybe_run_child(&do_child, "d", &tcase);
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		for (i = 0; i < TST_TOTAL; i++)
-			do_test(i);
-	}
-
-	tst_exit();
-}
-
-static void do_test(int tc)
+static void do_test(unsigned int n)
 {
 	pid_t pid;
 	int res;
-	pid = FORK_OR_VFORK();
+
+	struct tcase *tc = &tcases[n];
+
+	pid = SAFE_FORK();

 	switch (pid) {
 	case 0:
-#ifdef UCLINUX
-		if (self_exec(argv0, "d", tc) < 0)
-			tst_brkm(TBROK | TERRNO, NULL, "self_exec() failed");
-#else
-		tcase = tc;
-		do_child();
-#endif
-	break;
-	case -1:
-		tst_resm(TBROK | TERRNO, "fork() failed");
+		if (tc->kill) {
+			signal(SIGKILL, tc->sighandler);
+			pause();
+		}
+
+		TST_EXP_FAIL2((long)signal(SIGKILL, tc->sighandler), EINVAL);
+		return;
 	break;
 	default:
-		if (tcases[tc].kill) {
-			TST_PROCESS_STATE_WAIT(NULL, pid, 'S');
-
-			SAFE_KILL(NULL, pid, SIGKILL);
-
-			SAFE_WAITPID(NULL, pid, &res, 0);
-
-			if (WIFSIGNALED(res)) {
-				if (WTERMSIG(res) == SIGKILL) {
-					tst_resm(TPASS, "Child killed with SIGKILL");
-				} else {
-					tst_resm(TFAIL, "Child killed with %s",
-					         tst_strsig(WTERMSIG(res)));
-				}
-			} else {
-				tst_resm(TFAIL, "Child not killed by signal");
-			}
-		} else {
-			tst_record_childstatus(NULL, pid);
-		}
+		if (tc->kill) {
+			TST_PROCESS_STATE_WAIT(pid, 'S', 0);
+			SAFE_KILL(pid, SIGKILL);
+			SAFE_WAITPID(pid, &res, 0);
+
+			if (WIFSIGNALED(res))
+				TST_EXP_EQ_SSZ(WTERMSIG(res), SIGKILL);
+			else
+				tst_res(TFAIL, "Child not killed by signal");
+		} else
+			SAFE_WAITPID(pid, &res, 0);
 	break;
 	}
 }
@@ -146,48 +75,8 @@ static void catchsig(int sig)
 	(void)sig;
 }

-static const char *strhandler(void *sighandler)
-{
-	switch ((long)sighandler) {
-	case (long)SIG_DFL:
-		return "SIG_DFL";
-	case (long)SIG_IGN:
-		return "SIG_IGN";
-	default:
-		return "catchsig()";
-	}
-}
-
-static void do_child(void)
-{
-	void *ret;
-	void (*sighandler)(int) = tcases[tcase].sighandler;
-
-	ret = signal(SIGKILL, sighandler);
-
-	if (tcases[tcase].kill)
-		pause();
-
-	if (ret == SIG_ERR || errno == EINVAL) {
-		tst_resm(TPASS, "signal(SIGKILL, %p(%s)) failed with EINVAL",
-		         sighandler, strhandler(sighandler));
-	} else {
-		if (ret != SIG_ERR) {
-			tst_resm(TFAIL, "signal(SIGKILL, %p(%s)) didn't fail",
-			         sighandler, strhandler(sighandler));
-		} else {
-			tst_resm(TFAIL | TERRNO,
-			         "signal(SIGKILL, %p(%s)) should fail with EINVAL",
-			          sighandler, strhandler(sighandler));
-		}
-	}
-
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, NULL);
-
-	TEST_PAUSE;
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+	.test = do_test,
+};
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH 2/5] signal02.c: Rewrite using new LTP API
  2022-10-17  1:43 [LTP] [PATCH 0/5] signal:Rewrite using new LTP API Luo xiaoyu via ltp
  2022-10-17  1:43 ` [LTP] [PATCH 1/5] signal01.c: Rewrite " Luo xiaoyu via ltp
@ 2022-10-17  1:43 ` Luo xiaoyu via ltp
  2022-10-24 12:34   ` Richard Palethorpe
  2022-10-17  1:43 ` [LTP] [PATCH 3/5] signal03.c: " Luo xiaoyu via ltp
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Luo xiaoyu via ltp @ 2022-10-17  1:43 UTC (permalink / raw)
  To: ltp

Rewrite using new LTP API.

Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>
---
 testcases/kernel/syscalls/signal/signal02.c | 144 ++------------------
 1 file changed, 13 insertions(+), 131 deletions(-)

diff --git a/testcases/kernel/syscalls/signal/signal02.c b/testcases/kernel/syscalls/signal/signal02.c
index 8eb95b52b..54948646f 100644
--- a/testcases/kernel/syscalls/signal/signal02.c
+++ b/testcases/kernel/syscalls/signal/signal02.c
@@ -1,142 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   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
+ * Copyright (c) International Business Machines  Corp., 2001
  */

-/*
- * NAME
- *	signal02.c
- *
- * DESCRIPTION
- *	signal02 - Test that we get an error using illegal signals
- *
- * ALGORITHM
- *	loop if that option was specified
- *	issue the system call
- *	check the return value
- *	  if return value != -1
- *	    issue a FAIL message, break remaining tests and cleanup
- *	  if we get an EINVAL
- *	    issue a PASS message
- *	  else
- *	    issue a FAIL message, break remaining tests and cleanup
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  signal02 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on error 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
+/*\
+ * [Description]
  *
- * Restrictions
- *	none
+ * Test that we get an error using illegal signals.
  */

-#include "test.h"
-
-#include <errno.h>
-#include <signal.h>
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "signal02";
-int TST_TOTAL = 3;
-
-typedef void (*sighandler_t) (int);
-
-sighandler_t Tret;
-int sigs[] = { _NSIG + 1, SIGKILL, SIGSTOP };
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
+#include "tst_test.h"

-	/* The following loop checks looping state if -i option given */
+static int sigs[] = { _NSIG + 1, SIGKILL, SIGSTOP };

-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * There are three cases where we should get an EINVAL
-		 */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			errno = 0;
-			Tret = signal(sigs[i], SIG_IGN);
-			TEST_ERRNO = errno;
-
-			if (Tret != SIG_ERR) {
-				tst_brkm(TFAIL, cleanup, "%s call failed - "
-					 "errno = %d : %s", TCID, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			}
-
-			switch (TEST_ERRNO) {
-			case EINVAL:
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d - %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "call failed to produce "
-					 "expected error - errno = %d "
-					 "- %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			}
-		}
-		tst_count++;	/* incr. TEST_LOOP counter */
-	}
-
-	cleanup();
-
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void do_test(unsigned int n)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL2((long)signal(sigs[n], SIG_IGN), EINVAL);
 }

-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(sigs),
+	.test = do_test,
+};
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH 3/5] signal03.c: Rewrite using new LTP API
  2022-10-17  1:43 [LTP] [PATCH 0/5] signal:Rewrite using new LTP API Luo xiaoyu via ltp
  2022-10-17  1:43 ` [LTP] [PATCH 1/5] signal01.c: Rewrite " Luo xiaoyu via ltp
  2022-10-17  1:43 ` [LTP] [PATCH 2/5] signal02.c: " Luo xiaoyu via ltp
@ 2022-10-17  1:43 ` Luo xiaoyu via ltp
  2022-10-24 12:44   ` Richard Palethorpe
  2022-10-17  1:43 ` [LTP] [PATCH 4/5] signal04.c: " Luo xiaoyu via ltp
  2022-10-17  1:43 ` [LTP] [PATCH 5/5] signal05.c: " Luo xiaoyu via ltp
  4 siblings, 1 reply; 10+ messages in thread
From: Luo xiaoyu via ltp @ 2022-10-17  1:43 UTC (permalink / raw)
  To: ltp

Rewrite using new LTP API.

Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>
---
 testcases/kernel/syscalls/signal/signal03.c | 161 +++-----------------
 1 file changed, 20 insertions(+), 141 deletions(-)

diff --git a/testcases/kernel/syscalls/signal/signal03.c b/testcases/kernel/syscalls/signal/signal03.c
index 7975c770d..ad4c565ab 100644
--- a/testcases/kernel/syscalls/signal/signal03.c
+++ b/testcases/kernel/syscalls/signal/signal03.c
@@ -1,70 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   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
- *	signal03.c
- *
- * DESCRIPTION
- *	signal03 - set signals to be ignored
- *
- * ALGORITHM
- *	loop if that option was specified
- *	issue the system call
- *	check the return value
- *	  if return value == -1
- *	    issue a FAIL message, break remaining tests and cleanup
- *	  if we are doing functional testing
- *	    send the signal with kill()
- *	    if we catch the signal
- *	      issue a FAIL message
- *	    else
- *	      issue a PASS message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  signal01 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-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
+/*\
+ * [Description]
  *
- * Restrictions
- *	none
+ * Set signals to be ignored.
  */

-#include "test.h"
+#include "tst_test.h"

-#include <errno.h>
-#include <signal.h>
+static void sighandler(int);

-void cleanup(void);
-void setup(void);
-void sighandler(int);
-
-int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
+static int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
 	SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
 	SIGTERM,
 #ifdef SIGSTKFLT
@@ -78,97 +27,27 @@ int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
 #endif
 };

-char *TCID = "signal03";
-int TST_TOTAL = ARRAY_SIZE(siglist);
-
-typedef void (*sighandler_t) (int);
-
-sighandler_t Tret;
+static int ign_handler;

-int fail = 0;
-
-int main(int ac, char **av)
+static void do_test(unsigned int n)
 {
-	int lc;
 	pid_t pid;
-	int i, rval;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * loop through the list of signals and test each one
-		 */
-		for (i = 0; i < TST_TOTAL; i++) {

-			errno = 0;
-			Tret = signal(siglist[i], SIG_IGN);
-			TEST_ERRNO = errno;
+	SAFE_SIGNAL(siglist[n], sighandler);
+	SAFE_SIGNAL(siglist[n], SIG_IGN);

-			if (Tret == SIG_ERR) {
-				tst_brkm(TFAIL, cleanup, "%s call failed - "
-					 "errno = %d : %s", TCID,
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
+	pid = getpid();

-			/*
-			 * Send the signal.  If the signal is truly set
-			 * to be ignored, then the signal handler will
-			 * never be invoked and the test will pass.
-			 */
-			pid = getpid();
-
-			if ((rval = kill(pid, siglist[i])) != 0) {
-				tst_brkm(TBROK, cleanup, "call to "
-					 "kill failed");
-			}
-
-			if (fail == 0) {
-				tst_resm(TPASS, "%s call succeeded",
-					 TCID);
-			} else {
-				/* the signal was caught so we fail */
-				tst_resm(TFAIL, "signal caught when "
-					 "suppose to be ignored");
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	SAFE_KILL(pid, siglist[n]);
+	TST_EXP_EQ_SSZ(ign_handler, 0);
 }

-/*
- * sighandler() - the test fails if we ever get here.
- */
-void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
-	fail = 1;
+	ign_handler = 1;
 }

-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	/* capture signals in our own handler */
-	tst_sig(NOFORK, sighandler, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(siglist),
+	.test = do_test,
+};
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH 4/5] signal04.c: Rewrite using new LTP API
  2022-10-17  1:43 [LTP] [PATCH 0/5] signal:Rewrite using new LTP API Luo xiaoyu via ltp
                   ` (2 preceding siblings ...)
  2022-10-17  1:43 ` [LTP] [PATCH 3/5] signal03.c: " Luo xiaoyu via ltp
@ 2022-10-17  1:43 ` Luo xiaoyu via ltp
  2022-10-17  1:43 ` [LTP] [PATCH 5/5] signal05.c: " Luo xiaoyu via ltp
  4 siblings, 0 replies; 10+ messages in thread
From: Luo xiaoyu via ltp @ 2022-10-17  1:43 UTC (permalink / raw)
  To: ltp

Rewrite using new LTP API.

Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>
---
 testcases/kernel/syscalls/signal/signal04.c | 179 +++-----------------
 1 file changed, 25 insertions(+), 154 deletions(-)

diff --git a/testcases/kernel/syscalls/signal/signal04.c b/testcases/kernel/syscalls/signal/signal04.c
index 5a18fa604..73b24754f 100644
--- a/testcases/kernel/syscalls/signal/signal04.c
+++ b/testcases/kernel/syscalls/signal/signal04.c
@@ -1,181 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   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
+ * Copyright (c) International Business Machines  Corp., 2001
  */

-/*
- * NAME
- *	signal04.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	signal04 - restore signals to default behavior
- *
- * ALGORITHM
- *	loop if that option was specified
- *	for each signal in siglist[]
- *	  set the signal handler to our own and save the return value
- *	  issue the signal system call to restore the default behavior
- *	  check the return value
- *	  if return value == -1
- *	    issue a FAIL message, break remaining tests and cleanup
- *	  if we are doing functional testing
- *	    set the signal handler to our own again and save second return value
- *	    if the first return value matches the second return value
- *	      issue a PASS message
- *	    else
- *	      issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  signal04 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-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
- *
- * Restrictions
- *	none
+ * Restore signals to default behavior.
  */

-#include "test.h"
-
-#include <errno.h>
-#include <signal.h>
+#include "tst_test.h"

-void cleanup(void);
-void setup(void);
-void sighandler(int);
+static void sighandler(int);

-char *TCID = "signal04";
-
-int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
+static int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT,
 	SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
 	SIGTERM, SIGCHLD, SIGCONT, SIGTSTP, SIGTTIN,
 	SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF,
 	SIGWINCH, SIGIO, SIGPWR, SIGSYS
 };

-int TST_TOTAL = sizeof(siglist) / sizeof(int);
-
 typedef void (*sighandler_t) (int);

-sighandler_t Tret;
-
-int main(int ac, char **av)
+static void do_test(unsigned int n)
 {
-	int lc;
-	int i;
 	sighandler_t rval, first;

-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * loop through the list of signals and test each one
-		 */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			/* First reset the signal to the default
-			   action to clear out any pre-test
-			   execution settings */
-			signal(siglist[i], SIG_DFL);
-
-			/* then set the handler to our own handler */
-			if ((rval = signal(siglist[i], &sighandler)) == SIG_ERR) {
-				tst_brkm(TBROK, cleanup, "initial signal call"
-					 " failed");
-			}
+	SAFE_SIGNAL(siglist[n], SIG_DFL);
+	first = SAFE_SIGNAL(siglist[n], &sighandler);

-			/* store the return value */
-			first = rval;
+	SAFE_SIGNAL(siglist[n], SIG_DFL);
+	rval = SAFE_SIGNAL(siglist[n], &sighandler);

-			/* restore the default signal action */
-			errno = 0;
-			Tret = signal(siglist[i], SIG_DFL);
-			TEST_ERRNO = errno;
-
-			if (Tret == SIG_ERR) {
-				tst_brkm(TFAIL, cleanup, "%s call failed - "
-					 "errno = %d : %s", TCID, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			}
-
-			/* now set the handler back to our own */
-			if ((rval = signal(siglist[i], &sighandler))
-			    == SIG_ERR) {
-				tst_brkm(TBROK, cleanup, "initial "
-					 "signal call failed");
-			}
-
-			/*
-			 * the first return value should equal the
-			 * second one.
-			 */
-			if (rval == first) {
-				tst_resm(TPASS, "%s call succeeded "
-					 "received %p.", TCID, rval);
-			} else {
-				tst_brkm(TFAIL, cleanup, "return "
-					 "values for signal(%d) don't "
-					 "match. Got %p, expected %p.",
-					 siglist[i], rval, first);
-			}
-		}
+	if (rval == first) {
+		tst_res(TPASS, "signal(%d) restore succeeded "
+				"received %p.", siglist[n], rval);
+	} else {
+		tst_res(TFAIL, "return values for signal(%d) don't match. "
+				"Got %p, expected %p.",
+				siglist[n], rval, first);
 	}
-
-	cleanup();
-	tst_exit();
-
 }

-/*
- * sighandler() - handle the signals
- */
-void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 }

-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(siglist),
+	.test = do_test,
+};
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH 5/5] signal05.c: Rewrite using new LTP API
  2022-10-17  1:43 [LTP] [PATCH 0/5] signal:Rewrite using new LTP API Luo xiaoyu via ltp
                   ` (3 preceding siblings ...)
  2022-10-17  1:43 ` [LTP] [PATCH 4/5] signal04.c: " Luo xiaoyu via ltp
@ 2022-10-17  1:43 ` Luo xiaoyu via ltp
  2022-10-24 13:06   ` Richard Palethorpe
  4 siblings, 1 reply; 10+ messages in thread
From: Luo xiaoyu via ltp @ 2022-10-17  1:43 UTC (permalink / raw)
  To: ltp

Rewrite using new LTP API.

Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>
---
 testcases/kernel/syscalls/signal/signal05.c | 159 +++-----------------
 1 file changed, 20 insertions(+), 139 deletions(-)

diff --git a/testcases/kernel/syscalls/signal/signal05.c b/testcases/kernel/syscalls/signal/signal05.c
index 2a2894161..b191b9ae1 100644
--- a/testcases/kernel/syscalls/signal/signal05.c
+++ b/testcases/kernel/syscalls/signal/signal05.c
@@ -1,70 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   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
+ * Copyright (c) International Business Machines  Corp., 2001
  */

-/*
- * NAME
- *	signal05.c
- *
- * DESCRIPTION
- *	signal05 - set the signal handler to our own function
- *
- * ALGORITHM
- *	loop if that option was specified
- *	issue the system call
- *	check the return value
- *	  if return value == -1
- *	    issue a FAIL message, break remaining tests and cleanup
- *	  if we are doing functional testing
- *	    send the signal with kill()
- *	    if we catch the signal in the signal handler
- *	      issue a PASS message
- *	    else
- *	      issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  signal05 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -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
+/*\
+ * [Description]
  *
- * Restrictions
- *	none
+ * Set the signal handler to our own function.
  */

-#include "test.h"
+#include "tst_test.h"

-#include <errno.h>
-#include <signal.h>
+static void sighandler(int);

-void cleanup(void);
-void setup(void);
-void sighandler(int);
-
-int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
+static int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
 	SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
 	SIGTERM,
 #ifdef SIGSTKFLT
@@ -78,94 +27,26 @@ int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
 #endif
 };

-char *TCID = "signal05";
-int TST_TOTAL = ARRAY_SIZE(siglist);
-
-typedef void (*sighandler_t) (int);
-
-sighandler_t Tret;
-
-int pass = 0;
+static int sig_pass;

-int main(int ac, char **av)
+static void do_test(unsigned int n)
 {
-	int lc;
 	pid_t pid;
-	int i, rval;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;

-		/*
-		 * loop through the list of signals and test each one
-		 */
-		for (i = 0; i < TST_TOTAL; i++) {
+	SAFE_SIGNAL(siglist[n], &sighandler);

-			errno = 0;
-			Tret = signal(siglist[i], &sighandler);
-			TEST_ERRNO = errno;
+	pid = getpid();

-			if (Tret == SIG_ERR) {
-				tst_resm(TFAIL, "%s call failed - errno = %d "
-					 ": %s", TCID, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				continue;
-			}
-
-			/*
-			 * Send the signals and make sure they are
-			 * handled in our handler.
-			 */
-			pid = getpid();
-
-			if ((rval = kill(pid, siglist[i])) != 0) {
-				tst_brkm(TBROK, cleanup,
-					 "call to kill failed");
-			}
-
-			if (siglist[i] == pass) {
-				tst_resm(TPASS,
-					 "%s call succeeded", TCID);
-			} else {
-				tst_resm(TFAIL,
-					 "received unexpected signal");
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	SAFE_KILL(pid, siglist[n]);
+	TST_EXP_EQ_SSZ(siglist[n], sig_pass);
 }

-/*
- * sighandler() - handle the signals
- */
-void sighandler(int sig)
+static void sighandler(int sig)
 {
-	/* set the global pass variable = sig */
-	pass = sig;
+	sig_pass = sig;
 }

-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(siglist),
+	.test = do_test,
+};
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH 1/5] signal01.c: Rewrite using new LTP API
  2022-10-17  1:43 ` [LTP] [PATCH 1/5] signal01.c: Rewrite " Luo xiaoyu via ltp
@ 2022-10-24 12:29   ` Richard Palethorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Palethorpe @ 2022-10-24 12:29 UTC (permalink / raw)
  To: Luo xiaoyu; +Cc: ltp

Hello,

Luo xiaoyu via ltp <ltp@lists.linux.it> writes:

> Rewrite using new LTP API and remove the UCLinux support.
>
> Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>

I removed the switch statement and merged, thanks!

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH 2/5] signal02.c: Rewrite using new LTP API
  2022-10-17  1:43 ` [LTP] [PATCH 2/5] signal02.c: " Luo xiaoyu via ltp
@ 2022-10-24 12:34   ` Richard Palethorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Palethorpe @ 2022-10-24 12:34 UTC (permalink / raw)
  To: Luo xiaoyu; +Cc: ltp

Hello,

Merged, thanks!

Luo xiaoyu via ltp <ltp@lists.linux.it> writes:

> Rewrite using new LTP API.
>
> Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>
> ---
>  testcases/kernel/syscalls/signal/signal02.c | 144 ++------------------
>  1 file changed, 13 insertions(+), 131 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/signal/signal02.c b/testcases/kernel/syscalls/signal/signal02.c
> index 8eb95b52b..54948646f 100644
> --- a/testcases/kernel/syscalls/signal/signal02.c
> +++ b/testcases/kernel/syscalls/signal/signal02.c
> @@ -1,142 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
>  /*
> - *
> - *   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
> + * Copyright (c) International Business Machines  Corp., 2001
>   */
>
> -/*
> - * NAME
> - *	signal02.c
> - *
> - * DESCRIPTION
> - *	signal02 - Test that we get an error using illegal signals
> - *
> - * ALGORITHM
> - *	loop if that option was specified
> - *	issue the system call
> - *	check the return value
> - *	  if return value != -1
> - *	    issue a FAIL message, break remaining tests and cleanup
> - *	  if we get an EINVAL
> - *	    issue a PASS message
> - *	  else
> - *	    issue a FAIL message, break remaining tests and cleanup
> - *	call cleanup
> - *
> - * USAGE:  <for command-line>
> - *  signal02 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
> - *	where,  -c n : Run n copies concurrently.
> - *		-e   : Turn on error 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
> +/*\
> + * [Description]
>   *
> - * Restrictions
> - *	none
> + * Test that we get an error using illegal signals.
>   */
>
> -#include "test.h"
> -
> -#include <errno.h>
> -#include <signal.h>
> -
> -void cleanup(void);
> -void setup(void);
> -
> -char *TCID = "signal02";
> -int TST_TOTAL = 3;
> -
> -typedef void (*sighandler_t) (int);
> -
> -sighandler_t Tret;
> -int sigs[] = { _NSIG + 1, SIGKILL, SIGSTOP };
> -
> -int main(int ac, char **av)
> -{
> -	int lc;
> -	int i;
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();		/* global setup */
> +#include "tst_test.h"
>
> -	/* The following loop checks looping state if -i option given */
> +static int sigs[] = { _NSIG + 1, SIGKILL, SIGSTOP };
>
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -		/* reset tst_count in case we are looping */
> -		tst_count = 0;
> -
> -		/*
> -		 * There are three cases where we should get an EINVAL
> -		 */
> -		for (i = 0; i < TST_TOTAL; i++) {
> -
> -			errno = 0;
> -			Tret = signal(sigs[i], SIG_IGN);
> -			TEST_ERRNO = errno;
> -
> -			if (Tret != SIG_ERR) {
> -				tst_brkm(TFAIL, cleanup, "%s call failed - "
> -					 "errno = %d : %s", TCID, TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -			}
> -
> -			switch (TEST_ERRNO) {
> -			case EINVAL:
> -				tst_resm(TPASS, "expected failure - errno = "
> -					 "%d - %s", TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -				break;
> -			default:
> -				tst_resm(TFAIL, "call failed to produce "
> -					 "expected error - errno = %d "
> -					 "- %s", TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -			}
> -		}
> -		tst_count++;	/* incr. TEST_LOOP counter */
> -	}
> -
> -	cleanup();
> -
> -	tst_exit();
> -
> -}
> -
> -/*
> - * setup() - performs all the ONE TIME setup for this test.
> - */
> -void setup(void)
> +static void do_test(unsigned int n)
>  {
> -
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> +	TST_EXP_FAIL2((long)signal(sigs[n], SIG_IGN), EINVAL);
>  }
>
> -/*
> - * cleanup() - performs all the ONE TIME cleanup for this test at completion
> - * 	       or premature exit.
> - */
> -void cleanup(void)
> -{
> -
> -}
> +static struct tst_test test = {
> +	.tcnt = ARRAY_SIZE(sigs),
> +	.test = do_test,
> +};
> --
> 2.17.1


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH 3/5] signal03.c: Rewrite using new LTP API
  2022-10-17  1:43 ` [LTP] [PATCH 3/5] signal03.c: " Luo xiaoyu via ltp
@ 2022-10-24 12:44   ` Richard Palethorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Palethorpe @ 2022-10-24 12:44 UTC (permalink / raw)
  To: Luo xiaoyu; +Cc: ltp

Hello,

Luo xiaoyu via ltp <ltp@lists.linux.it> writes:

> Rewrite using new LTP API.
>
> Signed-off-by: Luo xiaoyu <luoxiaoyu9@huawei.com>

Merged with the addition of volatile to ign_handler, thanks!

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH 5/5] signal05.c: Rewrite using new LTP API
  2022-10-17  1:43 ` [LTP] [PATCH 5/5] signal05.c: " Luo xiaoyu via ltp
@ 2022-10-24 13:06   ` Richard Palethorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Palethorpe @ 2022-10-24 13:06 UTC (permalink / raw)
  To: Luo xiaoyu; +Cc: ltp

Hello,

signal04 and signal05 merged as well with addition of volatile and
removal of & when passing function pointer.

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2022-10-24 13:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-17  1:43 [LTP] [PATCH 0/5] signal:Rewrite using new LTP API Luo xiaoyu via ltp
2022-10-17  1:43 ` [LTP] [PATCH 1/5] signal01.c: Rewrite " Luo xiaoyu via ltp
2022-10-24 12:29   ` Richard Palethorpe
2022-10-17  1:43 ` [LTP] [PATCH 2/5] signal02.c: " Luo xiaoyu via ltp
2022-10-24 12:34   ` Richard Palethorpe
2022-10-17  1:43 ` [LTP] [PATCH 3/5] signal03.c: " Luo xiaoyu via ltp
2022-10-24 12:44   ` Richard Palethorpe
2022-10-17  1:43 ` [LTP] [PATCH 4/5] signal04.c: " Luo xiaoyu via ltp
2022-10-17  1:43 ` [LTP] [PATCH 5/5] signal05.c: " Luo xiaoyu via ltp
2022-10-24 13:06   ` Richard Palethorpe

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