From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: "Jinseok Kim" <always.starving0@gmail.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 2/2] fstat: add test for multiple file types using fstat
Date: Thu, 12 Mar 2026 11:22:22 +0000 [thread overview]
Message-ID: <69b2a1ef.050a0220.31a4ce.a1ea@mx.google.com> (raw)
In-Reply-To: <20260303133243.66845-2-always.starving0@gmail.com>
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
next prev parent reply other threads:[~2026-03-12 11:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=69b2a1ef.050a0220.31a4ce.a1ea@mx.google.com \
--to=ltp@lists.linux.it \
--cc=always.starving0@gmail.com \
--cc=andrea.cervesato@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox