mirror of https://github.com/golang/go.git
os: TestChtimes: separate hasNoatime
Move the noatime check to a separate function (to be used by CL 91535), adding some documentation along the way. Unify the atime error message. Change-Id: I5f75a4399f6e1b16ae20438003de5460f3eeb5aa Reviewed-on: https://go-review.googlesource.com/c/go/+/594075 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
0def9d5c02
commit
b98803e8e5
|
|
@ -1361,6 +1361,17 @@ func TestTruncateNonexistentFile(t *testing.T) {
|
||||||
assertPathError(t, path, err)
|
assertPathError(t, path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hasNoatime = sync.OnceValue(func() bool {
|
||||||
|
// A sloppy way to check if noatime flag is set (as all filesystems are
|
||||||
|
// checked, not just the one we're interested in). A correct way
|
||||||
|
// would be to use statvfs syscall and check if flags has ST_NOATIME,
|
||||||
|
// 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).
|
||||||
|
mounts, _ := ReadFile("/proc/mounts")
|
||||||
|
return bytes.Contains(mounts, []byte("noatime"))
|
||||||
|
})
|
||||||
|
|
||||||
func TestChtimes(t *testing.T) {
|
func TestChtimes(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
@ -1523,6 +1534,7 @@ func testChtimes(t *testing.T, name string) {
|
||||||
pat := Atime(postStat)
|
pat := Atime(postStat)
|
||||||
pmt := postStat.ModTime()
|
pmt := postStat.ModTime()
|
||||||
if !pat.Before(at) {
|
if !pat.Before(at) {
|
||||||
|
errormsg := fmt.Sprintf("AccessTime didn't go backwards; was=%v, after=%v", at, pat)
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "plan9":
|
case "plan9":
|
||||||
// Mtime is the time of the last change of
|
// Mtime is the time of the last change of
|
||||||
|
|
@ -1530,14 +1542,14 @@ func testChtimes(t *testing.T, name string) {
|
||||||
// the contents are accessed; also, it is set
|
// the contents are accessed; also, it is set
|
||||||
// whenever mtime is set.
|
// whenever mtime is set.
|
||||||
case "netbsd":
|
case "netbsd":
|
||||||
mounts, _ := ReadFile("/proc/mounts")
|
if hasNoatime() {
|
||||||
if strings.Contains(string(mounts), "noatime") {
|
t.Log(errormsg)
|
||||||
t.Logf("AccessTime didn't go backwards, but see a filesystem mounted noatime; ignoring. Issue 19293.")
|
t.Log("Known NetBSD issue (atime not changed on fs mounted with noatime); ignoring.")
|
||||||
} else {
|
} else {
|
||||||
t.Logf("AccessTime didn't go backwards; was=%v, after=%v (Ignoring on NetBSD, assuming noatime, Issue 19293)", at, pat)
|
t.Errorf(errormsg)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
t.Errorf("AccessTime didn't go backwards; was=%v, after=%v", at, pat)
|
t.Errorf(errormsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue