From 4aa0077bfc2503dc42c34ee69e95b7c5a6948930 Mon Sep 17 00:00:00 2001 From: Aquila Macedo Date: Mon, 30 Mar 2026 09:56:22 -0300 Subject: [PATCH] Add regression coverage for utime and utimes "now" handling Extend timetest to exercise utime(path, NULL) and utimes(path, NULL), so the older file timestamp wrappers are covered alongside the existing utimensat()/futimens() "set to now" checks. --- test/timetest.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/timetest.c b/test/timetest.c index e559b42..96fd054 100644 --- a/test/timetest.c +++ b/test/timetest.c @@ -41,6 +41,7 @@ #include #include #include +#include #define MONO_FIX_TIMEOUT_SECONDS 1 #define MONO_FIX_TOLERANCE_SECONDS 0.25 // Increased tolerance slightly for CI environments @@ -57,6 +58,50 @@ static int fake_monotonic_clock = 0; static int fake_monotonic_clock = 1; #endif +static void test_utime_now(void) +{ + char path[] = "/tmp/libfaketime-utime-XXXXXX"; + int fd; + + fd = mkstemp(path); + if (fd == -1) + { + perror("mkstemp"); + exit(EXIT_FAILURE); + } + + if (utime(path, NULL) == -1) + { + perror("utime(NULL)"); + close(fd); + unlink(path); + exit(EXIT_FAILURE); + } + + if (utimes(path, NULL) == -1) + { + perror("utimes(NULL)"); + close(fd); + unlink(path); + exit(EXIT_FAILURE); + } + + if (close(fd) == -1) + { + perror("close"); + unlink(path); + exit(EXIT_FAILURE); + } + + if (unlink(path) == -1) + { + perror("unlink"); + exit(EXIT_FAILURE); + } + + printf("utime()/utimes(): NOW handling passed\n"); +} + static void test_utimens_now(void) { char path[] = "/tmp/libfaketime-utimensat-XXXXXX"; @@ -369,6 +414,7 @@ printf("%s", 0 == 1 ? argv[0] : ""); printf("gettimeofday() : Current date and time: %s", ctime(&tv.tv_sec)); #ifndef __APPLE__ + test_utime_now(); test_utimens_now(); if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1) {