mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir
@ 2025-01-08  9:14 Ahmad Fatoum
  2025-01-08  9:14 ` [PATCH master 2/2] fs: fix resolving paths when directory name repeats Ahmad Fatoum
  2025-01-08 14:17 ` [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-01-08  9:14 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Recursive opendir with parent and child directory having the same name
is currently broken. Add a failing test, which will be fixed in the
follow-up commit.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/self/ramfs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)

diff --git a/test/self/ramfs.c b/test/self/ramfs.c
index 239e3e690740..3fb3812cb629 100644
--- a/test/self/ramfs.c
+++ b/test/self/ramfs.c
@@ -51,6 +51,44 @@ static inline int get_file_count(int i)
 	return i + 1;
 }
 
+struct test_tree_ctx {
+	unsigned nfiles;
+	unsigned ndirs;
+};
+
+static void test_tree(const char *path, struct test_tree_ctx *ctx)
+{
+	DIR *dir;
+	struct dirent *d;
+	char *oldwd;
+
+	dir = opendir(path);
+	if (!dir)
+		return;
+
+	oldwd = pushd(path);
+
+	while ((d = readdir(dir))) {
+		struct stat st;
+
+		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+			continue;
+
+		if (stat(d->d_name, &st))
+			continue;
+
+		if (S_ISDIR(st.st_mode))
+			ctx->ndirs++;
+		else if (S_ISREG(st.st_mode))
+			ctx->nfiles++;
+
+		test_tree(d->d_name, ctx);
+
+	}
+
+	popd(oldwd);
+}
+
 static void test_ramfs(void)
 {
 	int files[] = { 1, 3, 5, 7, 11, 13, 17 };
@@ -180,24 +218,34 @@ static void test_ramfs(void)
 	expect_success(i == 90 ? 0 : -EINVAL,
 		       "unexpected file count iterating directory: %u", i);
 
-	ret = make_directory("test/a/b/c/d/e/f/g/h/i/j/k/l");
+	ret = make_directory("test/a/b/c/d/d/f/g/h/i/j/k/l");
 	expect_success(ret, "make_directory()");
 
 	if (!ret) {
+		struct test_tree_ctx ctx = {};
 		const char hello[] = "hello";
 		char *buf;
 
-		ret = write_file("test/a/b/c/d/e/f/g/h/i/j/k/l/FILE",
+		ret = write_file("test/a/b/c/d/d/f/g/h/i/j/k/l/FILE",
 				 ARRAY_AND_SIZE(hello));
 		expect_success(ret, "write_file()");
 
-		buf = read_file("test/a/b/c/d/e/f/g/h/i/j/k/l/FILE", NULL);
+		buf = read_file("test/a/b/c/d/d/f/g/h/i/j/k/l/FILE", NULL);
 		if (expect_ptrok(buf, "read_file()")) {
 			expect_success(memcmp(buf, ARRAY_AND_SIZE(hello)),
 				       "read_file() content");
 		}
 
 		free(buf);
+
+		test_tree("test/", &ctx);
+
+		expect_success(ctx.nfiles == 1 ? 0 : -EINVAL,
+			       "wrong recursive opendir file count: %u",
+			       ctx.nfiles);
+		expect_success(ctx.ndirs == 12 ? 0 : -EINVAL,
+			       "wrong recursive opendir directory count: %u",
+			       ctx.ndirs);
 	}
 
 out:
-- 
2.39.5




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-08 14:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08  9:14 [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Ahmad Fatoum
2025-01-08  9:14 ` [PATCH master 2/2] fs: fix resolving paths when directory name repeats Ahmad Fatoum
2025-01-08 14:17 ` [PATCH master 1/2] test: self: ramfs: add regression test for recursive opendir Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox