All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Gongyi <zhaogongyi@huawei.com>
To: <linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <keescook@chromium.org>, <luto@amacapital.net>,
	<wad@chromium.org>, <shuah@kernel.org>, <zhaogongyi@huawei.com>,
	<cristian.marussi@arm.com>
Subject: [PATCH -next 1/2] selftests/mincore: Add checking of block dev for TEST(check_file_mmap)
Date: Fri, 21 Oct 2022 15:10:51 +0800	[thread overview]
Message-ID: <20221021071052.143393-1-zhaogongyi@huawei.com> (raw)

TEST(check_file_mmap) will fail when we run the test on tmpfs and report:
  mincore_selftest.c:261:check_file_mmap:Expected ra_pages (0) > 0 (0)
  mincore_selftest.c:262:check_file_mmap:No read-ahead pages found in memory

For some embaded system, maybe there is only tmpfs file system exist,
run the test will fail, or we install the test on a filesystem that
has no backend, also it will fail as unepected.

So add a checking of block dev for the filesystem at first.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../selftests/mincore/mincore_selftest.c      | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/tools/testing/selftests/mincore/mincore_selftest.c b/tools/testing/selftests/mincore/mincore_selftest.c
index 4c88238fc8f0..287351a599a2 100644
--- a/tools/testing/selftests/mincore/mincore_selftest.c
+++ b/tools/testing/selftests/mincore/mincore_selftest.c
@@ -14,6 +14,9 @@
 #include <sys/mman.h>
 #include <string.h>
 #include <fcntl.h>
+#include <mntent.h>
+#include <sys/stat.h>
+#include <linux/fs.h>

 #include "../kselftest.h"
 #include "../kselftest_harness.h"
@@ -173,6 +176,43 @@ TEST(check_huge_pages)
 	munmap(addr, page_size);
 }

+static struct mntent* find_mount_point(const char *name)
+{
+	struct stat s;
+	FILE *mtab_fp;
+	struct mntent *mountEntry;
+	dev_t devno_of_name;
+
+	if (stat(name, &s) != 0)
+		return NULL;
+
+	devno_of_name = s.st_dev;
+
+	mtab_fp = setmntent("/proc/mounts", "r");
+	if (!mtab_fp)
+		return NULL;
+
+	while ((mountEntry = getmntent(mtab_fp)) != NULL) {
+		if (strcmp(name, mountEntry->mnt_dir) == 0
+			|| strcmp(name, mountEntry->mnt_fsname) == 0) {
+			break;
+		}
+
+		if (mountEntry->mnt_fsname[0] == '/'
+			&& stat(mountEntry->mnt_fsname, &s) == 0
+			&& s.st_rdev == devno_of_name) {
+			break;
+		}
+
+		if (stat(mountEntry->mnt_dir, &s) == 0
+				&& s.st_dev == devno_of_name) {
+			break;
+		}
+	}
+	endmntent(mtab_fp);
+
+	return mountEntry;
+}

 /*
  * Test mincore() behavior on a file-backed page.
@@ -194,6 +234,19 @@ TEST(check_file_mmap)
 	int fd;
 	int i;
 	int ra_pages = 0;
+	struct stat s;
+	struct mntent *mount_entry;
+
+	mount_entry = find_mount_point(".");
+	ASSERT_NE(NULL, mount_entry) {
+		TH_LOG("Find mount point of '.' failed");
+	}
+
+	ASSERT_EQ(0, (stat(mount_entry->mnt_fsname, &s) != 0
+		|| !S_ISBLK(s.st_mode))) {
+		TH_LOG("There is no a block dev on mount point, "
+			"test is not supported");
+	}

 	page_size = sysconf(_SC_PAGESIZE);
 	vec_size = FILE_SIZE / page_size;
--
2.17.1


             reply	other threads:[~2022-10-21  7:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21  7:10 Zhao Gongyi [this message]
2022-10-21  7:10 ` [PATCH -next 2/2] selftests/mincore: Optimize TEST(check_file_mmap) accoring to filemap read around Zhao Gongyi

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=20221021071052.143393-1-zhaogongyi@huawei.com \
    --to=zhaogongyi@huawei.com \
    --cc=cristian.marussi@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=shuah@kernel.org \
    --cc=wad@chromium.org \
    /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 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.