All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] syscalls/alarm02: Rewrite to new library
@ 2018-07-24 11:30 Jinhui huang
  2018-07-24 11:30 ` [LTP] [PATCH 2/3] syscalls/alarm03: " Jinhui huang
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jinhui huang @ 2018-07-24 11:30 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/alarm/alarm02.c | 213 +++++++-----------------------
 1 file changed, 51 insertions(+), 162 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm02.c b/testcases/kernel/syscalls/alarm/alarm02.c
index d745e98..a663bb5 100644
--- a/testcases/kernel/syscalls/alarm/alarm02.c
+++ b/testcases/kernel/syscalls/alarm/alarm02.c
@@ -1,180 +1,69 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * 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/
- */
-/* $Id: alarm02.c,v 1.4 2009/08/28 10:57:29 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER   : alarm02
- *
- *    TEST TITLE        : Boundary Value Test for alarm(2)
- *
- *    PARENT DOCUMENT   : almtds02
- *
- *    TEST CASE TOTAL   : 3
- *
- *    WALL CLOCK TIME   : 1
- *
- *    CPU TYPES         : ALL
- *
- *    AUTHOR            : Billy Jean Horne
- *
- *    CO-PILOT          : Kathy Olmsted
- *
- *    DATE STARTED      : 06/01/92
- *
- *    INITIAL RELEASE   : UNICOS 7.0
- *
- *    TEST CASES
- *      Test Case One - A call to alarm() shall not return an error if
- *       seconds is a -1.
- *       Test FAILS if a non-zero value is returned.
- *      Test Case Two - A call to alarm() shall not return an error if
- *       seconds is the maximum unsigned integer (2**63).
- *       Test FAILS if a non-zero value is returned.
- *      Test Case Three - A call to alarm() shall not return an error if
- *       seconds is the maximum unsigned integer plus 1 ((2**63)+1).
- *       Test FAILS if a non-zero value is returned.
- *
- *    ENVIRONMENTAL NEEDS
- *      The libcuts.a and libsys.a libraries must be included in
- *      the compilation of this test.
- *
- *    DETAILED DESCRIPTION
- *
- *      Setup:
- *        Define a cleanup function.
- *
- *      Test:
- *       Loop for each test case.
- *        Execute alarm (0) system call to clear previous alarm.
- *        Check return code, if system call failed (return=-1)
- *           Issue a FAIL message and exit the test.
- *        Call alarm() with boundary values for seconds.
- *        Verify that returned value is as expected.
- *        Report results.
- *
- *      Cleanup:
- *
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Author: Billy Jean Horne
+ *
+ * Test Description:
+ *  1) alarm() not return an error if seconds is -1.
+ *  2) alarm() not return an error if seconds is ULONG_MAX.
+ *  3) alarm() not return an error if seconds is ULONG_MAX+1.
  */
-#include <sys/types.h>
+
+#include <unistd.h>
 #include <errno.h>
-#include <sys/signal.h>
+#include <signal.h>
 #include <limits.h>
-#include "test.h"
 
-void setup(void);
-void cleanup(void);
-void alarm_received(int sig);
+#include "tst_test.h"
 
-char *TCID = "alarm02";
-int TST_TOTAL = 3;
+static volatile int alarms_received = 0;
 
-int received_alarm = 0;		/* Indicates a SIGALRM was received */
+static struct tcase {
+	char *buf;
+	unsigned long int sec;
+} tcases[] = {
+	{"-1", -1},
+	{"ULONG_MAX", ULONG_MAX},
+	{"ULONG_MAX+1", ULONG_MAX + 1},
+};
 
-int main(int ac, char **av)
+static void verify_alarm(unsigned int n)
 {
-
-	/* Parameters for usc code  */
-	int lc;
-
-	/* Parameters for alarm test */
-	char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" };
-	unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 };
-	int exp[] = { 0, 0, 0 };
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			received_alarm = 0;
-			signal(SIGALRM, alarm_received);
-
-			TEST(alarm(sec[i]));
-			alarm(0);
-			if (TEST_RETURN != 0) {
-				tst_resm(TFAIL,
-					 "alarm(%lu) returned %ld, when %u was "
-					 "expected for value %s",
-					 sec[i], TEST_RETURN, exp[i], buf[i]);
-			} else {
-				if (received_alarm == 1) {
-					tst_resm(TFAIL,
-						 "alarm(%lu) returned %ldu but an "
-						 "alarm signal was received for "
-						 "value %s",
-						 sec[i], TEST_RETURN, buf[i]);
-				} else {
-					tst_resm(TPASS,
-						 "alarm(%lu) returned %ld as "
-						 "expected for value %s",
-						 sec[i], TEST_RETURN, buf[i]);
-				}
-
-			}
+	alarms_received = 0;
+	struct tcase *tc = &tcases[n];
+
+	TEST(alarm(tc->sec));
+	alarm(0);
+	if (TEST_RETURN != 0) {
+		tst_res(TFAIL,
+			"alarm(%lu) returned %ld, when 0 was ",
+			tc->sec, TEST_RETURN);
+	} else {
+		if (alarms_received == 1) {
+			tst_res(TFAIL,
+				"alarm(%lu) returned %ld but an alarm "
+				"signal was received for value %s",
+				tc->sec, TEST_RETURN, tc->buf);
+		} else {
+			tst_res(TPASS,
+				"alarm(%lu) returned %ld as "
+				"expected for value %s",
+				tc->sec, TEST_RETURN, tc->buf);
 		}
-		/*
-		 *  Reset alarm before cleanup.
-		 */
-
-		alarm(0);
-
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	alarms_received++;
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
 
-void alarm_received(int sig)
-{
-	received_alarm = 1;
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_alarm,
+	.setup = setup,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 2/3] syscalls/alarm03: Rewrite to new library
  2018-07-24 11:30 [LTP] [PATCH 1/3] syscalls/alarm02: Rewrite to new library Jinhui huang
@ 2018-07-24 11:30 ` Jinhui huang
  2018-07-25 14:20   ` Cyril Hrubis
  2018-07-24 11:30 ` [LTP] [PATCH 3/3] syscalls/alarm07: " Jinhui huang
  2018-07-25 13:48 ` [LTP] [PATCH 1/3] syscalls/alarm02: " Cyril Hrubis
  2 siblings, 1 reply; 11+ messages in thread
From: Jinhui huang @ 2018-07-24 11:30 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/alarm/alarm03.c | 222 +++++++-----------------------
 1 file changed, 49 insertions(+), 173 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm03.c b/testcases/kernel/syscalls/alarm/alarm03.c
index 60141f1..0ef51c6 100644
--- a/testcases/kernel/syscalls/alarm/alarm03.c
+++ b/testcases/kernel/syscalls/alarm/alarm03.c
@@ -1,193 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * 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: Richard Logan
+ *
+ * Test Description:
+ *  The process does a fork:
+ *	1) By the value returned by child's alarm(0), check whether child
+ *	   process cleared the previously specified alarm request or not.
+ *	2) By the value returned by parent's alarm(0), check whether parent
+ *	   process cleared the previously specified alarm request or not.
  */
-/* $Id: alarm03.c,v 1.10 2009/08/28 10:57:29 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: alarm03
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: alarm(2) cleared by a fork
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: Dennis Arason
- *
- *    DATE STARTED	: 08/96
- *
- *
- *    TEST CASES
- *
- * 	1.) alarm(100), fork, child's alarm(0) shall return 0;
- *	2.) alarm(100), fork, parent's alarm(0) shall return non-zero.
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the alarm(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	alarm(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
 #include <errno.h>
-#include <string.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <sys/wait.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void cleanup();
-void trapper();
+#include <unistd.h>
 
-char *TCID = "alarm03";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-int main(int ac, char **av)
+static void verify_alarm(void)
 {
-	int lc;
-	int status, retval = 0;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call alarm(2)
-		 */
-		TEST(alarm(100));
-
-		switch (FORK_OR_VFORK()) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
-			break;
-
-		case 0:
-			TEST(alarm(0));
-
-			if (TEST_RETURN != 0) {
-				retval = 1;
-				printf("%d: alarm(100), fork, alarm(0) child's "
-				       "alarm returned %ld\n",
-				       getpid(), TEST_RETURN);
-			} else {
-				printf("%d: alarm(100), fork, alarm(0) child's "
-				       "alarm returned %ld\n",
-				       getpid(), TEST_RETURN);
-			}
-
-			exit(retval);
-			break;
-
-		default:
-			tst_count++;
-			TEST(alarm(0));
-/* The timer may be rounded up to the next nearest second, this is OK */
-			if (TEST_RETURN <= 0 || TEST_RETURN > 101) {
-				retval = 1;
-				tst_resm(TFAIL,
-					 "alarm(100), fork, alarm(0) parent's alarm returned %ld",
-					 TEST_RETURN);
-			} else {
-				tst_resm(TPASS,
-					 "alarm(100), fork, alarm(0) parent's alarm returned %ld",
-					 TEST_RETURN);
-			}
-			SAFE_WAIT(cleanup, &status);
-			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-				tst_resm(TFAIL, "see failures reported above");
-
+	pid_t pid;
+
+	TEST(alarm(100));
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		TEST(alarm(0));
+		if (TEST_RETURN != 0) {
+			tst_res(TFAIL,
+				"alarm(100), fork, alarm(0) child's "
+				"alarm returned %ld", TEST_RETURN);
+		} else {
+			tst_res(TPASS,
+				"alarm(100), fork, alarm(0) child's "
+				"alarm returned %ld", TEST_RETURN);
 		}
-
+		exit(0);
+	} else {
+		TEST(alarm(0));
+		if (TEST_RETURN <= 0 || TEST_RETURN > 101) {
+			tst_res(TFAIL,
+				"alarm(100), fork, alarm(0) parent's "
+				"alarm returned %ld", TEST_RETURN);
+		} else {
+			tst_res(TPASS,
+				"alarm(100), fork, alarm(0) parent's "
+				"alarm returned %ld", TEST_RETURN);
+		}
+		tst_reap_children();
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	signal(SIGALRM, trapper);
-
-	TEST_PAUSE;
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
 
-void trapper(int sig)
-{
-	signal(SIGALRM, trapper);
-}
+static struct tst_test test = {
+	.test_all = verify_alarm,
+	.setup = setup,
+	.forks_child = 1,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 3/3] syscalls/alarm07: Rewrite to new library
  2018-07-24 11:30 [LTP] [PATCH 1/3] syscalls/alarm02: Rewrite to new library Jinhui huang
  2018-07-24 11:30 ` [LTP] [PATCH 2/3] syscalls/alarm03: " Jinhui huang
@ 2018-07-24 11:30 ` Jinhui huang
  2018-07-25 13:48 ` [LTP] [PATCH 1/3] syscalls/alarm02: " Cyril Hrubis
  2 siblings, 0 replies; 11+ messages in thread
From: Jinhui huang @ 2018-07-24 11:30 UTC (permalink / raw)
  To: ltp

1) Initialize alarms_received variable in loops
2) Add the output of TPASS

Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/alarm/alarm07.c | 175 ++++++------------------------
 1 file changed, 31 insertions(+), 144 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm07.c b/testcases/kernel/syscalls/alarm/alarm07.c
index 5f4d6e4..b874324 100644
--- a/testcases/kernel/syscalls/alarm/alarm07.c
+++ b/testcases/kernel/syscalls/alarm/alarm07.c
@@ -1,171 +1,58 @@
+// 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
- */
-
-/*
- * Test Name: alarm07
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Author: Wayne Boyer
  *
  * Test Description:
- *  Check the functionality of the alarm() when the time input
- *  parameter is non-zero and the process does a fork.
- *
- * Expected Result:
- *  The alarm request should be cleared in the child process.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *
- * Usage:  <for command-line>
- *  alarm07 [-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 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
+ *  By the SIGALRM signal, check whether the previously specified alarm request
+ *  was cleared in the child process or not.
  */
 
-#include <stdio.h>
 #include <unistd.h>
-#include <sys/types.h>
+#include <stdlib.h>
 #include <errno.h>
-#include <string.h>
 #include <signal.h>
-#include <sys/wait.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
-char *TCID = "alarm07";
-int TST_TOTAL = 1;
-int alarms_received = 0;
+static volatile int alarms_received = 0;
 
-void setup();
-void cleanup();
-void sigproc(int sig);
-
-int main(int ac, char **av)
+static void verify_alarm(void)
 {
-	int lc;
-	int sleep_time = 5;
-	int status;
-	int time_sec = 3;
-	pid_t cpid;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	pid_t pid;
+	alarms_received = 0;
 
-		tst_count = 0;
+	TEST(alarm(3));
 
-		/*
-		 * Call First alarm() with non-zero time parameter
-		 * 'time_sec' to send SIGALRM to the process.
-		 */
-		TEST(alarm(time_sec));
+	pid = SAFE_FORK();
 
-		/* Now, fork a child process */
-		cpid = FORK_OR_VFORK();
-		if (cpid < 0) {
-			tst_resm(TFAIL | TERRNO, "fork() failed");
-		}
-
-		sleep(sleep_time);
+	sleep(5);
 
-		if (cpid == 0) {
-			if (alarms_received == 0)
-				exit(0);
-			else {
-				printf("alarm request not cleared in "
-				       "child; alarms received:%d\n",
-				       alarms_received);
-				exit(1);
-			}
+	if (pid == 0) {
+		if (alarms_received == 0) {
+			tst_res(TPASS, "alarm() request cleared in child");
 		} else {
-			/* Wait for child to complete execution */
-			SAFE_WAIT(cleanup, &status);
-			if (!WIFEXITED(status) ||
-			    WEXITSTATUS(status) != 0)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "child exited abnormally");
+			tst_res(TFAIL, "alarm() request not cleared in "
+				"child; alarms received:%d", alarms_received);
 		}
+		 exit(0);
+	} else {
+		tst_reap_children();
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- *  Setup signal handler to catch SIGALRM signal.
- */
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Set the signal catching function */
-	if (signal(SIGALRM, sigproc) == SIG_ERR) {
-		tst_brkm(TFAIL | TERRNO, cleanup, "signal(SIGALRM, ..) failed");
-	}
-}
-
-/*
- * sigproc(int) - This function defines the action that has to be taken
- *	          when the SIGALRM signal is caught.
- *   It also sets the variable which is used to check whether the
- *   alarm system call was successful.
- */
-void sigproc(int sig)
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	alarms_received++;
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
+static void setup(void)
 {
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
+
+static struct tst_test test = {
+	.test_all = verify_alarm,
+	.setup = setup,
+	.forks_child = 1,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 1/3] syscalls/alarm02: Rewrite to new library
  2018-07-24 11:30 [LTP] [PATCH 1/3] syscalls/alarm02: Rewrite to new library Jinhui huang
  2018-07-24 11:30 ` [LTP] [PATCH 2/3] syscalls/alarm03: " Jinhui huang
  2018-07-24 11:30 ` [LTP] [PATCH 3/3] syscalls/alarm07: " Jinhui huang
@ 2018-07-25 13:48 ` Cyril Hrubis
  2018-07-26  5:32   ` [LTP] [PATCH v2 1/2] " Jinhui huang
  2 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2018-07-25 13:48 UTC (permalink / raw)
  To: ltp

Hi!
> +static struct tcase {
> +	char *buf;
> +	unsigned long int sec;
> +} tcases[] = {
> +	{"-1", -1},
> +	{"ULONG_MAX", ULONG_MAX},
> +	{"ULONG_MAX+1", ULONG_MAX + 1},
> +};

Looking at these values these seems to be a bit bogus, the alarm
prototype is defined with unsigned int, so the only value that makes
sense here would he UINT_MAX.

The -1 == ULONG_MAX when converted to unsigned int and ULONG_MAX + 1
would end up as 0.

Also alarm() returns the number of seconds remaining for the alarm, so
we should really do something as:

* call alarm(UINT_MAX);
* check the return value was 0
* call alarm(0);
* check that the return value was either UINT_MAX or UINT_MAX - 1

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/3] syscalls/alarm03: Rewrite to new library
  2018-07-24 11:30 ` [LTP] [PATCH 2/3] syscalls/alarm03: " Jinhui huang
@ 2018-07-25 14:20   ` Cyril Hrubis
  2018-07-25 14:52     ` Cyril Hrubis
  0 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2018-07-25 14:20 UTC (permalink / raw)
  To: ltp

Hi!
> +	TEST(alarm(100));
> +
> +	pid = SAFE_FORK();
> +	if (pid == 0) {
> +		TEST(alarm(0));
> +		if (TEST_RETURN != 0) {
> +			tst_res(TFAIL,
> +				"alarm(100), fork, alarm(0) child's "
> +				"alarm returned %ld", TEST_RETURN);
> +		} else {
> +			tst_res(TPASS,
> +				"alarm(100), fork, alarm(0) child's "
> +				"alarm returned %ld", TEST_RETURN);
>  		}
> -
> +		exit(0);
> +	} else {
> +		TEST(alarm(0));
> +		if (TEST_RETURN <= 0 || TEST_RETURN > 101) {
> +			tst_res(TFAIL,
> +				"alarm(100), fork, alarm(0) parent's "
> +				"alarm returned %ld", TEST_RETURN);
> +		} else {
> +			tst_res(TPASS,
> +				"alarm(100), fork, alarm(0) parent's "
> +				"alarm returned %ld", TEST_RETURN);
> +		}
> +		tst_reap_children();

There is no need for the else branch here as the child calls exit(0);

>  }
>  
> -void setup(void)
> +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
>  {
> -
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> -	signal(SIGALRM, trapper);
> -
> -	TEST_PAUSE;
> +	SAFE_SIGNAL(SIGALRM, sighandler);

I do wonder why do we call the SAFE_SIGNAL() here?

It does not make much sense.

>  }
>  
> -void cleanup(void)
> +static void setup(void)
>  {
> +	SAFE_SIGNAL(SIGALRM, sighandler);
>  }
>  
> -void trapper(int sig)
> -{
> -	signal(SIGALRM, trapper);
> -}
> +static struct tst_test test = {
> +	.test_all = verify_alarm,
> +	.setup = setup,
> +	.forks_child = 1,
> +};
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/3] syscalls/alarm03: Rewrite to new library
  2018-07-25 14:20   ` Cyril Hrubis
@ 2018-07-25 14:52     ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2018-07-25 14:52 UTC (permalink / raw)
  To: ltp

Hi!
> > -	tst_sig(FORK, DEF_HANDLER, cleanup);
> > -
> > -	signal(SIGALRM, trapper);
> > -
> > -	TEST_PAUSE;
> > +	SAFE_SIGNAL(SIGALRM, sighandler);
> 
> I do wonder why do we call the SAFE_SIGNAL() here?
> 
> It does not make much sense.

Actually why we are even installing the signal handler, we do not wait
for the alarm to fire anyways.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 1/2] syscalls/alarm02: Rewrite to new library
  2018-07-25 13:48 ` [LTP] [PATCH 1/3] syscalls/alarm02: " Cyril Hrubis
@ 2018-07-26  5:32   ` Jinhui huang
  2018-07-26  5:32     ` [LTP] [PATCH v2 2/2] syscalls/alarm03: " Jinhui huang
  2018-08-02 15:54     ` [LTP] [PATCH v2 1/2] syscalls/alarm02: " Cyril Hrubis
  0 siblings, 2 replies; 11+ messages in thread
From: Jinhui huang @ 2018-07-26  5:32 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/alarm/alarm02.c | 216 ++++++++----------------------
 1 file changed, 58 insertions(+), 158 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm02.c b/testcases/kernel/syscalls/alarm/alarm02.c
index d745e98..d1b15a9 100644
--- a/testcases/kernel/syscalls/alarm/alarm02.c
+++ b/testcases/kernel/syscalls/alarm/alarm02.c
@@ -1,180 +1,80 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * 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/
- */
-/* $Id: alarm02.c,v 1.4 2009/08/28 10:57:29 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER   : alarm02
- *
- *    TEST TITLE        : Boundary Value Test for alarm(2)
- *
- *    PARENT DOCUMENT   : almtds02
- *
- *    TEST CASE TOTAL   : 3
- *
- *    WALL CLOCK TIME   : 1
- *
- *    CPU TYPES         : ALL
- *
- *    AUTHOR            : Billy Jean Horne
- *
- *    CO-PILOT          : Kathy Olmsted
- *
- *    DATE STARTED      : 06/01/92
- *
- *    INITIAL RELEASE   : UNICOS 7.0
- *
- *    TEST CASES
- *      Test Case One - A call to alarm() shall not return an error if
- *       seconds is a -1.
- *       Test FAILS if a non-zero value is returned.
- *      Test Case Two - A call to alarm() shall not return an error if
- *       seconds is the maximum unsigned integer (2**63).
- *       Test FAILS if a non-zero value is returned.
- *      Test Case Three - A call to alarm() shall not return an error if
- *       seconds is the maximum unsigned integer plus 1 ((2**63)+1).
- *       Test FAILS if a non-zero value is returned.
- *
- *    ENVIRONMENTAL NEEDS
- *      The libcuts.a and libsys.a libraries must be included in
- *      the compilation of this test.
- *
- *    DETAILED DESCRIPTION
- *
- *      Setup:
- *        Define a cleanup function.
- *
- *      Test:
- *       Loop for each test case.
- *        Execute alarm (0) system call to clear previous alarm.
- *        Check return code, if system call failed (return=-1)
- *           Issue a FAIL message and exit the test.
- *        Call alarm() with boundary values for seconds.
- *        Verify that returned value is as expected.
- *        Report results.
- *
- *      Cleanup:
- *
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Author: Billy Jean Horne
+ *
+ * Test Description:
+ *  1) alarm() return UINT_MAX if seconds is -1.
+ *  2) alarm() return UINT_MAX  if seconds is UINT_MAX.
+ *  3) alarm() return 0 if seconds is UINT_MAX + 1.
  */
+
 #include <sys/types.h>
+#include <unistd.h>
 #include <errno.h>
 #include <sys/signal.h>
 #include <limits.h>
-#include "test.h"
 
-void setup(void);
-void cleanup(void);
-void alarm_received(int sig);
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-char *TCID = "alarm02";
-int TST_TOTAL = 3;
+static volatile int alarms_received;
 
-int received_alarm = 0;		/* Indicates a SIGALRM was received */
+static struct tcase {
+	char *buf;
+	unsigned int sec;
+} tcases[] = {
+	{"-1", -1},
+	{"UINT_MAX", UINT_MAX},
+	{"UINT_MAX + 1", UINT_MAX + 1},
+};
 
-int main(int ac, char **av)
+static void verify_alarm(unsigned int n)
 {
+	alarms_received = 0;
+	struct tcase *tc = &tcases[n];
+	unsigned int ret;
+
+	ret = alarm(tc->sec);
+	if (ret != 0) {
+		tst_res(TFAIL,
+			"alarm(%u) returned %ld, when 0 was ",
+			tc->sec, TEST_RETURN);
+	}
 
-	/* Parameters for usc code  */
-	int lc;
-
-	/* Parameters for alarm test */
-	char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" };
-	unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 };
-	int exp[] = { 0, 0, 0 };
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			received_alarm = 0;
-			signal(SIGALRM, alarm_received);
-
-			TEST(alarm(sec[i]));
-			alarm(0);
-			if (TEST_RETURN != 0) {
-				tst_resm(TFAIL,
-					 "alarm(%lu) returned %ld, when %u was "
-					 "expected for value %s",
-					 sec[i], TEST_RETURN, exp[i], buf[i]);
-			} else {
-				if (received_alarm == 1) {
-					tst_resm(TFAIL,
-						 "alarm(%lu) returned %ldu but an "
-						 "alarm signal was received for "
-						 "value %s",
-						 sec[i], TEST_RETURN, buf[i]);
-				} else {
-					tst_resm(TPASS,
-						 "alarm(%lu) returned %ld as "
-						 "expected for value %s",
-						 sec[i], TEST_RETURN, buf[i]);
-				}
-
-			}
-		}
-		/*
-		 *  Reset alarm before cleanup.
-		 */
-
-		alarm(0);
+	TEST(alarm(0));
+	if (alarms_received == 1) {
+		tst_res(TFAIL,
+			"alarm(%u) signal was received for value %s",
+			tc->sec, tc->buf);
+			return;
+	}
 
+	if (TEST_RETURN != tc->sec) {
+		tst_res(TFAIL,
+			"alarm(%u) returned %ld as unexpected",
+			tc->sec, TEST_RETURN);
+			return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS,
+		"alarm(%u) returned %ld as expected "
+		"for value %s",
+		tc->sec, TEST_RETURN, tc->buf);
 }
 
-void setup(void)
+static void sighandler(int sig)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	if (sig == SIGALRM)
+		alarms_received++;
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
 
-void alarm_received(int sig)
-{
-	received_alarm = 1;
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_alarm,
+	.setup = setup,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 2/2] syscalls/alarm03: Rewrite to new library
  2018-07-26  5:32   ` [LTP] [PATCH v2 1/2] " Jinhui huang
@ 2018-07-26  5:32     ` Jinhui huang
  2018-08-02 15:54     ` [LTP] [PATCH v2 1/2] syscalls/alarm02: " Cyril Hrubis
  1 sibling, 0 replies; 11+ messages in thread
From: Jinhui huang @ 2018-07-26  5:32 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/alarm/alarm03.c | 220 ++++++------------------------
 1 file changed, 43 insertions(+), 177 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm03.c b/testcases/kernel/syscalls/alarm/alarm03.c
index 60141f1..6e4e66a 100644
--- a/testcases/kernel/syscalls/alarm/alarm03.c
+++ b/testcases/kernel/syscalls/alarm/alarm03.c
@@ -1,193 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * 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: Richard Logan
+ *
+ * Test Description:
+ *  The process does a fork:
+ *	1) By the value returned by child's alarm(0), check whether child
+ *	   process cleared the previously specified alarm request or not.
+ *	2) By the value returned by parent's alarm(0), check whether parent
+ *	   process cleared the previously specified alarm request or not.
  */
-/* $Id: alarm03.c,v 1.10 2009/08/28 10:57:29 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: alarm03
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: alarm(2) cleared by a fork
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: Dennis Arason
- *
- *    DATE STARTED	: 08/96
- *
- *
- *    TEST CASES
- *
- * 	1.) alarm(100), fork, child's alarm(0) shall return 0;
- *	2.) alarm(100), fork, parent's alarm(0) shall return non-zero.
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the alarm(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	alarm(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
 #include <errno.h>
-#include <string.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <sys/wait.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <unistd.h>
 
-void setup();
-void cleanup();
-void trapper();
+#include "tst_test.h"
 
-char *TCID = "alarm03";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_alarm(void)
 {
-	int lc;
-	int status, retval = 0;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call alarm(2)
-		 */
-		TEST(alarm(100));
-
-		switch (FORK_OR_VFORK()) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
-			break;
-
-		case 0:
-			TEST(alarm(0));
-
-			if (TEST_RETURN != 0) {
-				retval = 1;
-				printf("%d: alarm(100), fork, alarm(0) child's "
-				       "alarm returned %ld\n",
-				       getpid(), TEST_RETURN);
-			} else {
-				printf("%d: alarm(100), fork, alarm(0) child's "
-				       "alarm returned %ld\n",
-				       getpid(), TEST_RETURN);
-			}
-
-			exit(retval);
-			break;
-
-		default:
-			tst_count++;
-			TEST(alarm(0));
-/* The timer may be rounded up to the next nearest second, this is OK */
-			if (TEST_RETURN <= 0 || TEST_RETURN > 101) {
-				retval = 1;
-				tst_resm(TFAIL,
-					 "alarm(100), fork, alarm(0) parent's alarm returned %ld",
-					 TEST_RETURN);
-			} else {
-				tst_resm(TPASS,
-					 "alarm(100), fork, alarm(0) parent's alarm returned %ld",
-					 TEST_RETURN);
-			}
-			SAFE_WAIT(cleanup, &status);
-			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-				tst_resm(TFAIL, "see failures reported above");
-
+	pid_t pid;
+
+	TEST(alarm(100));
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		TEST(alarm(0));
+		if (TEST_RETURN != 0) {
+			tst_res(TFAIL,
+				"alarm(100), fork, alarm(0) child's "
+				"alarm returned %ld", TEST_RETURN);
+		} else {
+			tst_res(TPASS,
+				"alarm(100), fork, alarm(0) child's "
+				"alarm returned %ld", TEST_RETURN);
 		}
-
+		exit(0);
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	signal(SIGALRM, trapper);
+	TEST(alarm(0));
+	if (TEST_RETURN != 100) {
+		tst_res(TFAIL,
+			"alarm(100), fork, alarm(0) parent's "
+			"alarm returned %ld", TEST_RETURN);
+	} else {
+		tst_res(TPASS,
+			"alarm(100), fork, alarm(0) parent's "
+			"alarm returned %ld", TEST_RETURN);
+	}
 
-	TEST_PAUSE;
+	tst_reap_children();
 }
 
-void cleanup(void)
-{
-}
-
-void trapper(int sig)
-{
-	signal(SIGALRM, trapper);
-}
+static struct tst_test test = {
+	.test_all = verify_alarm,
+	.forks_child = 1,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 1/2] syscalls/alarm02: Rewrite to new library
  2018-07-26  5:32   ` [LTP] [PATCH v2 1/2] " Jinhui huang
  2018-07-26  5:32     ` [LTP] [PATCH v2 2/2] syscalls/alarm03: " Jinhui huang
@ 2018-08-02 15:54     ` Cyril Hrubis
  2018-08-06  5:11       ` [LTP] [PATCH v3] " Jinhui huang
  1 sibling, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2018-08-02 15:54 UTC (permalink / raw)
  To: ltp

Hi!
> +} tcases[] = {
> +	{"-1", -1},
> +	{"UINT_MAX", UINT_MAX},
> +	{"UINT_MAX + 1", UINT_MAX + 1},
> +};

Can we get rid of the -1 and 0 (aka UINT_MAX + 1), or replace them with
something more meaningful?

I would probably go for UINT_MAX and UINT_MAX/2 or something similar, as
it is the overflows that these numbers are causing are very confusing.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3] syscalls/alarm02: Rewrite to new library
  2018-08-02 15:54     ` [LTP] [PATCH v2 1/2] syscalls/alarm02: " Cyril Hrubis
@ 2018-08-06  5:11       ` Jinhui huang
  2018-08-07  9:16         ` Cyril Hrubis
  0 siblings, 1 reply; 11+ messages in thread
From: Jinhui huang @ 2018-08-06  5:11 UTC (permalink / raw)
  To: ltp

Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/alarm/alarm02.c | 217 ++++++++----------------------
 1 file changed, 58 insertions(+), 159 deletions(-)

diff --git a/testcases/kernel/syscalls/alarm/alarm02.c b/testcases/kernel/syscalls/alarm/alarm02.c
index d745e98..3cb4d15 100644
--- a/testcases/kernel/syscalls/alarm/alarm02.c
+++ b/testcases/kernel/syscalls/alarm/alarm02.c
@@ -1,180 +1,79 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * 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/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Author: Billy Jean Horne
+ *
+ * Test Description:
+ *  1) alarm() return UINT_MAX if seconds is UINT_MAX.
+ *  2) alarm() return UINT_MAX/2 if seconds is UINT_MAX/2.
+ *  3) alarm() return UINT_MAX/4 if seconds is UINT_MAX/4.
  */
-/* $Id: alarm02.c,v 1.4 2009/08/28 10:57:29 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER   : alarm02
- *
- *    TEST TITLE        : Boundary Value Test for alarm(2)
- *
- *    PARENT DOCUMENT   : almtds02
- *
- *    TEST CASE TOTAL   : 3
- *
- *    WALL CLOCK TIME   : 1
- *
- *    CPU TYPES         : ALL
- *
- *    AUTHOR            : Billy Jean Horne
- *
- *    CO-PILOT          : Kathy Olmsted
- *
- *    DATE STARTED      : 06/01/92
- *
- *    INITIAL RELEASE   : UNICOS 7.0
- *
- *    TEST CASES
- *      Test Case One - A call to alarm() shall not return an error if
- *       seconds is a -1.
- *       Test FAILS if a non-zero value is returned.
- *      Test Case Two - A call to alarm() shall not return an error if
- *       seconds is the maximum unsigned integer (2**63).
- *       Test FAILS if a non-zero value is returned.
- *      Test Case Three - A call to alarm() shall not return an error if
- *       seconds is the maximum unsigned integer plus 1 ((2**63)+1).
- *       Test FAILS if a non-zero value is returned.
- *
- *    ENVIRONMENTAL NEEDS
- *      The libcuts.a and libsys.a libraries must be included in
- *      the compilation of this test.
- *
- *    DETAILED DESCRIPTION
- *
- *      Setup:
- *        Define a cleanup function.
- *
- *      Test:
- *       Loop for each test case.
- *        Execute alarm (0) system call to clear previous alarm.
- *        Check return code, if system call failed (return=-1)
- *           Issue a FAIL message and exit the test.
- *        Call alarm() with boundary values for seconds.
- *        Verify that returned value is as expected.
- *        Report results.
- *
- *      Cleanup:
- *
- */
-#include <sys/types.h>
+
+#include <unistd.h>
 #include <errno.h>
 #include <sys/signal.h>
 #include <limits.h>
-#include "test.h"
 
-void setup(void);
-void cleanup(void);
-void alarm_received(int sig);
+#include "tst_test.h"
 
-char *TCID = "alarm02";
-int TST_TOTAL = 3;
+static volatile int alarms_received;
 
-int received_alarm = 0;		/* Indicates a SIGALRM was received */
+static struct tcase {
+	char *buf;
+	unsigned int sec;
+} tcases[] = {
+	{"UINT_MAX", UINT_MAX},
+	{"UINT_MAX/2", UINT_MAX/2},
+	{"UINT_MAX/4", UINT_MAX/4},
+};
 
-int main(int ac, char **av)
+static void verify_alarm(unsigned int n)
 {
+	alarms_received = 0;
+	struct tcase *tc = &tcases[n];
+	unsigned int ret;
+
+	ret = alarm(tc->sec);
+	if (ret != 0) {
+		tst_res(TFAIL,
+			"alarm(%u) returned %ld, when 0 was ",
+			tc->sec, TST_RET);
+		return;
+	}
 
-	/* Parameters for usc code  */
-	int lc;
-
-	/* Parameters for alarm test */
-	char *buf[] = { "-1", "ULONG_MAX", "ULONG_MAX+1" };
-	unsigned long int sec[] = { -1, ULONG_MAX, ULONG_MAX + 1 };
-	int exp[] = { 0, 0, 0 };
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			received_alarm = 0;
-			signal(SIGALRM, alarm_received);
-
-			TEST(alarm(sec[i]));
-			alarm(0);
-			if (TEST_RETURN != 0) {
-				tst_resm(TFAIL,
-					 "alarm(%lu) returned %ld, when %u was "
-					 "expected for value %s",
-					 sec[i], TEST_RETURN, exp[i], buf[i]);
-			} else {
-				if (received_alarm == 1) {
-					tst_resm(TFAIL,
-						 "alarm(%lu) returned %ldu but an "
-						 "alarm signal was received for "
-						 "value %s",
-						 sec[i], TEST_RETURN, buf[i]);
-				} else {
-					tst_resm(TPASS,
-						 "alarm(%lu) returned %ld as "
-						 "expected for value %s",
-						 sec[i], TEST_RETURN, buf[i]);
-				}
-
-			}
-		}
-		/*
-		 *  Reset alarm before cleanup.
-		 */
-
-		alarm(0);
+	TEST(alarm(0));
+	if (alarms_received == 1) {
+		tst_res(TFAIL,
+			"alarm(%u) signal was received for value %s",
+			tc->sec, tc->buf);
+			return;
+	}
 
+	if (tc->sec != TST_RET) {
+		tst_res(TFAIL,
+			"alarm(%u) returned %ld as unexpected",
+			tc->sec, TST_RET);
+			return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS,
+		"alarm(%u) returned %ld as expected "
+		"for value %s",
+		tc->sec, TST_RET, tc->buf);
 }
 
-void setup(void)
+static void sighandler(int sig)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	if (sig == SIGALRM)
+		alarms_received++;
 }
 
-void cleanup(void)
+static void setup(void)
 {
+	SAFE_SIGNAL(SIGALRM, sighandler);
 }
 
-void alarm_received(int sig)
-{
-	received_alarm = 1;
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_alarm,
+	.setup = setup,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v3] syscalls/alarm02: Rewrite to new library
  2018-08-06  5:11       ` [LTP] [PATCH v3] " Jinhui huang
@ 2018-08-07  9:16         ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2018-08-07  9:16 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor changes, thanks.

* TEST_RETURN -> TST_RET
* There is no need to tst_reap_children() if child did exit(0).
* etc.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2018-08-07  9:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-24 11:30 [LTP] [PATCH 1/3] syscalls/alarm02: Rewrite to new library Jinhui huang
2018-07-24 11:30 ` [LTP] [PATCH 2/3] syscalls/alarm03: " Jinhui huang
2018-07-25 14:20   ` Cyril Hrubis
2018-07-25 14:52     ` Cyril Hrubis
2018-07-24 11:30 ` [LTP] [PATCH 3/3] syscalls/alarm07: " Jinhui huang
2018-07-25 13:48 ` [LTP] [PATCH 1/3] syscalls/alarm02: " Cyril Hrubis
2018-07-26  5:32   ` [LTP] [PATCH v2 1/2] " Jinhui huang
2018-07-26  5:32     ` [LTP] [PATCH v2 2/2] syscalls/alarm03: " Jinhui huang
2018-08-02 15:54     ` [LTP] [PATCH v2 1/2] syscalls/alarm02: " Cyril Hrubis
2018-08-06  5:11       ` [LTP] [PATCH v3] " Jinhui huang
2018-08-07  9:16         ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.