* [LTP] [PATCH] open: fix directory verification and misleading test description @ 2026-02-11 17:16 Jinseok Kim 2026-02-17 13:21 ` Andrea Cervesato via ltp 2026-02-19 10:31 ` Cyril Hrubis 0 siblings, 2 replies; 29+ messages in thread From: Jinseok Kim @ 2026-02-11 17:16 UTC (permalink / raw) To: ltp The directory test treated S_IFDIR as a permission bit and verified it using a generic st_mode bitwise check, which is not appropriate for file type verification. Use S_ISDIR() when verifying directories and keep bitwise checks only for permission bits such as S_ISVTX. The directory test case also referred to a "directory bit", which is misleading since directories are identified by file type rather than a permission bit. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index baf73ab11..1355592e1 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -37,7 +37,7 @@ static struct tcase { char *desc; } tcases[] = { {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"}, - {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "sirectory bit"} + {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "directory"} }; static void verify_open(unsigned int n) @@ -53,11 +53,17 @@ static void verify_open(unsigned int n) fd = TST_RET; SAFE_FSTAT(fd, &buf); - if (!(buf.st_mode & tc->tst_bit)) - tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc); - else - tst_res(TPASS, "%s is set as expected", tc->desc); - + if (tc->tst_bit == S_ISVTX) { + if (!(buf.st_mode & S_ISVTX)) + tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc); + else + tst_res(TPASS, "%s is set as expected", tc->desc); + } else if (tc->tst_bit == S_IFDIR) { + if (!S_ISDIR(buf.st_mode)) + tst_res(TFAIL, "%s is not a directory", tc->desc); + else + tst_res(TPASS, "%s is a directory", tc->desc); + } SAFE_CLOSE(fd); if (S_ISREG(buf.st_mode)) SAFE_UNLINK(tc->filename); -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH] open: fix directory verification and misleading test description 2026-02-11 17:16 [LTP] [PATCH] open: fix directory verification and misleading test description Jinseok Kim @ 2026-02-17 13:21 ` Andrea Cervesato via ltp 2026-02-19 10:31 ` Cyril Hrubis 1 sibling, 0 replies; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-02-17 13:21 UTC (permalink / raw) To: Jinseok Kim, ltp Hi! Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH] open: fix directory verification and misleading test description 2026-02-11 17:16 [LTP] [PATCH] open: fix directory verification and misleading test description Jinseok Kim 2026-02-17 13:21 ` Andrea Cervesato via ltp @ 2026-02-19 10:31 ` Cyril Hrubis 2026-02-19 14:57 ` Jinseok Kim 1 sibling, 1 reply; 29+ messages in thread From: Cyril Hrubis @ 2026-02-19 10:31 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi! > diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c > index baf73ab11..1355592e1 100644 > --- a/testcases/kernel/syscalls/open/open01.c > +++ b/testcases/kernel/syscalls/open/open01.c > @@ -37,7 +37,7 @@ static struct tcase { > char *desc; > } tcases[] = { > {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"}, > - {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "sirectory bit"} > + {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "directory"} > }; > > static void verify_open(unsigned int n) > @@ -53,11 +53,17 @@ static void verify_open(unsigned int n) > fd = TST_RET; > > SAFE_FSTAT(fd, &buf); > - if (!(buf.st_mode & tc->tst_bit)) > - tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc); > - else > - tst_res(TPASS, "%s is set as expected", tc->desc); > - > + if (tc->tst_bit == S_ISVTX) { > + if (!(buf.st_mode & S_ISVTX)) > + tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc); > + else > + tst_res(TPASS, "%s is set as expected", tc->desc); > + } else if (tc->tst_bit == S_IFDIR) { > + if (!S_ISDIR(buf.st_mode)) > + tst_res(TFAIL, "%s is not a directory", tc->desc); > + else > + tst_res(TPASS, "%s is a directory", tc->desc); > + } Hmm, I guess that the check for S_ISDIR() is technically testing fstat() since unlike the sticky bit case the directory is created in the test setup. I guess the cleaniest solutiont may be to add fstat test that would check all kinds of modes. Looking at the headers there are at least: - S_ISDIR - S_ISCHR - S_ISBLK - S_ISREG - S_ISFIFO - S_ISLNK -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH] open: fix directory verification and misleading test description 2026-02-19 10:31 ` Cyril Hrubis @ 2026-02-19 14:57 ` Jinseok Kim 2026-02-20 10:49 ` Cyril Hrubis 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-02-19 14:57 UTC (permalink / raw) To: chrubis, ltp Hi, Hrubis Thanks for the review. I checked fstat/: None of the existing fstat tests actually verify file type bits as you suggested. I think the cleanest solution is to introduce a new test `fstat04.c` that creates different file types (regular, directory, character, etc.) and explicitly checks `S_ISREG()`, `S_ISDIR()`, `S_ISCHR()` and so on. How do you think about removing the O_DIRECTORY case from open01.c and creating a separate fstat test? Thanks again, Jinseok. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH] open: fix directory verification and misleading test description 2026-02-19 14:57 ` Jinseok Kim @ 2026-02-20 10:49 ` Cyril Hrubis 2026-02-24 7:37 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Cyril Hrubis @ 2026-02-20 10:49 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi! > How do you think about removing the O_DIRECTORY case from open01.c and > creating a separate fstat test? Yes please. -- Cyril Hrubis chrubis@suse.cz -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-02-20 10:49 ` Cyril Hrubis @ 2026-02-24 7:37 ` Jinseok Kim 2026-02-24 7:37 ` [LTP] [PATCH 2/2] Add test for multiple file types using fstat Jinseok Kim 2026-02-24 8:17 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp 0 siblings, 2 replies; 29+ messages in thread From: Jinseok Kim @ 2026-02-24 7:37 UTC (permalink / raw) To: chrubis, ltp 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. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index baf73ab11..801859e68 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -8,16 +8,12 @@ /* * DESCRIPTION * Open a file with oflag = O_CREAT set, does it set the sticky bit off? - * Open a dir with O_DIRECTORY, does it set the S_IFDIR bit on? * * ALGORITHM * 1. open a new file with O_CREAT, fstat.st_mode should not have the * 01000 bit on. In Linux, the save text bit is *NOT* cleared. - * 2. open a new dir with O_DIRECTORY, fstat.st_mode should have the - * 040000 bit on. */ -#define _GNU_SOURCE /* for O_DIRECTORY */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -25,7 +21,6 @@ #include "tst_test.h" #define TEST_FILE "testfile" -#define TEST_DIR "testdir" static int fd; @@ -37,7 +32,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, "sirectory bit"} }; static void verify_open(unsigned int n) -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* [LTP] [PATCH 2/2] Add test for multiple file types using fstat 2026-02-24 7:37 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim @ 2026-02-24 7:37 ` Jinseok Kim 2026-02-24 8:17 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp 1 sibling, 0 replies; 29+ messages in thread From: Jinseok Kim @ 2026-02-24 7:37 UTC (permalink / raw) To: chrubis, ltp Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISLNK(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/fstat/fstat04.c | 103 ++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..6aa9a8e79 --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ + +#define _GNU_SOURCE +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include "tst_test.h" + +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define SYMLINK "symlink" +#define CHR_DEV "chrdev" +#define BLK_DEV "blkdev" + +static int fd = -1; + +static struct tcase { + const char *desc; + const char *path; + const char *macro_name; + mode_t exp_type; +} tcases[] = { + { "regular file", REG_FILE, "S_IFREG", S_IFREG }, + { "directory", DIR_FILE, "S_IFDIR", S_IFDIR }, + { "FIFO (pipe)", FIFO_FILE, "S_IFIFO", S_IFIFO }, + { "symbolic link", SYMLINK, "S_IFLNK", S_IFLNK }, + { "character dev", CHR_DEV, "S_IFCHR", S_IFCHR }, + { "block dev", BLK_DEV, "S_IFBLK", S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + fd = SAFE_OPEN(tc->path, flags); + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + int is_correct = 0; + switch (tc->exp_type) { + case S_IFREG: is_correct = S_ISREG(buf.st_mode); break; + case S_IFDIR: is_correct = S_ISDIR(buf.st_mode); break; + case S_IFIFO: is_correct = S_ISFIFO(buf.st_mode); break; + case S_IFLNK: is_correct = S_ISLNK(buf.st_mode); break; + case S_IFCHR: is_correct = S_ISCHR(buf.st_mode); break; + case S_IFBLK: is_correct = S_ISBLK(buf.st_mode); break; + } + + if (is_correct) + tst_res(TPASS, "%s: %s() macro matches", tc->desc, tc->macro_name); + else + tst_res(TFAIL, "%s: %s() macro does NOT match", tc->desc, tc->macro_name); +} + +static void setup(void) +{ + fd = SAFE_OPEN(REG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); + SAFE_CLOSE(fd); + + SAFE_MKDIR(DIR_FILE, 0755); + SAFE_SYMLINK(REG_FILE, SYMLINK); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + SAFE_UNLINK(SYMLINK); + SAFE_UNLINK(REG_FILE); + SAFE_RMDIR(DIR_FILE); + + SAFE_UNLINK(FIFO_FILE); + SAFE_UNLINK(CHR_DEV); + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .needs_tmpdir = 1, + .needs_root = 1, +}; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-02-24 7:37 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 2026-02-24 7:37 ` [LTP] [PATCH 2/2] Add test for multiple file types using fstat Jinseok Kim @ 2026-02-24 8:17 ` Andrea Cervesato via ltp 2026-02-24 10:07 ` [LTP] [PATCH v2 " Jinseok Kim 1 sibling, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-02-24 8:17 UTC (permalink / raw) To: Jinseok Kim, chrubis, ltp Hi! The patch is not compiling. Please verify that patch is applicable before sending it: https://patchwork.ozlabs.org/project/ltp/list/?series=493107&state=* https://linux-test-project.readthedocs.io/en/latest/developers/writing_tests.html#testing-builds-with-github-actions -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v2 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-02-24 8:17 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp @ 2026-02-24 10:07 ` Jinseok Kim 2026-02-24 10:07 ` [LTP] [PATCH v2 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-02-24 10:07 UTC (permalink / raw) To: ltp 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. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index baf73ab11..329c52586 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -8,16 +8,12 @@ /* * DESCRIPTION * Open a file with oflag = O_CREAT set, does it set the sticky bit off? - * Open a dir with O_DIRECTORY, does it set the S_IFDIR bit on? * * ALGORITHM * 1. open a new file with O_CREAT, fstat.st_mode should not have the * 01000 bit on. In Linux, the save text bit is *NOT* cleared. - * 2. open a new dir with O_DIRECTORY, fstat.st_mode should have the - * 040000 bit on. */ -#define _GNU_SOURCE /* for O_DIRECTORY */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -25,7 +21,6 @@ #include "tst_test.h" #define TEST_FILE "testfile" -#define TEST_DIR "testdir" static int fd; @@ -37,7 +32,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, "sirectory bit"} }; static void verify_open(unsigned int n) @@ -63,11 +57,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) @@ -77,7 +66,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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* [LTP] [PATCH v2 2/2] fstat: add test for multiple file types using fstat 2026-02-24 10:07 ` [LTP] [PATCH v2 " Jinseok Kim @ 2026-02-24 10:07 ` Jinseok Kim 2026-02-24 14:17 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-02-24 10:07 UTC (permalink / raw) To: ltp Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISLNK(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/fstat/fstat04.c | 103 ++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..6aa9a8e79 --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ + +#define _GNU_SOURCE +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include "tst_test.h" + +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define SYMLINK "symlink" +#define CHR_DEV "chrdev" +#define BLK_DEV "blkdev" + +static int fd = -1; + +static struct tcase { + const char *desc; + const char *path; + const char *macro_name; + mode_t exp_type; +} tcases[] = { + { "regular file", REG_FILE, "S_IFREG", S_IFREG }, + { "directory", DIR_FILE, "S_IFDIR", S_IFDIR }, + { "FIFO (pipe)", FIFO_FILE, "S_IFIFO", S_IFIFO }, + { "symbolic link", SYMLINK, "S_IFLNK", S_IFLNK }, + { "character dev", CHR_DEV, "S_IFCHR", S_IFCHR }, + { "block dev", BLK_DEV, "S_IFBLK", S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + fd = SAFE_OPEN(tc->path, flags); + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + int is_correct = 0; + switch (tc->exp_type) { + case S_IFREG: is_correct = S_ISREG(buf.st_mode); break; + case S_IFDIR: is_correct = S_ISDIR(buf.st_mode); break; + case S_IFIFO: is_correct = S_ISFIFO(buf.st_mode); break; + case S_IFLNK: is_correct = S_ISLNK(buf.st_mode); break; + case S_IFCHR: is_correct = S_ISCHR(buf.st_mode); break; + case S_IFBLK: is_correct = S_ISBLK(buf.st_mode); break; + } + + if (is_correct) + tst_res(TPASS, "%s: %s() macro matches", tc->desc, tc->macro_name); + else + tst_res(TFAIL, "%s: %s() macro does NOT match", tc->desc, tc->macro_name); +} + +static void setup(void) +{ + fd = SAFE_OPEN(REG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); + SAFE_CLOSE(fd); + + SAFE_MKDIR(DIR_FILE, 0755); + SAFE_SYMLINK(REG_FILE, SYMLINK); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + SAFE_UNLINK(SYMLINK); + SAFE_UNLINK(REG_FILE); + SAFE_RMDIR(DIR_FILE); + + SAFE_UNLINK(FIFO_FILE); + SAFE_UNLINK(CHR_DEV); + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .needs_tmpdir = 1, + .needs_root = 1, +}; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v2 2/2] fstat: add test for multiple file types using fstat 2026-02-24 10:07 ` [LTP] [PATCH v2 2/2] fstat: add test for multiple file types using fstat Jinseok Kim @ 2026-02-24 14:17 ` Andrea Cervesato via ltp 2026-02-25 13:19 ` [LTP] [PATCH v3 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-02-24 14:17 UTC (permalink / raw) To: Jinseok Kim, ltp Hi! Let's fix the following issues first. On Tue Feb 24, 2026 at 11:07 AM CET, Jinseok Kim wrote: > Following review feedback, create a dedicated fstat test that verifies > S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISLNK(), S_ISCHR(), S_ISBLK() > on different file types. > > Signed-off-by: Jinseok Kim <always.starving0@gmail.com> > --- > testcases/kernel/syscalls/fstat/fstat04.c | 103 ++++++++++++++++++++++ > 1 file changed, 103 insertions(+) > create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c > > diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c > new file mode 100644 > index 000000000..6aa9a8e79 > --- /dev/null > +++ b/testcases/kernel/syscalls/fstat/fstat04.c > @@ -0,0 +1,103 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> > + */ > +/*\ > + * Verify that fstat correctly identifies various file types > + */ > + > +#define _GNU_SOURCE > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <sys/sysmacros.h> > +#include <fcntl.h> > +#include <unistd.h> > +#include <errno.h> More likely these imports are not stricly needed. Please take a look at it. Also _GNU_SOURCE is not needed. > +#include "tst_test.h" > + > +#define REG_FILE "regfile" > +#define DIR_FILE "dirfile" > +#define FIFO_FILE "fifofile" > +#define SYMLINK "symlink" > +#define CHR_DEV "chrdev" > +#define BLK_DEV "blkdev" > + > +static int fd = -1; > + > +static struct tcase { > + const char *desc; > + const char *path; > + const char *macro_name; > + mode_t exp_type; > +} tcases[] = { > + { "regular file", REG_FILE, "S_IFREG", S_IFREG }, > + { "directory", DIR_FILE, "S_IFDIR", S_IFDIR }, > + { "FIFO (pipe)", FIFO_FILE, "S_IFIFO", S_IFIFO }, > + { "symbolic link", SYMLINK, "S_IFLNK", S_IFLNK }, > + { "character dev", CHR_DEV, "S_IFCHR", S_IFCHR }, > + { "block dev", BLK_DEV, "S_IFBLK", S_IFBLK }, > +}; > + > +static void verify_fstat(unsigned int i) > +{ > + struct tcase *tc = &tcases[i]; > + struct stat buf; > + > + int flags = O_RDONLY | O_NONBLOCK; > + > + if (tc->exp_type == S_IFDIR) > + flags |= O_DIRECTORY; > + > + fd = SAFE_OPEN(tc->path, flags); > + > + SAFE_FSTAT(fd, &buf); > + SAFE_CLOSE(fd); > + > + int is_correct = 0; > + switch (tc->exp_type) { > + case S_IFREG: is_correct = S_ISREG(buf.st_mode); break; > + case S_IFDIR: is_correct = S_ISDIR(buf.st_mode); break; > + case S_IFIFO: is_correct = S_ISFIFO(buf.st_mode); break; > + case S_IFLNK: is_correct = S_ISLNK(buf.st_mode); break; > + case S_IFCHR: is_correct = S_ISCHR(buf.st_mode); break; > + case S_IFBLK: is_correct = S_ISBLK(buf.st_mode); break; > + } > + > + if (is_correct) > + tst_res(TPASS, "%s: %s() macro matches", tc->desc, tc->macro_name); > + else > + tst_res(TFAIL, "%s: %s() macro does NOT match", tc->desc, tc->macro_name); > +} > + > +static void setup(void) > +{ > + fd = SAFE_OPEN(REG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); > + SAFE_CLOSE(fd); > + > + SAFE_MKDIR(DIR_FILE, 0755); > + SAFE_SYMLINK(REG_FILE, SYMLINK); > + > + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); > + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); > + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); > +} > + > +static void cleanup(void) > +{ > + SAFE_UNLINK(SYMLINK); > + SAFE_UNLINK(REG_FILE); > + SAFE_RMDIR(DIR_FILE); > + > + SAFE_UNLINK(FIFO_FILE); > + SAFE_UNLINK(CHR_DEV); > + SAFE_UNLINK(BLK_DEV); What if all these files/directories don't exist at cleanup? > +} > + > +static struct tst_test test = { > + .tcnt = ARRAY_SIZE(tcases), > + .setup = setup, > + .cleanup = cleanup, > + .test = verify_fstat, > + .needs_tmpdir = 1, > + .needs_root = 1, > +}; > -- > 2.43.0 I also get: fstat04.c:61: TPASS: regular file: S_IFREG() macro matches fstat04.c:61: TPASS: directory: S_IFDIR() macro matches fstat04.c:61: TPASS: FIFO (pipe): S_IFIFO() macro matches fstat04.c:63: TFAIL: symbolic link: S_IFLNK() macro does NOT match fstat04.c:45: TBROK: open(chrdev,2048,0000) failed: EACCES (13) Please, also fix the following: open01.c has 1 checkpatch error: - Line 43: Code indent should use tabs where possible fstat04.c has 9 checkpatch errors and 53 warnings: - Lines 28-93: Uses spaces instead of tabs for indentation throughout - Lines 58-63: Trailing statements should be on next line in switch cases - Line 57: Missing blank line after declarations - Line 49: Code indent should use tabs - Add fstat04 to .gitignore - Add fstat04 fstat04 to runtest/syscalls -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v3 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-02-24 14:17 ` Andrea Cervesato via ltp @ 2026-02-25 13:19 ` Jinseok Kim 2026-02-25 13:19 ` [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-02-25 13:19 UTC (permalink / raw) To: ltp 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. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index baf73ab11..3ae1b269b 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -8,16 +8,12 @@ /* * DESCRIPTION * Open a file with oflag = O_CREAT set, does it set the sticky bit off? - * Open a dir with O_DIRECTORY, does it set the S_IFDIR bit on? * * ALGORITHM * 1. open a new file with O_CREAT, fstat.st_mode should not have the * 01000 bit on. In Linux, the save text bit is *NOT* cleared. - * 2. open a new dir with O_DIRECTORY, fstat.st_mode should have the - * 040000 bit on. */ -#define _GNU_SOURCE /* for O_DIRECTORY */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -25,7 +21,6 @@ #include "tst_test.h" #define TEST_FILE "testfile" -#define TEST_DIR "testdir" static int fd; @@ -37,7 +32,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, "sirectory bit"} }; static void verify_open(unsigned int n) @@ -46,7 +40,7 @@ static void verify_open(unsigned int n) struct stat buf; TST_EXP_FD_SILENT(open(tc->filename, tc->flag, tc->mode), - "open() with %s", tc->desc); + "open() with %s", tc->desc); if (!TST_PASS) return; @@ -63,11 +57,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) @@ -77,7 +66,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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat 2026-02-25 13:19 ` [LTP] [PATCH v3 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim @ 2026-02-25 13:19 ` Jinseok Kim 2026-02-25 14:30 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-02-25 13:19 UTC (permalink / raw) To: ltp Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISLNK(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- runtest/syscalls | 2 + testcases/kernel/syscalls/fstat/.gitignore | 2 + testcases/kernel/syscalls/fstat/fstat04.c | 121 +++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/runtest/syscalls b/runtest/syscalls index 05bb3ceb1..5b34e6bdc 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -435,6 +435,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 diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore index 9b1089438..a1f538f7e 100644 --- a/testcases/kernel/syscalls/fstat/.gitignore +++ b/testcases/kernel/syscalls/fstat/.gitignore @@ -2,3 +2,5 @@ /fstat02_64 /fstat03 /fstat03_64 +/fstat04 +/fstat04_64 diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..97d0d6f50 --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include "tst_test.h" + +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define SYMLINK "symlink" +#define CHR_DEV "chrdev" +#define BLK_DEV "blkdev" + +static int fd = -1; + +static struct tcase { + const char *desc; + const char *path; + const char *macro_name; + mode_t exp_type; +} tcases[] = { + { "regular file", REG_FILE, "S_IFREG", S_IFREG }, + { "directory", DIR_FILE, "S_IFDIR", S_IFDIR }, + { "FIFO (pipe)", FIFO_FILE, "S_IFIFO", S_IFIFO }, + { "symbolic link", SYMLINK, "S_IFLNK", S_IFLNK }, + { "character dev", CHR_DEV, "S_IFCHR", S_IFCHR }, + { "block dev", BLK_DEV, "S_IFBLK", S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + fd = SAFE_OPEN(tc->path, flags); + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + int is_correct = 0; + + switch (tc->exp_type) { + case S_IFREG: + is_correct = S_ISREG(buf.st_mode); + break; + case S_IFDIR: + is_correct = S_ISDIR(buf.st_mode); + break; + case S_IFIFO: + is_correct = S_ISFIFO(buf.st_mode); + break; + case S_IFLNK: + is_correct = S_ISLNK(buf.st_mode); + break; + case S_IFCHR: + is_correct = S_ISCHR(buf.st_mode); + break; + case S_IFBLK: + is_correct = S_ISBLK(buf.st_mode); + break; + } + + if (is_correct) + tst_res(TPASS, "%s: %s() macro matches", tc->desc, tc->macro_name); + else + tst_res(TFAIL, "%s: %s() macro does NOT match", tc->desc, tc->macro_name); +} + +static void setup(void) +{ + fd = SAFE_OPEN(REG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); + SAFE_CLOSE(fd); + + SAFE_MKDIR(DIR_FILE, 0755); + SAFE_SYMLINK(REG_FILE, SYMLINK); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + if (!access(SYMLINK, F_OK)) + SAFE_UNLINK(SYMLINK); + + if (!access(REG_FILE, F_OK)) + SAFE_UNLINK(REG_FILE); + + if (!access(DIR_FILE, F_OK)) + SAFE_RMDIR(DIR_FILE); + + if (!access(FIFO_FILE, F_OK)) + SAFE_UNLINK(FIFO_FILE); + + if (!access(CHR_DEV, F_OK)) + SAFE_UNLINK(CHR_DEV); + + if (!access(BLK_DEV, F_OK)) + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .needs_tmpdir = 1, + .needs_root = 1, +}; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat 2026-02-25 13:19 ` [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat Jinseok Kim @ 2026-02-25 14:30 ` Andrea Cervesato via ltp 2026-02-26 15:32 ` Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-02-25 14:30 UTC (permalink / raw) To: Jinseok Kim, ltp Hi! > + > +static struct tcase { > + const char *desc; > + const char *path; > + const char *macro_name; > + mode_t exp_type; > +} tcases[] = { > + { "regular file", REG_FILE, "S_IFREG", S_IFREG }, > + { "directory", DIR_FILE, "S_IFDIR", S_IFDIR }, > + { "FIFO (pipe)", FIFO_FILE, "S_IFIFO", S_IFIFO }, > + { "symbolic link", SYMLINK, "S_IFLNK", S_IFLNK }, > + { "character dev", CHR_DEV, "S_IFCHR", S_IFCHR }, > + { "block dev", BLK_DEV, "S_IFBLK", S_IFBLK }, Makes more sense to merge desc and macro_name together. Then see below: > +}; > + > +static void verify_fstat(unsigned int i) > +{ > + struct tcase *tc = &tcases[i]; > + struct stat buf; > + > + int flags = O_RDONLY | O_NONBLOCK; > + > + if (tc->exp_type == S_IFDIR) > + flags |= O_DIRECTORY; > + > + fd = SAFE_OPEN(tc->path, flags); > + > + SAFE_FSTAT(fd, &buf); > + SAFE_CLOSE(fd); You can just use: SAFE_LSTAT(tc->path, &buf); Otherwise test will fail with: fstat04.c:74: TPASS: Expect: regular file: macro matches fstat04.c:74: TPASS: Expect: directory: macro matches fstat04.c:74: TPASS: Expect: FIFO (pipe): macro matches fstat04.c:74: TFAIL: Expect: symbolic link: macro matches fstat04.c:46: TBROK: open(chrdev,2048,0000) failed: EACCES (13) > + > + int is_correct = 0; > + > + switch (tc->exp_type) { > + case S_IFREG: > + is_correct = S_ISREG(buf.st_mode); > + break; > + case S_IFDIR: > + is_correct = S_ISDIR(buf.st_mode); > + break; > + case S_IFIFO: > + is_correct = S_ISFIFO(buf.st_mode); > + break; > + case S_IFLNK: > + is_correct = S_ISLNK(buf.st_mode); > + break; > + case S_IFCHR: > + is_correct = S_ISCHR(buf.st_mode); > + break; > + case S_IFBLK: > + is_correct = S_ISBLK(buf.st_mode); > + break; > + } > + > + if (is_correct) > + tst_res(TPASS, "%s: %s() macro matches", tc->desc, tc->macro_name); > + else > + tst_res(TFAIL, "%s: %s() macro does NOT match", tc->desc, tc->macro_name); We don't need an if statement here. We can just: TST_EXP_EXPR(is_correct, "%s macro matches", tc->desc); > +static void setup(void) > +{ > + fd = SAFE_OPEN(REG_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); > + SAFE_CLOSE(fd); Just use SAFE_TOUCH() in here, so `fd` can be removed also from the static variables. -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat 2026-02-25 14:30 ` Andrea Cervesato via ltp @ 2026-02-26 15:32 ` Jinseok Kim 2026-02-26 15:44 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-02-26 15:32 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp Hi, Thank you for the review. If we switch to using lstat() only, this test would no longer exercise fstat() at all, which changes the original intent of the test. In that case, should we consider renaming the test from fstat to lstat? Jinseok. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat 2026-02-26 15:32 ` Jinseok Kim @ 2026-02-26 15:44 ` Andrea Cervesato via ltp 2026-03-03 13:32 ` [LTP] [PATCH v4 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-02-26 15:44 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi, On Thu Feb 26, 2026 at 4:32 PM CET, Jinseok Kim wrote: > Hi, > > Thank you for the review. > > If we switch to using lstat() only, this test would no longer exercise > fstat() at all, which changes the original intent of the test. > > In that case, should we consider renaming the test from fstat to lstat? > > Jinseok. Sorry for the confusion...of course. The point is if we want to test inode macros or fstat(), and of course we want to test fstat(). According to that, we should correctly use the syscall. For instance, when using fstat(): fstat04.c:63: TFAIL: symbolic link: S_IFLNK() macro does NOT match fstat04.c:45: TBROK: open(chrdev,2048,0000) failed: EACCES (13) And this has to be fixed of course. -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v4 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-02-26 15:44 ` Andrea Cervesato via ltp @ 2026-03-03 13:32 ` Jinseok Kim 2026-03-03 13:32 ` [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-03-03 13:32 UTC (permalink / raw) To: ltp, andrea.cervesato 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. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index baf73ab11..3ae1b269b 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -8,16 +8,12 @@ /* * DESCRIPTION * Open a file with oflag = O_CREAT set, does it set the sticky bit off? - * Open a dir with O_DIRECTORY, does it set the S_IFDIR bit on? * * ALGORITHM * 1. open a new file with O_CREAT, fstat.st_mode should not have the * 01000 bit on. In Linux, the save text bit is *NOT* cleared. - * 2. open a new dir with O_DIRECTORY, fstat.st_mode should have the - * 040000 bit on. */ -#define _GNU_SOURCE /* for O_DIRECTORY */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -25,7 +21,6 @@ #include "tst_test.h" #define TEST_FILE "testfile" -#define TEST_DIR "testdir" static int fd; @@ -37,7 +32,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, "sirectory bit"} }; static void verify_open(unsigned int n) @@ -46,7 +40,7 @@ static void verify_open(unsigned int n) struct stat buf; TST_EXP_FD_SILENT(open(tc->filename, tc->flag, tc->mode), - "open() with %s", tc->desc); + "open() with %s", tc->desc); if (!TST_PASS) return; @@ -63,11 +57,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) @@ -77,7 +66,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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat 2026-03-03 13:32 ` [LTP] [PATCH v4 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim @ 2026-03-03 13:32 ` Jinseok Kim 2026-03-12 11:22 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-03-03 13:32 UTC (permalink / raw) To: ltp, andrea.cervesato Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISLNK(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- runtest/syscalls | 2 + testcases/kernel/syscalls/fstat/.gitignore | 2 + testcases/kernel/syscalls/fstat/fstat04.c | 119 +++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/runtest/syscalls b/runtest/syscalls index 05bb3ceb1..5b34e6bdc 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -435,6 +435,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 diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore index 9b1089438..a1f538f7e 100644 --- a/testcases/kernel/syscalls/fstat/.gitignore +++ b/testcases/kernel/syscalls/fstat/.gitignore @@ -2,3 +2,5 @@ /fstat02_64 /fstat03 /fstat03_64 +/fstat04 +/fstat04_64 diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..a7f2302f6 --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include "tst_test.h" + +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define SYMLINK "symlink" +#define CHR_DEV "chrdev" +#define BLK_DEV "blkdev" + +static struct tcase { + const char *desc; + const char *path; + mode_t exp_type; +} tcases[] = { + { "S_IFREG", REG_FILE, S_IFREG }, + { "S_IFDIR", DIR_FILE, S_IFDIR }, + { "S_IFIFO", FIFO_FILE, S_IFIFO }, + { "S_IFLNK", SYMLINK, S_IFLNK }, + { "S_IFCHR", CHR_DEV, S_IFCHR }, + { "S_IFBLK", BLK_DEV, S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + int fd = open(tc->path, flags); + + if (fd < 0) { + tst_res(TCONF | TERRNO, "cannot open %s, skipping", tc->desc); + return; + } + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + switch (tc->exp_type) { + case S_IFREG: + TST_EXP_EXPR(S_ISREG(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFDIR: + TST_EXP_EXPR(S_ISDIR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFIFO: + TST_EXP_EXPR(S_ISFIFO(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFLNK: + tst_res(TCONF, "Symbolic Link not available in this environment"); + break; + case S_IFCHR: + TST_EXP_EXPR(S_ISCHR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFBLK: + if (S_ISBLK(buf.st_mode)) + tst_res(TPASS, "%s macro matches", tc->desc); + else + tst_res(TCONF, "Block device not available in this environment"); + break; + } +} + +static void setup(void) +{ + SAFE_TOUCH(REG_FILE, 0644, NULL); + + SAFE_MKDIR(DIR_FILE, 0755); + SAFE_SYMLINK(REG_FILE, SYMLINK); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + if (!access(SYMLINK, F_OK)) + SAFE_UNLINK(SYMLINK); + + if (!access(REG_FILE, F_OK)) + SAFE_UNLINK(REG_FILE); + + if (!access(DIR_FILE, F_OK)) + SAFE_RMDIR(DIR_FILE); + + if (!access(FIFO_FILE, F_OK)) + SAFE_UNLINK(FIFO_FILE); + + if (!access(CHR_DEV, F_OK)) + SAFE_UNLINK(CHR_DEV); + + if (!access(BLK_DEV, F_OK)) + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .needs_tmpdir = 1, + .needs_root = 1, +}; + -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat 2026-03-03 13:32 ` [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat Jinseok Kim @ 2026-03-12 11:22 ` Andrea Cervesato via ltp 2026-03-13 14:07 ` Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-03-12 11:22 UTC (permalink / raw) To: Jinseok Kim, ltp Hi! > Following review feedback, create a dedicated fstat test that verifies > S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISLNK(), S_ISCHR(), S_ISBLK() > on different file types. > > Signed-off-by: Jinseok Kim <always.starving0@gmail.com> > --- > runtest/syscalls | 2 + > testcases/kernel/syscalls/fstat/.gitignore | 2 + > testcases/kernel/syscalls/fstat/fstat04.c | 119 +++++++++++++++++++++ > 3 files changed, 123 insertions(+) > create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c > > diff --git a/runtest/syscalls b/runtest/syscalls > index 05bb3ceb1..5b34e6bdc 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -435,6 +435,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 > diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore > index 9b1089438..a1f538f7e 100644 > --- a/testcases/kernel/syscalls/fstat/.gitignore > +++ b/testcases/kernel/syscalls/fstat/.gitignore > @@ -2,3 +2,5 @@ > /fstat02_64 > /fstat03 > /fstat03_64 > +/fstat04 > +/fstat04_64 > diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c > new file mode 100644 > index 000000000..a7f2302f6 > --- /dev/null > +++ b/testcases/kernel/syscalls/fstat/fstat04.c > @@ -0,0 +1,119 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> > + */ > +/*\ > + * Verify that fstat correctly identifies various file types > + */ > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <sys/sysmacros.h> > +#include "tst_test.h" > + > +#define REG_FILE "regfile" > +#define DIR_FILE "dirfile" > +#define FIFO_FILE "fifofile" > +#define SYMLINK "symlink" > +#define CHR_DEV "chrdev" > +#define BLK_DEV "blkdev" > + > +static struct tcase { > + const char *desc; > + const char *path; > + mode_t exp_type; > +} tcases[] = { > + { "S_IFREG", REG_FILE, S_IFREG }, > + { "S_IFDIR", DIR_FILE, S_IFDIR }, > + { "S_IFIFO", FIFO_FILE, S_IFIFO }, > + { "S_IFLNK", SYMLINK, S_IFLNK }, > + { "S_IFCHR", CHR_DEV, S_IFCHR }, > + { "S_IFBLK", BLK_DEV, S_IFBLK }, > +}; > + > +static void verify_fstat(unsigned int i) > +{ > + struct tcase *tc = &tcases[i]; > + struct stat buf; > + > + int flags = O_RDONLY | O_NONBLOCK; > + > + if (tc->exp_type == S_IFDIR) > + flags |= O_DIRECTORY; > + > + int fd = open(tc->path, flags); > + > + if (fd < 0) { > + tst_res(TCONF | TERRNO, "cannot open %s, skipping", tc->desc); > + return; > + } > + > + SAFE_FSTAT(fd, &buf); > + SAFE_CLOSE(fd); > + > + switch (tc->exp_type) { > + case S_IFREG: > + TST_EXP_EXPR(S_ISREG(buf.st_mode), "%s macro matches", tc->desc); > + break; > + case S_IFDIR: > + TST_EXP_EXPR(S_ISDIR(buf.st_mode), "%s macro matches", tc->desc); > + break; > + case S_IFIFO: > + TST_EXP_EXPR(S_ISFIFO(buf.st_mode), "%s macro matches", tc->desc); > + break; > + case S_IFLNK: > + tst_res(TCONF, "Symbolic Link not available in this environment"); What's the point of always sending TCONF? > + break; > + case S_IFCHR: > + TST_EXP_EXPR(S_ISCHR(buf.st_mode), "%s macro matches", tc->desc); > + break; > + case S_IFBLK: > + if (S_ISBLK(buf.st_mode)) > + tst_res(TPASS, "%s macro matches", tc->desc); > + else > + tst_res(TCONF, "Block device not available in this environment"); And here as well we can use TST_EXP_EXPR() > + break; > + } > +} > + > +static void setup(void) > +{ > + SAFE_TOUCH(REG_FILE, 0644, NULL); > + > + SAFE_MKDIR(DIR_FILE, 0755); > + SAFE_SYMLINK(REG_FILE, SYMLINK); > + > + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); > + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); > + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); > +} > + > +static void cleanup(void) > +{ > + if (!access(SYMLINK, F_OK)) > + SAFE_UNLINK(SYMLINK); > + > + if (!access(REG_FILE, F_OK)) > + SAFE_UNLINK(REG_FILE); > + > + if (!access(DIR_FILE, F_OK)) > + SAFE_RMDIR(DIR_FILE); > + > + if (!access(FIFO_FILE, F_OK)) > + SAFE_UNLINK(FIFO_FILE); > + > + if (!access(CHR_DEV, F_OK)) > + SAFE_UNLINK(CHR_DEV); > + > + if (!access(BLK_DEV, F_OK)) > + SAFE_UNLINK(BLK_DEV); > +} > + > +static struct tst_test test = { > + .tcnt = ARRAY_SIZE(tcases), > + .setup = setup, > + .cleanup = cleanup, > + .test = verify_fstat, > + .needs_tmpdir = 1, > + .needs_root = 1, > +}; > + > -- > 2.43.0 -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat 2026-03-12 11:22 ` Andrea Cervesato via ltp @ 2026-03-13 14:07 ` Jinseok Kim 2026-03-13 15:36 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-03-13 14:07 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp Hi, fstat() follows symbolic links and reports the type of the target file, so it cannot be used to detect S_IFLNK. Would it be better to drop the symlink testcase from this test? Jinseok. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat 2026-03-13 14:07 ` Jinseok Kim @ 2026-03-13 15:36 ` Andrea Cervesato via ltp 2026-03-15 7:27 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-03-13 15:36 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi! > Hi, > > fstat() follows symbolic links and reports the type of the target file, > so it cannot be used to detect S_IFLNK. > > Would it be better to drop the symlink testcase from this test? > > Jinseok. It doesn't make sense to add a test for a feature that we already know it can't be tested, so yes, it makes sense to remove this testcase. -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-03-13 15:36 ` Andrea Cervesato via ltp @ 2026-03-15 7:27 ` Jinseok Kim 2026-03-15 7:27 ` [LTP] [PATCH v5 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 2026-03-16 7:38 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp 0 siblings, 2 replies; 29+ messages in thread From: Jinseok Kim @ 2026-03-15 7:27 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp 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. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index baf73ab11..3ae1b269b 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -8,16 +8,12 @@ /* * DESCRIPTION * Open a file with oflag = O_CREAT set, does it set the sticky bit off? - * Open a dir with O_DIRECTORY, does it set the S_IFDIR bit on? * * ALGORITHM * 1. open a new file with O_CREAT, fstat.st_mode should not have the * 01000 bit on. In Linux, the save text bit is *NOT* cleared. - * 2. open a new dir with O_DIRECTORY, fstat.st_mode should have the - * 040000 bit on. */ -#define _GNU_SOURCE /* for O_DIRECTORY */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -25,7 +21,6 @@ #include "tst_test.h" #define TEST_FILE "testfile" -#define TEST_DIR "testdir" static int fd; @@ -37,7 +32,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, "sirectory bit"} }; static void verify_open(unsigned int n) @@ -46,7 +40,7 @@ static void verify_open(unsigned int n) struct stat buf; TST_EXP_FD_SILENT(open(tc->filename, tc->flag, tc->mode), - "open() with %s", tc->desc); + "open() with %s", tc->desc); if (!TST_PASS) return; @@ -63,11 +57,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) @@ -77,7 +66,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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* [LTP] [PATCH v5 2/2] fstat: add test for multiple file types using fstat 2026-03-15 7:27 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim @ 2026-03-15 7:27 ` Jinseok Kim 2026-03-16 7:38 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp 1 sibling, 0 replies; 29+ messages in thread From: Jinseok Kim @ 2026-03-15 7:27 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- runtest/syscalls | 2 + testcases/kernel/syscalls/fstat/.gitignore | 2 + testcases/kernel/syscalls/fstat/fstat04.c | 106 +++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/runtest/syscalls b/runtest/syscalls index 05bb3ceb1..5b34e6bdc 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -435,6 +435,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 diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore index 9b1089438..a1f538f7e 100644 --- a/testcases/kernel/syscalls/fstat/.gitignore +++ b/testcases/kernel/syscalls/fstat/.gitignore @@ -2,3 +2,5 @@ /fstat02_64 /fstat03 /fstat03_64 +/fstat04 +/fstat04_64 diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..80e14fa7f --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include "tst_test.h" + +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define CHR_DEV "chrdev" +#define BLK_DEV "blkdev" + +static struct tcase { + const char *desc; + const char *path; + mode_t exp_type; +} tcases[] = { + { "S_IFREG", REG_FILE, S_IFREG }, + { "S_IFDIR", DIR_FILE, S_IFDIR }, + { "S_IFIFO", FIFO_FILE, S_IFIFO }, + { "S_IFCHR", CHR_DEV, S_IFCHR }, + { "S_IFBLK", BLK_DEV, S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + int fd = open(tc->path, flags); + + if (fd < 0) { + tst_res(TCONF | TERRNO, "cannot open %s, skipping", tc->desc); + return; + } + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + switch (tc->exp_type) { + case S_IFREG: + TST_EXP_EXPR(S_ISREG(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFDIR: + TST_EXP_EXPR(S_ISDIR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFIFO: + TST_EXP_EXPR(S_ISFIFO(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFCHR: + TST_EXP_EXPR(S_ISCHR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFBLK: + TST_EXP_EXPR(S_ISBLK(buf.st_mode), "%s macro matches", tc->desc); + break; + } +} + +static void setup(void) +{ + SAFE_TOUCH(REG_FILE, 0644, NULL); + SAFE_MKDIR(DIR_FILE, 0755); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + if (!access(REG_FILE, F_OK)) + SAFE_UNLINK(REG_FILE); + + if (!access(DIR_FILE, F_OK)) + SAFE_RMDIR(DIR_FILE); + + if (!access(FIFO_FILE, F_OK)) + SAFE_UNLINK(FIFO_FILE); + + if (!access(CHR_DEV, F_OK)) + SAFE_UNLINK(CHR_DEV); + + if (!access(BLK_DEV, F_OK)) + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .needs_tmpdir = 1, + .needs_root = 1, +}; + -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-03-15 7:27 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 2026-03-15 7:27 ` [LTP] [PATCH v5 2/2] fstat: add test for multiple file types using fstat Jinseok Kim @ 2026-03-16 7:38 ` Andrea Cervesato via ltp 2026-03-16 15:00 ` [LTP] [PATCH v6 " Jinseok Kim 1 sibling, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-03-16 7:38 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Patch doesn't apply. Please verify CI before sending patches, otherwise they will ignored. https://patchwork.ozlabs.org/project/ltp/list/?series=495939 -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v6 1/2] open: remove O_DIRECTORY case (move to fstat test) 2026-03-16 7:38 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp @ 2026-03-16 15:00 ` Jinseok Kim 2026-03-16 15:00 ` [LTP] [PATCH v6 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-03-16 15:00 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp 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. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- testcases/kernel/syscalls/open/open01.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c index 1cefb4790..1413ccdec 100644 --- a/testcases/kernel/syscalls/open/open01.c +++ b/testcases/kernel/syscalls/open/open01.c @@ -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 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* [LTP] [PATCH v6 2/2] fstat: add test for multiple file types using fstat 2026-03-16 15:00 ` [LTP] [PATCH v6 " Jinseok Kim @ 2026-03-16 15:00 ` Jinseok Kim 2026-03-24 12:17 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-03-16 15:00 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- runtest/syscalls | 2 + testcases/kernel/syscalls/fstat/.gitignore | 2 + testcases/kernel/syscalls/fstat/fstat04.c | 105 +++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/runtest/syscalls b/runtest/syscalls index 2179e007c..eadd921b8 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore index 9b1089438..a1f538f7e 100644 --- a/testcases/kernel/syscalls/fstat/.gitignore +++ b/testcases/kernel/syscalls/fstat/.gitignore @@ -2,3 +2,5 @@ /fstat02_64 /fstat03 /fstat03_64 +/fstat04 +/fstat04_64 diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..8723ac2bd --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include "tst_test.h" + +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define CHR_DEV "chrdev" +#define BLK_DEV "blkdev" + +static struct tcase { + const char *desc; + const char *path; + mode_t exp_type; +} tcases[] = { + { "S_IFREG", REG_FILE, S_IFREG }, + { "S_IFDIR", DIR_FILE, S_IFDIR }, + { "S_IFIFO", FIFO_FILE, S_IFIFO }, + { "S_IFCHR", CHR_DEV, S_IFCHR }, + { "S_IFBLK", BLK_DEV, S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + int fd = open(tc->path, flags); + + if (fd < 0) { + tst_res(TCONF | TERRNO, "cannot open %s, skipping", tc->desc); + return; + } + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + switch (tc->exp_type) { + case S_IFREG: + TST_EXP_EXPR(S_ISREG(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFDIR: + TST_EXP_EXPR(S_ISDIR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFIFO: + TST_EXP_EXPR(S_ISFIFO(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFCHR: + TST_EXP_EXPR(S_ISCHR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFBLK: + TST_EXP_EXPR(S_ISBLK(buf.st_mode), "%s macro matches", tc->desc); + break; + } +} + +static void setup(void) +{ + SAFE_TOUCH(REG_FILE, 0644, NULL); + SAFE_MKDIR(DIR_FILE, 0755); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + if (!access(REG_FILE, F_OK)) + SAFE_UNLINK(REG_FILE); + + if (!access(DIR_FILE, F_OK)) + SAFE_RMDIR(DIR_FILE); + + if (!access(FIFO_FILE, F_OK)) + SAFE_UNLINK(FIFO_FILE); + + if (!access(CHR_DEV, F_OK)) + SAFE_UNLINK(CHR_DEV); + + if (!access(BLK_DEV, F_OK)) + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .needs_tmpdir = 1, + .needs_root = 1, +}; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v6 2/2] fstat: add test for multiple file types using fstat 2026-03-16 15:00 ` [LTP] [PATCH v6 2/2] fstat: add test for multiple file types using fstat Jinseok Kim @ 2026-03-24 12:17 ` Andrea Cervesato via ltp 2026-03-27 15:27 ` [LTP] [PATCH v7] " Jinseok Kim 0 siblings, 1 reply; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-03-24 12:17 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi Jinseok, there's one thing to fix: > + int fd = open(tc->path, flags); > + > + if (fd < 0) { > + tst_res(TCONF | TERRNO, "cannot open %s, skipping", tc->desc); > + return; > + } This must be SAFE_OPEN(). I guess your choice was related to the fact that open() is failing with EACCES when tc->exp_type is S_IFBLK or S_IFCHR. This happens because tmpfs is mounted with `nodev`. To enabled devs access, you need to specify a mount point and `.needs_devfs = 1` inside the test struct definition. You can take `fanotify22` test as a reference to understand how this works. After achieving it, we can proceed with merge. Regards, -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
* [LTP] [PATCH v7] fstat: add test for multiple file types using fstat 2026-03-24 12:17 ` Andrea Cervesato via ltp @ 2026-03-27 15:27 ` Jinseok Kim 2026-03-30 8:07 ` Andrea Cervesato via ltp 0 siblings, 1 reply; 29+ messages in thread From: Jinseok Kim @ 2026-03-27 15:27 UTC (permalink / raw) To: andrea.cervesato; +Cc: ltp Following review feedback, create a dedicated fstat test that verifies S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISCHR(), S_ISBLK() on different file types. Signed-off-by: Jinseok Kim <always.starving0@gmail.com> --- runtest/syscalls | 2 + testcases/kernel/syscalls/fstat/.gitignore | 2 + testcases/kernel/syscalls/fstat/fstat04.c | 103 +++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 testcases/kernel/syscalls/fstat/fstat04.c diff --git a/runtest/syscalls b/runtest/syscalls index 6ba0227a8..5a2e8f048 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore index 9b1089438..a1f538f7e 100644 --- a/testcases/kernel/syscalls/fstat/.gitignore +++ b/testcases/kernel/syscalls/fstat/.gitignore @@ -2,3 +2,5 @@ /fstat02_64 /fstat03 /fstat03_64 +/fstat04 +/fstat04_64 diff --git a/testcases/kernel/syscalls/fstat/fstat04.c b/testcases/kernel/syscalls/fstat/fstat04.c new file mode 100644 index 000000000..8a52de06a --- /dev/null +++ b/testcases/kernel/syscalls/fstat/fstat04.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com> + */ +/*\ + * Verify that fstat correctly identifies various file types + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include "tst_test.h" + +#define MOUNT_PATH "test_mnt" +#define REG_FILE "regfile" +#define DIR_FILE "dirfile" +#define FIFO_FILE "fifofile" +#define CHR_DEV MOUNT_PATH"/chrdev" +#define BLK_DEV MOUNT_PATH"/blkdev" + +static struct tcase { + const char *desc; + const char *path; + mode_t exp_type; +} tcases[] = { + { "S_IFREG", REG_FILE, S_IFREG }, + { "S_IFDIR", DIR_FILE, S_IFDIR }, + { "S_IFIFO", FIFO_FILE, S_IFIFO }, + { "S_IFCHR", CHR_DEV, S_IFCHR }, + { "S_IFBLK", BLK_DEV, S_IFBLK }, +}; + +static void verify_fstat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + struct stat buf; + + int flags = O_RDONLY | O_NONBLOCK; + + if (tc->exp_type == S_IFDIR) + flags |= O_DIRECTORY; + + int fd = SAFE_OPEN(tc->path, flags); + + SAFE_FSTAT(fd, &buf); + SAFE_CLOSE(fd); + + switch (tc->exp_type) { + case S_IFREG: + TST_EXP_EXPR(S_ISREG(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFDIR: + TST_EXP_EXPR(S_ISDIR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFIFO: + TST_EXP_EXPR(S_ISFIFO(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFCHR: + TST_EXP_EXPR(S_ISCHR(buf.st_mode), "%s macro matches", tc->desc); + break; + case S_IFBLK: + TST_EXP_EXPR(S_ISBLK(buf.st_mode), "%s macro matches", tc->desc); + break; + } +} + +static void setup(void) +{ + SAFE_TOUCH(REG_FILE, 0644, NULL); + SAFE_MKDIR(DIR_FILE, 0755); + + SAFE_MKNOD(FIFO_FILE, S_IFIFO | 0777, 0); + SAFE_MKNOD(CHR_DEV, S_IFCHR | 0777, makedev(1, 3)); + SAFE_MKNOD(BLK_DEV, S_IFBLK | 0777, makedev(7, 3)); +} + +static void cleanup(void) +{ + if (!access(REG_FILE, F_OK)) + SAFE_UNLINK(REG_FILE); + + if (!access(DIR_FILE, F_OK)) + SAFE_RMDIR(DIR_FILE); + + if (!access(FIFO_FILE, F_OK)) + SAFE_UNLINK(FIFO_FILE); + + if (!access(CHR_DEV, F_OK)) + SAFE_UNLINK(CHR_DEV); + + if (!access(BLK_DEV, F_OK)) + SAFE_UNLINK(BLK_DEV); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_fstat, + .mntpoint = MOUNT_PATH, + .needs_devfs = 1, + .needs_tmpdir = 1, + .needs_root = 1, +}; -- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [LTP] [PATCH v7] fstat: add test for multiple file types using fstat 2026-03-27 15:27 ` [LTP] [PATCH v7] " Jinseok Kim @ 2026-03-30 8:07 ` Andrea Cervesato via ltp 0 siblings, 0 replies; 29+ messages in thread From: Andrea Cervesato via ltp @ 2026-03-30 8:07 UTC (permalink / raw) To: Jinseok Kim; +Cc: ltp Hi Jinseok, Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> Regards, -- Andrea Cervesato SUSE QE Automation Engineer Linux andrea.cervesato@suse.com -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2026-03-30 8:07 UTC | newest] Thread overview: 29+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-11 17:16 [LTP] [PATCH] open: fix directory verification and misleading test description Jinseok Kim 2026-02-17 13:21 ` Andrea Cervesato via ltp 2026-02-19 10:31 ` Cyril Hrubis 2026-02-19 14:57 ` Jinseok Kim 2026-02-20 10:49 ` Cyril Hrubis 2026-02-24 7:37 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 2026-02-24 7:37 ` [LTP] [PATCH 2/2] Add test for multiple file types using fstat Jinseok Kim 2026-02-24 8:17 ` [LTP] [PATCH 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp 2026-02-24 10:07 ` [LTP] [PATCH v2 " Jinseok Kim 2026-02-24 10:07 ` [LTP] [PATCH v2 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 2026-02-24 14:17 ` Andrea Cervesato via ltp 2026-02-25 13:19 ` [LTP] [PATCH v3 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 2026-02-25 13:19 ` [LTP] [PATCH v3 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 2026-02-25 14:30 ` Andrea Cervesato via ltp 2026-02-26 15:32 ` Jinseok Kim 2026-02-26 15:44 ` Andrea Cervesato via ltp 2026-03-03 13:32 ` [LTP] [PATCH v4 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 2026-03-03 13:32 ` [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 2026-03-12 11:22 ` Andrea Cervesato via ltp 2026-03-13 14:07 ` Jinseok Kim 2026-03-13 15:36 ` Andrea Cervesato via ltp 2026-03-15 7:27 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Jinseok Kim 2026-03-15 7:27 ` [LTP] [PATCH v5 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 2026-03-16 7:38 ` [LTP] [PATCH v5 1/2] open: remove O_DIRECTORY case (move to fstat test) Andrea Cervesato via ltp 2026-03-16 15:00 ` [LTP] [PATCH v6 " Jinseok Kim 2026-03-16 15:00 ` [LTP] [PATCH v6 2/2] fstat: add test for multiple file types using fstat Jinseok Kim 2026-03-24 12:17 ` Andrea Cervesato via ltp 2026-03-27 15:27 ` [LTP] [PATCH v7] " Jinseok Kim 2026-03-30 8:07 ` Andrea Cervesato via ltp
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox