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.
This commit is contained in:
Aquila Macedo
2026-03-30 09:56:22 -03:00
parent 097ce79771
commit 4aa0077bfc

View File

@@ -41,6 +41,7 @@
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <utime.h>
#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)
{