public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v5] Add stat04 test
Date: Mon, 24 Jun 2024 14:22:50 +0200	[thread overview]
Message-ID: <ZnllGpZEj6TOsWqB@yuki> (raw)
In-Reply-To: <20240417144409.11411-1-andrea.cervesato@suse.de>

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

  reply	other threads:[~2024-06-24 12:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 14:44 [LTP] [PATCH v5] Add stat04 test Andrea Cervesato
2024-06-24 12:22 ` Cyril Hrubis [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZnllGpZEj6TOsWqB@yuki \
    --to=chrubis@suse.cz \
    --cc=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox