Commit 50cd8164 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

benchmark: modernize setupFS

Change-Id: I0dd07cf43fded2aa28ff83b2797e9222ae6e1295
parent ab014071
...@@ -24,8 +24,7 @@ func BenchmarkGoFuseMemoryRead(b *testing.B) { ...@@ -24,8 +24,7 @@ func BenchmarkGoFuseMemoryRead(b *testing.B) {
const blockSize = 64 * 1024 const blockSize = 64 * 1024
func benchmarkGoFuseRead(root fs.InodeEmbedder, b *testing.B) { func benchmarkGoFuseRead(root fs.InodeEmbedder, b *testing.B) {
wd, clean := setupFs(root, b.N) wd := setupFS(root, b.N, b)
defer clean()
jobs := 32 jobs := 32
cmds := make([]*exec.Cmd, jobs) cmds := make([]*exec.Cmd, jobs)
......
...@@ -22,22 +22,19 @@ import ( ...@@ -22,22 +22,19 @@ import (
"github.com/hanwen/go-fuse/v2/internal/testutil" "github.com/hanwen/go-fuse/v2/internal/testutil"
) )
func setupFs(node fs.InodeEmbedder, N int) (string, func()) { func setupFS(node fs.InodeEmbedder, N int, tb testing.TB) string {
opts := &fs.Options{} opts := &fs.Options{}
opts.Debug = testutil.VerboseTest() opts.Debug = testutil.VerboseTest()
mountPoint, err := os.MkdirTemp("", "") mountPoint := tb.TempDir()
if err != nil {
log.Panicf("TempDir: %v", err)
}
server, err := fs.Mount(mountPoint, node, opts) server, err := fs.Mount(mountPoint, node, opts)
if err != nil { if err != nil {
log.Panicf("cannot mount %v", err) tb.Fatalf("cannot mount %v", err)
} }
lmap := NewLatencyMap() lmap := NewLatencyMap()
if testutil.VerboseTest() { if testutil.VerboseTest() {
server.RecordLatencies(lmap) server.RecordLatencies(lmap)
} }
return mountPoint, func() { tb.Cleanup(func() {
if testutil.VerboseTest() { if testutil.VerboseTest() {
var total time.Duration var total time.Duration
for _, n := range []string{"LOOKUP", "GETATTR", "OPENDIR", "READDIR", for _, n := range []string{"LOOKUP", "GETATTR", "OPENDIR", "READDIR",
...@@ -57,7 +54,8 @@ func setupFs(node fs.InodeEmbedder, N int) (string, func()) { ...@@ -57,7 +54,8 @@ func setupFs(node fs.InodeEmbedder, N int) (string, func()) {
if err != nil { if err != nil {
log.Println("error during unmount", err) log.Println("error during unmount", err)
} }
} })
return mountPoint
} }
func TestNewStatFs(t *testing.T) { func TestNewStatFs(t *testing.T) {
...@@ -68,8 +66,7 @@ func TestNewStatFs(t *testing.T) { ...@@ -68,8 +66,7 @@ func TestNewStatFs(t *testing.T) {
fs.AddFile(n, fuse.Attr{Mode: syscall.S_IFREG}) fs.AddFile(n, fuse.Attr{Mode: syscall.S_IFREG})
} }
wd, clean := setupFs(fs, 1) wd := setupFS(fs, 1, t)
defer clean()
names, err := ioutil.ReadDir(wd) names, err := ioutil.ReadDir(wd)
if err != nil { if err != nil {
...@@ -121,15 +118,14 @@ func BenchmarkGoFuseStat(b *testing.B) { ...@@ -121,15 +118,14 @@ func BenchmarkGoFuseStat(b *testing.B) {
fs.AddFile(fn, fuse.Attr{Mode: syscall.S_IFREG}) fs.AddFile(fn, fuse.Attr{Mode: syscall.S_IFREG})
} }
wd, clean := setupFs(fs, b.N) mnt := setupFS(fs, b.N, b)
defer clean()
for i, l := range files { for i, l := range files {
files[i] = filepath.Join(wd, l) files[i] = filepath.Join(mnt, l)
} }
threads := runtime.GOMAXPROCS(0) threads := runtime.GOMAXPROCS(0)
if err := TestingBOnePass(b, threads, fileList, wd); err != nil { if err := TestingBOnePass(b, threads, fileList, mnt); err != nil {
b.Fatalf("TestingBOnePass %v8", err) b.Fatalf("TestingBOnePass %v8", err)
} }
} }
...@@ -157,12 +153,11 @@ func BenchmarkGoFuseReaddir(b *testing.B) { ...@@ -157,12 +153,11 @@ func BenchmarkGoFuseReaddir(b *testing.B) {
dirSet[filepath.Dir(fn)] = struct{}{} dirSet[filepath.Dir(fn)] = struct{}{}
} }
wd, clean := setupFs(fs, b.N) mnt := setupFS(fs, b.N, b)
defer clean()
var dirs []string var dirs []string
for dir := range dirSet { for dir := range dirSet {
dirs = append(dirs, filepath.Join(wd, dir)) dirs = append(dirs, filepath.Join(mnt, dir))
} }
b.StartTimer() b.StartTimer()
todo := b.N todo := b.N
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment