From e06107eb7a553ed77fd64691eabfe212df4a9b04 Mon Sep 17 00:00:00 2001 From: Andrei Fedotov Date: Sun, 3 Mar 2024 21:17:28 +0300 Subject: [PATCH] Fix test and formating --- bpf/lib/common.h | 4 +-- pkg/procsyms/procsyms.go | 1 + pkg/sensors/tracing/kprobe_test.go | 44 +++++++++++++++--------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/bpf/lib/common.h b/bpf/lib/common.h index 8833f083e1f..acd23496346 100644 --- a/bpf/lib/common.h +++ b/bpf/lib/common.h @@ -4,9 +4,9 @@ #define _MSG_COMMON__ /* msg_common internal flags */ -#define MSG_COMMON_FLAG_RETURN BIT(0) +#define MSG_COMMON_FLAG_RETURN BIT(0) #define MSG_COMMON_FLAG_KERNEL_STACKTRACE BIT(1) -#define MSG_COMMON_FLAG_USER_STACKTRACE BIT(2) +#define MSG_COMMON_FLAG_USER_STACKTRACE BIT(2) /* Msg Layout */ struct msg_common { diff --git a/pkg/procsyms/procsyms.go b/pkg/procsyms/procsyms.go index 25d22d7cd1c..7113d1d5ec8 100644 --- a/pkg/procsyms/procsyms.go +++ b/pkg/procsyms/procsyms.go @@ -97,6 +97,7 @@ func GetFnSymbol(pid int, addr uint64) (*FnSym, error) { } if binary, err := elf.Open(entry.Pathname); err == nil { + defer binary.Close() syms, _ := binary.Symbols() if dsyms, err := binary.DynamicSymbols(); err == nil { syms = append(syms, dsyms...) diff --git a/pkg/sensors/tracing/kprobe_test.go b/pkg/sensors/tracing/kprobe_test.go index 45da90280de..4c438a9671f 100644 --- a/pkg/sensors/tracing/kprobe_test.go +++ b/pkg/sensors/tracing/kprobe_test.go @@ -6121,10 +6121,21 @@ spec: WithProcess(ec.NewProcessChecker().WithBinary(sm.Full(unameBin))). WithKernelStackTrace(ec.NewStackTraceEntryListMatcher().WithValues( ec.NewStackTraceEntryChecker().WithSymbol(sm.Suffix(("sys_newuname"))), - //syscall openat /tmp/ust_test - //User space: - // 0x0: __open64 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x11453b) - //exit /tmp/ust_test 0 + // we could technically check for more but stack traces look + // different on different archs, at least we check that the stack + // trace is enabled, works and exports something coherent + // + // syscall /usr/bin/uname __x64_sys_newuname + // 0x0: __x64_sys_newuname+0x5 + // 0x0: entry_SYSCALL_64_after_hwframe+0x72 + // + // syscall /usr/bin/uname __arm64_sys_newuname + // 0x0: __do_sys_newuname+0x2f0 + // 0x0: el0_svc_common.constprop.0+0x180 + // 0x0: do_el0_svc+0x30 + // 0x0: el0_svc+0x48 + // 0x0: el0t_64_sync_handler+0xa4 + // 0x0: el0t_64_sync+0x1a4 )) checker := ec.NewUnorderedEventChecker(stackTraceChecker) @@ -6161,10 +6172,10 @@ void main(void) { sleep(5); }` if err := os.WriteFile("/tmp/ust_test.c", []byte(testSrc), 0644); err != nil { - + t.Fatalf("failed write test src: %s", err) } testBin := "/tmp/ust_test" - if err := exec.Command("clang", "/tmp/ust_test.c", "-o", testBin).Run(); err != nil { + if err := exec.Command("gcc", "/tmp/ust_test.c", "-o", testBin).Run(); err != nil { t.Fatalf("failed to compile /tmp/ust_test: %s", err) } @@ -6181,25 +6192,14 @@ void main(void) { t.Fatalf("failed to run %s: %s", testBin, err) } - stackTraceChecker := ec.NewProcessKprobeChecker("stack-trace"). + stackTraceChecker := ec.NewProcessKprobeChecker("user-stack-trace"). WithProcess(ec.NewProcessChecker().WithBinary(sm.Full(testBin))). WithUserStackTrace(ec.NewStackTraceEntryListMatcher().WithValues( ec.NewStackTraceEntryChecker().WithSymbol(sm.Suffix(("__open64"))), - // we could technically check for more but stack traces look - // different on different archs, at least we check that the stack - // trace is enabled, works and exports something coherent - // - // syscall /usr/bin/uname __x64_sys_newuname - // 0x0: __x64_sys_newuname+0x5 - // 0x0: entry_SYSCALL_64_after_hwframe+0x72 - // - // syscall /usr/bin/uname __arm64_sys_newuname - // 0x0: __do_sys_newuname+0x2f0 - // 0x0: el0_svc_common.constprop.0+0x180 - // 0x0: do_el0_svc+0x30 - // 0x0: el0_svc+0x48 - // 0x0: el0t_64_sync_handler+0xa4 - // 0x0: el0t_64_sync+0x1a4 + // syscall openat /tmp/ust_test + // User space: + // 0x0: __open64 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x11453b) + // exit /tmp/ust_test 0 )) checker := ec.NewUnorderedEventChecker(stackTraceChecker)