From 4bc6c71ee013addb613c39dae364cf7a06694b47 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 19 Mar 2025 16:37:16 -0700 Subject: [PATCH] os: skip Root.Chtimes atime check on netbsd, truncate a/mtime on plan9 The NetBSD builder has noatime set on its filesystem. Skip testing the atime on this builder. Plan9 has second precision on its atime and mtimes. Truncate the values passed to Chtimes. For #72957 Change-Id: I963e2dd34075a9ba025e80641f0b675d5d912188 Reviewed-on: https://go-review.googlesource.com/c/go/+/659356 Auto-Submit: Damien Neil LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- src/os/os_test.go | 3 +++ src/os/root_test.go | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/os/os_test.go b/src/os/os_test.go index 4c90525bb1..cca1b58fe7 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -1345,6 +1345,9 @@ var hasNoatime = sync.OnceValue(func() bool { // but the syscall is OS-specific and is not even wired into Go stdlib. // // Only used on NetBSD (which ignores explicit atime updates with noatime). + if runtime.GOOS != "netbsd" { + return false + } mounts, _ := ReadFile("/proc/mounts") return bytes.Contains(mounts, []byte("noatime")) }) diff --git a/src/os/root_test.go b/src/os/root_test.go index 6c8c892429..b91d85d176 100644 --- a/src/os/root_test.go +++ b/src/os/root_test.go @@ -449,7 +449,8 @@ func TestRootChtimes(t *testing.T) { atime: time.Now(), mtime: time.Time{}, }} { - if runtime.GOOS == "js" { + switch runtime.GOOS { + case "js", "plan9": times.atime = times.atime.Truncate(1 * time.Second) times.mtime = times.mtime.Truncate(1 * time.Second) } @@ -465,8 +466,10 @@ func TestRootChtimes(t *testing.T) { if got := st.ModTime(); !times.mtime.IsZero() && !got.Equal(times.mtime) { t.Errorf("after root.Chtimes(%q, %v, %v): got mtime=%v, want %v", test.open, times.atime, times.mtime, got, times.mtime) } - if got := os.Atime(st); !times.atime.IsZero() && !got.Equal(times.atime) { - t.Errorf("after root.Chtimes(%q, %v, %v): got atime=%v, want %v", test.open, times.atime, times.mtime, got, times.atime) + if !hasNoatime() { + if got := os.Atime(st); !times.atime.IsZero() && !got.Equal(times.atime) { + t.Errorf("after root.Chtimes(%q, %v, %v): got atime=%v, want %v", test.open, times.atime, times.mtime, got, times.atime) + } } } })