elf: support dynamic symbol table lookup
[lttng-tools.git] / tests / regression / kernel / test_callstack
1 #!/bin/bash
2 #
3 # Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
4 #
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.
8 #
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
12 # more details.
13 #
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.
17
18 TEST_DESC="Kernel tracer - Callstack context"
19
20 CURDIR=$(dirname "$0")/
21 TESTDIR=$CURDIR/../..
22 NUM_TESTS=11
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"
26
27 SESSION_NAME="callstack"
28 CHANNEL_NAME="chan0"
29
30 source "$TESTDIR/utils/utils.sh"
31
32 function lttng_untrack_all()
33 {
34 lttng_untrack 0 "-s $SESSION_NAME --all --pid -k"
35 }
36
37 function lttng_track_pid()
38 {
39 local PID=$1
40 lttng_track 0 "-s $SESSION_NAME -k --pid=$PID"
41 }
42
43 function run_workload()
44 {
45 local TEST_APP=$1
46 local start_file_sync
47 start_file_sync=$(mktemp -u)
48
49 lttng_untrack_all
50
51 ./"$TEST_APP" "$start_file_sync" &
52 PID=$!
53 lttng_track_pid $PID
54
55 start_lttng_tracing_ok
56
57 # Create start file to launch the execution of the syscall call by the
58 # test app.
59 touch "$start_file_sync"
60
61 wait $PID
62
63 stop_lttng_tracing_ok
64
65 # Clean up the synchronization file.
66 rm -f "$start_file_sync"
67 }
68
69 function test_user_callstack()
70 {
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"
74 EVENT_NAME="gettid"
75
76 diag "Userspace callstack test"
77 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
78 lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME"
79
80 lttng_enable_kernel_syscall_ok "$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
81 add_context_kernel_ok "$SESSION_NAME" "$CHANNEL_NAME" "callstack-user"
82
83 run_workload $TEST_APP_USERSPACE
84
85 destroy_lttng_session_ok "$SESSION_NAME"
86
87 "$BABELTRACE_BIN" "$TRACE_PATH" | grep $EVENT_NAME | ./"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED
88 ok $? "Validate userspace callstack"
89
90 rm -rf "$TRACE_PATH"
91 }
92
93 function test_kernel_callstack()
94 {
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.
98
99 # FIXME: we used to test for the following symbols as well:
100 # save_stack_trace, lttng_callstack_get_size, but they were removed
101 # because:
102 # 1. kernel commit 77072f09 make it so that save_stack_trace is
103 # omitted from the callstack itself, and
104 #
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
110 # addresses.
111 KERNEL_CS_EXPECTED="lttng_event_reserve"
112 EVENT_NAME="read"
113
114 diag "Kernel callstack test"
115 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
116 lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME"
117
118 lttng_enable_kernel_syscall_ok "$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME"
119 add_context_kernel_ok "$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel"
120
121 run_workload $TEST_APP_KERNELSPACE
122
123 destroy_lttng_session_ok "$SESSION_NAME"
124
125 "$BABELTRACE_BIN" "$TRACE_PATH" | grep $EVENT_NAME | ./"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED
126 ok $? "Validate kernel callstack"
127
128 rm -rf "$TRACE_PATH"
129 }
130
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))
135 RUN_USERSPACE_TEST=1
136 else
137 RUN_USERSPACE_TEST=0
138 fi
139
140 # MUST set TESTDIR before calling those functions
141 plan_tests $NUM_TESTS
142
143 print_test_banner "$TEST_DESC"
144
145 if [ "$(id -u)" == "0" ]; then
146 isroot=1
147 else
148 isroot=0
149 fi
150
151 skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" ||
152 {
153 which "$BABELTRACE_BIN" > /dev/null
154 test $? -ne 0
155 skip $? "Babeltrace binary not found. Skipping callstack tests" "$NUM_TESTS" ||
156 {
157 start_lttng_sessiond
158
159 if test $RUN_USERSPACE_TEST == 1; then
160 test_user_callstack
161 fi
162
163 test_kernel_callstack
164
165 stop_lttng_sessiond
166 }
167 }
This page took 0.035451 seconds and 5 git commands to generate.