From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 3/3] test: dirfs: use ramfs rather than devfs
Date: Wed, 10 Dec 2025 11:16:01 +0100 [thread overview]
Message-ID: <20251210-devfs-prep-v1-3-3a2a3aa27eab@pengutronix.de> (raw)
In-Reply-To: <20251210-devfs-prep-v1-0-3a2a3aa27eab@pengutronix.de>
devfs as a filesystem is going away, so do not use it in the dirfd test.
Switch to ramfs, but this means we have to mount it ourselves. This
has the advantage though that it might reveal some bugs in the fs layer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
test/self/dirfd.c | 46 +++++++++++++++++++++++++++++++++-------------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/test/self/dirfd.c b/test/self/dirfd.c
index 1f9b375e84ffa948a511b7ad94cd40fabeee4af3..04cbf6e285f3184f3e5b1680271aabffc272c8be 100644
--- a/test/self/dirfd.c
+++ b/test/self/dirfd.c
@@ -9,6 +9,7 @@
#include <linux/bitfield.h>
#include <unistd.h>
#include <bselftest.h>
+#include <libfile.h>
BSELFTEST_GLOBALS();
@@ -26,7 +27,7 @@ BSELFTEST_GLOBALS();
static void check_statat(const char *at, int dirfd, const char *prefix, unsigned expected)
{
- static const char *paths[] = { ".", "..", "zero", "dev" };
+ static const char *paths[] = { ".", "..", "testfile", "dirfdtest" };
struct stat s;
for (int i = 0; i < ARRAY_SIZE(paths); i++) {
@@ -63,9 +64,9 @@ static void check_statat(const char *at, int dirfd, const char *prefix, unsigned
fullpath, at, testpath))
goto next;
- ret = strcmp_ptr(fsdev1->path, "/dev");
+ ret = strcmp_ptr(fsdev1->path, "/dirfdtest");
if (!expect(ret == 0, FIELD_GET(BIT(0), expected),
- "fsdev_of(%s)->path = %s != /dev", fullpath, fsdev1->path))
+ "fsdev_of(%s)->path = %s != /dirfdtest", fullpath, fsdev1->path))
goto next;
next:
@@ -84,9 +85,9 @@ static void do_test_dirfd(const char *at, int dirfd,
check_statat(at, dirfd, "", expected1);
check_statat(at, dirfd, "./", expected1);
- check_statat(at, dirfd, "/dev/", expected2);
- check_statat(at, dirfd, "/dev/./", expected2);
- check_statat(at, dirfd, "/dev/../dev/", expected2);
+ check_statat(at, dirfd, "/dirfdtest/", expected2);
+ check_statat(at, dirfd, "/dirfdtest/./", expected2);
+ check_statat(at, dirfd, "/dirfdtest/../dirfdtest/", expected2);
check_statat(at, dirfd, "/", expected3);
check_statat(at, dirfd, "../", expected4);
@@ -97,19 +98,31 @@ static void do_test_dirfd(const char *at, int dirfd,
static void test_dirfd(void)
{
- int fd;
+ int fd, ret;
fd = open("/", O_PATH | O_DIRECTORY);
- if (expect(fd < 0, false, "open(/, O_PATH | O_DIRECTORY) = %d", fd))
+ if (!expect(fd < 0, false, "open(/, O_PATH | O_DIRECTORY) = %d", fd))
close(fd);
+ ret = make_directory("/dirfdtest");
+ if (!expect(ret == 0, true, "make_directory(\"/dirfdtest\") = %d", ret))
+ return;
+
+ ret = mount("none", "ramfs", "/dirfdtest", NULL);
+ if (!expect(ret == 0, true, "mount(\"none\", \"ramfs\", \"/dirfdtest\") = %d", ret))
+ goto out;
+
+ ret = write_file("/dirfdtest/testfile", __func__, strlen(__func__));
+ if (!expect(ret == 0, true, "write_file() = %d", ret))
+ goto out;
+
#define B(dot, dotdot, zero, dev) 0b##dev##zero##dotdot##dot
/* We do fiften tests for every configuration
- * for dir in ./ /dev / ../ ; do
- * for file in . .. zero dev ; do
+ * for dir in ./ /dirfdtest / ../ ; do
+ * for file in . .. zero dirfdtest ; do
* test if file exists
* test if file can be canonicalized
- * test if parent FS is mounted at /dev
+ * test if parent FS is mounted at /dirfdtest
* done
* done
*
@@ -119,11 +132,18 @@ static void test_dirfd(void)
do_test_dirfd("AT_FDCWD", AT_FDCWD,
B(110,110,000,111), B(111,110,111,000),
B(110,110,000,111), B(110,110,000,111));
- do_test_dirfd("/dev", open("/dev", O_PATH | O_DIRECTORY),
+ do_test_dirfd("/dirfdtest", open("/dirfdtest", O_PATH | O_DIRECTORY),
B(111,110,111,000), B(111,110,111,000),
B(110,110,000,111), B(110,110,000,111));
- do_test_dirfd("/dev O_CHROOT", open("/dev", O_PATH | O_CHROOT),
+ do_test_dirfd("/dirfdtest O_CHROOT", open("/dirfdtest", O_PATH | O_CHROOT),
B(111,111,111,000), B(000,000,000,000),
B(111,111,111,000), B(111,111,111,000));
+
+out:
+ ret = umount("/dirfdtest");
+ expect(ret == 0, true, "umount(\"/dirfdtest\") = %d", ret);
+
+ ret = rmdir("/dirfdtest");
+ expect(ret == 0, true, "rmdir(\"/dirfdtest\") = %d", ret);
}
bselftest(core, test_dirfd);
--
2.47.3
next prev parent reply other threads:[~2025-12-10 10:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 10:15 [PATCH 0/3] selftest: preparations for devfs changes Sascha Hauer
2025-12-10 10:15 ` [PATCH 1/3] fs: get path in path_init() Sascha Hauer
2025-12-10 10:16 ` [PATCH 2/3] fs: warn when mount reference count becomes negative Sascha Hauer
2025-12-10 10:16 ` Sascha Hauer [this message]
2025-12-15 9:30 ` [PATCH 0/3] selftest: preparations for devfs changes Sascha Hauer
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=20251210-devfs-prep-v1-3-3a2a3aa27eab@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox