[LTP] [PATCH v1] Refactor timerfd_create01 using new LTP API

Andrea Cervesato andrea.cervesato@suse.de
Mon Sep 4 16:04:24 CEST 2023


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

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 .../syscalls/timerfd/timerfd_create01.c       | 99 +++++--------------
 1 file changed, 22 insertions(+), 77 deletions(-)

diff --git a/testcases/kernel/syscalls/timerfd/timerfd_create01.c b/testcases/kernel/syscalls/timerfd/timerfd_create01.c
index 3d70b84f0..18a233586 100644
--- a/testcases/kernel/syscalls/timerfd/timerfd_create01.c
+++ b/testcases/kernel/syscalls/timerfd/timerfd_create01.c
@@ -1,95 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2014 Fujitsu Ltd.
- * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
- *
- * 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.
+ *         Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
-/*
- * DESCRIPTION
- *  Verify that,
- *   1. The clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME,
- *	EINVAL would return.
- *   2. flags is invalid, EINVAL would return.
+/*\
+ * [Description]
+ *
+ * This test verifies that:
+ * - clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME,
+ * EINVAL would return.
+ * - flags is invalid, EINVAL would return.
  */
 
-#define _GNU_SOURCE
-
 #include <errno.h>
 
-#include "test.h"
-#include "lapi/timerfd.h"
-
-char *TCID = "timerfd_create01";
+#include "tst_test.h"
+#include "tst_safe_timerfd.h"
 
 static struct test_case_t {
 	int clockid;
 	int flags;
 	int exp_errno;
-} test_cases[] = {
-	{-1, 0, EINVAL},
-	{0, -1, EINVAL},
+} tcases[] = {
+	{ -1,  0, EINVAL },
+	{  0, -1, EINVAL },
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-static void setup(void);
-static void timerfd_create_verify(const struct test_case_t *);
-static void cleanup(void);
-
-int main(int argc, char *argv[])
+static void run(unsigned int i)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
+	struct test_case_t *test = &tcases[i];
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			timerfd_create_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(timerfd_create(test->clockid, test->flags), test->exp_errno);
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void timerfd_create_verify(const struct test_case_t *test)
-{
-	TEST(timerfd_create(test->clockid, test->flags));
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "timerfd_create() succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == test->exp_errno) {
-		tst_resm(TPASS | TTERRNO,
-			 "timerfd_create() failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "timerfd_create() failed unexpectedly; expected: "
-			 "%d - %s", test->exp_errno, strerror(test->exp_errno));
-	}
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+};
-- 
2.35.3



More information about the ltp mailing list