* [LTP] [PATCH v3] Add stat04 test
@ 2024-02-19 15:31 Andrea Cervesato
2024-02-21 14:52 ` Cyril Hrubis
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Cervesato @ 2024-02-19 15:31 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.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
TST_EXP_PASS for stat() and SAFE_SYMLINK for symlink()
Removed tests which were already tested by stat03
Removed memory leak using tst_get_tmpdir()
runtest/smoketest | 2 +-
runtest/syscalls | 4 +-
testcases/kernel/syscalls/stat/.gitignore | 2 +
testcases/kernel/syscalls/stat/stat04.c | 47 +++++++++++++++++++++++
4 files changed, 52 insertions(+), 3 deletions(-)
create mode 100644 testcases/kernel/syscalls/stat/stat04.c
diff --git a/runtest/smoketest b/runtest/smoketest
index 83eebfe7b..5608417f9 100644
--- a/runtest/smoketest
+++ b/runtest/smoketest
@@ -8,7 +8,7 @@ time01 time01
wait02 wait02
write01 write01
symlink01 symlink01
-stat04 symlink01 -T stat04
+stat04 stat04
utime01A symlink01 -T utime01
rename01A symlink01 -T rename01
splice02 splice02 -s 20
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..ef90076e4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1529,8 +1529,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..bf2f34083
--- /dev/null
+++ b/testcases/kernel/syscalls/stat/stat04.c
@@ -0,0 +1,47 @@
+// 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 checks that stat() executed on file provide the same information
+ * of symlink linking to it.
+ */
+
+#include "tst_test.h"
+
+static void run(void)
+{
+ char *symname = "my_symlink0";
+ char *tmpdir = tst_get_tmpdir();
+
+ SAFE_SYMLINK(tmpdir, symname);
+
+ struct stat path_stat;
+ struct stat link_stat;
+
+ TST_EXP_PASS(stat(tmpdir, &path_stat));
+ TST_EXP_PASS(stat(symname, &link_stat));
+
+ TST_EXP_EQ_LI(path_stat.st_dev, link_stat.st_dev);
+ TST_EXP_EQ_LI(path_stat.st_mode, link_stat.st_mode);
+ TST_EXP_EQ_LI(path_stat.st_nlink, link_stat.st_nlink);
+ TST_EXP_EQ_LI(path_stat.st_uid, link_stat.st_uid);
+ TST_EXP_EQ_LI(path_stat.st_gid, link_stat.st_gid);
+ TST_EXP_EQ_LI(path_stat.st_size, link_stat.st_size);
+ TST_EXP_EQ_LI(path_stat.st_atime, link_stat.st_atime);
+ TST_EXP_EQ_LI(path_stat.st_mtime, link_stat.st_mtime);
+ TST_EXP_EQ_LI(path_stat.st_ctime, link_stat.st_ctime);
+
+ SAFE_UNLINK(symname);
+}
+
+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 v3] Add stat04 test
2024-02-19 15:31 [LTP] [PATCH v3] Add stat04 test Andrea Cervesato
@ 2024-02-21 14:52 ` Cyril Hrubis
0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2024-02-21 14:52 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +// 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 checks that stat() executed on file provide the same information
> + * of symlink linking to it.
> + */
> +
> +#include "tst_test.h"
> +
> +static void run(void)
> +{
> + char *symname = "my_symlink0";
> + char *tmpdir = tst_get_tmpdir();
This is stil a memory leak. I guess that the test will allocate huge
amount of memory with large enough -i parameter.
Either call it once in the test setup() or use "." instead.
> + SAFE_SYMLINK(tmpdir, symname);
> +
> + struct stat path_stat;
> + struct stat link_stat;
I guess that the output of the comparsions below would look better if we
call these variables just path and link.
> + TST_EXP_PASS(stat(tmpdir, &path_stat));
> + TST_EXP_PASS(stat(symname, &link_stat));
> +
> + TST_EXP_EQ_LI(path_stat.st_dev, link_stat.st_dev);
> + TST_EXP_EQ_LI(path_stat.st_mode, link_stat.st_mode);
> + TST_EXP_EQ_LI(path_stat.st_nlink, link_stat.st_nlink);
> + TST_EXP_EQ_LI(path_stat.st_uid, link_stat.st_uid);
> + TST_EXP_EQ_LI(path_stat.st_gid, link_stat.st_gid);
> + TST_EXP_EQ_LI(path_stat.st_size, link_stat.st_size);
> + TST_EXP_EQ_LI(path_stat.st_atime, link_stat.st_atime);
> + TST_EXP_EQ_LI(path_stat.st_mtime, link_stat.st_mtime);
> + TST_EXP_EQ_LI(path_stat.st_ctime, link_stat.st_ctime);
> +
> + SAFE_UNLINK(symname);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .needs_tmpdir = 1,
> +};
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-21 14:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-19 15:31 [LTP] [PATCH v3] Add stat04 test Andrea Cervesato
2024-02-21 14:52 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox