3 # Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
8 TEST_DESC
="Kernel tracer - Callstack context"
10 CURDIR
=$
(dirname "$0")/
13 TEST_APP_USERSPACE
="$TESTDIR/utils/testapp/gen-syscall-events-callstack/gen-syscall-events-callstack"
14 TEST_APP_KERNELSPACE
="$TESTDIR/utils/testapp/gen-syscall-events/gen-syscall-events"
15 PARSE_CALLSTACK
="$TESTDIR/utils/parse-callstack.py"
17 SESSION_NAME
="callstack"
20 source "$TESTDIR/utils/utils.sh"
22 function lttng_untrack_all
()
24 lttng_untrack
0 "-s $SESSION_NAME --all --pid -k"
27 function lttng_track_pid
()
30 lttng_track
0 "-s $SESSION_NAME -k --pid=$PID"
33 function run_workload
()
36 # shift the first argument, passing along the other args if any to the
40 start_file_sync
=$
(mktemp
-u)
44 .
/"$TEST_APP" "$start_file_sync" "$@" &
48 start_lttng_tracing_ok
50 # Create start file to launch the execution of the syscall call by the
52 touch "$start_file_sync"
58 # Clean up the synchronization file.
59 rm -f "$start_file_sync"
62 function test_user_callstack
()
64 TRACE_PATH
=$
(mktemp
-d)
65 # This is the expected userspace callstack. (see gen-syscall-events-callstack.c)
66 USER_CS_EXPECTED
="main fct_a fct_b fct_c my_gettid"
69 diag
"Userspace callstack test"
70 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
71 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
73 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
74 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-user"
76 run_workload
$TEST_APP_USERSPACE
78 destroy_lttng_session_ok
"$SESSION_NAME"
80 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED
81 ok $?
"Validate userspace callstack"
86 function test_kernel_callstack
()
88 TRACE_PATH
=$
(mktemp
-d)
89 # Those are symbol expected to be present in the kernel callstack. This
90 # is not an exhaustive list since it's kernel dependent.
92 # FIXME: we used to test for the following symbols as well:
93 # save_stack_trace, lttng_callstack_get_size, but they were removed
95 # 1. kernel commit 77072f09 make it so that save_stack_trace is
96 # omitted from the callstack itself, and
98 # 2. the code (of this commit) can trigger Tail Call Optimization
99 # which mess up with the stacktrace by omiting the wrong address
100 # from the stacktrace.
101 # When this is fixed, we should add both save_stack_trace and
102 # lttng_callstack_get_size symbols back in the list of expected
104 KERNEL_CS_EXPECTED
="lttng_event_reserve"
107 diag
"Kernel callstack test"
108 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
109 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
111 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
112 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel"
114 run_workload
"$TEST_APP_KERNELSPACE" "/proc/cpuinfo" "/proc/cmdline"
116 destroy_lttng_session_ok
"$SESSION_NAME"
118 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED
119 ok $?
"Validate kernel callstack"
124 # Only run userspace callstack test on x86
125 uname
-m |
grep -E "x86" >/dev
/null
2>&1
126 if test $?
== 0; then
127 NUM_TESTS
=$
((NUM_TESTS
+11))
133 # MUST set TESTDIR before calling those functions
134 plan_tests
$NUM_TESTS
136 print_test_banner
"$TEST_DESC"
138 if [ "$(id -u)" == "0" ]; then
144 skip
$isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" ||
146 which "$BABELTRACE_BIN" > /dev
/null
148 skip $?
"Babeltrace binary not found. Skipping callstack tests" "$NUM_TESTS" ||
152 if test $RUN_USERSPACE_TEST == 1; then
156 test_kernel_callstack