From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/5] Add lstat03 test
Date: Tue, 02 Jul 2024 16:12:49 +0200 [thread overview]
Message-ID: <20240702-stat04-v1-3-e27d9953210d@suse.com> (raw)
In-Reply-To: <20240702-stat04-v1-0-e27d9953210d@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 test and it checks that
lstat() provides the right information, according with device, access
time, block size, ownership, etc.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 4 +-
testcases/kernel/syscalls/lstat/.gitignore | 2 +
testcases/kernel/syscalls/lstat/lstat03.c | 102 +++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 2 deletions(-)
diff --git a/runtest/syscalls b/runtest/syscalls
index 3e7a5ca1b..d78b6822b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -725,12 +725,12 @@ lseek02 lseek02
lseek07 lseek07
lseek11 lseek11
-lstat01A symlink01 -T lstat01
-lstat01A_64 symlink01 -T lstat01_64
lstat01 lstat01
lstat01_64 lstat01_64
lstat02 lstat02
lstat02_64 lstat02_64
+lstat03 lstat03
+lstat03_64 lstat03_64
mallinfo02 mallinfo02
diff --git a/testcases/kernel/syscalls/lstat/.gitignore b/testcases/kernel/syscalls/lstat/.gitignore
index a497a445f..72cba871f 100644
--- a/testcases/kernel/syscalls/lstat/.gitignore
+++ b/testcases/kernel/syscalls/lstat/.gitignore
@@ -2,3 +2,5 @@
/lstat01_64
/lstat02
/lstat02_64
+/lstat03
+/lstat03_64
diff --git a/testcases/kernel/syscalls/lstat/lstat03.c b/testcases/kernel/syscalls/lstat/lstat03.c
new file mode 100644
index 000000000..b52ba0c35
--- /dev/null
+++ b/testcases/kernel/syscalls/lstat/lstat03.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Author: David Fenner, Jon Hendrickson
+ * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that lstat() provides correct information according
+ * with device, access time, block size, ownership, etc.
+ * The implementation provides a set of tests which are specific for each one
+ * of the `struct stat` used to read file and symlink information.
+ */
+
+#include "tst_test.h"
+
+#define FILENAME "file.txt"
+#define MNTPOINT "mntpoint"
+#define SYMBNAME MNTPOINT"/file_symlink"
+
+static struct stat *file_stat;
+static struct stat *symb_stat;
+
+static void run(void)
+{
+ TST_EXP_EXPR(file_stat->st_dev != symb_stat->st_dev);
+ TST_EXP_EXPR(file_stat->st_mode != symb_stat->st_mode);
+ TST_EXP_EXPR(file_stat->st_nlink != symb_stat->st_nlink);
+ TST_EXP_EXPR(file_stat->st_ino != symb_stat->st_ino);
+ TST_EXP_EXPR(file_stat->st_uid != symb_stat->st_uid);
+ TST_EXP_EXPR(file_stat->st_gid != symb_stat->st_gid);
+ TST_EXP_EXPR(file_stat->st_size != symb_stat->st_size);
+ TST_EXP_EXPR(file_stat->st_blocks != symb_stat->st_blocks);
+ TST_EXP_EXPR(file_stat->st_blksize != symb_stat->st_blksize);
+ TST_EXP_EXPR(file_stat->st_atime != symb_stat->st_atime);
+ TST_EXP_EXPR(file_stat->st_mtime != symb_stat->st_mtime);
+ TST_EXP_EXPR(file_stat->st_ctime != symb_stat->st_ctime);
+}
+
+static void setup(void)
+{
+ char opt_bsize[32];
+ const char *const fs_opts[] = {opt_bsize, NULL};
+ struct stat sb;
+ int pagesize;
+ int fd;
+
+ /* change st_blksize / st_dev */
+ SAFE_STAT(".", &sb);
+ pagesize = sb.st_blksize == 4096 ? 1024 : 4096;
+
+ snprintf(opt_bsize, sizeof(opt_bsize), "-b %i", pagesize);
+ SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
+ SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, 0);
+
+ SAFE_TOUCH(FILENAME, 0777, NULL);
+
+ /* change st_nlink */
+ SAFE_LINK(FILENAME, "linked_file");
+
+ /* change st_uid and st_gid */
+ SAFE_CHOWN(FILENAME, 1000, 1000);
+
+ /* change st_size */
+ fd = SAFE_OPEN(FILENAME, O_WRONLY, 0777);
+ tst_fill_fd(fd, 'a', TST_KB, 500);
+ SAFE_CLOSE(fd);
+
+ /* change st_atime / st_mtime / st_ctime */
+ sleep(1);
+
+ SAFE_SYMLINK(FILENAME, SYMBNAME);
+
+ SAFE_LSTAT(FILENAME, file_stat);
+ SAFE_LSTAT(SYMBNAME, symb_stat);
+}
+
+static void cleanup(void)
+{
+ SAFE_UNLINK(SYMBNAME);
+
+ if (tst_is_mounted(MNTPOINT))
+ SAFE_UMOUNT(MNTPOINT);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .needs_device = 1,
+ .mntpoint = MNTPOINT,
+ .dev_fs_type = "ext2",
+ .bufs = (struct tst_buffers []) {
+ {&file_stat, .size = sizeof(struct stat)},
+ {&symb_stat, .size = sizeof(struct stat)},
+ {}
+ }
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-07-02 14:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 14:12 [LTP] [PATCH 0/5] symlink01 split Andrea Cervesato
2024-07-02 14:12 ` [LTP] [PATCH 1/5] Add stat04 test Andrea Cervesato
2024-07-04 7:06 ` Li Wang
2024-07-04 9:17 ` Cyril Hrubis
2024-07-04 9:23 ` Cyril Hrubis
2024-07-04 11:27 ` Li Wang
2024-07-04 11:55 ` Cyril Hrubis
2024-07-04 12:02 ` Li Wang
2024-07-02 14:12 ` [LTP] [PATCH 2/5] Fix TST_EXP_EXTR() stringification Andrea Cervesato
2024-07-04 7:11 ` Li Wang
2024-07-04 9:19 ` Cyril Hrubis
2024-07-02 14:12 ` Andrea Cervesato [this message]
2024-07-04 6:36 ` [LTP] [PATCH 3/5] Add lstat03 test Li Wang
2024-07-04 6:56 ` Li Wang
2024-07-02 14:12 ` [LTP] [PATCH 4/5] Add chmod08 test Andrea Cervesato
2024-07-04 7:12 ` Li Wang
2024-07-02 14:12 ` [LTP] [PATCH 5/5] Add open15 test Andrea Cervesato
2024-07-04 7:18 ` Li Wang
2024-07-04 7:32 ` Li Wang
2024-07-09 10:31 ` 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=20240702-stat04-v1-3-e27d9953210d@suse.com \
--to=andrea.cervesato@suse.de \
--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.