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
39 local start_file_sync
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
43 .
/"$TEST_APP" "$start_file_sync" "$@" &
47 start_lttng_tracing_ok
49 # Create start file to launch the execution of the syscall call by the
51 touch "$start_file_sync"
57 # Clean up the synchronization file.
58 rm -f "$start_file_sync"
61 function test_user_callstack
()
63 TRACE_PATH
=$
(mktemp
--tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
64 # This is the expected userspace callstack. (see gen-syscall-events-callstack.c)
65 USER_CS_EXPECTED
="main fct_a fct_b fct_c my_gettid"
68 diag
"Userspace callstack test"
69 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
70 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
72 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
73 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-user"
75 run_workload
$TEST_APP_USERSPACE
77 destroy_lttng_session_ok
"$SESSION_NAME"
79 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED
80 ok $?
"Validate userspace callstack"
85 function test_kernel_callstack
()
87 TRACE_PATH
=$
(mktemp
--tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
88 # Those are symbol expected to be present in the kernel callstack. This
89 # is not an exhaustive list since it's kernel dependent.
91 # FIXME: we used to test for the following symbols as well:
92 # save_stack_trace, lttng_callstack_get_size, but they were removed
94 # 1. kernel commit 77072f09 make it so that save_stack_trace is
95 # omitted from the callstack itself, and
97 # 2. the code (of this commit) can trigger Tail Call Optimization
98 # which mess up with the stacktrace by omiting the wrong address
99 # from the stacktrace.
100 # When this is fixed, we should add both save_stack_trace and
101 # lttng_callstack_get_size symbols back in the list of expected
103 KERNEL_CS_EXPECTED
="lttng_event_reserve"
106 diag
"Kernel callstack test"
107 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
108 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
110 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
111 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel"
113 run_workload
"$TEST_APP_KERNELSPACE" "/proc/cpuinfo" "/proc/cmdline"
115 destroy_lttng_session_ok
"$SESSION_NAME"
117 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED
118 ok $?
"Validate kernel callstack"
123 # Only run userspace callstack test on x86
124 uname
-m |
grep -E "x86" >/dev
/null
2>&1
125 if test $?
== 0; then
126 NUM_TESTS
=$
((NUM_TESTS
+11))
132 # MUST set TESTDIR before calling those functions
133 plan_tests
$NUM_TESTS
135 print_test_banner
"$TEST_DESC"
137 if [ "$(id -u)" == "0" ]; then
143 skip
$isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" ||
145 validate_lttng_modules_present
148 if test $RUN_USERSPACE_TEST == 1; then
152 test_kernel_callstack