Bruno Haible via GNU coreutils General Discussion <[email protected]>
writes:

> The test tests/stat/stat-nanoseconds fails on FreeBSD 14.0 and NetBSD 10.0.
>
> Here's the output on FreeBSD:
>
>
> FAIL: tests/stat/stat-nanoseconds
> =================================
>
> -rw-r--r-- 1 root wheel 0 1970-01-01 18:43:33.023456789 +0000 k
> FAIL tests/stat/stat-nanoseconds.sh (exit status: 1)

This one took me an annoyingly long time to investigate. I am tempted to
just remove it because I don't think the behavior is that important and
I can see a few places where it can go wrong.

The specific issue here is that FreeBSD (and probably NetBSD) use
attributes set to -1 to indicate that the vnode should not have it's
corresponding attribute updated. In this case we are calling futimens
with two "struct timespec" values identically defined to:

   (struct timespec) { .tv_sec = -1, .tv_usec = 123456789 }

When FreeBSD goes to update the vnode, it sees tv_sec == -1 for both
timestamps and doesn't update them. So it is pretty much a useless call.

I suspect you also may run into issues with file systems using unsigned
integers from the epoch to represent time stamps. I don't have any
evidence of that yet, but it doesn't seem impossible. Perhaps a file
system expert can correct me.

Pádraig, any opinion on the attached patch vs. just removing this test?
I think I am 50/50 on it right now...

Collin

>From 6ee3a603f8dbecce6e4a9040a3a3a19db4a7e839 Mon Sep 17 00:00:00 2001
Message-ID: <6ee3a603f8dbecce6e4a9040a3a3a19db4a7e839.1787635016.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Mon, 24 Aug 2026 21:54:33 -0700
Subject: [PATCH] tests: stat: fix a test failure on FreeBSD

* tests/stat/stat-nanoseconds.sh: Don't assume that we can create a file
with timestamps before the epoch.
Reported by Bruno Haible.
---
 tests/stat/stat-nanoseconds.sh | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/stat/stat-nanoseconds.sh b/tests/stat/stat-nanoseconds.sh
index f8e8c2ed0..9923c8b90 100755
--- a/tests/stat/stat-nanoseconds.sh
+++ b/tests/stat/stat-nanoseconds.sh
@@ -56,11 +56,14 @@ test "$(stat -c %.9Y recent)" = 1777863721.987654321  || fail=1
 
 # Timestamps before the Epoch truncate towards minus infinity.
 # Use epoch notation for '1969-12-31 23:59:59.123456789'
-touch -d '@-0.876543211' old || framework_failure_
-
-test "$(stat -c   %Y old)" = -1            || fail=1
-test "$(stat -c  %.Y old)" = -0.876543211  || fail=1
-test "$(stat -c %.3Y old)" = -0.876        || fail=1
-test "$(stat -c %.9Y old)" = -0.876543211  || fail=1
+#
+# Note that FreeBSD uses tv_sec == -1 to indicate that vnode
+# should not have it's timestamp adjusted.  Also, some file
+# systems may not support timestamps before the epoch.
+if touch -d '@-0.876543211' old && test "$(stat -c   %Y old)" = -1; then
+  test "$(stat -c  %.Y old)" = -0.876543211  || fail=1
+  test "$(stat -c %.3Y old)" = -0.876        || fail=1
+  test "$(stat -c %.9Y old)" = -0.876543211  || fail=1
+fi
 
 Exit $fail
-- 
2.55.0

Reply via email to