summaryrefslogtreecommitdiff
path: root/cmd/ioworkload/scenario_flock.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-06 10:05:22 +0300
committerPaul Buetow <paul@buetow.org>2026-06-06 10:05:22 +0300
commit92ca9482e44432b85ce09ebdd8a1b4d199b1c77b (patch)
tree353e3bf366b6d3e5f8a5fd7e623bd60a6c2cf7ba /cmd/ioworkload/scenario_flock.go
parentd807c1ad9eb8b176e36300c6ea41744431a05bf0 (diff)
test: add end-to-end coverage for getrandom (READ byte count) and flock (KindFd)
Two previously-untested syscalls now have integration coverage: - getrandom (Security family, READ_CLASSIFIED): new security-getrandom scenario fills a 32-byte buffer via unix.Getrandom, looping past any signal-interrupted short reads so the cumulative byte count is strictly positive. TestSecurityGetrandom asserts enter_getrandom MinCount>=1, bytes>=1 (locking in the READ byte-count classification end-to-end), and a positive duration. - flock (FamilyFS, KindFd@args[0], UNCLASSIFIED): new flock-basic scenario opens a temp file, takes LOCK_EX then LOCK_UN via syscall.Flock, and closes it. TestFlockBasic asserts enter_flock with PathContains the temp filename, confirming the fd resolves to the file path via the procfd cache. Both scenarios use raw unix/syscall calls so the exact sys_enter tracepoints fire, and are registered in cmd/ioworkload/scenarios.go. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'cmd/ioworkload/scenario_flock.go')
-rw-r--r--cmd/ioworkload/scenario_flock.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/cmd/ioworkload/scenario_flock.go b/cmd/ioworkload/scenario_flock.go
new file mode 100644
index 0000000..a54f5d0
--- /dev/null
+++ b/cmd/ioworkload/scenario_flock.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "fmt"
+ "path/filepath"
+ "syscall"
+)
+
+// flockBasic exercises the flock syscall end-to-end. It opens a temp file,
+// acquires an exclusive advisory lock (LOCK_EX), releases it (LOCK_UN), then
+// closes the file and removes the temp dir.
+//
+// flock is unprivileged (FamilyFS) and captured as KindFd at args[0]; ior
+// resolves that fd to the underlying file path via the procfd cache, so the
+// enter_flock record carries the temp filename. Its return value is
+// UNCLASSIFIED (0 on success), so this scenario only locks in the enter path.
+func flockBasic() error {
+ dir, cleanup, err := makeTempDir("flock-basic")
+ if err != nil {
+ return err
+ }
+ defer cleanup()
+
+ path := filepath.Join(dir, "flockfile.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)
+
+ // Use raw syscall.Flock so the exact sys_enter_flock tracepoint fires.
+ if err := syscall.Flock(fd, syscall.LOCK_EX); err != nil {
+ return fmt.Errorf("flock LOCK_EX: %w", err)
+ }
+ if err := syscall.Flock(fd, syscall.LOCK_UN); err != nil {
+ return fmt.Errorf("flock LOCK_UN: %w", err)
+ }
+ return nil
+}