1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// Copyright 2025 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package benchmark
import (
"context"
"os"
"os/exec"
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
)
type memFile struct {
fs.MemRegularFile
}
var _ = (fs.NodeGetxattrer)((*memFile)(nil))
var _ = (fs.NodeFsyncer)((*memFile)(nil))
func (mf *memFile) Getxattr(ctx context.Context, attr string, dest []byte) (uint32, syscall.Errno) {
// Suppress security attribute reads
return 0, syscall.ENOSYS
}
func (mf *memFile) Fsync(context.Context, fs.FileHandle, uint32) syscall.Errno {
return 0
}
type memDir struct {
fs.Inode
}
func (md *memDir) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (node *fs.Inode, fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
mrf := memFile{}
ch := md.NewInode(ctx, &mrf, fs.StableAttr{Mode: fuse.S_IFREG})
md.AddChild(name, ch, true)
return ch, nil, 0, 0
}
func TestBenchmarkMemFSFio(t *testing.T) {
root := &memDir{}
mnt := t.TempDir()
opts := fs.Options{}
opts.Debug = false // logging impacts performance.
ttl := 100 * time.Second
opts.EntryTimeout = &ttl
opts.AttrTimeout = &ttl
srv, err := fs.Mount(mnt, root, &opts)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
srv.Unmount()
})
srv.WaitMount()
mode := "read"
cmd := exec.Command("fio", "--directory="+mnt,
"--rw="+mode, "--name="+mode,
"--bs=128k", "--size=1G", "--direct=1")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
}
|