public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: xuyang2018.jy@fujitsu.com <xuyang2018.jy@fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] copy_file_range03: comparing timestamp in tst_timespec_diff
Date: Mon, 6 Sep 2021 07:54:30 +0000	[thread overview]
Message-ID: <6135C939.4020903@fujitsu.com> (raw)
In-Reply-To: <20210906060020.3219023-1-liwang@redhat.com>

Hi Li

Looks good to me.
Acked-by: Yang Xu <xuyang2018.jy@fujitsu.com>


Best Regards
Yang Xu
> The st_mtime field is defined as st_mtim.tv_sec for backward
> compatibility in struct stat, which might not precise enough
> for timestamp comparing.
>
> Here switch to timespec diff (with compare nanosecond as well) to
> get rid of this kind of rare faliure:
>
>     7	tst_test.c:1345: TINFO: Timeout per run is 0h 05m 00s
>     8	copy_file_range.h:36: TINFO: Testing libc copy_file_range()
>     9	copy_file_range03.c:48: TPASS: copy_file_range sucessfully updated the timestamp
>     10	tst_test.c:1345: TINFO: Timeout per run is 0h 05m 00s
>     11	copy_file_range.h:39: TINFO: Testing __NR_copy_file_range syscall
>     12	copy_file_range03.c:46: TFAIL: copy_file_range did not update timestamp.
>
> Also, raise the sleep time to 1.5 sec to make test more robust.
>
> Signed-off-by: Li Wang<liwang@redhat.com>
> ---
>   .../copy_file_range/copy_file_range03.c         | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
> index 253eb57ad..5950c80c1 100644
> --- a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
> +++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
> @@ -12,26 +12,27 @@
>   #define _GNU_SOURCE
>
>   #include "tst_test.h"
> +#include "tst_timer.h"
>   #include "copy_file_range.h"
>
>   static int fd_src;
>   static int fd_dest;
>
> -unsigned long get_timestamp(int fd)
> +struct timespec get_timestamp(int fd)
>   {
>   	struct stat filestat;
>
>   	fstat(fd,&filestat);
> -	return filestat.st_mtime;
> +	return filestat.st_mtim;
>   }
>
>   static void verify_copy_file_range_timestamp(void)
>   {
>   	loff_t offset;
> -	unsigned long timestamp, updated_timestamp;
> +	struct timespec timestamp1, timestamp2, diff;
>
> -	timestamp = get_timestamp(fd_dest);
> -	usleep(1000000);
> +	timestamp1 = get_timestamp(fd_dest);
> +	usleep(1500000);
>
>   	offset = 0;
>   	TEST(sys_copy_file_range(fd_src,&offset,
> @@ -40,9 +41,11 @@ static void verify_copy_file_range_timestamp(void)
>   		tst_brk(TBROK | TTERRNO,
>   				"copy_file_range unexpectedly failed");
>
> -	updated_timestamp = get_timestamp(fd_dest);
> +	timestamp2 = get_timestamp(fd_dest);
>
> -	if (timestamp == updated_timestamp)
> +	diff = tst_timespec_diff(timestamp1, timestamp2);
> +
> +	if (!diff.tv_sec&&  !diff.tv_nsec)
>   		tst_brk(TFAIL, "copy_file_range did not update timestamp.");
>
>   	tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");

WARNING: multiple messages have this Message-ID (diff)
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: Li Wang <liwang@redhat.com>
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2] copy_file_range03: comparing timestamp in tst_timespec_diff
Date: Mon, 6 Sep 2021 07:54:30 +0000	[thread overview]
Message-ID: <6135C939.4020903@fujitsu.com> (raw)
Message-ID: <20210906075430.FFk285k3vAOxC1SbeEvpHZ1cvGBGgPeWvI7yOqdQMec@z> (raw)
In-Reply-To: <20210906060020.3219023-1-liwang@redhat.com>

Hi Li

Looks good to me.
Acked-by: Yang Xu <xuyang2018.jy@fujitsu.com>


Best Regards
Yang Xu
> The st_mtime field is defined as st_mtim.tv_sec for backward
> compatibility in struct stat, which might not precise enough
> for timestamp comparing.
>
> Here switch to timespec diff (with compare nanosecond as well) to
> get rid of this kind of rare faliure:
>
>     7	tst_test.c:1345: TINFO: Timeout per run is 0h 05m 00s
>     8	copy_file_range.h:36: TINFO: Testing libc copy_file_range()
>     9	copy_file_range03.c:48: TPASS: copy_file_range sucessfully updated the timestamp
>     10	tst_test.c:1345: TINFO: Timeout per run is 0h 05m 00s
>     11	copy_file_range.h:39: TINFO: Testing __NR_copy_file_range syscall
>     12	copy_file_range03.c:46: TFAIL: copy_file_range did not update timestamp.
>
> Also, raise the sleep time to 1.5 sec to make test more robust.
>
> Signed-off-by: Li Wang<liwang@redhat.com>
> ---
>   .../copy_file_range/copy_file_range03.c         | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
> index 253eb57ad..5950c80c1 100644
> --- a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
> +++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
> @@ -12,26 +12,27 @@
>   #define _GNU_SOURCE
>
>   #include "tst_test.h"
> +#include "tst_timer.h"
>   #include "copy_file_range.h"
>
>   static int fd_src;
>   static int fd_dest;
>
> -unsigned long get_timestamp(int fd)
> +struct timespec get_timestamp(int fd)
>   {
>   	struct stat filestat;
>
>   	fstat(fd,&filestat);
> -	return filestat.st_mtime;
> +	return filestat.st_mtim;
>   }
>
>   static void verify_copy_file_range_timestamp(void)
>   {
>   	loff_t offset;
> -	unsigned long timestamp, updated_timestamp;
> +	struct timespec timestamp1, timestamp2, diff;
>
> -	timestamp = get_timestamp(fd_dest);
> -	usleep(1000000);
> +	timestamp1 = get_timestamp(fd_dest);
> +	usleep(1500000);
>
>   	offset = 0;
>   	TEST(sys_copy_file_range(fd_src,&offset,
> @@ -40,9 +41,11 @@ static void verify_copy_file_range_timestamp(void)
>   		tst_brk(TBROK | TTERRNO,
>   				"copy_file_range unexpectedly failed");
>
> -	updated_timestamp = get_timestamp(fd_dest);
> +	timestamp2 = get_timestamp(fd_dest);
>
> -	if (timestamp == updated_timestamp)
> +	diff = tst_timespec_diff(timestamp1, timestamp2);
> +
> +	if (!diff.tv_sec&&  !diff.tv_nsec)
>   		tst_brk(TFAIL, "copy_file_range did not update timestamp.");
>
>   	tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2021-09-06  7:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06  6:00 [LTP] [PATCH v2] copy_file_range03: comparing timestamp in tst_timespec_diff Li Wang
2021-09-06  6:00 ` Li Wang
2021-09-06  7:54 ` xuyang2018.jy [this message]
2021-09-06  7:54   ` xuyang2018.jy
2021-09-06  8:59 ` Cyril Hrubis
2021-09-06  8:59   ` Cyril Hrubis
2021-09-06 10:35   ` Li Wang
2021-09-06 10:35     ` Li Wang
2021-09-06 10:38     ` Cyril Hrubis
2021-09-06 10:38       ` Cyril Hrubis
2021-09-06 10:42       ` Li Wang
2021-09-06 10:42         ` Li Wang

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=6135C939.4020903@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --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