Skip to contentSkip to conversation

Enable .all_filesystems in readdir() and getdents() tests

PATCH In review Martin Doucha 2 participants 8 messages Sep 11, 2024 – Sep 12, 2024

lore
Share & tools
lore
#0 lore raw

cover Enable .all_filesystems in readdir() and getdents() tests

The readdir() and getdents() syscalls are currently subtly broken on bcachefs. However, this was missed until recently because the respective syscall tests do not test multiple filesystems. Enable .all_filesystems in readdir() and getdents() tests to increase coverage.

Martin Doucha (5):
readdir01: Enable .all_filesystems
readdir21: Enable .all_filesystems
getdents01: Enable .all_filesystems
getdents02: Remove obsolete TCID
getdents02: Enable .all_filesystems

 .../kernel/syscalls/getdents/getdents01.c     | 54 ++++++++++++-------
 .../kernel/syscalls/getdents/getdents02.c     | 15 +++---
 testcases/kernel/syscalls/readdir/readdir01.c | 11 ++--
 testcases/kernel/syscalls/readdir/readdir21.c | 12 +++--
 4 files changed, 61 insertions(+), 31 deletions(-)
Signature · 5 lines
2.46.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/5 readdir01: Enable .all_filesystems

Run the functional readdir() test on all filesystems.

---
 testcases/kernel/syscalls/readdir/readdir01.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/readdir/readdir01.c +8 -3
index 1bf70fd1f..2dc8f916d 100644
@@ -22,6 +22,8 @@
 #include <stdio.h>
 #include "tst_test.h"
 
+#define MNTPOINT "mntpoint"
+
 static const char prefix[] = "readdirfile";
 static int nfiles = 10;
 
@@ -32,7 +34,7 @@ static void setup(void)
 	int fd;
 
 	for (i = 0; i < nfiles; i++) {
-		sprintf(fname, "%s_%d", prefix, i);
+		sprintf(fname, "%s/%s_%d", MNTPOINT, prefix, i);
 		fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
 		SAFE_WRITE(SAFE_WRITE_ALL, fd, "hello\n", 6);
 		SAFE_CLOSE(fd);
@@ -45,7 +47,7 @@ static void verify_readdir(void)
 	DIR *test_dir;
 	struct dirent *ent;
 
-	test_dir = SAFE_OPENDIR(".");
+	test_dir = SAFE_OPENDIR(MNTPOINT);
 	while ((ent = SAFE_READDIR(test_dir))) {
 		if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
 			continue;
@@ -66,5 +68,8 @@ static void verify_readdir(void)
 static struct tst_test test = {
 	.setup = setup,
 	.test_all = verify_readdir,
-	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT
 };
Signature · 5 lines
2.46.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH 2/5 readdir21: Enable .all_filesystems

In reply to Martin Doucha

Run the readdir() error test on all filesystems.

---
 testcases/kernel/syscalls/readdir/readdir21.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/readdir/readdir21.c +8 -4
index 7308c8bcc..7b747dbd3 100644
@@ -20,9 +20,10 @@
 #include "lapi/syscalls.h"
 #include "lapi/readdir.h"
 
-#define TEST_DIR	"test_dir"
-#define TEST_DIR4	"test_dir4"
-#define TEST_FILE	"test_file"
+#define MNTPOINT	"mntpoint"
+#define TEST_DIR	MNTPOINT "/test_dir"
+#define TEST_DIR4	MNTPOINT "/test_dir4"
+#define TEST_FILE	MNTPOINT "/test_file"
 #define DIR_MODE	0755
 
 static unsigned int del_dir_fd, file_fd;
@@ -75,5 +76,8 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.test = verify_readdir,
-	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT
 };
Signature · 5 lines
2.46.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH 3/5 getdents01: Enable .all_filesystems

In reply to Martin Doucha

Run the functional getdents() test on all filesystems.

---
 .../kernel/syscalls/getdents/getdents01.c     | 54 ++++++++++++-------
 1 file changed, 36 insertions(+), 18 deletions(-)
testcases/kernel/syscalls/getdents/getdents01.c +36 -18
index e5e4689ee..d6c4b4979 100644
@@ -22,6 +22,9 @@
 
 #include <stdlib.h>
 
+#define MNTPOINT "mntpoint"
+#define WORKDIR MNTPOINT "/workdir"
+
 static void reset_flags(void);
 static void check_flags(void);
 static void set_flag(const char *name);
@@ -61,7 +64,7 @@ static void run(void)
 {
 	int rval;
 
-	fd = SAFE_OPEN(".", O_RDONLY|O_DIRECTORY);
+	fd = SAFE_OPEN(WORKDIR, O_RDONLY|O_DIRECTORY);
 
 	rval = tst_getdents(fd, dirp, BUFSIZE);
 
@@ -147,31 +150,37 @@ static void set_flag(const char *name)
 static void setup(void)
 {
 	size_t i;
+	char path[255];
 
 	getdents_info();
 
-	if (!tst_variant) {
-		for (i = 0; i < ARRAY_SIZE(testcases); i++) {
-			if (!testcases[i].create)
-				continue;
-
-			switch (testcases[i].type) {
-			case ENTRY_DIR:
-				SAFE_MKDIR(testcases[i].name, 0777);
-			break;
-			case ENTRY_FILE:
-				SAFE_FILE_PRINTF(testcases[i].name, " ");
-			break;
-			case ENTRY_SYMLINK:
-				SAFE_SYMLINK("nonexistent", testcases[i].name);
-			break;
-			}
+	/*
+	 * Work in a subdirectory because some filesystems add special files
+	 * or directories to their root.
+	 */
+	SAFE_MKDIR(WORKDIR, 0777);
+
+	for (i = 0; i < ARRAY_SIZE(testcases); i++) {
+		if (!testcases[i].create)
+			continue;
+
+		sprintf(path, "%s/%s", WORKDIR, testcases[i].name);
+
+		switch (testcases[i].type) {
+		case ENTRY_DIR:
+			SAFE_MKDIR(path, 0777);
+		break;
+		case ENTRY_FILE:
+			SAFE_FILE_PRINTF(path, " ");
+		break;
+		case ENTRY_SYMLINK:
+			SAFE_SYMLINK("nonexistent", path);
+		break;
 		}
 	}
 }
 
 static struct tst_test test = {
-	.needs_tmpdir = 1,
 	.test_all = run,
 	.setup = setup,
 	.bufs = (struct tst_buffers []) {
@@ -179,4 +188,13 @@ static struct tst_test test = {
 		{},
 	},
 	.test_variants = TEST_VARIANTS,
+	.needs_root = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
+	}
 };
Signature · 5 lines
2.46.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH 4/5 getdents02: Remove obsolete TCID

In reply to Martin Doucha
---
 testcases/kernel/syscalls/getdents/getdents02.c | 2 --
 1 file changed, 2 deletions(-)
testcases/kernel/syscalls/getdents/getdents02.c +0 -2
index 578db9d1e..25aa30d9d 100644
@@ -28,8 +28,6 @@
 			 S_IXGRP|S_IROTH|S_IXOTH)
 #define TEST_DIR	"test_dir"
 
-char *TCID = "getdents02";
-
 static char *dirp;
 static size_t size;
 
Signature · 5 lines
2.46.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH 5/5 getdents02: Enable .all_filesystems

In reply to Martin Doucha

Run the getdents() error test on all filesystems.

---
 testcases/kernel/syscalls/getdents/getdents02.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/getdents/getdents02.c +9 -4
index 25aa30d9d..805a8bc48 100644
@@ -26,7 +26,9 @@
 
 #define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
 			 S_IXGRP|S_IROTH|S_IXOTH)
-#define TEST_DIR	"test_dir"
+#define MNTPOINT	"mntpoint"
+#define TEST_DIR	MNTPOINT "/test_dir"
+#define TEST_FILE	MNTPOINT "/test"
 
 static char *dirp;
 static size_t size;
@@ -61,8 +63,8 @@ static void setup(void)
 	size = tst_dirp_size();
 	dirp = tst_alloc(size);
 
-	fd = SAFE_OPEN(".", O_RDONLY);
-	fd_file = SAFE_OPEN("test", O_CREAT | O_RDWR, 0644);
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+	fd_file = SAFE_OPEN(TEST_FILE, O_CREAT | O_RDWR, 0644);
 
 	dirp_bad = tst_get_bad_addr(NULL);
 
@@ -92,9 +94,12 @@ static void run(unsigned int i)
 }
 
 static struct tst_test test = {
-	.needs_tmpdir = 1,
 	.test = run,
 	.setup = setup,
 	.tcnt = ARRAY_SIZE(tcases),
 	.test_variants = TEST_VARIANTS,
+	.needs_root = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT
 };
Signature · 5 lines
2.46.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH 5/5] getdents02: Enable .all_filesystems

Hi!
I did merged the patchset, thanks.

I've also notice that there are failures on -m32 build but that happens before these patches as well:

$ ./getdents02
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_getxryBmt as tmpdir (ext2/ext3/ext4 filesystem)
tst_test.c:1809: TINFO: LTP version: 20240524-236-g0ae6bcc6f
tst_test.c:1813: TINFO: Tested kernel: 6.9.3 #1 SMP PREEMPT_DYNAMIC Fri Jun  7 11:00:48 CEST 2024 x86_64
tst_test.c:1652: TINFO: Timeout per run is 0h 00m 30s
getdents.h:148: TINFO: Testing the SYS_getdents syscall
tst_buffers.c:57: TINFO: Test is using guarded buffers
getdents02.c:86: TPASS: getdents failed as expected: EBADF (9)
getdents02.c:86: TPASS: getdents failed as expected: EINVAL (22)
getdents02.c:86: TPASS: getdents failed as expected: ENOTDIR (20)
getdents02.c:86: TPASS: getdents failed as expected: ENOENT (2)
getdents02.c:90: TFAIL: getdents failed unexpectedly: EINVAL (22)
getdents.h:151: TINFO: Testing the SYS_getdents64 syscall
tst_buffers.c:57: TINFO: Test is using guarded buffers
getdents02.c:86: TPASS: getdents failed as expected: EBADF (9)
getdents02.c:86: TPASS: getdents failed as expected: EINVAL (22)
getdents02.c:86: TPASS: getdents failed as expected: ENOTDIR (20)
getdents02.c:86: TPASS: getdents failed as expected: ENOENT (2)
getdents02.c:90: TFAIL: getdents failed unexpectedly: EINVAL (22)
getdents.h:157: TCONF: libc getdents() is not implemented
getdents.h:162: TINFO: Testing libc getdents64()
tst_buffers.c:57: TINFO: Test is using guarded buffers
getdents02.c:86: TPASS: getdents failed as expected: EBADF (9)
getdents02.c:86: TPASS: getdents failed as expected: EINVAL (22)
getdents02.c:86: TPASS: getdents failed as expected: ENOTDIR (20)
getdents02.c:86: TPASS: getdents failed as expected: ENOENT (2)
getdents02.c:86: TPASS: getdents failed as expected: EFAULT (14)

It looks like the tst_dirp_size() function does not work properly when the code is compiled with -m32. Do we see these failures anywhere in openQA?

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH 5/5] getdents02: Enable .all_filesystems

Quoted 34 lines · Cyril Hrubis

Hi!
I did merged the patchset, thanks.

I've also notice that there are failures on -m32 build but that happens before these patches as well:

$ ./getdents02
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_getxryBmt as tmpdir (ext2/ext3/ext4 filesystem)
tst_test.c:1809: TINFO: LTP version: 20240524-236-g0ae6bcc6f
tst_test.c:1813: TINFO: Tested kernel: 6.9.3 #1 SMP PREEMPT_DYNAMIC Fri Jun  7 11:00:48 CEST 2024 x86_64
tst_test.c:1652: TINFO: Timeout per run is 0h 00m 30s
getdents.h:148: TINFO: Testing the SYS_getdents syscall
tst_buffers.c:57: TINFO: Test is using guarded buffers
getdents02.c:86: TPASS: getdents failed as expected: EBADF (9)
getdents02.c:86: TPASS: getdents failed as expected: EINVAL (22)
getdents02.c:86: TPASS: getdents failed as expected: ENOTDIR (20)
getdents02.c:86: TPASS: getdents failed as expected: ENOENT (2)
getdents02.c:90: TFAIL: getdents failed unexpectedly: EINVAL (22)
getdents.h:151: TINFO: Testing the SYS_getdents64 syscall
tst_buffers.c:57: TINFO: Test is using guarded buffers
getdents02.c:86: TPASS: getdents failed as expected: EBADF (9)
getdents02.c:86: TPASS: getdents failed as expected: EINVAL (22)
getdents02.c:86: TPASS: getdents failed as expected: ENOTDIR (20)
getdents02.c:86: TPASS: getdents failed as expected: ENOENT (2)
getdents02.c:90: TFAIL: getdents failed unexpectedly: EINVAL (22)
getdents.h:157: TCONF: libc getdents() is not implemented
getdents.h:162: TINFO: Testing libc getdents64()
tst_buffers.c:57: TINFO: Test is using guarded buffers
getdents02.c:86: TPASS: getdents failed as expected: EBADF (9)
getdents02.c:86: TPASS: getdents failed as expected: EINVAL (22)
getdents02.c:86: TPASS: getdents failed as expected: ENOTDIR (20)
getdents02.c:86: TPASS: getdents failed as expected: ENOENT (2)
getdents02.c:86: TPASS: getdents failed as expected: EFAULT (14)
Quoted 3 lines

It looks like the tst_dirp_size() function does not work properly when the code is compiled with -m32. Do we see these failures anywhere in openQA?

Yes, 32bit getdents02 has been failing on Tumbleweed since the subtest was added:
https://openqa.opensuse.org/tests/4458950#step/getdents02/8

Signature · 11 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp