Skip to content

Commit

Permalink
Fix test and formating
Browse files Browse the repository at this point in the history
  • Loading branch information
anfedotoff committed Mar 3, 2024
1 parent 3f91653 commit e06107e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions bpf/lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/procsyms/procsyms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
44 changes: 22 additions & 22 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down

0 comments on commit e06107e

Please sign in to comment.