summaryrefslogtreecommitdiff
path: root/internal/eventloop_process_test.go
blob: 9a067802be3453a9cff14122f24db33f2a07d47c (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
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
package internal

import (
	"testing"

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

func TestHandleExecExitSetsPathAndComm(t *testing.T) {
	el := mustNewEventLoop(t, eventLoopConfig{})
	enter := &types.ExecEvent{
		EventType: types.ENTER_EXEC_EVENT,
		TraceId:   types.SYS_ENTER_EXECVEAT,
		Time:      100,
		Pid:       200,
		Tid:       201,
		Dirfd:     -100,
		Flags:     0,
	}
	copy(enter.Filename[:], "/definitely-missing-execveat")
	copy(enter.Comm[:], "ioworkload")
	exit := &types.RetEvent{
		EventType: types.EXIT_RET_EVENT,
		TraceId:   types.SYS_EXIT_EXECVEAT,
		Time:      200,
		Ret:       -2,
		Pid:       200,
		Tid:       201,
	}
	ep := &event.Pair{EnterEv: enter, ExitEv: exit}

	if ok := el.handleExecExit(ep, enter); !ok {
		t.Fatal("handleExecExit returned false")
	}
	if got := ep.File.Name(); got != "/definitely-missing-execveat" {
		t.Fatalf("exec path = %q, want %q", got, "/definitely-missing-execveat")
	}
	if got := ep.Comm; got != "ioworkload" {
		t.Fatalf("comm = %q, want %q", got, "ioworkload")
	}
}

func TestHandleExecExitAppliesPairFilter(t *testing.T) {
	el := mustNewEventLoop(t, eventLoopConfig{
		filter: globalfilter.Filter{
			Syscall: &globalfilter.StringFilter{Pattern: "openat"},
		},
	})
	enter := &types.ExecEvent{
		EventType: types.ENTER_EXEC_EVENT,
		TraceId:   types.SYS_ENTER_EXECVE,
		Time:      100,
		Pid:       210,
		Tid:       211,
	}
	copy(enter.Filename[:], "/definitely-missing-execve")
	copy(enter.Comm[:], "ioworkload")
	exit := &types.RetEvent{
		EventType: types.EXIT_RET_EVENT,
		TraceId:   types.SYS_EXIT_EXECVE,
		Time:      200,
		Ret:       -2,
		Pid:       210,
		Tid:       211,
	}
	ep := &event.Pair{EnterEv: enter, ExitEv: exit}

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

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