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
()
37 start_file_sync
=$
(mktemp
-u)
41 .
/"$TEST_APP" "$start_file_sync" &
45 start_lttng_tracing_ok
47 # Create start file to launch the execution of the syscall call by the
49 touch "$start_file_sync"
55 # Clean up the synchronization file.
56 rm -f "$start_file_sync"
59 function test_user_callstack
()
61 TRACE_PATH
=$
(mktemp
-d)
62 # This is the expected userspace callstack. (see gen-syscall-events-callstack.c)
63 USER_CS_EXPECTED
="main fct_a fct_b fct_c my_gettid"
66 diag
"Userspace callstack test"
67 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
68 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
70 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
71 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-user"
73 run_workload
$TEST_APP_USERSPACE
75 destroy_lttng_session_ok
"$SESSION_NAME"
77 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED
78 ok $?
"Validate userspace callstack"
83 function test_kernel_callstack
()
85 TRACE_PATH
=$
(mktemp
-d)
86 # Those are symbol expected to be present in the kernel callstack. This
87 # is not an exhaustive list since it's kernel dependent.
89 # FIXME: we used to test for the following symbols as well:
90 # save_stack_trace, lttng_callstack_get_size, but they were removed
92 # 1. kernel commit 77072f09 make it so that save_stack_trace is
93 # omitted from the callstack itself, and
95 # 2. the code (of this commit) can trigger Tail Call Optimization
96 # which mess up with the stacktrace by omiting the wrong address
97 # from the stacktrace.
98 # When this is fixed, we should add both save_stack_trace and
99 # lttng_callstack_get_size symbols back in the list of expected
101 KERNEL_CS_EXPECTED
="lttng_event_reserve"
104 diag
"Kernel callstack test"
105 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
106 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
108 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
109 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel"
111 run_workload
$TEST_APP_KERNELSPACE
113 destroy_lttng_session_ok
"$SESSION_NAME"
115 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED
116 ok $?
"Validate kernel callstack"
121 # Only run userspace callstack test on x86
122 uname
-m |
grep -E "x86" >/dev
/null
2>&1
123 if test $?
== 0; then
124 NUM_TESTS
=$
((NUM_TESTS
+11))
130 # MUST set TESTDIR before calling those functions
131 plan_tests
$NUM_TESTS
133 print_test_banner
"$TEST_DESC"
135 if [ "$(id -u)" == "0" ]; then
141 skip
$isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" ||
143 which "$BABELTRACE_BIN" > /dev
/null
145 skip $?
"Babeltrace binary not found. Skipping callstack tests" "$NUM_TESTS" ||
149 if test $RUN_USERSPACE_TEST == 1; then
153 test_kernel_callstack