diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-10 22:30:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-10 22:30:59 +0300 |
| commit | 865ccd8a8bc0eff72686577a9fc159a6a8934b31 (patch) | |
| tree | f3369e6b0d4e5cf14103a47a9713e2a7718e5b28 /internal/eventloop_test.go | |
| parent | 3e30b02f76b3a46b50e041c2c6c0db6678e14e4e (diff) | |
feat: Add comprehensive filtering and comm tracking tests
Implemented three test suites for eventloop filtering functionality:
1. TestCommPropagation - Verifies that comm names established via OpenEvent
are properly propagated to subsequent syscalls from the same thread ID.
2. TestEventTypeFiltering - Tests filter behavior for each event type:
- OpenEvent: Filters by both comm and path
- PathEvent: Filters by path only
- NameEvent: Filters by path (checks both oldname and newname)
- FdEvent: Filters by comm and path via eventPair
3. TestCommFilterToggle - Tests that comm filter enable/disable works correctly,
demonstrating that FdEvents without established comm names are filtered when
comm filter is enabled.
Also fixed buffer overflow issues when setting custom comm names in tests by
clearing the buffer before copying new values.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/eventloop_test.go')
| -rw-r--r-- | internal/eventloop_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/eventloop_test.go b/internal/eventloop_test.go index b2354d9..b4ab460 100644 --- a/internal/eventloop_test.go +++ b/internal/eventloop_test.go @@ -2,7 +2,10 @@ package internal import ( "context" + "fmt" "ior/internal/event" + "ior/internal/file" + "ior/internal/flamegraph" "ior/internal/types" "syscall" "testing" @@ -787,6 +790,34 @@ func verifyMismatchCount(t *testing.T, el *eventLoop, expectedCount uint) { } } +// Helper functions for filter testing +func newEventLoopWithFilter(commFilter, pathFilter string) *eventLoop { + el := &eventLoop{ + filter: &eventFilter{ + commFilterEnable: commFilter != "", + commFilter: commFilter, + pathFilterEnable: pathFilter != "", + pathFilter: pathFilter, + }, + enterEvs: make(map[uint32]*event.Pair), + files: make(map[int32]file.File), + comms: make(map[uint32]string), + prevPairTimes: make(map[uint32]uint64), + printCb: func(ep *event.Pair) { fmt.Println(ep); ep.Recycle() }, + flamegraph: flamegraph.New(), + done: make(chan struct{}), + } + return el +} + +func verifyCommName(t *testing.T, el *eventLoop, tid uint32, expectedComm string) { + if comm, ok := el.comms[tid]; !ok { + t.Errorf("Expected comm name for tid %d but it wasn't found", tid) + } else if comm != expectedComm { + t.Errorf("Expected comm name '%s' for tid %d but got '%s'", expectedComm, tid, comm) + } +} + // Test open→read→write→close lifecycle func makeFdLifecycleTestData(t *testing.T) (td testData) { fd := int32(42) |
