diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 16:43:54 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 16:43:54 +0200 |
| commit | 3791264d60df194f144f8b55eeca8f7aa9ea0a6b (patch) | |
| tree | 19d5734d0ae322f1430f3bef06c7ccb8a231810b /internal | |
| parent | a1b48634add8c5cdd3d362b592bb6f6eb5bf69ee (diff) | |
refactor: make wrappers the only eventloop state maps (task 383)
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/eventloop.go | 6 | ||||
| -rw-r--r-- | internal/eventloop_filter_test.go | 14 | ||||
| -rw-r--r-- | internal/eventloop_seed_test.go | 4 | ||||
| -rw-r--r-- | internal/eventloop_test.go | 40 |
4 files changed, 29 insertions, 35 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go index 2ac0bcc..8e336a2 100644 --- a/internal/eventloop.go +++ b/internal/eventloop.go @@ -210,10 +210,8 @@ type eventLoop struct { filter *eventFilter enterEvs map[uint32]*event.Pair // Temp. store of sys_enter tracepoints per Tid. pendingHandles map[uint32]string // map of TID to pathname from name_to_handle_at - files map[int32]file.File // Track all open files by file descriptor. fdTracker *fdTracker procFdCache map[uint64]file.FdFile // Cache procfs-resolved metadata for unknown fds. - comms map[uint32]string // Program or thread name of the current Tid. commResolver *commResolver prevPairTimes map[uint32]uint64 // Previous event's time (to calculate time differences between two events) rawHandlers map[types.EventType]rawEventHandler @@ -243,10 +241,8 @@ func newEventLoop(cfg eventLoopConfig) (*eventLoop, error) { filter: filter, enterEvs: make(map[uint32]*event.Pair), pendingHandles: make(map[uint32]string), - files: fdState.files, fdTracker: fdState, procFdCache: make(map[uint64]file.FdFile), - comms: commState.comms, commResolver: commState, prevPairTimes: make(map[uint32]uint64), rawHandlers: make(map[types.EventType]rawEventHandler), @@ -297,7 +293,6 @@ func (e *eventLoop) fdState() *fdTracker { if e.fdTracker.files == nil { e.fdTracker.files = make(map[int32]file.File) } - e.files = e.fdTracker.files return e.fdTracker } @@ -312,7 +307,6 @@ func (e *eventLoop) commState() *commResolver { e.commResolver.pending = make(map[uint32]struct{}) } e.commResolver.ensureLookupConfig() - e.comms = e.commResolver.comms return e.commResolver } diff --git a/internal/eventloop_filter_test.go b/internal/eventloop_filter_test.go index 6418adf..d0b7933 100644 --- a/internal/eventloop_filter_test.go +++ b/internal/eventloop_filter_test.go @@ -123,7 +123,7 @@ func makeCommPropagationTestData(t *testing.T) (td testData) { t.Errorf("Expected no comm name for different thread but got '%s'", ep.Comm) } // Verify comm map doesn't have entry for this tid - if _, ok := el.comms[differentTid]; ok { + if _, ok := el.cachedComm(differentTid); ok { t.Errorf("Expected no comm entry for tid %d but one was found", differentTid) } }) @@ -438,8 +438,8 @@ func TestCommFilterToggle(t *testing.T) { commFilterEnable: false, }, enterEvs: make(map[uint32]*event.Pair), - files: make(map[int32]file.File), - comms: make(map[uint32]string), + fdTracker: newFDTracker(make(map[int32]file.File)), + commResolver: newCommResolver(make(map[uint32]string)), prevPairTimes: make(map[uint32]uint64), printCb: func(ep *event.Pair) { outCh <- ep }, done: make(chan struct{}), @@ -478,8 +478,8 @@ func TestCommFilterToggle(t *testing.T) { commFilterBytes: []byte("test"), }, enterEvs: make(map[uint32]*event.Pair), - files: make(map[int32]file.File), - comms: make(map[uint32]string), + fdTracker: newFDTracker(make(map[int32]file.File)), + commResolver: newCommResolver(make(map[uint32]string)), prevPairTimes: make(map[uint32]uint64), printCb: func(ep *event.Pair) { outCh <- ep }, done: make(chan struct{}), @@ -514,8 +514,8 @@ func newEventLoopWithFilter(commFilter, pathFilter string) *eventLoop { pathFilterBytes: []byte(pathFilter), }, enterEvs: make(map[uint32]*event.Pair), - files: make(map[int32]file.File), - comms: make(map[uint32]string), + fdTracker: newFDTracker(make(map[int32]file.File)), + commResolver: newCommResolver(make(map[uint32]string)), prevPairTimes: make(map[uint32]uint64), printCb: func(ep *event.Pair) { fmt.Println(ep); ep.Recycle() }, done: make(chan struct{}), diff --git a/internal/eventloop_seed_test.go b/internal/eventloop_seed_test.go index 3447da2..427869e 100644 --- a/internal/eventloop_seed_test.go +++ b/internal/eventloop_seed_test.go @@ -16,7 +16,7 @@ func TestSeedTrackedPidCommCachesTrackedPidComm(t *testing.T) { cfg: eventLoopConfig{ pidFilter: int(pid), }, - comms: make(map[uint32]string), + commResolver: newCommResolver(make(map[uint32]string)), } el.seedTrackedPidComm() @@ -35,7 +35,7 @@ func TestSeedTrackedPidCommSeedsCurrentProcessWhenPidFilterDisabled(t *testing.T cfg: eventLoopConfig{ pidFilter: -1, }, - comms: make(map[uint32]string), + commResolver: newCommResolver(make(map[uint32]string)), } el.seedTrackedPidComm() diff --git a/internal/eventloop_test.go b/internal/eventloop_test.go index d1bcc16..cfc18e8 100644 --- a/internal/eventloop_test.go +++ b/internal/eventloop_test.go @@ -774,7 +774,7 @@ func makePidfdGetfdEventTestData(t *testing.T) (td testData) { if got, want := ep.File.Name(), path; got != want { t.Errorf("Expected transferred file '%v' but got '%v'", want, got) } - if _, ok := el.files[int32(fd)]; !ok { + if _, ok := el.fdState().files[int32(fd)]; !ok { t.Errorf("Expected transferred fd %d to be tracked", fd) } }) @@ -796,7 +796,7 @@ func makePidfdGetfdFailureTestData(t *testing.T) (td testData) { if !exitEv.Equals(ep.ExitEv) { t.Errorf("Expected '%v' but got '%v'", exitEv, ep.ExitEv) } - if _, ok := el.files[9999]; ok { + if _, ok := el.fdState().files[9999]; ok { t.Errorf("Expected no tracked fd for failed pidfd_getfd") } }) @@ -1382,7 +1382,7 @@ func makeIoUringSetupEventTestData(t *testing.T) (td testData) { if ep.File == nil { t.Errorf("Expected io_uring fd to be tracked") } - if _, ok := el.files[48]; !ok { + if _, ok := el.fdState().files[48]; !ok { t.Errorf("Expected io_uring fd 48 to be tracked") } }) @@ -1408,7 +1408,7 @@ func makeIoUringSetupFailureTestData(t *testing.T) (td testData) { if ep.File != nil { t.Errorf("Expected io_uring_setup failure to have no file tracked") } - if len(el.files) != 0 { + if len(el.fdState().files) != 0 { t.Errorf("Expected no fds to be tracked after io_uring_setup failure") } }) @@ -1434,7 +1434,7 @@ func makeIoUringEnterEventTestData(t *testing.T) (td testData) { if ep.File == nil { t.Errorf("Expected io_uring_enter to have a file") } - if _, ok := el.files[fd]; ok { + if _, ok := el.fdState().files[fd]; ok { t.Errorf("Expected io_uring_enter to not track fd %d", fd) } }) @@ -1460,7 +1460,7 @@ func makeIoUringRegisterEventTestData(t *testing.T) (td testData) { if ep.File == nil { t.Errorf("Expected io_uring_register to have a file") } - if _, ok := el.files[fd]; ok { + if _, ok := el.fdState().files[fd]; ok { t.Errorf("Expected io_uring_register to not track fd %d", fd) } }) @@ -1526,7 +1526,7 @@ func makeDup3WithCloexecTestData(t *testing.T) (td testData) { verifyFileDescriptor(t, el, newFd, filename) // Verify the new fd has O_CLOEXEC flag - if newFile, ok := el.files[newFd]; ok { + if newFile, ok := el.fdState().files[newFd]; ok { fdFile, ok := newFile.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -1611,7 +1611,7 @@ func makeDup2TestData(t *testing.T) (td testData) { verifyFileDescriptor(t, el, targetFd, filename) // Verify the new fd does NOT have O_CLOEXEC flag (unlike dup3) - if newFile, ok := el.files[targetFd]; ok { + if newFile, ok := el.fdState().files[targetFd]; ok { fdFile, ok := newFile.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -1662,7 +1662,7 @@ func makeDup2TestData(t *testing.T) (td testData) { // Helper functions for FD lifecycle tests func verifyFileDescriptor(t *testing.T, el *eventLoop, fd int32, expectedFileName string) { - if file, ok := el.files[fd]; ok { + if file, ok := el.fdState().files[fd]; ok { if file.Name() != expectedFileName { t.Errorf("Expected fd %d to map to file '%s' but got '%s'", fd, expectedFileName, file.Name()) } @@ -1672,7 +1672,7 @@ func verifyFileDescriptor(t *testing.T, el *eventLoop, fd int32, expectedFileNam } func verifyFdNotTracked(t *testing.T, el *eventLoop, fd int32) { - if _, ok := el.files[fd]; ok { + if _, ok := el.fdState().files[fd]; ok { t.Errorf("Expected fd %d to not be tracked but it was found", fd) } } @@ -1718,7 +1718,7 @@ func verifyMismatchCount(t *testing.T, el *eventLoop, expectedCount uint) { } func verifyCommName(t *testing.T, el *eventLoop, tid uint32, expectedComm string) { - if comm, ok := el.comms[tid]; !ok { + if comm, ok := el.commState().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) @@ -1764,7 +1764,7 @@ func makeFcntlSetFlagsTestData(t *testing.T) (td testData) { } // Verify flags were updated on the file descriptor - if f, ok := el.files[int32(fd)]; ok { + if f, ok := el.fdState().files[int32(fd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -1800,7 +1800,7 @@ func makeFcntlSetFlagsTestData(t *testing.T) (td testData) { } // Verify flags were updated correctly - if f, ok := el.files[int32(fd)]; ok { + if f, ok := el.fdState().files[int32(fd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -1878,7 +1878,7 @@ func makeFcntlDupfdTestData(t *testing.T) (td testData) { verifyFileDescriptor(t, el, int32(newFd), filename) // Verify the new fd does NOT have O_CLOEXEC flag (F_DUPFD doesn't set it) - if f, ok := el.files[int32(newFd)]; ok { + if f, ok := el.fdState().files[int32(newFd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -1962,7 +1962,7 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { td.validates = append(td.validates, func(t *testing.T, el *eventLoop, ep *event.Pair) { verifyFileDescriptor(t, el, int32(origFd), filename) // Verify original fd doesn't have O_CLOEXEC - if f, ok := el.files[int32(origFd)]; ok { + if f, ok := el.fdState().files[int32(origFd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -1993,7 +1993,7 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { verifyFileDescriptor(t, el, int32(newFd), filename) // Verify the new fd has O_CLOEXEC flag - if f, ok := el.files[int32(newFd)]; ok { + if f, ok := el.fdState().files[int32(newFd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -2003,7 +2003,7 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { } // Verify original fd still doesn't have O_CLOEXEC - if f, ok := el.files[int32(origFd)]; ok { + if f, ok := el.fdState().files[int32(origFd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -2122,7 +2122,7 @@ func makeFcntlErrorTestData(t *testing.T) (td testData) { } // Verify flags were NOT updated due to error - if f, ok := el.files[int32(fd)]; ok { + if f, ok := el.fdState().files[int32(fd)]; ok { fdFile, ok := f.(file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") @@ -2149,8 +2149,8 @@ func makeFcntlErrorTestData(t *testing.T) (td testData) { } // Only original fd should be tracked - if len(el.files) != 1 { - t.Errorf("Expected only 1 fd to be tracked, got %d", len(el.files)) + if len(el.fdState().files) != 1 { + t.Errorf("Expected only 1 fd to be tracked, got %d", len(el.fdState().files)) } verifyFileDescriptor(t, el, int32(fd), filename) }) |
