-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathutils_test.go
47 lines (40 loc) · 1.47 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package manager
import (
"strings"
"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)
}
}
func TestGetSyscallFnNameWithSymFile(t *testing.T) {
expectedFnName := "sys_exit"
fnName, err := GetSyscallFnNameWithSymFile(expectedFnName, "")
if err != nil {
t.Error(err)
}
if !strings.HasSuffix(fnName, expectedFnName) {
t.Errorf("Expected function name %s, but got %s", expectedFnName, fnName)
}
t.Logf("Expected function name %s, got %s", expectedFnName, fnName)
}