From ca114f296a69f486dcf7584c2abfbcf80d38c581 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 9 Sep 2015 12:21:47 +0000 Subject: [PATCH] Fixed most tests on Linux. --- fuseops/ops.go | 5 +-- samples/statfs/statfs_linux_test.go | 49 ++++++++++++----------------- samples/statfs/statfs_test.go | 12 ++++++- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/fuseops/ops.go b/fuseops/ops.go index aa56176..eee34c5 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -46,8 +46,9 @@ type StatFSOp struct { // with the block counts below, by callers of statfs(2) to infer the file // system's capacity and space availability. // - // TODO(jacobsa): Document the range of values accepted on OS X and Linux. - // Cite sources in Linux if possible. + // On Linux this can be any value, which will be faitfully returned to the + // 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 // "optimal transfer block size". It does not appear to cause osxfuse to diff --git a/samples/statfs/statfs_linux_test.go b/samples/statfs/statfs_linux_test.go index fc4179d..f7cb63d 100644 --- a/samples/statfs/statfs_linux_test.go +++ b/samples/statfs/statfs_linux_test.go @@ -16,6 +16,7 @@ package statfs_test import ( "fmt" + "math" "syscall" "github.com/jacobsa/fuse/fuseops" @@ -36,8 +37,8 @@ func (t *StatFSTest) Syscall_ZeroValues() { err = syscall.Statfs(t.Dir, &stat) AssertEq(nil, err) - ExpectEq(4096, stat.Bsize) - ExpectEq(65536, stat.Frsize) + ExpectEq(0, stat.Bsize) + ExpectEq(0, stat.Frsize) ExpectEq(0, stat.Blocks) ExpectEq(0, stat.Bfree) ExpectEq(0, stat.Bavail) @@ -76,38 +77,28 @@ func (t *StatFSTest) Syscall_NonZeroValues() { ExpectEq(canned.InodesFree, stat.Ffree) } -func (t *StatFSTest) UnsupportedBlockSizes() { +func (t *StatFSTest) WackyBlockSizes() { var err error - // Test a bunch of block sizes that the OS doesn't support faithfully, - // checking what it transforms them too. - testCases := []struct { - fsBlockSize uint32 - expectedBsize uint32 - expectedFrsize uint32 - }{ - 0: {0, 4096, 65536}, - 1: {1, 512, 512}, - 2: {3, 512, 512}, - 3: {511, 512, 512}, - 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}, + // Test a bunch of weird block sizes that OS X would be cranky about. + blockSizes := []uint32{ + 0, + 1, + 3, + 17, + 1<<20 - 1, + 1<<20 + 0, + 1<<20 + 1, + math.MaxInt32, + math.MaxUint32, } - for i, tc := range testCases { - desc := fmt.Sprintf("Case %d: block size %d", i, tc.fsBlockSize) + for _, bs := range blockSizes { + desc := fmt.Sprintf("block size %d", bs) // Set up. canned := fuseops.StatFSOp{ - BlockSize: tc.fsBlockSize, + BlockSize: bs, Blocks: 10, } @@ -118,7 +109,7 @@ func (t *StatFSTest) UnsupportedBlockSizes() { err = syscall.Statfs(t.Dir, &stat) AssertEq(nil, err) - ExpectEq(tc.expectedBsize, stat.Bsize, "%s", desc) - ExpectEq(tc.expectedFrsize, stat.Frsize, "%s", desc) + ExpectEq(bs, stat.Bsize, "%s", desc) + ExpectEq(bs, stat.Frsize, "%s", desc) } } diff --git a/samples/statfs/statfs_test.go b/samples/statfs/statfs_test.go index 5d4c22a..677b53d 100644 --- a/samples/statfs/statfs_test.go +++ b/samples/statfs/statfs_test.go @@ -22,6 +22,7 @@ import ( "path" "path/filepath" "regexp" + "runtime" "strconv" "testing" @@ -190,5 +191,14 @@ func (t *StatFSTest) WriteSize() { // Despite the small block size, the OS shouldn't have given us pitifully // 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) + } }