* [LTP] [PATCH v1] Add utime07 test
@ 2024-01-19 9:16 Andrea Cervesato
2024-03-04 18:14 ` Petr Vorel
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Cervesato @ 2024-01-19 9:16 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test has been extracted from symlink01 test and it verifies that
utime() is working correctly on symlink() generated files.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/smoketest | 2 +-
runtest/syscalls | 2 +-
testcases/kernel/syscalls/utime/.gitignore | 1 +
testcases/kernel/syscalls/utime/utime07.c | 78 ++++++++++++++++++++++
4 files changed, 81 insertions(+), 2 deletions(-)
create mode 100644 testcases/kernel/syscalls/utime/utime07.c
diff --git a/runtest/smoketest b/runtest/smoketest
index 83eebfe7b..f6f14fd2b 100644
--- a/runtest/smoketest
+++ b/runtest/smoketest
@@ -9,7 +9,7 @@ wait02 wait02
write01 write01
symlink01 symlink01
stat04 symlink01 -T stat04
-utime01A symlink01 -T utime01
+utime07 utime07
rename01A symlink01 -T rename01
splice02 splice02 -s 20
df01_sh df01.sh
diff --git a/runtest/syscalls b/runtest/syscalls
index 6e2407879..5fd107e35 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1676,12 +1676,12 @@ ustat01 ustat01
ustat02 ustat02
utime01 utime01
-utime01A symlink01 -T utime01
utime02 utime02
utime03 utime03
utime04 utime04
utime05 utime05
utime06 utime06
+utime07 utime07
utimes01 utimes01
diff --git a/testcases/kernel/syscalls/utime/.gitignore b/testcases/kernel/syscalls/utime/.gitignore
index 94c0ae07c..403764521 100644
--- a/testcases/kernel/syscalls/utime/.gitignore
+++ b/testcases/kernel/syscalls/utime/.gitignore
@@ -4,3 +4,4 @@
/utime04
/utime05
/utime06
+/utime07
diff --git a/testcases/kernel/syscalls/utime/utime07.c b/testcases/kernel/syscalls/utime/utime07.c
new file mode 100644
index 000000000..eaf832099
--- /dev/null
+++ b/testcases/kernel/syscalls/utime/utime07.c
@@ -0,0 +1,78 @@
+// 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 utime() is working correctly on symlink()
+ * generated files.
+ */
+
+#include <utime.h>
+#include "tst_test.h"
+
+static void test_utime(void)
+{
+ char *symname = "my_symlink0";
+ struct stat oldsym_stat;
+ struct stat newsym_stat;
+
+ SAFE_SYMLINK(tst_get_tmpdir(), symname);
+ SAFE_STAT(symname, &oldsym_stat);
+
+ struct utimbuf utimes = {
+ .actime = oldsym_stat.st_atime + 100,
+ .modtime = oldsym_stat.st_mtime + 100
+ };
+
+ TST_EXP_PASS(utime(symname, &utimes));
+ SAFE_STAT(symname, &newsym_stat);
+
+ time_t temp, diff;
+
+ temp = newsym_stat.st_atime - oldsym_stat.st_atime;
+ diff = newsym_stat.st_mtime - oldsym_stat.st_mtime - temp;
+
+ TST_EXP_EQ_LI(diff, 0);
+
+ SAFE_UNLINK(symname);
+}
+
+static void test_utime_no_path(void)
+{
+ char *symname = "my_symlink1";
+ struct utimbuf utimes;
+
+ SAFE_SYMLINK("bc+eFhi!k", symname);
+ TST_EXP_FAIL(utime(symname, &utimes), ENOENT);
+
+ SAFE_UNLINK(symname);
+}
+
+static void test_utime_loop(void)
+{
+ char *symname = "my_symlink2";
+ struct utimbuf utimes;
+
+ SAFE_SYMLINK(symname, symname);
+ TST_EXP_FAIL(utime(symname, &utimes), ELOOP);
+
+ SAFE_UNLINK(symname);
+}
+
+static void run(void)
+{
+ test_utime();
+ test_utime_no_path();
+ test_utime_loop();
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH v1] Add utime07 test
2024-01-19 9:16 [LTP] [PATCH v1] Add utime07 test Andrea Cervesato
@ 2024-03-04 18:14 ` Petr Vorel
0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2024-03-04 18:14 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
> This test has been extracted from symlink01 test and it verifies that
> utime() is working correctly on symlink() generated files.
According to VFS doc [1] VFS does open(2), stat(2), read(2), write(2), chmod(2).
Although the main comparison is done through stat(), it's about utime on
symlink. struct inode_operations described in the docs contain also symlink and
update_time callbacks (filesystem specific). Wouldn't it make sense to run this
on all_filesystems?
[1] https://www.kernel.org/doc/html/latest/filesystems/vfs.html
..
> +++ b/runtest/smoketest
> @@ -9,7 +9,7 @@ wait02 wait02
> write01 write01
> symlink01 symlink01
> stat04 symlink01 -T stat04
> -utime01A symlink01 -T utime01
> +utime07 utime07
> rename01A symlink01 -T rename01
> splice02 splice02 -s 20
> df01_sh df01.sh
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 6e2407879..5fd107e35 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1676,12 +1676,12 @@ ustat01 ustat01
> ustat02 ustat02
> utime01 utime01
> -utime01A symlink01 -T utime01
> utime02 utime02
> utime03 utime03
> utime04 utime04
> utime05 utime05
> utime06 utime06
> +utime07 utime07
> utimes01 utimes01
> diff --git a/testcases/kernel/syscalls/utime/.gitignore b/testcases/kernel/syscalls/utime/.gitignore
> index 94c0ae07c..403764521 100644
> --- a/testcases/kernel/syscalls/utime/.gitignore
> +++ b/testcases/kernel/syscalls/utime/.gitignore
> @@ -4,3 +4,4 @@
> /utime04
> /utime05
> /utime06
> +/utime07
> diff --git a/testcases/kernel/syscalls/utime/utime07.c b/testcases/kernel/syscalls/utime/utime07.c
> new file mode 100644
> index 000000000..eaf832099
> --- /dev/null
> +++ b/testcases/kernel/syscalls/utime/utime07.c
> @@ -0,0 +1,78 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
> + * Author: David Fenner
> + * Copilot: Jon Hendrickson
nit: original test is v2 only. But we are writing from scratch, using a previous
just as an inspiration. I suppose we still need to use the original copyright
and likely also the license v2 only.
> + * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that utime() is working correctly on symlink()
> + * generated files.
> + */
> +
> +#include <utime.h>
> +#include "tst_test.h"
> +
> +static void test_utime(void)
> +{
> + char *symname = "my_symlink0";
> + struct stat oldsym_stat;
> + struct stat newsym_stat;
> +
> + SAFE_SYMLINK(tst_get_tmpdir(), symname);
Original test actually also perform lstat() on the symlink
and checks for S_IFLNK. You consider SAFE_SYMLINK() enough?
The rest LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
> + SAFE_STAT(symname, &oldsym_stat);
> +
> + struct utimbuf utimes = {
> + .actime = oldsym_stat.st_atime + 100,
> + .modtime = oldsym_stat.st_mtime + 100
> + };
> +
> + TST_EXP_PASS(utime(symname, &utimes));
> + SAFE_STAT(symname, &newsym_stat);
> +
> + time_t temp, diff;
> +
> + temp = newsym_stat.st_atime - oldsym_stat.st_atime;
> + diff = newsym_stat.st_mtime - oldsym_stat.st_mtime - temp;
> +
> + TST_EXP_EQ_LI(diff, 0);
> +
> + SAFE_UNLINK(symname);
> +}
> +
> +static void test_utime_no_path(void)
> +{
> + char *symname = "my_symlink1";
> + struct utimbuf utimes;
> +
> + SAFE_SYMLINK("bc+eFhi!k", symname);
> + TST_EXP_FAIL(utime(symname, &utimes), ENOENT);
> +
> + SAFE_UNLINK(symname);
> +}
> +
> +static void test_utime_loop(void)
> +{
> + char *symname = "my_symlink2";
> + struct utimbuf utimes;
> +
> + SAFE_SYMLINK(symname, symname);
> + TST_EXP_FAIL(utime(symname, &utimes), ELOOP);
> +
> + SAFE_UNLINK(symname);
> +}
> +
> +static void run(void)
> +{
> + test_utime();
> + test_utime_no_path();
> + test_utime_loop();
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .needs_tmpdir = 1,
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-04 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19 9:16 [LTP] [PATCH v1] Add utime07 test Andrea Cervesato
2024-03-04 18:14 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox