[PATCH] tests: stat: check nanosecond precision away from the Epoch
From:
Pádraig Brady
Subject:
[PATCH] tests: stat: check nanosecond precision away from the Epoch
Date:
Thu, 20 Aug 2026 16:16:01 +0100
From: Sylvestre Ledru <sylvestre@debian.org>
The existing checks all use a timestamp only 67413 seconds after the
Epoch, which a double can still represent exactly to the nanosecond, so
they do not detect a formatter that goes through floating point. They
also never look at a timestamp before the Epoch, where the fraction has
to be truncated towards minus infinity.
* tests/stat/stat-nanoseconds.sh: Also check %Y, %.Y, %.3Y and %.9Y on a
2026 timestamp and on a timestamp shortly before the Epoch.
Link: https://github.com/uutils/coreutils/pull/13976
Link: https://github.com/coreutils/coreutils/pull/331
---
tests/stat/stat-nanoseconds.sh | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tests/stat/stat-nanoseconds.sh b/tests/stat/stat-nanoseconds.sh
index 44914751a..f8e8c2ed0 100755
--- a/tests/stat/stat-nanoseconds.sh
+++ b/tests/stat/stat-nanoseconds.sh
@@ -43,4 +43,24 @@ test "$(stat -c %I18.10Y k)" = ' 67413.0234567890' ||
fail=1
test "$(stat -c %018.10Y k)" = 0067413.0234567890 || fail=1
test "$(stat -c %-18.10Y k)" = '67413.0234567890 ' || fail=1
+# A recent timestamp needs more than the 53 bits of a double to hold
+# all nine fractional digits.
+# Use the epoch notation for '2026-05-04 03:02:01.987654321'
+# to avoid any leap second ambiguities.
+touch -d '@1777863721.987654321' recent || framework_failure_
+
+test "$(stat -c %Y recent)" = 1777863721 || fail=1
+test "$(stat -c %.Y recent)" = 1777863721.987654321 || fail=1
+test "$(stat -c %.3Y recent)" = 1777863721.987 || fail=1
+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
+
Exit $fail
--
2.55.0
[Prev in Thread]
Current Thread
[Next in Thread]
[PATCH] tests: stat: check nanosecond precision away from the Epoch,
Pádraig Brady<=