forked from DataDog/ebpf-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
33 lines (28 loc) · 1.09 KB
/
utils_test.go
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
package manager
import (
"testing"
)
func TestGenerateEventName(t *testing.T) {
probeType := "p"
funcName := "func"
UID := "UID"
kprobeAttachPID := 1234
eventName, err := GenerateEventName(probeType, funcName, UID, kprobeAttachPID)
if err != nil {
t.Error(err)
}
if len(eventName) > MaxEventNameLen {
t.Errorf("Event name too long, kernel limit is %d : MaxEventNameLen", MaxEventNameLen)
}
// should be truncated
funcName = "01234567890123456790123456789012345678901234567890123456789"
eventName, err = GenerateEventName(probeType, funcName, UID, kprobeAttachPID)
if (err != nil) || (len(eventName) != MaxEventNameLen) || (eventName != "p_01234567890123456790123456789012345678901234567890123_UID_1234") {
t.Errorf("Should not failed and truncate the function name (len %d)", len(eventName))
}
UID = "12345678901234567890123456789012345678901234567890"
_, err = GenerateEventName(probeType, funcName, UID, kprobeAttachPID)
if err == nil {
t.Errorf("Test should failed as event name length is too big for the kernel and free space for function Name is < %d", MinFunctionNameLen)
}
}