From: Petr Vorel <pvorel@suse.cz>
To: Jinseok Kim <always.starving0@gmail.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v7] fstat: add test for multiple file types using fstat
Date: Fri, 17 Apr 2026 12:57:59 +0200 [thread overview]
Message-ID: <20260417105759.GA395133@pevik> (raw)
In-Reply-To: <20260327152751.3637-1-always.starving0@gmail.com>
Hi Jinseok,
> Following review feedback, create a dedicated fstat test that verifies
> S_ISREG(), S_ISDIR(), S_ISFIFO(), S_ISCHR(), S_ISBLK() on different file
> types.
> 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
nit: Please use :manpage:`fstat(2)` instead of just fstat.
nit: missing dot at the end.
> + */
> +#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 },
FYI It's better to use macros to not repeat yourself ("S_IFDIR" and S_IFREG),
together with designated initializers, e.g. what is being used in e.g.
testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c.
#define DESC(x) .desc = #x, .exp_type = x
{ DESC(S_IFREG), .path = REG_FILE },
But I would prefer to drop desc entirely (useless see below).
> + { "S_IFDIR", DIR_FILE, S_IFDIR },
> + { "S_IFIFO", FIFO_FILE, S_IFIFO },
> + { "S_IFCHR", CHR_DEV, S_IFCHR },
> + { "S_IFBLK", BLK_DEV, S_IFBLK },
How about others two? At least S_IFLNK (symlink) should be simple to add,
I suppose S_IFSOCK (socket) as well.
> +};
> +
> +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);
TST_EXP_EXPR(S_ISREG(buf.st_mode));
Not using desc is IMHO good enough for debugging:
fstat04.c:49: TPASS: Expect: S_ISREG(buf.st_mode)
Original code did not have much of added value:
fstat04.c:49: TPASS: Expect: S_IFREG macro matches
The rest LGTM.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-04-17 10:58 UTC|newest]
Thread overview: 31+ 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
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
2026-04-17 10:57 ` Petr Vorel [this message]
2026-04-21 15:24 ` Jinseok Kim
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=20260417105759.GA395133@pevik \
--to=pvorel@suse.cz \
--cc=always.starving0@gmail.com \
--cc=ltp@lists.linux.it \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.