[LTP] [PATCH v1] Refactor timer_getoverrun test using new LTP API

Andrea Cervesato andrea.cervesato@suse.de
Mon Sep 4 13:00:28 CEST 2023


From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 .../kernel/syscalls/timer_getoverrun/Makefile |   2 +
 .../timer_getoverrun/timer_getoverrun01.c     | 106 +++++-------------
 2 files changed, 32 insertions(+), 76 deletions(-)

diff --git a/testcases/kernel/syscalls/timer_getoverrun/Makefile b/testcases/kernel/syscalls/timer_getoverrun/Makefile
index 1273a4e9c..58376e379 100644
--- a/testcases/kernel/syscalls/timer_getoverrun/Makefile
+++ b/testcases/kernel/syscalls/timer_getoverrun/Makefile
@@ -5,4 +5,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+LDLIBS			:= -lrt $(LDLIBS)
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
index aa9881f27..cb221268d 100644
--- a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
+++ b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
@@ -1,88 +1,42 @@
-/******************************************************************************
- * Copyright (c) Crackerjack Project., 2007                                   *
- * Porting from Crackerjack to LTP is done by:                                *
- *              Manas Kumar Nayak <maknayak@in.ibm.com>                       *
- * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>                          *
- *                                                                            *
- * 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           *
- *                                                                            *
- ******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2001
+ * Porting from Crackerjack to LTP is done by:
+ *              Manas Kumar Nayak <maknayak@in.ibm.com>
+ *
+ * Copyright (c) Linux Test Project, 2009-2023
+ * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test checks base timer_getoverrun() functionality.
+ */
 
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
 #include <signal.h>
-#include <sys/syscall.h>
-
-#include "test.h"
+#include "tst_test.h"
+#include "tst_safe_clocks.h"
 #include "lapi/syscalls.h"
 
-char *TCID = "timer_getoverrun01";
-int TST_TOTAL = 1;
-
-static void cleanup(void)
-{
-
-	tst_rmdir();
-}
-
-static void setup(void)
+static void run(void)
 {
-	TEST_PAUSE;
-	tst_tmpdir();
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-	int timer;
+	timer_t timer;
 	struct sigevent ev;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
 	ev.sigev_value = (union sigval) 0;
-	ev.sigev_signo = SIGALRM;
 	ev.sigev_notify = SIGEV_SIGNAL;
-	TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));
-
-	if (TEST_RETURN != 0)
-		tst_brkm(TBROK | TTERRNO, cleanup, "Failed to create timer");
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-
-		TEST(tst_syscall(__NR_timer_getoverrun, timer));
-		if (TEST_RETURN == 0) {
-			tst_resm(TPASS,
-			         "timer_getoverrun(CLOCK_REALTIME) Passed");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-			         "timer_getoverrun(CLOCK_REALTIME) Failed");
-		}
+	ev.sigev_signo = SIGALRM;
 
-		TEST(tst_syscall(__NR_timer_getoverrun, -1));
-		if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) {
-			tst_resm(TPASS,	"timer_gettime(-1) Failed: EINVAL");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-			         "timer_gettime(-1) = %li", TEST_RETURN);
-		}
-	}
+	TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));
+	if (TST_RET)
+		tst_brk(TBROK | TERRNO, "timer_create() error");
 
-	cleanup();
-	tst_exit();
+	TST_EXP_POSITIVE(tst_syscall(__NR_timer_getoverrun, timer));
+	TST_EXP_FAIL(tst_syscall(__NR_timer_getoverrun, -1), EINVAL);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+};
-- 
2.35.3



More information about the ltp mailing list