From 8e8cad2f1a085366eff89f6299d49637cb4d425f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 2 Jun 2026 21:29:42 +0300 Subject: test(integration): add inotify family tracing coverage Add an inotify-basic ioworkload scenario and an end-to-end integration test covering the inotify IPC family, which previously had no integration coverage (only inotify_init1 had a unit-level eventloop test). The scenario issues inotify_init1(IN_CLOEXEC) -> inotify_add_watch on a temp file (IN_CREATE|IN_DELETE|IN_MODIFY) -> inotify_rm_watch -> close. It is non-blocking: it registers and removes the watch without reading events, and cleans up the temp dir on return. TestInotifyBasic asserts enter_inotify_init1, enter_inotify_add_watch, enter_inotify_rm_watch and enter_close each fire at least once, with positive durations and PID/comm hermetic guards. The init1 instance fd resolves to the inotifyfd: path label; add_watch/rm_watch capture the instance fd@arg0 which resolves to the same registered label. Co-Authored-By: Claude Opus 4.8 --- cmd/ioworkload/scenario_inotify.go | 57 ++++++++++++++++++++++++++++++++++++++ cmd/ioworkload/scenarios.go | 1 + 2 files changed, 58 insertions(+) create mode 100644 cmd/ioworkload/scenario_inotify.go (limited to 'cmd') diff --git a/cmd/ioworkload/scenario_inotify.go b/cmd/ioworkload/scenario_inotify.go new file mode 100644 index 0000000..770d0ff --- /dev/null +++ b/cmd/ioworkload/scenario_inotify.go @@ -0,0 +1,57 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "syscall" + + "golang.org/x/sys/unix" +) + +// inotifyBasic exercises the inotify IPC family end-to-end: +// inotify_init1(IN_CLOEXEC) creates the inotify instance fd (registered as an +// eventfd-kind descriptor, exit ret UNCLASSIFIED, path label "inotifyfd:"), +// inotify_add_watch registers a watch on a file under a temp dir and returns a +// watch descriptor (NOT a tracked fd; exit ret UNCLASSIFIED), inotify_rm_watch +// removes that watch by descriptor, and close releases the instance fd. +// +// It is deliberately non-blocking: it only registers and removes the watch and +// never reads pending events, so the workload returns promptly regardless of +// filesystem activity. The watched path lives under a temp dir that is removed +// on return. +func inotifyBasic() error { + dir, cleanup, err := makeTempDir("inotify") + if err != nil { + return err + } + defer cleanup() + + // Create a concrete file to watch so the path resolves to a real inode. + watched := filepath.Join(dir, "watched") + if err := os.WriteFile(watched, []byte("ior"), 0o600); err != nil { + return fmt.Errorf("create watched file: %w", err) + } + + // inotify_init1 with IN_CLOEXEC; returns the inotify instance fd. + fd, err := unix.InotifyInit1(unix.IN_CLOEXEC) + if err != nil { + return fmt.Errorf("inotify_init1: %w", err) + } + defer syscall.Close(fd) + + // inotify_add_watch on the instance fd; returns a watch descriptor (wd), + // which is NOT a file descriptor and must not be registered as a tracked fd. + mask := uint32(unix.IN_CREATE | unix.IN_DELETE | unix.IN_MODIFY) + wd, err := unix.InotifyAddWatch(fd, watched, mask) + if err != nil { + return fmt.Errorf("inotify_add_watch: %w", err) + } + + // inotify_rm_watch removes the watch by descriptor on the instance fd. + if _, err := unix.InotifyRmWatch(fd, uint32(wd)); err != nil { + return fmt.Errorf("inotify_rm_watch: %w", err) + } + + return nil +} diff --git a/cmd/ioworkload/scenarios.go b/cmd/ioworkload/scenarios.go index 690386b..68dc3d0 100644 --- a/cmd/ioworkload/scenarios.go +++ b/cmd/ioworkload/scenarios.go @@ -42,6 +42,7 @@ var scenarios = map[string]func() error{ "eventfd-basic": eventfdBasic, "eventfd2-basic": eventfd2Basic, "fd-from-air-eventfd-users": fdFromAirEventfdUsers, + "inotify-basic": inotifyBasic, "mq-posix-basic": mqPosixBasic, "sysv-shm-basic": sysvShmBasic, "sysv-msg-basic": sysvMsgBasic, -- cgit v1.2.3