* [LTP] [PATCH v5] Add stat04 test
@ 2024-04-17 14:44 Andrea Cervesato
2024-06-24 12:22 ` Cyril Hrubis
0 siblings, 1 reply; 5+ messages in thread
From: Andrea Cervesato @ 2024-04-17 14:44 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>
---
Change Author description adding copilot
Fetch tmpdir in setup() and free it in cleanup()
runtest/smoketest | 2 +-
runtest/syscalls | 4 +-
testcases/kernel/syscalls/stat/.gitignore | 2 +
testcases/kernel/syscalls/stat/stat04.c | 60 +++++++++++++++++++++++
4 files changed, 65 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 010a1a752..b18e14d7c 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..edb94656d
--- /dev/null
+++ b/testcases/kernel/syscalls/stat/stat04.c
@@ -0,0 +1,60 @@
+// 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"
+
+static char *tmpdir;
+
+static void run(void)
+{
+ char *symname = "my_symlink0";
+
+ SAFE_SYMLINK(tmpdir, symname);
+
+ struct stat path;
+ struct stat link;
+
+ TST_EXP_PASS(stat(tmpdir, &path));
+ TST_EXP_PASS(stat(symname, &link));
+
+ TST_EXP_EQ_LI(path.st_dev, link.st_dev);
+ TST_EXP_EQ_LI(path.st_mode, link.st_mode);
+ TST_EXP_EQ_LI(path.st_nlink, link.st_nlink);
+ TST_EXP_EQ_LI(path.st_uid, link.st_uid);
+ TST_EXP_EQ_LI(path.st_gid, link.st_gid);
+ TST_EXP_EQ_LI(path.st_size, link.st_size);
+ TST_EXP_EQ_LI(path.st_atime, link.st_atime);
+ TST_EXP_EQ_LI(path.st_mtime, link.st_mtime);
+ TST_EXP_EQ_LI(path.st_ctime, link.st_ctime);
+
+ SAFE_UNLINK(symname);
+}
+
+static void setup(void)
+{
+ tmpdir = tst_get_tmpdir();
+}
+
+static void cleanup(void)
+{
+ free(tmpdir);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v5] Add stat04 test
2024-04-17 14:44 [LTP] [PATCH v5] Add stat04 test Andrea Cervesato
@ 2024-06-24 12:22 ` Cyril Hrubis
2024-07-02 13:10 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2024-06-24 12:22 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +/*\
> + * [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"
> +
> +static char *tmpdir;
> +
> +static void run(void)
> +{
> + char *symname = "my_symlink0";
> +
> + SAFE_SYMLINK(tmpdir, symname);
> +
> + struct stat path;
> + struct stat link;
> +
> + TST_EXP_PASS(stat(tmpdir, &path));
> + TST_EXP_PASS(stat(symname, &link));
> +
> + TST_EXP_EQ_LI(path.st_dev, link.st_dev);
> + TST_EXP_EQ_LI(path.st_mode, link.st_mode);
> + TST_EXP_EQ_LI(path.st_nlink, link.st_nlink);
> + TST_EXP_EQ_LI(path.st_uid, link.st_uid);
> + TST_EXP_EQ_LI(path.st_gid, link.st_gid);
> + TST_EXP_EQ_LI(path.st_size, link.st_size);
> + TST_EXP_EQ_LI(path.st_atime, link.st_atime);
> + TST_EXP_EQ_LI(path.st_mtime, link.st_mtime);
> + TST_EXP_EQ_LI(path.st_ctime, link.st_ctime);
Looking at these, most of the would be the same both for the link and
the actual target. Maybe we should do some extra work in the test setup
to make sure they differ. I would create a file in the temporary
directory as a target for the symlink and use chown() to set a different
owner and group, we can use utime() to change access and modification
time to the beginning of the unix epoch. If we write a megabyte or so to
the file the size should differ as well. If we link() the file it's
nlink counter should increase. And I suppose that if we create either
the file or the symlink on a mounted loop device, it will have different
dev number as well.
I think that the only part that is not changed easily is the creation
time (also called birth time), the rest should be under our control.
> + SAFE_UNLINK(symname);
> +}
> +
> +static void setup(void)
> +{
> + tmpdir = tst_get_tmpdir();
> +}
> +
> +static void cleanup(void)
> +{
> + free(tmpdir);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .setup = setup,
> + .cleanup = cleanup,
> + .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] 5+ messages in thread* Re: [LTP] [PATCH v5] Add stat04 test
2024-06-24 12:22 ` Cyril Hrubis
@ 2024-07-02 13:10 ` Andrea Cervesato via ltp
2024-07-02 13:26 ` Cyril Hrubis
0 siblings, 1 reply; 5+ messages in thread
From: Andrea Cervesato via ltp @ 2024-07-02 13:10 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
Hi!
This test is basically a clone of the lstat03 test. I'm wondering if it
makes sense to have both, when we already have that one.
Andrea
On 6/24/24 14:22, Cyril Hrubis wrote:
> Hi!
>> +/*\
>> + * [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"
>> +
>> +static char *tmpdir;
>> +
>> +static void run(void)
>> +{
>> + char *symname = "my_symlink0";
>> +
>> + SAFE_SYMLINK(tmpdir, symname);
>> +
>> + struct stat path;
>> + struct stat link;
>> +
>> + TST_EXP_PASS(stat(tmpdir, &path));
>> + TST_EXP_PASS(stat(symname, &link));
>> +
>> + TST_EXP_EQ_LI(path.st_dev, link.st_dev);
>> + TST_EXP_EQ_LI(path.st_mode, link.st_mode);
>> + TST_EXP_EQ_LI(path.st_nlink, link.st_nlink);
>> + TST_EXP_EQ_LI(path.st_uid, link.st_uid);
>> + TST_EXP_EQ_LI(path.st_gid, link.st_gid);
>> + TST_EXP_EQ_LI(path.st_size, link.st_size);
>> + TST_EXP_EQ_LI(path.st_atime, link.st_atime);
>> + TST_EXP_EQ_LI(path.st_mtime, link.st_mtime);
>> + TST_EXP_EQ_LI(path.st_ctime, link.st_ctime);
> Looking at these, most of the would be the same both for the link and
> the actual target. Maybe we should do some extra work in the test setup
> to make sure they differ. I would create a file in the temporary
> directory as a target for the symlink and use chown() to set a different
> owner and group, we can use utime() to change access and modification
> time to the beginning of the unix epoch. If we write a megabyte or so to
> the file the size should differ as well. If we link() the file it's
> nlink counter should increase. And I suppose that if we create either
> the file or the symlink on a mounted loop device, it will have different
> dev number as well.
>
> I think that the only part that is not changed easily is the creation
> time (also called birth time), the rest should be under our control.
>
>> + SAFE_UNLINK(symname);
>> +}
>> +
>> +static void setup(void)
>> +{
>> + tmpdir = tst_get_tmpdir();
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> + free(tmpdir);
>> +}
>> +
>> +static struct tst_test test = {
>> + .test_all = run,
>> + .setup = setup,
>> + .cleanup = cleanup,
>> + .needs_tmpdir = 1,
>> +};
>> --
>> 2.35.3
>>
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH v5] Add stat04 test
2024-07-02 13:10 ` Andrea Cervesato via ltp
@ 2024-07-02 13:26 ` Cyril Hrubis
2024-07-02 13:30 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2024-07-02 13:26 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> This test is basically a clone of the lstat03 test. I'm wondering if it
> makes sense to have both, when we already have that one.
You are stil missing the point of this test, the end result we expect is
different for stat() and lstat(). The point I'm trying to make is that
we should:
1. Make sure that as many attributes are diffent for the symlink and the
symlink target for *both* stat() and lstat() tests, since if they are
not made different the test does results are not conclusive at all
2. For stat() you should get same result on the file and symlink since
stat actually follows the symlink then gets the data
3. For lstat() you should get different result on the file and symlink
since lstat() *does not* follow the symlink before it gets the data
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH v5] Add stat04 test
2024-07-02 13:26 ` Cyril Hrubis
@ 2024-07-02 13:30 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 5+ messages in thread
From: Andrea Cervesato via ltp @ 2024-07-02 13:30 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi,
yes I got lost in the code and missed the point. I think I need more sleep..
Thanks for the reply,
Andrea
On 7/2/24 15:26, Cyril Hrubis wrote:
> Hi!
>> This test is basically a clone of the lstat03 test. I'm wondering if it
>> makes sense to have both, when we already have that one.
> You are stil missing the point of this test, the end result we expect is
> different for stat() and lstat(). The point I'm trying to make is that
> we should:
>
> 1. Make sure that as many attributes are diffent for the symlink and the
> symlink target for *both* stat() and lstat() tests, since if they are
> not made different the test does results are not conclusive at all
>
> 2. For stat() you should get same result on the file and symlink since
> stat actually follows the symlink then gets the data
>
> 3. For lstat() you should get different result on the file and symlink
> since lstat() *does not* follow the symlink before it gets the data
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-07-02 13:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-17 14:44 [LTP] [PATCH v5] Add stat04 test Andrea Cervesato
2024-06-24 12:22 ` Cyril Hrubis
2024-07-02 13:10 ` Andrea Cervesato via ltp
2024-07-02 13:26 ` Cyril Hrubis
2024-07-02 13:30 ` Andrea Cervesato via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox