All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] mmap14: Convert to new API
@ 2024-10-25 19:37 Ricardo B. Marliere via ltp
  2024-10-30 16:21 ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Ricardo B. Marliere via ltp @ 2024-10-25 19:37 UTC (permalink / raw)
  To: ltp

Signed-off-by: Ricardo B. Marliere <rbm@suse.com>
---
 testcases/kernel/syscalls/mmap/mmap14.c | 97 ++++++++++-----------------------
 1 file changed, 30 insertions(+), 67 deletions(-)

diff --git a/testcases/kernel/syscalls/mmap/mmap14.c b/testcases/kernel/syscalls/mmap/mmap14.c
index 31632601bbed85b60f1dfee7044bf961b1f2a756..63a2f9e4cab2f7ab12b1ad982bc690f9fabcc252 100644
--- a/testcases/kernel/syscalls/mmap/mmap14.c
+++ b/testcases/kernel/syscalls/mmap/mmap14.c
@@ -1,22 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2013 FNST, DAN LI <li.dan@cn.fujitsu.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]
+ *
  * Test Description:
  *  Verify MAP_LOCKED works fine.
  *  "Lock the pages of the mapped region into memory in the manner of mlock(2)."
@@ -28,65 +18,45 @@
 #include <stdio.h>
 #include <sys/mman.h>
 
-#include "test.h"
+#include "tst_test.h"
 
 #define TEMPFILE        "mmapfile"
 #define MMAPSIZE        (1UL<<20)
 #define LINELEN         256
 
-char *TCID = "mmap14";
-int TST_TOTAL = 1;
-
 static char *addr;
 
 static void getvmlck(unsigned int *lock_sz);
-static void setup(void);
-static void cleanup(void);
 
-int main(int argc, char *argv[])
+static void run(unsigned int n)
 {
-	int lc;
 	unsigned int sz_before;
 	unsigned int sz_after;
 	unsigned int sz_ch;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		getvmlck(&sz_before);
+	getvmlck(&sz_before);
 
-		addr = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE,
-			    MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS,
-			    -1, 0);
+	addr = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS,
+			-1, 0);
 
-		if (addr == MAP_FAILED) {
-			tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
-			continue;
-		}
+	if (addr == MAP_FAILED)
+		tst_res(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
 
-		getvmlck(&sz_after);
+	getvmlck(&sz_after);
 
-		sz_ch = sz_after - sz_before;
-		if (sz_ch == MMAPSIZE / 1024) {
-			tst_resm(TPASS, "Functionality of mmap() "
-					"successful");
-		} else {
-			tst_resm(TFAIL, "Expected %luK locked, "
-					"get %uK locked",
-					MMAPSIZE / 1024, sz_ch);
-		}
-
-		if (munmap(addr, MMAPSIZE) != 0)
-			tst_brkm(TFAIL | TERRNO, NULL, "munmap failed");
+	sz_ch = sz_after - sz_before;
+	if (sz_ch == MMAPSIZE / 1024) {
+		tst_res(TPASS, "Functionality of mmap() "
+				"successful");
+	} else {
+		tst_res(TFAIL, "Expected %luK locked, "
+				"get %uK locked",
+				MMAPSIZE / 1024, sz_ch);
 	}
 
-	cleanup();
-	tst_exit();
+	if (munmap(addr, MMAPSIZE) != 0)
+		tst_res(TFAIL | TERRNO, "munmap failed");
 }
 
 void getvmlck(unsigned int *lock_sz)
@@ -97,7 +67,7 @@ void getvmlck(unsigned int *lock_sz)
 
 	fstatus = fopen("/proc/self/status", "r");
 	if (fstatus == NULL)
-		tst_brkm(TFAIL | TERRNO, NULL, "Open dev status failed");
+		tst_res(TFAIL | TERRNO, "Open dev status failed");
 
 	while (fgets(line, LINELEN, fstatus) != NULL)
 		if (strstr(line, "VmLck") != NULL)
@@ -105,20 +75,13 @@ void getvmlck(unsigned int *lock_sz)
 
 	ret = sscanf(line, "%*[^0-9]%d%*[^0-9]", lock_sz);
 	if (ret != 1)
-		tst_brkm(TFAIL | TERRNO, NULL, "Get lock size failed");
+		tst_res(TFAIL | TERRNO, "Get lock size failed");
 
 	fclose(fstatus);
 }
 
-static void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.test = run,
+	.tcnt = 1,
+};

---
base-commit: 34e6dd2d233abcebae435d34d793b6a49d08c190
change-id: 20241025-convert_mmap14-93b0a247741e

Best regards,
-- 
Ricardo B. Marliere <rbm@suse.com>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2024-10-30 19:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 19:37 [LTP] [PATCH] mmap14: Convert to new API Ricardo B. Marliere via ltp
2024-10-30 16:21 ` Petr Vorel
2024-10-30 19:37   ` Ricardo B. Marliere via ltp

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.