summaryrefslogtreecommitdiff
path: root/internal/eventloop_memory_test.go
blob: 4ac95809e65650cff0ac3fbb412fb77b67f84715 (plain)
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
package internal

import (
	"testing"

	"ior/internal/event"
	"ior/internal/globalfilter"
	"ior/internal/types"
)

func TestHandleMemExitAppliesPairFilter(t *testing.T) {
	el := mustNewEventLoop(t, eventLoopConfig{
		filter: globalfilter.Filter{
			Syscall: &globalfilter.StringFilter{Pattern: "openat"},
		},
	})

	enter := &types.MemEvent{
		EventType: types.ENTER_MEM_EVENT,
		TraceId:   types.SYS_ENTER_MUNMAP,
		Time:      100,
		Pid:       91,
		Tid:       92,
		Length:    4096,
	}
	exit := &types.RetEvent{
		EventType: types.EXIT_RET_EVENT,
		TraceId:   types.SYS_EXIT_MUNMAP,
		Time:      200,
		Pid:       91,
		Tid:       92,
		Ret:       0,
	}
	ep := &event.Pair{EnterEv: enter, ExitEv: exit}

	if ok := el.handleMemExit(ep, enter); ok {
		t.Fatal("handleMemExit should reject pair due to filter mismatch")
	}
}

func TestInitRawHandlersRegistersMemoryEvents(t *testing.T) {
	el := mustNewEventLoop(t, eventLoopConfig{})
	if _, ok := el.rawHandlers[types.ENTER_MEM_EVENT]; !ok {
		t.Fatal("ENTER_MEM_EVENT handler is not registered")
	}
}