[LTP] [PATCH v2 08/13] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv

Tarun Sahu tsahu@linux.ibm.com
Wed Jan 4 13:22:19 CET 2023


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>
Reviewed-by: Li Wang <liwang@redhat.com>

---
 runtest/hugetlb                               |  1 +
 testcases/kernel/mem/.gitignore               |  1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap28.c  | 66 +++++++++++++++++++
 3 files changed, 68 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index d108542d2..95afe009e 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..060d1c858
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 LG Electronics.
+ * Author: Joonsoo Kim
+ */
+
+/*\
+ * [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.
+ */
+
+#include "hugetlb.h"
+
+#define MNTPOINT "hugetlbfs/"
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+	unsigned long initial_resv, end_resv;
+	int fd;
+	char *p, *q;
+
+	initial_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+
+	fd = tst_creat_unlinked(MNTPOINT, 0);
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+	q = SAFE_MMAP(NULL, hpage_size,
+		PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0);
+
+	*q = 's';
+
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(q, hpage_size);
+	SAFE_CLOSE(fd);
+
+	end_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+
+	TST_EXP_EQ_LU(initial_resv, end_resv);
+}
+
+static void setup(void)
+{
+	hpage_size = tst_get_hugepage_size();
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_NEEDS},
+};
-- 
2.31.1



More information about the ltp mailing list