Skip to content

Commit 8aa1efa

Browse files
committed
cmd/link: in TestFallocate, only check number of blocks on Darwin
The number-of-blocks check was introduced when fixing a Darwin- specific bug. On Darwin, the file allocation syscall is a bit tricky. On Linux and BSDs, it is more straightforward and unlikely to go wrong. The test itself, on the other hand, is less reliable on Linux (and perhaps BSDs), as it is considered less portable and is an implementation detail of the file system. Given these two reasons, only check it on Darwin. Fixes golang#75795. Change-Id: I3da891fd60a141c3eca5d0f5ec20c2cad65b8862 Reviewed-on: https://go-review.googlesource.com/c/go/+/711095 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent b497a29 commit 8aa1efa

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/cmd/link/internal/ld/fallocate_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"os"
1212
"path/filepath"
13+
"runtime"
1314
"syscall"
1415
"testing"
1516
)
@@ -53,12 +54,24 @@ func TestFallocate(t *testing.T) {
5354
if got := stat.Size(); got != sz {
5455
t.Errorf("unexpected file size: got %d, want %d", got, sz)
5556
}
56-
// The number of blocks must be enough for the requested size.
57-
// We used to require an exact match, but it appears that
58-
// some file systems allocate a few extra blocks in some cases.
59-
// See issue #41127.
60-
if got, want := stat.Sys().(*syscall.Stat_t).Blocks, (sz+511)/512; got < want {
61-
t.Errorf("unexpected disk usage: got %d blocks, want at least %d", got, want)
57+
if runtime.GOOS == "darwin" {
58+
// Check the number of allocated blocks on Darwin. On Linux (and
59+
// perhaps BSDs), stat's Blocks field may not be portable as it
60+
// is an implementation detail of the file system. On Darwin, it
61+
// is documented as "the actual number of blocks allocated for
62+
// the file in 512-byte units".
63+
// The check is introduced when fixing a Darwin-specific bug. On
64+
// Darwin, the file allocation syscall is a bit tricky. On Linux
65+
// and BSDs, it is more straightforward and unlikely to go wrong.
66+
// Given these two reasons, only check it on Darwin.
67+
//
68+
// The number of blocks must be enough for the requested size.
69+
// We used to require an exact match, but it appears that
70+
// some file systems allocate a few extra blocks in some cases.
71+
// See issue #41127.
72+
if got, want := stat.Sys().(*syscall.Stat_t).Blocks, (sz+511)/512; got < want {
73+
t.Errorf("unexpected disk usage: got %d blocks, want at least %d", got, want)
74+
}
6275
}
6376
out.munmap()
6477
}

0 commit comments

Comments
 (0)