linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tarun Sahu <tsahu@linux.ibm.com>
To: ltp@lists.linux.it, linux-kselftest@vger.kernel.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, aneesh.kumar@linux.ibm.com,
	Tarun Sahu <tsahu@linux.ibm.com>
Subject: [RFC PATCH] Hugetlb: Migrating hugetlb tests from libhugetlbfs
Date: Thu,  8 Sep 2022 23:09:47 +0530	[thread overview]
Message-ID: <20220908173947.17956-1-tsahu@linux.ibm.com> (raw)

Libhugetlbfs is not being maintained actively, and some distro is
dropping support for it. There are some tests that are good for testing
hugetlb functionality in kernel, which can be migrated to either kernel
kselftests or LTP.
I am submitting this patch to get comments from community on the
following
    1. The test framework in ltp is most suitable for the tests that are
    in libhugetlbfs/tests/ which follow similar test framework. And there
    is already a section for hugetlb specific tests in LTP. So it makes
    more sense and less effort to migrate the test to LTP. Though I
    recommend migrating these tests to LTP, I would like to discuss tests
    should be migrated to LTP or kselftests.
    2. Libhugetlbfs tests has license GNU Lesser GPL 2.1 or later, while
    kernel and LTP has license GPL2 or later, so can the test be
    migrated to kernel/kselftests or LTP.

The below patch is libhugetlbfs/tests/direct.c which has been migrated
to ltp/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   2 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap07.c  | 106 ++++++++++++++++++
 3 files changed, 109 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index f719217ab..ee02835d3 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -3,6 +3,8 @@ hugemmap02 hugemmap02
 hugemmap04 hugemmap04
 hugemmap05 hugemmap05
 hugemmap06 hugemmap06
+hugemmap07 hugemmap07
+
 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 ff2910533..df5256ec8 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -4,6 +4,7 @@
 /hugetlb/hugemmap/hugemmap04
 /hugetlb/hugemmap/hugemmap05
 /hugetlb/hugemmap/hugemmap06
+/hugetlb/hugemmap/hugemmap07
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
new file mode 100644
index 000000000..798735ed0
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
@@ -0,0 +1,106 @@
+/*
+ * License/Copyright Details
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "tst_test.h"
+
+#define P0 "ffffffff"
+#define IOSZ 4096
+char buf[IOSZ] __attribute__((aligned(IOSZ)));
+static int  fildes = -1, nfildes = -1;
+static char TEMPFILE[MAXPATHLEN];
+static char NTEMPFILE[MAXPATHLEN];
+
+void test_directio(void)
+{
+	long hpage_size;
+	void *p;
+	int ret;
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:");
+
+	fildes = SAFE_OPEN(TEMPFILE, O_RDWR | O_CREAT, 0600);
+	nfildes = SAFE_OPEN(NTEMPFILE, O_CREAT|O_EXCL|O_RDWR|O_DIRECT, 0600);
+
+	p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fildes, 0);
+	if (p == MAP_FAILED)
+		tst_brk(TFAIL | TERRNO, "mmap() Failed on %s", TEMPFILE);
+
+	memcpy(p, P0, 8);
+
+	/* Direct write from huge page */
+	ret = write(nfildes, p, IOSZ);
+	if (ret == -1)
+		tst_brk(TFAIL | TERRNO, "Direct-IO write from huge page");
+	if (ret != IOSZ)
+		tst_brk(TFAIL, "Short direct-IO write from huge page");
+	if (lseek(nfildes, 0, SEEK_SET) == -1)
+		tst_brk(TFAIL | TERRNO, "lseek");
+
+	/* Check for accuracy */
+	ret = read(nfildes, buf, IOSZ);
+	if (ret == -1)
+		tst_brk(TFAIL | TERRNO, "Direct-IO read to normal memory");
+	if (ret != IOSZ)
+		tst_brk(TFAIL, "Short direct-IO read to normal memory");
+	if (memcmp(P0, buf, 8))
+		tst_brk(TFAIL, "Memory mismatch after Direct-IO write");
+	if (lseek(nfildes, 0, SEEK_SET) == -1)
+		tst_brk(TFAIL | TERRNO, "lseek");
+
+	/* Direct read to huge page */
+	memset(p, 0, IOSZ);
+	ret = read(nfildes, p, IOSZ);
+	if (ret == -1)
+		tst_brk(TFAIL | TERRNO, "Direct-IO read to huge page");
+	if (ret != IOSZ)
+		tst_brk(TFAIL, "Short direct-IO read to huge page");
+
+	/* Check for accuracy */
+	if (memcmp(p, P0, 8))
+		tst_brk(TFAIL, "Memory mismatch after Direct-IO read");
+	tst_res(TPASS, "Successfully tested Hugepage Direct I/O");
+}
+
+void setup(void)
+{
+	if (tst_hugepages == 0)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid());
+	snprintf(NTEMPFILE, sizeof(NTEMPFILE), "%s/nmmapfile%d", "/home/", getpid());
+}
+
+void cleanup(void)
+{
+	close(fildes);
+	close(nfildes);
+	remove(TEMPFILE);
+	remove(NTEMPFILE);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"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 = test_directio,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1



             reply	other threads:[~2022-09-08 17:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-08 17:39 Tarun Sahu [this message]
2022-09-09  9:06 ` [LTP] [RFC PATCH] Hugetlb: Migrating hugetlb tests from libhugetlbfs Cyril Hrubis
2022-09-12  8:33   ` Tarun Sahu
2022-09-12  8:43     ` Cyril Hrubis
2022-09-12 10:06       ` Tarun Sahu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220908173947.17956-1-tsahu@linux.ibm.com \
    --to=tsahu@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).