3 # Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 TEST_DESC
="Kernel tracer - Callstack context"
20 CURDIR
=$
(dirname "$0")/
23 TEST_APP_USERSPACE
="$TESTDIR/utils/testapp/gen-syscall-events-callstack/gen-syscall-events-callstack"
24 TEST_APP_KERNELSPACE
="$TESTDIR/utils/testapp/gen-syscall-events/gen-syscall-events"
25 PARSE_CALLSTACK
="$TESTDIR/utils/parse-callstack.py"
27 SESSION_NAME
="callstack"
30 source "$TESTDIR/utils/utils.sh"
32 function lttng_untrack_all
()
34 lttng_untrack
0 "-s $SESSION_NAME --all --pid -k"
37 function lttng_track_pid
()
40 lttng_track
0 "-s $SESSION_NAME -k --pid=$PID"
43 function run_workload
()
47 start_file_sync
=$
(mktemp
-u)
51 .
/"$TEST_APP" "$start_file_sync" &
55 start_lttng_tracing_ok
57 # Create start file to launch the execution of the syscall call by the
59 touch "$start_file_sync"
65 # Clean up the synchronization file.
66 rm -f "$start_file_sync"
69 function test_user_callstack
()
71 TRACE_PATH
=$
(mktemp
-d)
72 # This is the expected userspace callstack. (see gen-syscall-events-callstack.c)
73 USER_CS_EXPECTED
="main fct_a fct_b fct_c my_gettid"
76 diag
"Userspace callstack test"
77 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
78 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
80 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
81 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-user"
83 run_workload
$TEST_APP_USERSPACE
85 destroy_lttng_session_ok
"$SESSION_NAME"
87 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED
88 ok $?
"Validate userspace callstack"
93 function test_kernel_callstack
()
95 TRACE_PATH
=$
(mktemp
-d)
96 # Those are symbol expected to be present in the kernel callstack. This
97 # is not an exhaustive list since it's kernel dependent.
99 # FIXME: we used to test for the following symbols as well:
100 # save_stack_trace, lttng_callstack_get_size, but they were removed
102 # 1. kernel commit 77072f09 make it so that save_stack_trace is
103 # omitted from the callstack itself, and
105 # 2. the code (of this commit) can trigger Tail Call Optimization
106 # which mess up with the stacktrace by omiting the wrong address
107 # from the stacktrace.
108 # When this is fixed, we should add both save_stack_trace and
109 # lttng_callstack_get_size symbols back in the list of expected
111 KERNEL_CS_EXPECTED
="lttng_event_reserve"
114 diag
"Kernel callstack test"
115 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
116 lttng_enable_kernel_channel_ok
"$SESSION_NAME" "$CHANNEL_NAME"
118 lttng_enable_kernel_syscall_ok
"$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
119 add_context_kernel_ok
"$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel"
121 run_workload
$TEST_APP_KERNELSPACE
123 destroy_lttng_session_ok
"$SESSION_NAME"
125 "$BABELTRACE_BIN" "$TRACE_PATH" |
grep $EVENT_NAME | .
/"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED
126 ok $?
"Validate kernel callstack"
131 # Only run userspace callstack test on x86
132 uname
-m |
grep -E "x86" >/dev
/null
2>&1
133 if test $?
== 0; then
134 NUM_TESTS
=$
((NUM_TESTS
+11))
140 # MUST set TESTDIR before calling those functions
141 plan_tests
$NUM_TESTS
143 print_test_banner
"$TEST_DESC"
145 if [ "$(id -u)" == "0" ]; then
151 skip
$isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" ||
153 which "$BABELTRACE_BIN" > /dev
/null
155 skip $?
"Babeltrace binary not found. Skipping callstack tests" "$NUM_TESTS" ||
159 if test $RUN_USERSPACE_TEST == 1; then
163 test_kernel_callstack