Skip to contentSkip to conversation

timers/timer_delete0{2, 3}: Ported to new library

PATCH New Christian Amann 3 participants 6 messages Jul 23, 2019 – Jul 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 timers/timer_delete0{2, 3}: Ported to new library

Cleaned up and ported both timer_delete(2) tests to new library.

---
 .../kernel/timers/timer_delete/timer_delete02.c    | 188 +++++++--------------
 .../kernel/timers/timer_delete/timer_delete03.c    | 175 +++++--------------
 2 files changed, 102 insertions(+), 261 deletions(-)

rewrite testcases/kernel/timers/timer_delete/timer_delete02.c (93%) rewrite testcases/kernel/timers/timer_delete/timer_delete03.c (93%)

testcases/kernel/timers/timer_delete/timer_delete02.c +63 -125
dissimilarity index 93%
index b9b9c7ffc..6380a34cf 100644
@@ -1,125 +1,63 @@
-/*
- * Copyright (c) Wipro Technologies Ltd, 2003.  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.
- *
- * 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.
- *
- */
-/**************************************************************************
- *
- *    TEST IDENTIFIER	: timer_delete02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for timer_delete(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Aniruddha Marathe <[email protected]>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *     This is a Phase I test for the timer_delete(2) system call.
- *     It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	 Create a POSIX timer
- *	 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
- *
- * USAGE:  <for command-line>
- * timer_delete02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
- * where:
- * 	-c n : Run n copies simultaneously.
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- * None
- *****************************************************************************/
-
-#include <stdlib.h>
-#include <errno.h>
-#include <time.h>
-#include <signal.h>
-
-#include "test.h"
-#include "common_timers.h"
-
-void setup(void);
-
-char *TCID = "timer_delete02";	/* Test program identifier.    */
-int TST_TOTAL = 1;		/* Total number of test cases. */
-
-int main(int ac, char **av)
-{
-	int lc;
-	kernel_timer_t timer_id;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* Create a Posix timer */
-		if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL,
-			&timer_id) < 0) {
-			tst_count = TST_TOTAL;
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "timer_delete can't be tested because "
-				 "timer_create failed");
-		}
-		TEST(ltp_syscall(__NR_timer_delete, timer_id));
-		tst_resm((TEST_RETURN == 0 ? TPASS : TFAIL | TTERRNO),
-			 "%s", (TEST_RETURN == 0 ? "passed" : "failed"));
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - Performs one time cleanup for this test at
- * completion or premature exit
- */
-void cleanup(void)
-{
-}
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) Wipro Technologies Ltd, 2003.  All Rights Reserved.
+ *
+ * Author:	Aniruddha Marathe <[email protected]>
+ *
+ * Ported to new library:
+ * 07/2019      Christian Amann <[email protected]>
+ */
+/*
+ * Basic test for timer_delete(2)
+ *
+ *	Creates a timer for each available clock and then tries
+ *	to delete them again.
+ */
+
+#include <errno.h>
+#include <time.h>
+#include "tst_test.h"
+#include "common_timers.h"
+
+static void run(void)
+{
+	unsigned int i;
+	kernel_timer_t timer_id;
+
+	for (i = 0; i < CLOCKS_DEFINED; ++i) {
+		clock_t clock = clock_list[i];
+
+		if (clock == CLOCK_PROCESS_CPUTIME_ID ||
+			clock == CLOCK_THREAD_CPUTIME_ID) {
+			if (!have_cputime_timers())
+				continue;
+		}
+
+		tst_res(TINFO, "Testing %s", get_clock_str(clock));
+
+		TEST(tst_syscall(__NR_timer_create, clock, NULL, &timer_id));
+		if (TST_RET != 0) {
+			if (possibly_unsupported(clock) && TST_ERR == EINVAL) {
+				tst_res(TPASS | TTERRNO,
+					"%s unsupported, failed as expected",
+					get_clock_str(clock));
+			} else {
+				tst_res(TBROK | TTERRNO,
+					"Aborting test - timer_create(%s) failed",
+					get_clock_str(clock));
+			}
+			continue;
+		}
+
+		TEST(tst_syscall(__NR_timer_delete, timer_id));
+		if (TST_RET == 0)
+			tst_res(TPASS, "Timer deleted successfully!");
+		else
+			tst_res(TFAIL | TTERRNO, "Timer deletion failed!");
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
testcases/kernel/timers/timer_delete/timer_delete03.c +39 -136

175 lines not on this page · raw message

Signature · 1 line
2.16.4
#1 lore raw

PATCH 2/3 timers/timer_settime0{2, 3}: Ported to new library

Cleaned up and ported both timer_settime(2) tests to new library.

---
 .../kernel/timers/timer_settime/timer_settime02.c  | 318 ++++++++-------------
 .../kernel/timers/timer_settime/timer_settime03.c  | 314 ++++++++------------
 2 files changed, 249 insertions(+), 383 deletions(-)

rewrite testcases/kernel/timers/timer_settime/timer_settime02.c (92%) rewrite testcases/kernel/timers/timer_settime/timer_settime03.c (95%)

testcases/kernel/timers/timer_settime/timer_settime02.c +125 -193
dissimilarity index 92%
index cfeb7b3d3..36d9a745f 100644
@@ -1,193 +1,125 @@
-/*
- * Copyright (c) Wipro Technologies Ltd, 2003.  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.
- *
- * 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.
- *
- */
-/**************************************************************************
- *
- *    TEST IDENTIFIER	: timer_settime02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for timer_settime(2)
- *
- *    TEST CASE TOTAL	: 4
- *
- *    AUTHOR		: Aniruddha Marathe <[email protected]>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *     This is a Phase I test for the timer_settime(2) system call.
- *     It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	 setup individual test
- *	 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
- *
- * USAGE:  <for command-line>
- * timer_settime02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
- * where:
- * 	-c n : Run n copies simultaneously.
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- * None
- *****************************************************************************/
-
-#include <stdlib.h>
-#include <errno.h>
-#include <time.h>
-#include <signal.h>
-
-#include "test.h"
-#include "common_timers.h"
-
-void setup(void);
-static int setup_test(int option);
-
-char *TCID = "timer_settime02";	/* Test program identifier.    */
-int TST_TOTAL = 4;		/* Total number of test cases. */
-
-static struct itimerspec new_set, old_set, *old_temp;
-static kernel_timer_t timer;
-static int flag;
-
-int main(int ac, char **av)
-{
-	int lc, 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++) {
-
-			/* Set up individual test */
-			if (setup_test(i) == 0) {
-				TEST(ltp_syscall(__NR_timer_settime, timer,
-					flag, &new_set, old_temp));
-				tst_resm((TEST_RETURN == 0 ?
-					  TPASS :
-					  TFAIL | TTERRNO),
-					 "%s",
-					 (TEST_RETURN ==
-					  0 ? "passed" : "failed")
-				    );
-			}
-
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/* This function does set up for individual tests */
-static int setup_test(int option)
-{
-	struct timespec timenow;	/* Used to obtain current time */
-	int rc = 0;
-
-	switch (option) {
-	case 0:
-		/* This is general initialization.
-		 * make old_setting NULL
-		 * make flags equal to zero
-		 * use one-shot timer
-		 */
-		old_temp = NULL;
-		new_set.it_interval.tv_sec = 0;
-		new_set.it_interval.tv_nsec = 0;
-		new_set.it_value.tv_sec = 5;
-		new_set.it_value.tv_nsec = 0;
-		flag = 0;
-		break;
-	case 1:
-		/* get the old_setting in old_set
-		 * This test case also takes care
-		 * of situation where the timerid is
-		 * already armed
-		 */
-		old_temp = &old_set;
-		break;
-	case 2:
-		/* Use the periodic timer */
-		new_set.it_interval.tv_sec = 5;
-		new_set.it_value.tv_sec = 0;
-		break;
-	case 3:
-		/* Use TIMER_ABSTIME flag for setting
-		 * absolute time for timer
-		 */
-		flag = TIMER_ABSTIME;
-		/*
-		 * Let's not use the linux_syscall_number syscall(2)
-		 * wrapper here because our primary test focus is
-		 * timer_create, not clock_gettime. That's covered in
-		 * those respective tests.
-		 */
-		if (clock_gettime(CLOCK_REALTIME, &timenow) < 0) {
-			tst_resm(TWARN | TERRNO,
-				 "clock_gettime failed; skipping the test");
-			rc = -1;
-		} else {
-			new_set.it_value.tv_sec = timenow.tv_sec + 25;
-		}
-		break;
-	}
-	return rc;
-}
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	if (ltp_syscall(__NR_timer_create, CLOCK_REALTIME, NULL, &timer) < 0)
-		tst_brkm(TBROK, NULL, "timer_create failed");
-}
-
-/*
- * cleanup() - Performs one time cleanup for this test at
- * completion or premature exit
- */
-void cleanup(void)
-{
-}
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) Wipro Technologies Ltd, 2003.  All Rights Reserved.
+ *
+ * Author:	Aniruddha Marathe <[email protected]>
+ *
+ * Ported to new library:
+ * 07/2019      Christian Amann <[email protected]>
+ */
+/*
+ * This tests the timer_settime(2) syscall under various conditions:
+ *
+ * 1) General initialization: No old_value, no flags, 5-second-timer
+ * 2) Setting a pointer to a itimerspec struct as old_set parameter
+ * 3) Using a periodic timer
+ * 4) Using absolute time
+ *
+ * All of these tests are supposed to be successful.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <time.h>
+#include <signal.h>
+#include "tst_test.h"
+#include "common_timers.h"
+
+static struct timespec timenow;
+static struct itimerspec new_set, old_set;
+static kernel_timer_t timer;
+
+static struct testcase {
+	struct itimerspec	*old_ptr;
+	int			it_value_tv_sec;
+	int			it_internal_tv_sec;
+	int			check_clock_gettime;
+	int			flag;
+	char			*description;
+} tcases[] = {
+	{NULL, 5, 0, 0, 0, "general initialization"},
+	{&old_set, 5, 0, 0, 0, "setting old_value"},
+	{&old_set, 0, 5, 0, 0, "using periodic timer"},
+	{&old_set, 5, 0, 1, TIMER_ABSTIME, "using absolute time"},
+};
+
+static void run(unsigned int n)
+{
+	unsigned int i;
+	struct testcase *tc = &tcases[n];
+
+	tst_res(TINFO, "Testing for %s:", tc->description);
+
+	for (i = 0; i < CLOCKS_DEFINED; ++i) {
+		clock_t clock = clock_list[i];
+
+		if (clock == CLOCK_PROCESS_CPUTIME_ID ||
+			clock == CLOCK_THREAD_CPUTIME_ID) {
+			if (!have_cputime_timers())
+				continue;
+		}
+
+		TEST(tst_syscall(__NR_timer_create, clock, NULL, &timer));
+		if (TST_RET != 0) {
+			if (possibly_unsupported(clock) && TST_ERR == EINVAL) {
+				tst_res(TPASS | TTERRNO,
+					"%s unsupported, failed as expected",
+					get_clock_str(clock));
+			} else {
+				tst_res(TBROK | TTERRNO,
+					"timer_create(%s) failed",
+					get_clock_str(clock));
+			}
+			continue;
+		}
+
+		memset(&new_set, 0, sizeof(new_set));
+		memset(&old_set, 0, sizeof(old_set));
+
+		new_set.it_value.tv_sec = tc->it_value_tv_sec;
+		new_set.it_interval.tv_sec = tc->it_internal_tv_sec;
+
+		if (tc->check_clock_gettime) {
+			if (clock_gettime(clock, &timenow) < 0) {
+				tst_res(TBROK,
+					"clock_gettime(%s) failed - skipping the test",
+					get_clock_str(clock));
+				continue;
+			}
+			new_set.it_value.tv_sec = timenow.tv_sec + 25;
+		}
+
+		TEST(tst_syscall(__NR_timer_settime, timer,
+			tc->flag, &new_set, tc->old_ptr));
+
+		if (TST_RET != 0) {
+			tst_res(TFAIL | TTERRNO, "%s failed",
+					get_clock_str(clock));
+		} else {
+			tst_res(TPASS, "%s was successful",
+					get_clock_str(clock));
+		}
+
+		TEST(tst_syscall(__NR_timer_delete, timer));
+		if (TST_RET != 0)
+			tst_res(TFAIL | TTERRNO, "timer_delete() failed!");
+	}
+}
+
+static void sighandler(int sig)
+{
+	/* sighandler for CLOCK_*_ALARM */
+	tst_res(TINFO, "Caught signal %s", tst_strsig(sig));
+}
+
+static void setup(void)
+{
+	SAFE_SIGNAL(SIGALRM, sighandler);
+}
+
+static struct tst_test test = {
+	.test = run,
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+};
testcases/kernel/timers/timer_settime/timer_settime03.c +124 -190

314 lines not on this page · raw message

Signature · 1 line
2.16.4
#2 lore raw

PATCH 2/3 timers/timer_settime0{2, 3}: Ported to new library

Hi!
Pushed with a minor enhancements, thanks.

testcases/kernel/timers/timer_settime/timer_settime02.c +8 -9
index 36d9a745f..6c431c53d 100644
@@ -32,15 +32,14 @@ static kernel_timer_t timer;
 static struct testcase {
 	struct itimerspec	*old_ptr;
 	int			it_value_tv_sec;
-	int			it_internal_tv_sec;
-	int			check_clock_gettime;
+	int			it_interval_tv_sec;
 	int			flag;
 	char			*description;
 } tcases[] = {
-	{NULL, 5, 0, 0, 0, "general initialization"},
-	{&old_set, 5, 0, 0, 0, "setting old_value"},
-	{&old_set, 0, 5, 0, 0, "using periodic timer"},
-	{&old_set, 5, 0, 1, TIMER_ABSTIME, "using absolute time"},
+	{NULL,     5, 0, 0, "general initialization"},
+	{&old_set, 5, 0, 0, "setting old_value"},
+	{&old_set, 0, 5, 0, "using periodic timer"},
+	{&old_set, 5, 0, TIMER_ABSTIME, "using absolute time"},
 };
 
 static void run(unsigned int n)
@@ -77,16 +76,16 @@ static void run(unsigned int n)
 		memset(&old_set, 0, sizeof(old_set));
 
 		new_set.it_value.tv_sec = tc->it_value_tv_sec;
-		new_set.it_interval.tv_sec = tc->it_internal_tv_sec;
+		new_set.it_interval.tv_sec = tc->it_interval_tv_sec;
 
-		if (tc->check_clock_gettime) {
+		if (tc->flag & TIMER_ABSTIME) {
 			if (clock_gettime(clock, &timenow) < 0) {
 				tst_res(TBROK,
 					"clock_gettime(%s) failed - skipping the test",
 					get_clock_str(clock));
 				continue;
 			}
-			new_set.it_value.tv_sec = timenow.tv_sec + 25;
+			new_set.it_value.tv_sec += timenow.tv_sec;
 		}
 
 		TEST(tst_syscall(__NR_timer_settime, timer,
testcases/kernel/timers/timer_settime/timer_settime03.c +2 -7
index 80861995f..bc3a0f2c8 100644
@@ -26,7 +26,8 @@
 #include "common_timers.h"
 
 static struct itimerspec new_set, old_set;
-static kernel_timer_t timer, timer_inval;
+static kernel_timer_t timer;
+static kernel_timer_t timer_inval = -1;
 
 /* separate description-array to (hopefully) improve readability */
 static const char * const descriptions[] = {
@@ -111,14 +112,8 @@ static void run(unsigned int n)
 	}
 }
 
-static void setup(void)
-{
-	timer_inval = -1;
-}
-
 static struct tst_test test = {
 	.test = run,
 	.needs_root = 1,
 	.tcnt = ARRAY_SIZE(tcases),
-	.setup = setup,
 };
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 3/3 timers/leapsec_timer: Ported to new library

In reply to Christian Amann

Ported the test to the new library

Notes:
The leapsec timer is still a mess, even after porting it. Cleaning it up would probably be its own patch as the best solution would be to rewrite it from scratch

---
 testcases/kernel/timers/include/common_timers.h |   1 -
 testcases/kernel/timers/leapsec/leapsec_timer.c | 174 +++++++++++-------------
 2 files changed, 80 insertions(+), 95 deletions(-)
testcases/kernel/timers/include/common_timers.h +0 -1
index 154be670f..df4196eeb 100644
@@ -7,7 +7,6 @@
 #ifndef __COMMON_TIMERS_H__
 #define __COMMON_TIMERS_H__
 
-#define CLEANUP cleanup
 #include "config.h"
 #include "lapi/syscalls.h"
 #include "lapi/posix_clocks.h"
testcases/kernel/timers/leapsec/leapsec_timer.c +80 -94

267 lines not on this page · raw message

Signature · 1 line
2.16.4