Fixed most tests on Linux.
parent
56d0249304
commit
ca114f296a
|
@ -46,8 +46,9 @@ type StatFSOp struct {
|
||||||
// with the block counts below, by callers of statfs(2) to infer the file
|
// with the block counts below, by callers of statfs(2) to infer the file
|
||||||
// system's capacity and space availability.
|
// system's capacity and space availability.
|
||||||
//
|
//
|
||||||
// TODO(jacobsa): Document the range of values accepted on OS X and Linux.
|
// On Linux this can be any value, which will be faitfully returned to the
|
||||||
// Cite sources in Linux if possible.
|
// caller of statfs(2) (see the code walk above). On OS X it appears it must
|
||||||
|
// be a power of 2 in [2^9, 2^17].
|
||||||
//
|
//
|
||||||
// On OS X this also affects statfs::f_iosize, which is documented as the
|
// On OS X this also affects statfs::f_iosize, which is documented as the
|
||||||
// "optimal transfer block size". It does not appear to cause osxfuse to
|
// "optimal transfer block size". It does not appear to cause osxfuse to
|
||||||
|
|
|
@ -16,6 +16,7 @@ package statfs_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
|
@ -36,8 +37,8 @@ func (t *StatFSTest) Syscall_ZeroValues() {
|
||||||
err = syscall.Statfs(t.Dir, &stat)
|
err = syscall.Statfs(t.Dir, &stat)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
ExpectEq(4096, stat.Bsize)
|
ExpectEq(0, stat.Bsize)
|
||||||
ExpectEq(65536, stat.Frsize)
|
ExpectEq(0, stat.Frsize)
|
||||||
ExpectEq(0, stat.Blocks)
|
ExpectEq(0, stat.Blocks)
|
||||||
ExpectEq(0, stat.Bfree)
|
ExpectEq(0, stat.Bfree)
|
||||||
ExpectEq(0, stat.Bavail)
|
ExpectEq(0, stat.Bavail)
|
||||||
|
@ -76,38 +77,28 @@ func (t *StatFSTest) Syscall_NonZeroValues() {
|
||||||
ExpectEq(canned.InodesFree, stat.Ffree)
|
ExpectEq(canned.InodesFree, stat.Ffree)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *StatFSTest) UnsupportedBlockSizes() {
|
func (t *StatFSTest) WackyBlockSizes() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Test a bunch of block sizes that the OS doesn't support faithfully,
|
// Test a bunch of weird block sizes that OS X would be cranky about.
|
||||||
// checking what it transforms them too.
|
blockSizes := []uint32{
|
||||||
testCases := []struct {
|
0,
|
||||||
fsBlockSize uint32
|
1,
|
||||||
expectedBsize uint32
|
3,
|
||||||
expectedFrsize uint32
|
17,
|
||||||
}{
|
1<<20 - 1,
|
||||||
0: {0, 4096, 65536},
|
1<<20 + 0,
|
||||||
1: {1, 512, 512},
|
1<<20 + 1,
|
||||||
2: {3, 512, 512},
|
math.MaxInt32,
|
||||||
3: {511, 512, 512},
|
math.MaxUint32,
|
||||||
4: {513, 1024, 1024},
|
|
||||||
5: {1023, 1024, 1024},
|
|
||||||
6: {4095, 4096, 4096},
|
|
||||||
7: {1<<17 - 1, 1 << 17, 131072},
|
|
||||||
8: {1<<17 + 1, 1 << 17, 1 << 18},
|
|
||||||
9: {1<<18 + 1, 1 << 17, 1 << 19},
|
|
||||||
10: {1<<19 + 1, 1 << 17, 1 << 20},
|
|
||||||
11: {1<<20 + 1, 1 << 17, 1 << 20},
|
|
||||||
12: {1 << 21, 1 << 17, 1 << 20},
|
|
||||||
13: {1 << 30, 1 << 17, 1 << 20},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for _, bs := range blockSizes {
|
||||||
desc := fmt.Sprintf("Case %d: block size %d", i, tc.fsBlockSize)
|
desc := fmt.Sprintf("block size %d", bs)
|
||||||
|
|
||||||
// Set up.
|
// Set up.
|
||||||
canned := fuseops.StatFSOp{
|
canned := fuseops.StatFSOp{
|
||||||
BlockSize: tc.fsBlockSize,
|
BlockSize: bs,
|
||||||
Blocks: 10,
|
Blocks: 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +109,7 @@ func (t *StatFSTest) UnsupportedBlockSizes() {
|
||||||
err = syscall.Statfs(t.Dir, &stat)
|
err = syscall.Statfs(t.Dir, &stat)
|
||||||
AssertEq(nil, err)
|
AssertEq(nil, err)
|
||||||
|
|
||||||
ExpectEq(tc.expectedBsize, stat.Bsize, "%s", desc)
|
ExpectEq(bs, stat.Bsize, "%s", desc)
|
||||||
ExpectEq(tc.expectedFrsize, stat.Frsize, "%s", desc)
|
ExpectEq(bs, stat.Frsize, "%s", desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -190,5 +191,14 @@ func (t *StatFSTest) WriteSize() {
|
||||||
|
|
||||||
// Despite the small block size, the OS shouldn't have given us pitifully
|
// Despite the small block size, the OS shouldn't have given us pitifully
|
||||||
// small chunks of data.
|
// small chunks of data.
|
||||||
ExpectEq(1<<20, t.fs.MostRecentWriteSize())
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
ExpectEq(1<<17, t.fs.MostRecentWriteSize())
|
||||||
|
|
||||||
|
case "darwin":
|
||||||
|
ExpectEq(1<<20, t.fs.MostRecentWriteSize())
|
||||||
|
|
||||||
|
default:
|
||||||
|
AddFailure("Unhandled OS: %s", runtime.GOOS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue