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
e2910a4d
Commit
e2910a4d
authored
Sep 09, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StatFSTest.CapacityAndFreeSpace
parent
d5cd319a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
1 deletion
+84
-1
samples/statfs/statfs_test.go
samples/statfs/statfs_test.go
+84
-1
No files found.
samples/statfs/statfs_test.go
View file @
e2910a4d
...
...
@@ -15,8 +15,13 @@
package
statfs_test
import
(
"bytes"
"fmt"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
"syscall"
"testing"
...
...
@@ -48,6 +53,62 @@ func convertName(in []int8) (s string) {
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
// (1 KiB).
func
df
(
dir
string
)
(
capacity
,
used
,
available
uint64
,
err
error
)
{
// Sample output:
//
// Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
// fake@bucket 32 16 16 50% 0 0 100% /Users/jacobsa/tmp/mp
//
re
:=
regexp
.
MustCompile
(
`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+\d+\s+\d+\s+\d+%.*$`
)
// Call df with a block size of 1024 and capture its output.
cmd
:=
exec
.
Command
(
"df"
,
dir
)
cmd
.
Env
=
[]
string
{
"BLOCKSIZE=1024"
}
output
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
return
}
// Scrape it.
for
_
,
line
:=
range
bytes
.
Split
(
output
,
[]
byte
{
'\n'
})
{
// Is this the line we're interested in?
if
!
bytes
.
Contains
(
line
,
[]
byte
(
dir
))
{
continue
}
submatches
:=
re
.
FindSubmatch
(
line
)
if
submatches
==
nil
{
err
=
fmt
.
Errorf
(
"Unable to parse line: %q"
,
line
)
return
}
capacity
,
err
=
strconv
.
ParseUint
(
string
(
submatches
[
1
]),
10
,
64
)
if
err
!=
nil
{
return
}
used
,
err
=
strconv
.
ParseUint
(
string
(
submatches
[
2
]),
10
,
64
)
if
err
!=
nil
{
return
}
available
,
err
=
strconv
.
ParseUint
(
string
(
submatches
[
3
]),
10
,
64
)
if
err
!=
nil
{
return
}
return
}
err
=
fmt
.
Errorf
(
"Unable to parse df output:
\n
%s"
,
output
)
return
}
////////////////////////////////////////////////////////////////////////
// Boilerplate
////////////////////////////////////////////////////////////////////////
...
...
@@ -151,7 +212,29 @@ func (t *StatFSTest) Syscall_NonZeroValues() {
}
func
(
t
*
StatFSTest
)
CapacityAndFreeSpace
()
{
AssertTrue
(
false
,
"TODO: Use df"
)
canned
:=
fuseops
.
StatFSOp
{
Blocks
:
1024
,
BlocksFree
:
896
,
BlocksAvailable
:
768
,
}
// Check that df agrees with us about a range of block sizes.
for
log2BlockSize
:=
uint
(
9
);
log2BlockSize
<
31
;
log2BlockSize
++
{
bs
:=
uint64
(
1
)
<<
log2BlockSize
desc
:=
fmt
.
Sprintf
(
"block size: %d (2^%d)"
,
bs
,
log2BlockSize
)
// Set up the canned response.
canned
.
BlockSize
=
uint32
(
bs
)
t
.
fs
.
SetStatFSResponse
(
canned
)
// Call df.
capacity
,
used
,
available
,
err
:=
df
(
t
.
canonicalDir
)
AssertEq
(
nil
,
err
)
ExpectEq
(
bs
*
canned
.
Blocks
,
capacity
,
"%s"
,
desc
)
ExpectEq
(
bs
*
(
canned
.
Blocks
-
canned
.
BlocksAvailable
),
used
,
"%s"
,
desc
)
ExpectEq
(
bs
*
canned
.
BlocksAvailable
,
available
,
"%s"
,
desc
)
}
}
func
(
t
*
StatFSTest
)
WriteSize
()
{
...
...
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