* [LTP] [PATCH v4 1/4] Add stat04 test
2024-07-11 7:43 [LTP] [PATCH v4 0/4] symlink01 split Andrea Cervesato
@ 2024-07-11 7:43 ` Andrea Cervesato
2024-07-11 7:43 ` [LTP] [PATCH v4 2/4] Add lstat03 test Andrea Cervesato
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-11 7:43 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 test and it checks that
stat() executed on file provide the same information of symlink linking
to it.
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/smoketest | 4 +-
runtest/syscalls | 4 +-
testcases/kernel/syscalls/stat/.gitignore | 2 +
testcases/kernel/syscalls/stat/stat04.c | 109 ++++++++++++++++++++++++++++++
4 files changed, 114 insertions(+), 5 deletions(-)
diff --git a/runtest/smoketest b/runtest/smoketest
index f6f14fd2b..aeb74c9ee 100644
--- a/runtest/smoketest
+++ b/runtest/smoketest
@@ -8,9 +8,7 @@ time01 time01
wait02 wait02
write01 write01
symlink01 symlink01
-stat04 symlink01 -T stat04
-utime07 utime07
-rename01A symlink01 -T rename01
+stat04 stat04
splice02 splice02 -s 20
df01_sh df01.sh
shell_test01 echo "SUCCESS" | shell_pipe01.sh
diff --git a/runtest/syscalls b/runtest/syscalls
index b6cadb2df..1e1203503 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1535,8 +1535,8 @@ stat02 stat02
stat02_64 stat02_64
stat03 stat03
stat03_64 stat03_64
-stat04 symlink01 -T stat04
-stat04_64 symlink01 -T stat04_64
+stat04 stat04
+stat04_64 stat04_64
statfs01 statfs01
statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/stat/.gitignore b/testcases/kernel/syscalls/stat/.gitignore
index fa0a4ce9f..0a62dc6ee 100644
--- a/testcases/kernel/syscalls/stat/.gitignore
+++ b/testcases/kernel/syscalls/stat/.gitignore
@@ -4,3 +4,5 @@
/stat02_64
/stat03
/stat03_64
+/stat04
+/stat04_64
diff --git a/testcases/kernel/syscalls/stat/stat04.c b/testcases/kernel/syscalls/stat/stat04.c
new file mode 100644
index 000000000..8dbf58a1d
--- /dev/null
+++ b/testcases/kernel/syscalls/stat/stat04.c
@@ -0,0 +1,109 @@
+// 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 checks that stat() executed on file provide the same information
+ * of symlink linking to it.
+ */
+
+#include <stdlib.h>
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+
+#define FILENAME "file.txt"
+#define MNTPOINT "mntpoint"
+#define SYMBNAME MNTPOINT"/file_symlink"
+
+static char *symb_path;
+static char *file_path;
+static struct stat *file_stat;
+static struct stat *symb_stat;
+
+static void run(void)
+{
+ SAFE_STAT(file_path, file_stat);
+ SAFE_STAT(symb_path, symb_stat);
+
+ TST_EXP_EQ_LI(file_stat->st_dev, symb_stat->st_dev);
+ TST_EXP_EQ_LI(file_stat->st_mode, symb_stat->st_mode);
+ TST_EXP_EQ_LI(file_stat->st_nlink, symb_stat->st_nlink);
+ TST_EXP_EQ_LI(file_stat->st_uid, symb_stat->st_uid);
+ TST_EXP_EQ_LI(file_stat->st_gid, symb_stat->st_gid);
+ TST_EXP_EQ_LI(file_stat->st_size, symb_stat->st_size);
+ TST_EXP_EQ_LI(file_stat->st_atime, symb_stat->st_atime);
+ TST_EXP_EQ_LI(file_stat->st_mtime, symb_stat->st_mtime);
+ TST_EXP_EQ_LI(file_stat->st_ctime, symb_stat->st_ctime);
+}
+
+static void setup(void)
+{
+ char opt_bsize[32];
+ char *tmpdir;
+ const char *const fs_opts[] = {opt_bsize, NULL};
+ struct stat sb;
+ int pagesize;
+ int fd;
+
+ tmpdir = tst_get_tmpdir();
+ SAFE_ASPRINTF(&file_path, "%s/%s", tmpdir, FILENAME);
+ SAFE_ASPRINTF(&symb_path, "%s/%s", tmpdir, SYMBNAME);
+ free(tmpdir);
+
+ /* 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 */
+ usleep(1001000);
+
+ SAFE_SYMLINK(file_path, symb_path);
+}
+
+static void cleanup(void)
+{
+ if (file_path)
+ free(file_path);
+
+ if (symb_path)
+ free(symb_path);
+
+ if (tst_is_mounted(MNTPOINT))
+ SAFE_UMOUNT(MNTPOINT);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run,
+ .needs_root = 1,
+ .needs_device = 1,
+ .mntpoint = MNTPOINT,
+ .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
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH v4 2/4] Add lstat03 test
2024-07-11 7:43 [LTP] [PATCH v4 0/4] symlink01 split Andrea Cervesato
2024-07-11 7:43 ` [LTP] [PATCH v4 1/4] Add stat04 test Andrea Cervesato
@ 2024-07-11 7:43 ` Andrea Cervesato
2024-07-11 8:33 ` Cyril Hrubis
2024-07-11 7:43 ` [LTP] [PATCH v4 3/4] Add chmod08 test Andrea Cervesato
2024-07-11 7:43 ` [LTP] [PATCH v4 4/4] Add open15 test Andrea Cervesato
3 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-11 7:43 UTC (permalink / raw)
To: ltp
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.
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 4 +-
testcases/kernel/syscalls/lstat/.gitignore | 2 +
testcases/kernel/syscalls/lstat/lstat03.c | 99 ++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+), 2 deletions(-)
diff --git a/runtest/syscalls b/runtest/syscalls
index 1e1203503..160725893 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..4edabba7b
--- /dev/null
+++ b/testcases/kernel/syscalls/lstat/lstat03.c
@@ -0,0 +1,99 @@
+// 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)
+{
+ SAFE_LSTAT(FILENAME, file_stat);
+ SAFE_LSTAT(SYMBNAME, symb_stat);
+
+ 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 */
+ usleep(1001000);
+
+ SAFE_SYMLINK(FILENAME, SYMBNAME);
+}
+
+static void cleanup(void)
+{
+ 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,
+ .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
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH v4 3/4] Add chmod08 test
2024-07-11 7:43 [LTP] [PATCH v4 0/4] symlink01 split Andrea Cervesato
2024-07-11 7:43 ` [LTP] [PATCH v4 1/4] Add stat04 test Andrea Cervesato
2024-07-11 7:43 ` [LTP] [PATCH v4 2/4] Add lstat03 test Andrea Cervesato
@ 2024-07-11 7:43 ` Andrea Cervesato
2024-07-11 8:43 ` Cyril Hrubis
2024-07-11 7:43 ` [LTP] [PATCH v4 4/4] Add open15 test Andrea Cervesato
3 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-11 7:43 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 and it verifies that
chmod() is working correctly on symlink() generated files.
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/chmod/.gitignore | 1 +
testcases/kernel/syscalls/chmod/chmod08.c | 45 ++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 160725893..40c0dd070 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -72,6 +72,7 @@ chmod03 chmod03
chmod05 chmod05
chmod06 chmod06
chmod07 chmod07
+chmod08 chmod08
chown01 chown01
chown01_16 chown01_16
diff --git a/testcases/kernel/syscalls/chmod/.gitignore b/testcases/kernel/syscalls/chmod/.gitignore
index 27ddfce16..f295f4dcb 100644
--- a/testcases/kernel/syscalls/chmod/.gitignore
+++ b/testcases/kernel/syscalls/chmod/.gitignore
@@ -3,3 +3,4 @@
/chmod05
/chmod06
/chmod07
+/chmod08
diff --git a/testcases/kernel/syscalls/chmod/chmod08.c b/testcases/kernel/syscalls/chmod/chmod08.c
new file mode 100644
index 000000000..87519dbe8
--- /dev/null
+++ b/testcases/kernel/syscalls/chmod/chmod08.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Author: David Fenner
+ * Copilot: Jon Hendrickson
+ * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that chmod() is working correctly on symlink()
+ * generated files.
+ */
+
+#include "tst_test.h"
+
+#define PERMS 01777
+#define TESTFILE "myobject"
+#define SYMBNAME "my_symlink0"
+
+static void run(void)
+{
+ struct stat oldsym_stat;
+ struct stat newsym_stat;
+
+ SAFE_TOUCH(TESTFILE, 0644, NULL);
+ SAFE_SYMLINK(TESTFILE, SYMBNAME);
+ SAFE_STAT(SYMBNAME, &oldsym_stat);
+
+ TST_EXP_PASS(chmod(SYMBNAME, PERMS));
+ SAFE_STAT(SYMBNAME, &newsym_stat);
+
+ TST_EXP_EQ_LI(newsym_stat.st_mode & PERMS, PERMS);
+ TST_EXP_EXPR(oldsym_stat.st_mode != newsym_stat.st_mode,
+ "file mode has changed");
+
+ SAFE_UNLINK(SYMBNAME);
+ SAFE_UNLINK(TESTFILE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH v4 4/4] Add open15 test
2024-07-11 7:43 [LTP] [PATCH v4 0/4] symlink01 split Andrea Cervesato
` (2 preceding siblings ...)
2024-07-11 7:43 ` [LTP] [PATCH v4 3/4] Add chmod08 test Andrea Cervesato
@ 2024-07-11 7:43 ` Andrea Cervesato
2024-07-11 8:50 ` Cyril Hrubis
3 siblings, 1 reply; 10+ messages in thread
From: Andrea Cervesato @ 2024-07-11 7:43 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 and it verifies that
open() is working correctly on symlink() generated files.
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +-
testcases/kernel/syscalls/open/.gitignore | 1 +
testcases/kernel/syscalls/open/open15.c | 75 +++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/runtest/syscalls b/runtest/syscalls
index 40c0dd070..4dfdf3782 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -923,7 +923,6 @@ nice04 nice04
nice05 nice05
open01 open01
-open01A symlink01 -T open01
open02 open02
open03 open03
open04 open04
@@ -936,6 +935,7 @@ open11 open11
open12 open12
open13 open13
open14 open14
+open15 open15
openat01 openat01
openat02 openat02
diff --git a/testcases/kernel/syscalls/open/.gitignore b/testcases/kernel/syscalls/open/.gitignore
index 001d874d6..af5997572 100644
--- a/testcases/kernel/syscalls/open/.gitignore
+++ b/testcases/kernel/syscalls/open/.gitignore
@@ -12,3 +12,4 @@
/open12_child
/open13
/open14
+/open15
diff --git a/testcases/kernel/syscalls/open/open15.c b/testcases/kernel/syscalls/open/open15.c
new file mode 100644
index 000000000..09d7a1f3b
--- /dev/null
+++ b/testcases/kernel/syscalls/open/open15.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ * Author: David Fenner
+ * Copilot: Jon Hendrickson
+ * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that open() is working correctly on symlink()
+ * generated files. We generate a file via symlink, then we read both from file
+ * and symlink, comparing that data has been correctly written.
+ */
+
+#include "tst_test.h"
+
+#define FILENAME "myfile.txt"
+#define SYMBNAME "myfile_symlink"
+#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
+
+static char buff_file[128];
+static char buff_symb[128];
+static int str_size;
+
+static void run(void)
+{
+ int fd_file, fd_symb;
+
+ memset(buff_file, 0, sizeof(buff_file));
+ memset(buff_symb, 0, sizeof(buff_symb));
+
+ tst_res(TINFO, "Create symlink");
+ SAFE_TOUCH(FILENAME, 0777, NULL);
+ SAFE_SYMLINK(FILENAME, SYMBNAME);
+
+ fd_file = SAFE_OPEN(FILENAME, O_RDONLY, 0777);
+ fd_symb = SAFE_OPEN(SYMBNAME, O_RDWR, 0777);
+
+ tst_res(TINFO, "Write data via symlink");
+ SAFE_WRITE(SAFE_WRITE_ALL, fd_symb, BIG_STRING, str_size);
+ SAFE_LSEEK(fd_symb, 0, 0);
+
+ tst_res(TINFO, "Read data via file");
+ SAFE_READ(1, fd_file, buff_file, str_size);
+ SAFE_LSEEK(fd_file, 0, 0);
+
+ tst_res(TINFO, "Read data via symlink");
+ SAFE_READ(1, fd_symb, buff_symb, str_size);
+ SAFE_LSEEK(fd_symb, 0, 0);
+
+ TST_EXP_EXPR(!strncmp(buff_file, BIG_STRING, str_size),
+ "file data has been correctly written");
+
+ TST_EXP_EXPR(!strncmp(buff_file, buff_symb, str_size),
+ "file data is the equivalent to symlink generated file data");
+
+ SAFE_CLOSE(fd_file);
+ SAFE_CLOSE(fd_symb);
+
+ SAFE_UNLINK(SYMBNAME);
+ SAFE_UNLINK(FILENAME);
+}
+
+static void setup(void)
+{
+ str_size = strlen(BIG_STRING);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .needs_tmpdir = 1,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread