[LTP] [PATCH v1] Add lstat03 test

Cyril Hrubis chrubis@suse.cz
Fri Feb 2 18:05:58 CET 2024


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 verifies that lstat() is working correctly on symlink()
> + * generated files.
> + */
> +
> +#include "tst_test.h"
> +
> +static void test_lstat(void)
> +{
> +	char *symname = "my_symlink0";
> +
> +	TST_EXP_PASS(symlink(tst_get_tmpdir(), symname));
> +
> +	struct stat path_stat;
> +	struct stat link_stat;
> +
> +	SAFE_LSTAT(tst_get_tmpdir(), &path_stat);
> +	SAFE_LSTAT(symname, &link_stat);

Apart from the leakage of memory does this even work correctly?

If we request information about the link itself via lstat() we get the
stat results for the link. If we call lstat() on the target of the
symlink we get the info about the target. How are these two supposed to
yield the same result?

I suppose that if we do stat() on the link and stat() on the link
tharget then we would end up with an identical results, but not for
lstat().

> +	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");
> +
> +	SAFE_UNLINK(symname);
> +}
> +
> +static void test_lstat_no_path(void)
> +{
> +	char *symname = "my_symlink1";
> +	struct stat link_stat;
> +
> +	TST_EXP_PASS(symlink("bc+eFhi!k", symname));
> +
> +	SAFE_LSTAT(symname, &link_stat);

So this is a lstat() test, right? So it should rather be SAFE_SYMLIK()
then TST_EXP_PASS(lstat(...))

> +	TST_EXP_EXPR((link_stat.st_mode & S_IFMT) == S_IFLNK,
> +		"can read symlink file information");
> +
> +	SAFE_UNLINK(symname);
> +}
> +
> +static void run(void)
> +{
> +	test_lstat();
> +	test_lstat_no_path();
> +}
> +
> +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