diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-23 13:23:23 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-23 13:23:23 +0200 |
| commit | 4bdb0505635e66e07aa7edd9d1f842f860aa581c (patch) | |
| tree | 433e464e36aeb23cbe966c5796bdb164ec04c597 | |
| parent | 2b1c849422973cf926e2bfda31703f4bfef5563d (diff) | |
tests: cover durationToPrev gap semantics
| -rw-r--r-- | integrationtests/cmd/ioworkload/scenario_open.go | 29 | ||||
| -rw-r--r-- | integrationtests/cmd/ioworkload/scenarios.go | 1 | ||||
| -rw-r--r-- | integrationtests/open_test.go | 34 | ||||
| -rw-r--r-- | internal/event/pair_test.go | 56 |
4 files changed, 119 insertions, 1 deletions
diff --git a/integrationtests/cmd/ioworkload/scenario_open.go b/integrationtests/cmd/ioworkload/scenario_open.go index 449549c..d86e53b 100644 --- a/integrationtests/cmd/ioworkload/scenario_open.go +++ b/integrationtests/cmd/ioworkload/scenario_open.go @@ -6,6 +6,7 @@ import ( "path/filepath" "runtime" "syscall" + "time" "unsafe" ) @@ -226,3 +227,31 @@ func openByHandleAtSyscall(mountFD int, handle []byte, flags int) (int, error) { } return int(fd), nil } + +// openDurationGap creates two openat syscalls separated by a deliberate sleep. +// Integration tests use this to assert durationToPrev captures inter-syscall gaps. +func openDurationGap() error { + dir, cleanup, err := makeTempDir("open-duration-gap") + if err != nil { + return err + } + defer cleanup() + + first := filepath.Join(dir, "gap-first.txt") + fd1, err := syscall.Open(first, syscall.O_RDWR|syscall.O_CREAT, 0o644) + if err != nil { + return fmt.Errorf("open first: %w", err) + } + if err := syscall.Close(fd1); err != nil { + return fmt.Errorf("close first: %w", err) + } + + time.Sleep(800 * time.Millisecond) + + second := filepath.Join(dir, "gap-second.txt") + fd2, err := syscall.Open(second, syscall.O_RDWR|syscall.O_CREAT, 0o644) + if err != nil { + return fmt.Errorf("open second: %w", err) + } + return syscall.Close(fd2) +} diff --git a/integrationtests/cmd/ioworkload/scenarios.go b/integrationtests/cmd/ioworkload/scenarios.go index a6e7a5f..6910314 100644 --- a/integrationtests/cmd/ioworkload/scenarios.go +++ b/integrationtests/cmd/ioworkload/scenarios.go @@ -11,6 +11,7 @@ var scenarios = map[string]func() error{ "open-basic": openBasic, "open-creat": openCreat, "open-by-handle-at": openByHandleAt, + "open-duration-gap": openDurationGap, "open-enoent": openEnoent, "open-rdonly-write": openRdonlyWrite, "open-pid-filter": openPidFilter, diff --git a/integrationtests/open_test.go b/integrationtests/open_test.go index dae5244..c2a0366 100644 --- a/integrationtests/open_test.go +++ b/integrationtests/open_test.go @@ -1,6 +1,9 @@ package integrationtests -import "testing" +import ( + "strings" + "testing" +) func TestOpenBasic(t *testing.T) { runScenario(t, "open-basic", []ExpectedEvent{ @@ -93,3 +96,32 @@ func TestOpenPidFilter(t *testing.T) { }, }) } + +func TestOpenDurationGap(t *testing.T) { + h := newTestHarness(t) + result, pid, err := h.Run("open-duration-gap", defaultDuration) + if err != nil { + t.Fatalf("run scenario open-duration-gap: %v", err) + } + + AssertNoUnexpectedPID(t, result, pid) + AssertNoUnexpectedComm(t, result, "ioworkload") + + // We intentionally sleep 800ms between first and second openat. + const minGapNs = uint64(500 * 1_000_000) + + for _, rec := range result.Records { + if !strings.Contains(rec.TraceID.String(), "enter_openat") { + continue + } + if !strings.Contains(rec.Path, "gap-second.txt") { + continue + } + if rec.Cnt.DurationToPrev < minGapNs { + t.Fatalf("durationToPrev for second openat = %d ns, want >= %d ns", rec.Cnt.DurationToPrev, minGapNs) + } + return + } + + t.Fatalf("did not find second openat record for gap-second.txt") +} diff --git a/internal/event/pair_test.go b/internal/event/pair_test.go new file mode 100644 index 0000000..a1cb8ab --- /dev/null +++ b/internal/event/pair_test.go @@ -0,0 +1,56 @@ +package event + +import ( + "ior/internal/types" + "testing" +) + +func TestPairCalculateDurationsFirstEvent(t *testing.T) { + enter := &types.OpenEvent{ + Time: 1000, + Pid: 1, + Tid: 2, + } + exit := &types.RetEvent{ + Time: 1100, + Pid: 1, + Tid: 2, + Ret: 0, + } + + pair := NewPair(enter) + pair.ExitEv = exit + pair.CalculateDurations(0) + + if pair.Duration != 100 { + t.Fatalf("Duration = %d, want 100", pair.Duration) + } + if pair.DurationToPrev != 0 { + t.Fatalf("DurationToPrev = %d, want 0 for first event", pair.DurationToPrev) + } +} + +func TestPairCalculateDurationsWithPreviousExit(t *testing.T) { + enter := &types.OpenEvent{ + Time: 2000, + Pid: 1, + Tid: 2, + } + exit := &types.RetEvent{ + Time: 2100, + Pid: 1, + Tid: 2, + Ret: 0, + } + + pair := NewPair(enter) + pair.ExitEv = exit + pair.CalculateDurations(1500) + + if pair.Duration != 100 { + t.Fatalf("Duration = %d, want 100", pair.Duration) + } + if pair.DurationToPrev != 500 { + t.Fatalf("DurationToPrev = %d, want 500", pair.DurationToPrev) + } +} |
