[LTP] [PATCH v2] Add lstat03 test
Cyril Hrubis
chrubis@suse.cz
Wed Feb 21 16:05:37 CET 2024
Hi!
> This test has been extracted from symlink01 test and it checks that
> lstat() executed on file provide the same information of symlink
> linking to it.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> Remove test_lstat_no_path() test
> TST_EXP_PASS for lstat() and SAFE_SYMLINK for symlink()
> Removed memory leak using tst_get_tmpdir()
The leak is stil there, as far as I can tell.
> runtest/syscalls | 4 +-
> testcases/kernel/syscalls/lstat/.gitignore | 2 +
> testcases/kernel/syscalls/lstat/lstat03.c | 50 ++++++++++++++++++++++
> 3 files changed, 54 insertions(+), 2 deletions(-)
> create mode 100644 testcases/kernel/syscalls/lstat/lstat03.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 7794f1465..a7f22d907 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -723,12 +723,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..30932f1fa
> --- /dev/null
> +++ b/testcases/kernel/syscalls/lstat/lstat03.c
> @@ -0,0 +1,50 @@
> +// 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 lstat() 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(lstat(tmpdir, &path_stat));
> + TST_EXP_PASS(lstat(symname, &link_stat));
> +
> + TST_EXP_EQ_LI(path_stat.st_dev, link_stat.st_dev);
> + 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_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);
> +
> + TST_EXP_EXPR(path_stat.st_mode != link_stat.st_mode,
> + "object and symbolic link have different st_mode");
> + TST_EXP_EXPR(path_stat.st_size != link_stat.st_size,
> + "object and symbolic link have different st_size");
Now shouldn't this be the other way around, i.e. we are doing stat on
two different entities and we should concentrate on the parts that are
different?
I guess that one way would be to explicitly set different gid/uid for
the symlink and then check that these values are not equal.
Also if we fill the file with a megabyte of data I'm pretty sure that
st_size will be different from the symlink st_size.
I guess that the inode should differ.
The same for the timestamps, if we go for the more granular timestaps
the creation time would differ.
It's mostly accidental that these values actually match.
> + 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
More information about the ltp
mailing list