diff options
Diffstat (limited to 'internal/eventloop_test.go')
| -rw-r--r-- | internal/eventloop_test.go | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/internal/eventloop_test.go b/internal/eventloop_test.go index 4ae8597..7fcd438 100644 --- a/internal/eventloop_test.go +++ b/internal/eventloop_test.go @@ -96,7 +96,7 @@ func TestEventloop(t *testing.T) { inCh := make(chan []byte) outCh := make(chan *event.Pair) - el := newEventLoop(eventLoopConfig{}) + el := mustNewEventLoop(t, eventLoopConfig{}) el.printCb = func(ev *event.Pair) { outCh <- ev } go el.run(ctx, inCh) @@ -142,7 +142,7 @@ func TestEventloop(t *testing.T) { } func TestHandleFdExitCloseClearsProcFdCache(t *testing.T) { - el := newEventLoop(eventLoopConfig{}) + el := mustNewEventLoop(t, eventLoopConfig{}) pid := uint32(1001) fd := int32(55) @@ -170,7 +170,7 @@ func TestHandleFdExitCloseClearsProcFdCache(t *testing.T) { } func TestHandleFdExitCloseRangeClearsProcFdCacheRange(t *testing.T) { - el := newEventLoop(eventLoopConfig{}) + el := mustNewEventLoop(t, eventLoopConfig{}) pid := uint32(2002) el.setProcFdCache(10, pid, file.NewFd(10, "keep", syscall.O_RDONLY)) @@ -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,8 +1526,8 @@ 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 { - fdFile, ok := newFile.(file.FdFile) + if newFile, ok := el.fdState().files[newFd]; ok { + fdFile, ok := newFile.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if !fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1611,8 +1611,8 @@ 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 { - fdFile, ok := newFile.(file.FdFile) + if newFile, ok := el.fdState().files[targetFd]; ok { + fdFile, ok := newFile.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -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,8 +1764,8 @@ func makeFcntlSetFlagsTestData(t *testing.T) (td testData) { } // Verify flags were updated on the file descriptor - if f, ok := el.files[int32(fd)]; ok { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(fd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else { @@ -1800,8 +1800,8 @@ func makeFcntlSetFlagsTestData(t *testing.T) (td testData) { } // Verify flags were updated correctly - if f, ok := el.files[int32(fd)]; ok { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(fd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else { @@ -1878,8 +1878,8 @@ 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 { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(newFd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1962,8 +1962,8 @@ 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 { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(origFd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1993,8 +1993,8 @@ 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 { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(newFd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if !fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -2003,8 +2003,8 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { } // Verify original fd still doesn't have O_CLOEXEC - if f, ok := el.files[int32(origFd)]; ok { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(origFd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -2122,8 +2122,8 @@ func makeFcntlErrorTestData(t *testing.T) (td testData) { } // Verify flags were NOT updated due to error - if f, ok := el.files[int32(fd)]; ok { - fdFile, ok := f.(file.FdFile) + if f, ok := el.fdState().files[int32(fd)]; ok { + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_NONBLOCK) { @@ -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) }) @@ -2193,7 +2193,7 @@ func makeFcntlInvalidFdTestData(t *testing.T) (td testData) { if ep.File == nil { t.Errorf("Expected file to be created for invalid fd") } else { - _, ok := ep.File.(file.FdFile) + _, ok := ep.File.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } |
