[LTP] [PATCH v2] syscalls/utime03: use realtime clock for upper bound check

Jan Stancek jstancek@redhat.com
Mon Feb 24 12:24:01 CET 2025


This test rarely fails with recent kernels (after 6.13-rc1):
  tst_test.c:1833: TINFO: === Testing on ext4 ===
  tst_test.c:1170: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
  mke2fs 1.47.2 (1-Jan-2025)
  tst_test.c:1182: TINFO: Mounting /dev/loop0 to /tmp/LTP_uti42UpHj/mntpoint fstyp=ext4 flags=0
  utime03.c:74: TPASS: utime(TEMP_FILE, NULL) passed
  utime03.c:80: TFAIL: utime() did not set expected atime, mintime: 1738291930, maxtime: 1738291930, st_atime: 1738291931
  utime03.c:85: TFAIL: utime() did not set expected mtime, mintime: 1738291930, maxtime: 1738291930, st_mtime: 1738291931

Since 4e40eff0b573 ("fs: add infrastructure for multigrain timestamps"),
filesystem can use more precise clock to update the inode.

Relax the check by using realtime clock for upper bound check.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/utime/utime03.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
index 564e1de3dd77..56eb9e722896 100644
--- a/testcases/kernel/syscalls/utime/utime03.c
+++ b/testcases/kernel/syscalls/utime/utime03.c
@@ -55,6 +55,7 @@ static void run(void)
 	struct utimbuf utbuf;
 	struct stat statbuf;
 	time_t mintime, maxtime;
+	struct timespec ts;
 
 	utbuf.modtime = time(0) - 5;
 	utbuf.actime = utbuf.modtime + 1;
@@ -70,7 +71,8 @@ static void run(void)
 	SAFE_SETEUID(user_uid);
 	mintime = tst_get_fs_timestamp();
 	TST_EXP_PASS(utime(TEMP_FILE, NULL));
-	maxtime = tst_get_fs_timestamp();
+	tst_clock_gettime(CLOCK_REALTIME, &ts);
+	maxtime = ts.tv_sec;
 	SAFE_SETEUID(root_uid);
 	SAFE_STAT(TEMP_FILE, &statbuf);
 
-- 
2.43.0



More information about the ltp mailing list