Skip to contentSkip to conversation

open: remove O_DIRECTORY case (move to fstat test)

PATCH In review Jinseok Kim 2 participants 3 messages Jun 21

lore
Share & tools
lore
#0 lore raw

PATCH v9 1/2 open: remove O_DIRECTORY case (move to fstat test)

The O_DIRECTORY test case was mostly verifying fstat() behavior on an existing directory rather than testing any specific open() behavior.

Following review suggestion, remove it from open01.c. A separate fstat test will be added in a follow-up patch to cover file type checks (S_ISDIR, etc.) more comprehensively.

---
 testcases/kernel/syscalls/open/open01.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
testcases/kernel/syscalls/open/open01.c +1 -12
index 1cefb4790..1413ccdec 100644
@@ -6,15 +6,12 @@
  */
 
 /*\
- * Basic :manpage:`open(2)` test, checking sticky/directory bit.
+ * Basic :manpage:`open(2)` test, checking sticky bit.
  *
  * 1. Open a new file with O_CREAT, fstat.st_mode should not have the
  *    01000 (S_ISVTX) bit on. In Linux, the save text bit is *NOT* cleared.
- * 2. Open a new directory with O_DIRECTORY, fstat.st_mode should have the
- *    040000 (S_IFDIR) bit on.
  */
 
-#define _GNU_SOURCE		/* for O_DIRECTORY */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -22,7 +19,6 @@
 #include "tst_test.h"
 
 #define TEST_FILE	"testfile"
-#define TEST_DIR	"testdir"
 
 static int fd;
 
@@ -34,7 +30,6 @@ static struct tcase {
 	char *desc;
 } tcases[] = {
 	{TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"},
-	{TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "directory bit"}
 };
 
 static void verify_open(unsigned int n)
@@ -60,11 +55,6 @@ static void verify_open(unsigned int n)
 		SAFE_UNLINK(tc->filename);
 }
 
-static void setup(void)
-{
-	SAFE_MKDIR(TEST_DIR, 0755);
-}
-
 static void cleanup(void)
 {
 	if (fd > 0)
@@ -74,7 +64,6 @@ static void cleanup(void)
 static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.needs_tmpdir = 1,
-	.setup = setup,
 	.cleanup = cleanup,
 	.test = verify_open,
 };

--
2.43.0

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

PATCH v9 2/2 fstat: add test for multiple file types using fstat

Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISCHR(), S_ISBLK() on different file types.

---
Changes in v9:
- Open test files with O_PATH to avoid unnecessary device access
- Link to v8: https://lore.kernel.org/ltp/[email protected]

Changes in v8:
- Link to the man page
- Remove desc from tcase and TST_EXP_EXPR
- Link to v7: https://lore.kernel.org/ltp/[email protected]

---
 runtest/syscalls                           |   2 +
 testcases/kernel/syscalls/fstat/.gitignore |   2 +
 testcases/kernel/syscalls/fstat/fstat04.c  | 107 +++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c
runtest/syscalls +2 -0
index 43951df2a..a38743ded 100644
@@ -436,6 +436,8 @@ fstat02 fstat02
 fstat02_64 fstat02_64
 fstat03 fstat03
 fstat03_64 fstat03_64
+fstat04 fstat04
+fstat04_64 fstat04_64
 
 #fstatat64/newfstatat test cases
 fstatat01 fstatat01
testcases/kernel/syscalls/fstat/.gitignore +2 -0
index 9b1089438..a1f538f7e 100644
@@ -2,3 +2,5 @@
 /fstat02_64
 /fstat03
 /fstat03_64
+/fstat04
+/fstat04_64
testcases/kernel/syscalls/fstat/fstat04.c new file +107 -0

107 lines not on this page · raw message

--
2.43.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Jinseok Kim

Hi Jinseok,

Quoted 1 line · Jinseok Kim

open: remove O_DIRECTORY case (move to fstat test)

--- [PATCH 2/2] ---

Quoted 4 lines

+/*\
+ * Verify that :manpage:fstat(2) correctly identifies various
+ * file types.
+ */

The test uses .needs_root = 1 for mknod() to create device nodes, but the doc comment does not mention why root is required.

Quoted 7 lines
(quoted diff) +7 -0
+	switch (tc->exp_type) {
+	case S_IFREG:
+		TST_EXP_EXPR(S_ISREG(buf.st_mode));
+		break;
+	case S_IFDIR:
+		TST_EXP_EXPR(S_ISDIR(buf.st_mode));
+		break;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	case S_IFIFO:
+		TST_EXP_EXPR(S_ISFIFO(buf.st_mode));
+		break;
+	case S_IFCHR:
+		TST_EXP_EXPR(S_ISCHR(buf.st_mode));
+		break;
+	case S_IFBLK:
+		TST_EXP_EXPR(S_ISBLK(buf.st_mode));
+		break;
+	}

Each S_IS*() macro is equivalent to (st_mode & S_IFMT) == S_IF*, and tc->exp_type already holds the expected S_IF* value. Could the whole switch be replaced with a single check?

TST_EXP_EXPR((buf.st_mode & S_IFMT) == tc->exp_type,

      "fstat on %s", tc->path);

This would also give more informative output on failure by identifying the file being tested.

Verdict - Needs revision

Pre-existing issues in open01.c (not introduced by this series):

- static int fd; should be static int fd = -1;
- cleanup() uses if (fd > 0) which should be if (fd != -1)

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp