[LTP] [PATCH 24/29] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv
Tarun Sahu
tsahu@linux.ibm.com
Sun Oct 16 14:57:26 CEST 2022
Migrating the libhugetlbfs/testcases/noresv-regarded-as-resv.c test
Test Description: Test to correct handling for reserve count. If no
reserved mapping is created to reserved file region, it should be
considered as reserve mapping. Otherwise, reserve count will be
overflowed.
Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../kernel/mem/hugetlb/hugemmap/hugemmap28.c | 107 ++++++++++++++++++
3 files changed, 109 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index c1c2c38bf..f9a9501b7 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -28,6 +28,7 @@ hugemmap23 hugemmap23
hugemmap25 hugemmap25
hugemmap26 hugemmap26
hugemmap27 hugemmap27
+hugemmap28 hugemmap28
hugemmap05_1 hugemmap05 -m
hugemmap05_2 hugemmap05 -s
hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 9862414c6..2f8ed0df0 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -27,6 +27,7 @@
/hugetlb/hugemmap/hugemmap25
/hugetlb/hugemmap/hugemmap26
/hugetlb/hugemmap/hugemmap27
+/hugetlb/hugemmap/hugemmap28
/hugetlb/hugeshmat/hugeshmat01
/hugetlb/hugeshmat/hugeshmat02
/hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
new file mode 100644
index 000000000..55399c3b6
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
+ *
+ * Test Name: noresv-regarded-as-resv
+ *
+ * Test Description: Test to correct handling for reserve count. If no
+ * reserved mapping is created to reserved file region, it should be
+ * considered as reserve mapping. Otherwise, reserve count will be
+ * overflowed.
+ *
+ * HISTORY
+ * Written by Joonsoo Kim
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+ int nr_resvpages1, nr_resvpages2;
+ int fd;
+ char *p, *q;
+
+ nr_resvpages1 = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+ if (verbose)
+ tst_res(TINFO, "Number of reserve page is %d\n", nr_resvpages1);
+
+ fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+ SAFE_UNLINK(hfile);
+
+ p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ if (verbose)
+ tst_res(TINFO, "Reserve a page to file offset 0");
+
+ q = SAFE_MMAP(NULL, hpage_size,
+ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0);
+
+ if (verbose)
+ tst_res(TINFO, "Map a page of file offset 0 with no resv mapping");
+ *q = 's';
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_MUNMAP(q, hpage_size);
+ SAFE_CLOSE(fd);
+
+ nr_resvpages2 = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+ if (verbose)
+ tst_res(TINFO, "Number of reserve page is now %d\n", nr_resvpages2);
+
+ if (nr_resvpages1 != nr_resvpages2) {
+ tst_res(TFAIL, "Reserve count overflowed");
+ tst_brk(TBROK, "Once failed, No point in continuing the test");
+ }
+
+ tst_res(TPASS, "Successful");
+}
+
+static void setup(void)
+{
+ if (tst_hugepages < 2)
+ tst_brk(TCONF, "Not enough hugepages for testing.");
+
+ if (!Hopt)
+ Hopt = tst_get_tmpdir();
+ SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+ snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlb1file%d", Hopt, getpid());
+
+ hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+ if (fd >= 0)
+ SAFE_CLOSE(fd);
+ umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .options = (struct tst_option[]) {
+ {"v", &verbose, "Turns on verbose mode"},
+ {"H:", &Hopt, "Location of hugetlbfs, i.e. -H /var/hugetlbfs"},
+ {"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+ {}
+ },
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {2, TST_REQUEST},
+};
--
2.31.1
More information about the ltp
mailing list