All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] copy_file_range03: comparing timestamp by tst_timespec_diff_us
@ 2021-09-06 11:41 ` Li Wang
  2021-09-06 12:33     ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Li Wang @ 2021-09-06 11:41 UTC (permalink / raw)
  To: ltp

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 include nanosecond changes) 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.

Acked-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Cyril Hrubis <chrubis@suse.cz>
---

Notes:
    v2 --> v3
      relax the diff_us to 30 seconds

 .../copy_file_range/copy_file_range03.c       | 22 +++++++++++--------
 1 file changed, 13 insertions(+), 9 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..21a5d553b 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,28 @@
 #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;
+	long long diff_us;
 
-	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,12 +42,14 @@ 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)
-		tst_brk(TFAIL, "copy_file_range did not update timestamp.");
+	diff_us = tst_timespec_diff_us(timestamp2, timestamp1);
 
-	tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");
+	if (diff_us >= 1000000 && diff_us <= 30000000)
+		tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");
+	else
+		tst_brk(TFAIL, "diff_us = %lld, copy_file_range might not update timestamp", diff_us);
 }
 
 static void cleanup(void)
-- 
2.31.1


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v3] copy_file_range03: comparing timestamp by tst_timespec_diff_us
@ 2021-09-06 12:33     ` Cyril Hrubis
  2021-09-07  2:25         ` Li Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2021-09-06 12:33 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v3] copy_file_range03: comparing timestamp by tst_timespec_diff_us
@ 2021-09-07  2:25         ` Li Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Li Wang @ 2021-09-07  2:25 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 179 bytes --]

On Mon, Sep 6, 2021 at 8:33 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
>

Thanks for the review, pushed.


-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 804 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-07  2:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 11:41 [LTP] [PATCH v3] copy_file_range03: comparing timestamp by tst_timespec_diff_us Li Wang
2021-09-06 11:41 ` Li Wang
2021-09-06 12:33   ` Cyril Hrubis
2021-09-06 12:33     ` Cyril Hrubis
2021-09-07  2:25       ` Li Wang
2021-09-07  2:25         ` Li Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.