Commit | Line | Data |
---|---|---|
591ee332 FD |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com> |
591ee332 | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
591ee332 | 6 | # |
591ee332 FD |
7 | |
8 | TEST_DESC="Kernel tracer - Callstack context" | |
9 | ||
10 | CURDIR=$(dirname "$0")/ | |
11 | TESTDIR=$CURDIR/../.. | |
12 | NUM_TESTS=11 | |
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" | |
16 | ||
17 | SESSION_NAME="callstack" | |
18 | CHANNEL_NAME="chan0" | |
19 | ||
20 | source "$TESTDIR/utils/utils.sh" | |
21 | ||
22 | function lttng_untrack_all() | |
23 | { | |
24 | lttng_untrack 0 "-s $SESSION_NAME --all --pid -k" | |
25 | } | |
26 | ||
27 | function lttng_track_pid() | |
28 | { | |
29 | local PID=$1 | |
30 | lttng_track 0 "-s $SESSION_NAME -k --pid=$PID" | |
31 | } | |
32 | ||
33 | function run_workload() | |
34 | { | |
35 | local TEST_APP=$1 | |
ca342eaf JR |
36 | # shift the first argument, passing along the other args if any to the |
37 | # test app. | |
38 | shift | |
591ee332 FD |
39 | local start_file_sync |
40 | start_file_sync=$(mktemp -u) | |
41 | ||
42 | lttng_untrack_all | |
43 | ||
ca342eaf | 44 | ./"$TEST_APP" "$start_file_sync" "$@" & |
591ee332 FD |
45 | PID=$! |
46 | lttng_track_pid $PID | |
47 | ||
48 | start_lttng_tracing_ok | |
49 | ||
50 | # Create start file to launch the execution of the syscall call by the | |
51 | # test app. | |
52 | touch "$start_file_sync" | |
53 | ||
54 | wait $PID | |
55 | ||
56 | stop_lttng_tracing_ok | |
57 | ||
58 | # Clean up the synchronization file. | |
59 | rm -f "$start_file_sync" | |
60 | } | |
61 | ||
62 | function test_user_callstack() | |
63 | { | |
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" | |
67 | EVENT_NAME="gettid" | |
68 | ||
69 | diag "Userspace callstack test" | |
70 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" | |
71 | lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME" | |
72 | ||
73 | lttng_enable_kernel_syscall_ok "$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME" | |
74 | add_context_kernel_ok "$SESSION_NAME" "$CHANNEL_NAME" "callstack-user" | |
75 | ||
76 | run_workload $TEST_APP_USERSPACE | |
77 | ||
78 | destroy_lttng_session_ok "$SESSION_NAME" | |
79 | ||
80 | "$BABELTRACE_BIN" "$TRACE_PATH" | grep $EVENT_NAME | ./"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED | |
81 | ok $? "Validate userspace callstack" | |
82 | ||
83 | rm -rf "$TRACE_PATH" | |
84 | } | |
85 | ||
86 | function test_kernel_callstack() | |
87 | { | |
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. | |
91 | ||
92 | # FIXME: we used to test for the following symbols as well: | |
93 | # save_stack_trace, lttng_callstack_get_size, but they were removed | |
94 | # because: | |
95 | # 1. kernel commit 77072f09 make it so that save_stack_trace is | |
96 | # omitted from the callstack itself, and | |
97 | # | |
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 | |
103 | # addresses. | |
104 | KERNEL_CS_EXPECTED="lttng_event_reserve" | |
105 | EVENT_NAME="read" | |
106 | ||
107 | diag "Kernel callstack test" | |
108 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" | |
109 | lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME" | |
110 | ||
111 | lttng_enable_kernel_syscall_ok "$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME" | |
112 | add_context_kernel_ok "$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel" | |
113 | ||
ca342eaf | 114 | run_workload "$TEST_APP_KERNELSPACE" "/proc/cpuinfo" "/proc/cmdline" |
591ee332 FD |
115 | |
116 | destroy_lttng_session_ok "$SESSION_NAME" | |
117 | ||
118 | "$BABELTRACE_BIN" "$TRACE_PATH" | grep $EVENT_NAME | ./"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED | |
119 | ok $? "Validate kernel callstack" | |
120 | ||
121 | rm -rf "$TRACE_PATH" | |
122 | } | |
123 | ||
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)) | |
128 | RUN_USERSPACE_TEST=1 | |
129 | else | |
130 | RUN_USERSPACE_TEST=0 | |
131 | fi | |
132 | ||
133 | # MUST set TESTDIR before calling those functions | |
134 | plan_tests $NUM_TESTS | |
135 | ||
136 | print_test_banner "$TEST_DESC" | |
137 | ||
138 | if [ "$(id -u)" == "0" ]; then | |
139 | isroot=1 | |
140 | else | |
141 | isroot=0 | |
142 | fi | |
143 | ||
144 | skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" || | |
145 | { | |
146 | which "$BABELTRACE_BIN" > /dev/null | |
147 | test $? -ne 0 | |
148 | skip $? "Babeltrace binary not found. Skipping callstack tests" "$NUM_TESTS" || | |
149 | { | |
150 | start_lttng_sessiond | |
151 | ||
152 | if test $RUN_USERSPACE_TEST == 1; then | |
153 | test_user_callstack | |
154 | fi | |
155 | ||
156 | test_kernel_callstack | |
157 | ||
158 | stop_lttng_sessiond | |
159 | } | |
160 | } |