diff options
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/cmd/ioworkload/scenarios.go | 57 | ||||
| -rw-r--r-- | integrationtests/sync_test.go | 46 |
2 files changed, 101 insertions, 2 deletions
diff --git a/integrationtests/cmd/ioworkload/scenarios.go b/integrationtests/cmd/ioworkload/scenarios.go index bf1561c..e87d53e 100644 --- a/integrationtests/cmd/ioworkload/scenarios.go +++ b/integrationtests/cmd/ioworkload/scenarios.go @@ -48,8 +48,11 @@ var scenarios = map[string]func() error{ "stat-statx": statStatx, "stat-access": statAccess, "stat-faccessat": statFaccessat, - "sync-basic": syncBasic, - "truncate-basic": truncateBasic, + "sync-basic": syncBasic, + "sync-fdatasync": syncFdatasync, + "sync-sync": syncSync, + "sync-sync-file-range": syncSyncFileRange, + "truncate-basic": truncateBasic, } func makeTempDir(prefix string) (string, func(), error) { @@ -1285,6 +1288,56 @@ func syncBasic() error { return syscall.Fsync(fd) } +// syncFdatasync opens a file, writes data, and fdatasyncs it. +func syncFdatasync() error { + dir, cleanup, err := makeTempDir("sync-fdatasync") + if err != nil { + return err + } + defer cleanup() + + path := filepath.Join(dir, "fdatasyncfile.txt") + fd, err := syscall.Open(path, syscall.O_RDWR|syscall.O_CREAT, 0o644) + if err != nil { + return fmt.Errorf("open: %w", err) + } + defer syscall.Close(fd) + + if _, err := syscall.Write(fd, []byte("fdatasync me")); err != nil { + return fmt.Errorf("write: %w", err) + } + return syscall.Fdatasync(fd) +} + +// syncSync calls sync(2) to flush all filesystem caches. +// sync is a null_event with no file arguments. +func syncSync() error { + syscall.Sync() + return nil +} + +// syncSyncFileRange opens a file, writes data, then calls sync_file_range(2). +func syncSyncFileRange() error { + dir, cleanup, err := makeTempDir("sync-sync-file-range") + if err != nil { + return err + } + defer cleanup() + + path := filepath.Join(dir, "syncrangefile.txt") + fd, err := syscall.Open(path, syscall.O_RDWR|syscall.O_CREAT, 0o644) + if err != nil { + return fmt.Errorf("open: %w", err) + } + defer syscall.Close(fd) + + data := []byte("sync file range data") + if _, err := syscall.Write(fd, data); err != nil { + return fmt.Errorf("write: %w", err) + } + return syscall.SyncFileRange(fd, 0, int64(len(data)), 0) +} + // truncateBasic opens a file, writes data, and truncates it. func truncateBasic() error { dir, cleanup, err := makeTempDir("truncate-basic") diff --git a/integrationtests/sync_test.go b/integrationtests/sync_test.go new file mode 100644 index 0000000..5f6a314 --- /dev/null +++ b/integrationtests/sync_test.go @@ -0,0 +1,46 @@ +package integrationtests + +import "testing" + +func TestSyncBasic(t *testing.T) { + runScenario(t, "sync-basic", []ExpectedEvent{ + { + PathContains: "syncfile.txt", + Tracepoint: "enter_fsync", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} + +func TestSyncFdatasync(t *testing.T) { + runScenario(t, "sync-fdatasync", []ExpectedEvent{ + { + PathContains: "fdatasyncfile.txt", + Tracepoint: "enter_fdatasync", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} + +func TestSyncSync(t *testing.T) { + runScenario(t, "sync-sync", []ExpectedEvent{ + { + Tracepoint: "enter_sync", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} + +func TestSyncSyncFileRange(t *testing.T) { + runScenario(t, "sync-sync-file-range", []ExpectedEvent{ + { + PathContains: "syncrangefile.txt", + Tracepoint: "enter_sync_file_range", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} |
