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 | |
8d5a3312 | 39 | local start_file_sync=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX") |
591ee332 FD |
40 | |
41 | lttng_untrack_all | |
42 | ||
ca342eaf | 43 | ./"$TEST_APP" "$start_file_sync" "$@" & |
591ee332 FD |
44 | PID=$! |
45 | lttng_track_pid $PID | |
46 | ||
47 | start_lttng_tracing_ok | |
48 | ||
49 | # Create start file to launch the execution of the syscall call by the | |
50 | # test app. | |
51 | touch "$start_file_sync" | |
52 | ||
53 | wait $PID | |
54 | ||
55 | stop_lttng_tracing_ok | |
56 | ||
57 | # Clean up the synchronization file. | |
58 | rm -f "$start_file_sync" | |
59 | } | |
60 | ||
61 | function test_user_callstack() | |
62 | { | |
8d5a3312 | 63 | TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
591ee332 FD |
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" | |
66 | EVENT_NAME="gettid" | |
67 | ||
68 | diag "Userspace callstack test" | |
69 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" | |
70 | lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME" | |
71 | ||
72 | lttng_enable_kernel_syscall_ok "$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME" | |
73 | add_context_kernel_ok "$SESSION_NAME" "$CHANNEL_NAME" "callstack-user" | |
74 | ||
75 | run_workload $TEST_APP_USERSPACE | |
76 | ||
77 | destroy_lttng_session_ok "$SESSION_NAME" | |
78 | ||
79 | "$BABELTRACE_BIN" "$TRACE_PATH" | grep $EVENT_NAME | ./"$PARSE_CALLSTACK" --user "$TEST_APP_USERSPACE" $USER_CS_EXPECTED | |
80 | ok $? "Validate userspace callstack" | |
81 | ||
82 | rm -rf "$TRACE_PATH" | |
83 | } | |
84 | ||
85 | function test_kernel_callstack() | |
86 | { | |
8d5a3312 | 87 | TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
591ee332 FD |
88 | # Those are symbol expected to be present in the kernel callstack. This |
89 | # is not an exhaustive list since it's kernel dependent. | |
90 | ||
91 | # FIXME: we used to test for the following symbols as well: | |
92 | # save_stack_trace, lttng_callstack_get_size, but they were removed | |
93 | # because: | |
94 | # 1. kernel commit 77072f09 make it so that save_stack_trace is | |
95 | # omitted from the callstack itself, and | |
96 | # | |
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 | |
102 | # addresses. | |
103 | KERNEL_CS_EXPECTED="lttng_event_reserve" | |
104 | EVENT_NAME="read" | |
105 | ||
106 | diag "Kernel callstack test" | |
107 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" | |
108 | lttng_enable_kernel_channel_ok "$SESSION_NAME" "$CHANNEL_NAME" | |
109 | ||
110 | lttng_enable_kernel_syscall_ok "$SESSION_NAME" "$EVENT_NAME" "$CHANNEL_NAME" | |
111 | add_context_kernel_ok "$SESSION_NAME" "$CHANNEL_NAME" "callstack-kernel" | |
112 | ||
ca342eaf | 113 | run_workload "$TEST_APP_KERNELSPACE" "/proc/cpuinfo" "/proc/cmdline" |
591ee332 FD |
114 | |
115 | destroy_lttng_session_ok "$SESSION_NAME" | |
116 | ||
117 | "$BABELTRACE_BIN" "$TRACE_PATH" | grep $EVENT_NAME | ./"$PARSE_CALLSTACK" --kernel $KERNEL_CS_EXPECTED | |
118 | ok $? "Validate kernel callstack" | |
119 | ||
120 | rm -rf "$TRACE_PATH" | |
121 | } | |
122 | ||
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)) | |
127 | RUN_USERSPACE_TEST=1 | |
128 | else | |
129 | RUN_USERSPACE_TEST=0 | |
130 | fi | |
131 | ||
132 | # MUST set TESTDIR before calling those functions | |
133 | plan_tests $NUM_TESTS | |
134 | ||
135 | print_test_banner "$TEST_DESC" | |
136 | ||
c125de8f FD |
137 | bail_out_if_no_babeltrace |
138 | ||
591ee332 FD |
139 | if [ "$(id -u)" == "0" ]; then |
140 | isroot=1 | |
141 | else | |
142 | isroot=0 | |
143 | fi | |
144 | ||
145 | skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" || | |
146 | { | |
0159fa50 | 147 | validate_lttng_modules_present |
c125de8f | 148 | start_lttng_sessiond |
591ee332 | 149 | |
c125de8f FD |
150 | if test $RUN_USERSPACE_TEST == 1; then |
151 | test_user_callstack | |
152 | fi | |
591ee332 | 153 | |
c125de8f | 154 | test_kernel_callstack |
591ee332 | 155 | |
c125de8f | 156 | stop_lttng_sessiond |
591ee332 | 157 | } |