summaryrefslogtreecommitdiff
path: root/integrationtests/cmd/ioworkload/scenario_sync.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-21 22:03:57 +0200
committerPaul Buetow <paul@buetow.org>2026-02-21 22:03:57 +0200
commit3ec3c117bb280a377fea1a3eef84a70e2a3d4150 (patch)
treeb017e330eeaa1cafe95d2a730675b46342afd92a /integrationtests/cmd/ioworkload/scenario_sync.go
parent311b827599251d8d68526293815e8d4dcba632c8 (diff)
Split ioworkload scenarios.go into per-category files
Split the 2494-line scenarios.go monolith into 14 focused files by syscall category: open, readwrite, close, dup, fcntl, rename, link, unlink, dir, stat, sync, truncate, iouring, plus the slimmed-down scenarios.go containing only the registry map, makeTempDir, and crash. Extracted rawLink, rawSymlink, rawReadlink helpers in scenario_link.go to reduce code duplication in linkBasic. Task: #349 (Go best practices: split oversized scenarios file) Amp-Thread-ID: https://ampcode.com/threads/T-019c81c6-e1b6-747a-9144-40f6be997e60 Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'integrationtests/cmd/ioworkload/scenario_sync.go')
-rw-r--r--integrationtests/cmd/ioworkload/scenario_sync.go108
1 files changed, 108 insertions, 0 deletions
diff --git a/integrationtests/cmd/ioworkload/scenario_sync.go b/integrationtests/cmd/ioworkload/scenario_sync.go
new file mode 100644
index 0000000..214c783
--- /dev/null
+++ b/integrationtests/cmd/ioworkload/scenario_sync.go
@@ -0,0 +1,108 @@
+package main
+
+import (
+ "fmt"
+ "path/filepath"
+ "syscall"
+)
+
+// syncBasic opens a file, writes data, and fsyncs it.
+func syncBasic() error {
+ dir, cleanup, err := makeTempDir("sync-basic")
+ if err != nil {
+ return err
+ }
+ defer cleanup()
+
+ path := filepath.Join(dir, "syncfile.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("sync me")); err != nil {
+ return fmt.Errorf("write: %w", err)
+ }
+ 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)
+}
+
+// syncFsyncEbadf calls fsync on an invalid fd.
+// The syscall fails with EBADF, but ior captures the enter_fsync tracepoint.
+func syncFsyncEbadf() error {
+ _, _, errno := syscall.Syscall(syscall.SYS_FSYNC, 99999, 0, 0)
+ if errno == 0 {
+ return fmt.Errorf("expected EBADF, but fsync succeeded")
+ }
+ return nil
+}
+
+// syncFdatasyncEbadf calls fdatasync on an invalid fd.
+// The syscall fails with EBADF, but ior captures the enter_fdatasync tracepoint.
+func syncFdatasyncEbadf() error {
+ _, _, errno := syscall.Syscall(syscall.SYS_FDATASYNC, 99999, 0, 0)
+ if errno == 0 {
+ return fmt.Errorf("expected EBADF, but fdatasync succeeded")
+ }
+ return nil
+}
+
+// syncFileRangeEbadf calls sync_file_range on an invalid fd.
+// The syscall fails with EBADF, but ior captures the enter_sync_file_range tracepoint.
+func syncFileRangeEbadf() error {
+ _, _, errno := syscall.Syscall6(syscall.SYS_SYNC_FILE_RANGE, 99999, 0, 0, 0, 0, 0)
+ if errno == 0 {
+ return fmt.Errorf("expected EBADF, but sync_file_range succeeded")
+ }
+ return nil
+}