1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
package internal
import (
"testing"
"ior/internal/event"
"ior/internal/file"
"ior/internal/globalfilter"
"ior/internal/types"
)
func TestHandleEpollCtlExitUsesEpollInstanceFd(t *testing.T) {
el := mustNewEventLoop(t, eventLoopConfig{})
el.fdState().set(41, file.NewFd(41, "anon_inode:[eventpoll]", -1))
enter := &types.EpollCtlEvent{
EventType: types.ENTER_EPOLL_CTL_EVENT,
TraceId: types.SYS_ENTER_EPOLL_CTL,
Time: 100,
Pid: 90,
Tid: 91,
Epfd: 41,
Op: 1,
Fd: 42,
Events: 1,
}
exit := &types.RetEvent{
EventType: types.EXIT_RET_EVENT,
TraceId: types.SYS_EXIT_EPOLL_CTL,
Time: 200,
Ret: 0,
Pid: 90,
Tid: 91,
}
ep := &event.Pair{EnterEv: enter, ExitEv: exit}
if ok := el.handleEpollCtlExit(ep, enter); !ok {
t.Fatal("handleEpollCtlExit returned false")
}
if ep.File == nil || ep.File.FD() != 41 {
t.Fatalf("expected resolved epoll instance fd 41, got file=%v", ep.File)
}
}
func TestHandleEpollCtlExitAppliesPairFilter(t *testing.T) {
el := mustNewEventLoop(t, eventLoopConfig{
filter: globalfilter.Filter{
Syscall: &globalfilter.StringFilter{Pattern: "openat"},
},
})
enter := &types.EpollCtlEvent{
EventType: types.ENTER_EPOLL_CTL_EVENT,
TraceId: types.SYS_ENTER_EPOLL_CTL,
Time: 100,
Pid: 92,
Tid: 93,
Epfd: 51,
Op: 1,
Fd: 52,
Events: 1,
}
exit := &types.RetEvent{
EventType: types.EXIT_RET_EVENT,
TraceId: types.SYS_EXIT_EPOLL_CTL,
Time: 200,
Ret: 0,
Pid: 92,
Tid: 93,
}
ep := &event.Pair{EnterEv: enter, ExitEv: exit}
if ok := el.handleEpollCtlExit(ep, enter); ok {
t.Fatal("handleEpollCtlExit should reject pair due to filter mismatch")
}
}
func TestInitRawHandlersRegistersPollingEvents(t *testing.T) {
el := mustNewEventLoop(t, eventLoopConfig{})
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")
}
})
}
|