diff options
Diffstat (limited to 'internal/eventloop_polling_test.go')
| -rw-r--r-- | internal/eventloop_polling_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/eventloop_polling_test.go b/internal/eventloop_polling_test.go index 9d807d5..5158b53 100644 --- a/internal/eventloop_polling_test.go +++ b/internal/eventloop_polling_test.go @@ -80,4 +80,68 @@ func TestInitRawHandlersRegistersPollingEvents(t *testing.T) { if _, ok := el.rawHandlers[types.ENTER_EPOLL_CTL_EVENT]; !ok { t.Fatal("ENTER_EPOLL_CTL_EVENT handler is not registered") } + if _, ok := el.rawHandlers[types.ENTER_POLL_EVENT]; !ok { + t.Fatal("ENTER_POLL_EVENT handler is not registered") + } +} + +func TestHandlePollExitCarriesCommAndAppliesFilter(t *testing.T) { + t.Run("accepted", func(t *testing.T) { + el := mustNewEventLoop(t, eventLoopConfig{}) + enter := &types.PollEvent{ + EventType: types.ENTER_POLL_EVENT, + TraceId: types.SYS_ENTER_POLL, + Time: 300, + Pid: 120, + Tid: 121, + Nfds: 2, + TimeoutNs: 5_000_000, + } + exit := &types.RetEvent{ + EventType: types.EXIT_RET_EVENT, + TraceId: types.SYS_EXIT_POLL, + Time: 320, + Ret: 1, + Pid: 120, + Tid: 121, + } + ep := &event.Pair{EnterEv: enter, ExitEv: exit} + + if ok := el.handlePollExit(ep, enter); !ok { + t.Fatal("handlePollExit returned false") + } + if ep.Comm != "" { + t.Fatalf("expected empty comm for unresolved tid, got %q", ep.Comm) + } + }) + + t.Run("filtered", func(t *testing.T) { + el := mustNewEventLoop(t, eventLoopConfig{ + filter: globalfilter.Filter{ + Syscall: &globalfilter.StringFilter{Pattern: "openat"}, + }, + }) + enter := &types.PollEvent{ + EventType: types.ENTER_POLL_EVENT, + TraceId: types.SYS_ENTER_POLL, + Time: 300, + Pid: 120, + Tid: 121, + Nfds: 2, + TimeoutNs: 5_000_000, + } + exit := &types.RetEvent{ + EventType: types.EXIT_RET_EVENT, + TraceId: types.SYS_EXIT_POLL, + Time: 320, + Ret: 1, + Pid: 120, + Tid: 121, + } + ep := &event.Pair{EnterEv: enter, ExitEv: exit} + + if ok := el.handlePollExit(ep, enter); ok { + t.Fatal("handlePollExit should reject pair due to filter mismatch") + } + }) } |
