Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
81110063
Commit
81110063
authored
Sep 09, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Isolated darwin-specific tests.
parent
69c97c57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
153 additions
and
123 deletions
+153
-123
samples/statfs/statfs_darwin_test.go
samples/statfs/statfs_darwin_test.go
+153
-0
samples/statfs/statfs_test.go
samples/statfs/statfs_test.go
+0
-123
No files found.
samples/statfs/statfs_darwin_test.go
0 → 100644
View file @
81110063
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
statfs_test
import
(
"fmt"
"syscall"
"github.com/jacobsa/fuse/fuseops"
.
"github.com/jacobsa/oglematchers"
.
"github.com/jacobsa/ogletest"
)
////////////////////////////////////////////////////////////////////////
// Helpers
////////////////////////////////////////////////////////////////////////
func
convertName
(
in
[]
int8
)
(
s
string
)
{
var
tmp
[]
byte
for
_
,
v
:=
range
in
{
if
v
==
0
{
break
}
tmp
=
append
(
tmp
,
byte
(
v
))
}
s
=
string
(
tmp
)
return
}
////////////////////////////////////////////////////////////////////////
// Tests
////////////////////////////////////////////////////////////////////////
func
(
t
*
StatFSTest
)
Syscall_ZeroValues
()
{
var
err
error
var
stat
syscall
.
Statfs_t
// Call without configuring a canned response, meaning the OS will see the
// zero value for each field. The assertions below act as documentation for
// the OS's behavior in this case.
err
=
syscall
.
Statfs
(
t
.
Dir
,
&
stat
)
AssertEq
(
nil
,
err
)
ExpectEq
(
4096
,
stat
.
Bsize
)
ExpectEq
(
65536
,
stat
.
Iosize
)
ExpectEq
(
0
,
stat
.
Blocks
)
ExpectEq
(
0
,
stat
.
Bfree
)
ExpectEq
(
0
,
stat
.
Bavail
)
ExpectEq
(
0
,
stat
.
Files
)
ExpectEq
(
0
,
stat
.
Ffree
)
ExpectEq
(
"osxfusefs"
,
convertName
(
stat
.
Fstypename
[
:
]))
ExpectEq
(
t
.
canonicalDir
,
convertName
(
stat
.
Mntonname
[
:
]))
ExpectThat
(
convertName
(
stat
.
Mntfromname
[
:
]),
MatchesRegexp
(
`mount_osxfusefs@osxfuse\d+`
))
}
func
(
t
*
StatFSTest
)
Syscall_NonZeroValues
()
{
var
err
error
var
stat
syscall
.
Statfs_t
// Set up the canned response.
canned
:=
fuseops
.
StatFSOp
{
BlockSize
:
1
<<
15
,
Blocks
:
1
<<
51
+
3
,
BlocksFree
:
1
<<
43
+
5
,
BlocksAvailable
:
1
<<
41
+
7
,
Inodes
:
1
<<
59
+
11
,
InodesFree
:
1
<<
58
+
13
,
}
t
.
fs
.
SetStatFSResponse
(
canned
)
// Stat.
err
=
syscall
.
Statfs
(
t
.
Dir
,
&
stat
)
AssertEq
(
nil
,
err
)
ExpectEq
(
canned
.
BlockSize
,
stat
.
Bsize
)
ExpectEq
(
canned
.
BlockSize
,
stat
.
Iosize
)
ExpectEq
(
canned
.
Blocks
,
stat
.
Blocks
)
ExpectEq
(
canned
.
BlocksFree
,
stat
.
Bfree
)
ExpectEq
(
canned
.
BlocksAvailable
,
stat
.
Bavail
)
ExpectEq
(
canned
.
Inodes
,
stat
.
Files
)
ExpectEq
(
canned
.
InodesFree
,
stat
.
Ffree
)
ExpectEq
(
"osxfusefs"
,
convertName
(
stat
.
Fstypename
[
:
]))
ExpectEq
(
t
.
canonicalDir
,
convertName
(
stat
.
Mntonname
[
:
]))
ExpectThat
(
convertName
(
stat
.
Mntfromname
[
:
]),
MatchesRegexp
(
`mount_osxfusefs@osxfuse\d+`
))
}
func
(
t
*
StatFSTest
)
UnsupportedBlockSizes
()
{
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
expectedIosize
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
},
}
for
i
,
tc
:=
range
testCases
{
desc
:=
fmt
.
Sprintf
(
"Case %d: block size %d"
,
i
,
tc
.
fsBlockSize
)
// Set up.
canned
:=
fuseops
.
StatFSOp
{
BlockSize
:
tc
.
fsBlockSize
,
Blocks
:
10
,
}
t
.
fs
.
SetStatFSResponse
(
canned
)
// Check.
var
stat
syscall
.
Statfs_t
err
=
syscall
.
Statfs
(
t
.
Dir
,
&
stat
)
AssertEq
(
nil
,
err
)
ExpectEq
(
tc
.
expectedBsize
,
stat
.
Bsize
,
"%s"
,
desc
)
ExpectEq
(
tc
.
expectedIosize
,
stat
.
Iosize
,
"%s"
,
desc
)
}
}
samples/statfs/statfs_test.go
View file @
81110063
...
...
@@ -23,14 +23,12 @@ import (
"path/filepath"
"regexp"
"strconv"
"syscall"
"testing"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/samples"
"github.com/jacobsa/fuse/samples/statfs"
.
"github.com/jacobsa/oglematchers"
.
"github.com/jacobsa/ogletest"
)
...
...
@@ -40,20 +38,6 @@ func TestStatFS(t *testing.T) { RunTests(t) }
// Helpers
////////////////////////////////////////////////////////////////////////
func
convertName
(
in
[]
int8
)
(
s
string
)
{
var
tmp
[]
byte
for
_
,
v
:=
range
in
{
if
v
==
0
{
break
}
tmp
=
append
(
tmp
,
byte
(
v
))
}
s
=
string
(
tmp
)
return
}
// Ask `df` for statistics about the file system's capacity and free space,
// useful for checking that our reading of statfs(2) output matches the
// system's. The output is not guaranteed to have resolution greater than 2^10
...
...
@@ -157,66 +141,6 @@ func (t *StatFSTest) SetUp(ti *TestInfo) {
// Tests
////////////////////////////////////////////////////////////////////////
func
(
t
*
StatFSTest
)
Syscall_ZeroValues
()
{
var
err
error
var
stat
syscall
.
Statfs_t
// Call without configuring a canned response, meaning the OS will see the
// zero value for each field. The assertions below act as documentation for
// the OS's behavior in this case.
err
=
syscall
.
Statfs
(
t
.
Dir
,
&
stat
)
AssertEq
(
nil
,
err
)
ExpectEq
(
4096
,
stat
.
Bsize
)
ExpectEq
(
65536
,
stat
.
Iosize
)
ExpectEq
(
0
,
stat
.
Blocks
)
ExpectEq
(
0
,
stat
.
Bfree
)
ExpectEq
(
0
,
stat
.
Bavail
)
ExpectEq
(
0
,
stat
.
Files
)
ExpectEq
(
0
,
stat
.
Ffree
)
ExpectEq
(
"osxfusefs"
,
convertName
(
stat
.
Fstypename
[
:
]))
ExpectEq
(
t
.
canonicalDir
,
convertName
(
stat
.
Mntonname
[
:
]))
ExpectThat
(
convertName
(
stat
.
Mntfromname
[
:
]),
MatchesRegexp
(
`mount_osxfusefs@osxfuse\d+`
))
}
func
(
t
*
StatFSTest
)
Syscall_NonZeroValues
()
{
var
err
error
var
stat
syscall
.
Statfs_t
// Set up the canned response.
canned
:=
fuseops
.
StatFSOp
{
BlockSize
:
1
<<
15
,
Blocks
:
1
<<
51
+
3
,
BlocksFree
:
1
<<
43
+
5
,
BlocksAvailable
:
1
<<
41
+
7
,
Inodes
:
1
<<
59
+
11
,
InodesFree
:
1
<<
58
+
13
,
}
t
.
fs
.
SetStatFSResponse
(
canned
)
// Stat.
err
=
syscall
.
Statfs
(
t
.
Dir
,
&
stat
)
AssertEq
(
nil
,
err
)
ExpectEq
(
canned
.
BlockSize
,
stat
.
Bsize
)
ExpectEq
(
canned
.
BlockSize
,
stat
.
Iosize
)
ExpectEq
(
canned
.
Blocks
,
stat
.
Blocks
)
ExpectEq
(
canned
.
BlocksFree
,
stat
.
Bfree
)
ExpectEq
(
canned
.
BlocksAvailable
,
stat
.
Bavail
)
ExpectEq
(
canned
.
Inodes
,
stat
.
Files
)
ExpectEq
(
canned
.
InodesFree
,
stat
.
Ffree
)
ExpectEq
(
"osxfusefs"
,
convertName
(
stat
.
Fstypename
[
:
]))
ExpectEq
(
t
.
canonicalDir
,
convertName
(
stat
.
Mntonname
[
:
]))
ExpectThat
(
convertName
(
stat
.
Mntfromname
[
:
]),
MatchesRegexp
(
`mount_osxfusefs@osxfuse\d+`
))
}
func
(
t
*
StatFSTest
)
CapacityAndFreeSpace
()
{
canned
:=
fuseops
.
StatFSOp
{
Blocks
:
1024
,
...
...
@@ -268,50 +192,3 @@ func (t *StatFSTest) WriteSize() {
// small chunks of data.
ExpectEq
(
1
<<
20
,
t
.
fs
.
MostRecentWriteSize
())
}
func
(
t
*
StatFSTest
)
UnsupportedBlockSizes
()
{
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
expectedIosize
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
},
}
for
i
,
tc
:=
range
testCases
{
desc
:=
fmt
.
Sprintf
(
"Case %d: block size %d"
,
i
,
tc
.
fsBlockSize
)
// Set up.
canned
:=
fuseops
.
StatFSOp
{
BlockSize
:
tc
.
fsBlockSize
,
Blocks
:
10
,
}
t
.
fs
.
SetStatFSResponse
(
canned
)
// Check.
var
stat
syscall
.
Statfs_t
err
=
syscall
.
Statfs
(
t
.
Dir
,
&
stat
)
AssertEq
(
nil
,
err
)
ExpectEq
(
tc
.
expectedBsize
,
stat
.
Bsize
,
"%s"
,
desc
)
ExpectEq
(
tc
.
expectedIosize
,
stat
.
Iosize
,
"%s"
,
desc
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment