[LTP] [PATCH v1] Add stat04 test
Cyril Hrubis
chrubis@suse.cz
Fri Feb 2 17:48:29 CET 2024
Hi!
> +#include "tst_test.h"
> +
> +static void test_stat(void)
> +{
> + char *symname = "my_symlink0";
> +
> + TST_EXP_PASS(symlink(tst_get_tmpdir(), symname));
This one leaks memory from the tst_get_tmpdir() call, also I suppose
that the symlink can be created once in the test setup and removed once
in the test cleanup.
> + struct stat path_stat;
> + struct stat link_stat;
> +
> + SAFE_STAT(tst_get_tmpdir(), &path_stat);
Here as well, leak. I suppose that we can instead use "."
> + SAFE_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 void test_stat_no_path(void)
> +{
> + char *symname = "my_symlink1";
> + struct stat link_stat;
> +
> + TST_EXP_PASS(symlink("bc+eFhi!k", symname));
> + TST_EXP_FAIL(stat(symname, &link_stat), ENOENT);
> +
> + SAFE_UNLINK(symname);
> +}
This one should rather go into stat03.c
> +static void test_stat_loop(void)
> +{
> + char *symname = "my_symlink2";
> + struct stat link_stat;
> +
> + TST_EXP_PASS(symlink(symname, symname));
> + TST_EXP_FAIL(stat(symname, &link_stat), ELOOP);
> +
> + SAFE_UNLINK(symname);
> +}
This one is already tested in stat03.c
> +static void run(void)
> +{
> + test_stat();
> + test_stat_no_path();
> + test_stat_loop();
> +}
> +
> +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