[LTP] [PATCH 1/2] getrlimit/getrlimit01: Convert to new API

tangmeng tangmeng@uniontech.com
Thu Nov 4 00:56:30 CET 2021


Signed-off-by: tangmeng <tangmeng@uniontech.com>
---
 .../kernel/syscalls/getrlimit/getrlimit01.c   | 90 +++++--------------
 1 file changed, 23 insertions(+), 67 deletions(-)

diff --git a/testcases/kernel/syscalls/getrlimit/getrlimit01.c b/testcases/kernel/syscalls/getrlimit/getrlimit01.c
index 68e8bf818..0f7c2150f 100644
--- a/testcases/kernel/syscalls/getrlimit/getrlimit01.c
+++ b/testcases/kernel/syscalls/getrlimit/getrlimit01.c
@@ -1,41 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
  *   Author: Suresh Babu V. <suresh.babu@wipro.com>
- *
- *   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
  */

-/*
+/*\
+ * [Description]
+ *
  * Verify that getrlimit(2) call will be successful for all possible resource
  * types.
  */
-#include <stdio.h>
-#include <errno.h>
-#include <sys/time.h>
 #include <sys/resource.h>
-#include "test.h"
-
-static void cleanup(void);
-static void setup(void);
+#include "tst_test.h"

 static struct rlimit rlim;
-static struct test_t {
+static struct tcase {
 	int res;
 	char *res_str;
-} testcases[] = {
+} tcases[] = {
 	{RLIMIT_CPU, "RLIMIT_CPU"},
 	{RLIMIT_FSIZE, "RLIMIT_FSIZE"},
 	{RLIMIT_DATA, "RLIMIT_DATA"},
@@ -60,49 +42,23 @@ static struct test_t {
 #endif
 };

-char *TCID = "getrlimit01";
-int TST_TOTAL = ARRAY_SIZE(testcases);
-
-int main(int ac, char **av)
+static void verify_getrlimit(unsigned int i)
 {
-	int i;
-	int lc;
-
-	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) {
-
-			TEST(getrlimit(testcases[i].res, &rlim));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL | TTERRNO,
-					 "getrlimit() test %s failed",
-					 testcases[i].res_str);
-			} else {
-				tst_resm(TPASS,
-					 "getrlimit() test %s success",
-					 testcases[i].res_str);
-			}
-		}
+	struct tcase *tc = &tcases[i];
+	TEST(getrlimit(tc->res, &rlim));
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO,
+			 "getrlimit() test %s failed",
+			 tc->res_str);
+	} else {
+		tst_res(TPASS,
+			 "getrlimit() test %s success",
+			 tc->res_str);
 	}
-
-	cleanup();
-	tst_exit();
 }

-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_getrlimit,
+};
--
2.20.1





More information about the ltp mailing list