Commit | Line | Data |
---|---|---|
e7716c6a JD |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com> |
e7716c6a | 4 | # |
9d16b343 MJ |
5 | # SPDX-License-Identifier: LGPL-2.1-only |
6 | ||
e7716c6a JD |
7 | TEST_DESC="Rotation - User space tracing" |
8 | ||
9 | CURDIR=$(dirname $0)/ | |
10 | TESTDIR=$CURDIR/../../.. | |
e7716c6a JD |
11 | NR_USEC_WAIT=0 |
12 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
13 | TESTAPP_NAME="gen-ust-events" | |
14 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
15 | SESSION_NAME="stream" | |
16 | EVENT_NAME="tp:tptest" | |
e7716c6a | 17 | |
8d5a3312 | 18 | TRACE_PATH=$(mktemp -d -t tmp.test_ust_rotation_trace_path.XXXXXX) |
e7716c6a | 19 | |
bf1e8411 | 20 | NUM_TESTS=152 |
e7716c6a JD |
21 | |
22 | source $TESTDIR/utils/utils.sh | |
23 | source $CURDIR/rotate_utils.sh | |
24 | ||
25 | if [ ! -x "$TESTAPP_BIN" ]; then | |
26 | BAIL_OUT "No UST events binary detected." | |
27 | fi | |
28 | ||
3c4c3582 JR |
29 | XPATH_CMD_OUTPUT="//lttng:command/lttng:output" |
30 | XPATH_PID="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type = 'UST']/lttng:pids/lttng:pid/lttng:id" | |
31 | ||
d09115ee | 32 | function enable_channel_per_pid () |
e7716c6a JD |
33 | { |
34 | sess_name=$1 | |
35 | channel_name=$2 | |
36 | ||
da0e4484 | 37 | enable_ust_lttng_channel_ok $sess_name $channel_name --buffers-pid |
e7716c6a JD |
38 | } |
39 | ||
e7716c6a JD |
40 | # MUST set TESTDIR before calling those functions |
41 | ||
42 | function rotate_ust_test () | |
43 | { | |
44 | local_path=$1 | |
45 | app_path=$2 | |
46 | per_pid=$3 | |
47 | ||
48 | start_lttng_tracing_ok $SESSION_NAME | |
49 | today=$(date +%Y%m%d) | |
50 | ||
6c4a91d6 | 51 | $TESTAPP_BIN -i 10 -w $NR_USEC_WAIT > /dev/null 2>&1 |
e7716c6a JD |
52 | rotate_session_ok $SESSION_NAME |
53 | ||
6c4a91d6 | 54 | $TESTAPP_BIN -i 20 -w $NR_USEC_WAIT > /dev/null 2>&1 |
e7716c6a JD |
55 | stop_lttng_tracing_ok $SESSION_NAME |
56 | ||
57 | # Third chunk contains no event (rotate after stop). | |
58 | rotate_session_ok $SESSION_NAME | |
59 | ||
60 | destroy_lttng_session_ok $SESSION_NAME | |
61 | ||
6f7eb8e1 | 62 | validate_test_chunks "${local_path}" $today $app_path ust |
e7716c6a JD |
63 | } |
64 | ||
65 | function test_ust_streaming_uid () | |
66 | { | |
67 | diag "Test UST streaming with session rotation per UID" | |
f0d43d3d | 68 | create_lttng_session_uri $SESSION_NAME net://localhost |
e7716c6a JD |
69 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
70 | ||
3b33e9e7 | 71 | rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" "ust/uid/*/*/" 0 |
e7716c6a JD |
72 | } |
73 | ||
74 | function test_ust_local_uid () | |
75 | { | |
76 | diag "Test UST local with session rotation per UID" | |
77 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
78 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME | |
79 | ||
3b33e9e7 | 80 | rotate_ust_test "${TRACE_PATH}/archives" "ust/uid/*/*/" 0 |
e7716c6a JD |
81 | } |
82 | ||
83 | function test_ust_streaming_pid () | |
84 | { | |
85 | diag "Test UST streaming with session rotation per PID" | |
f0d43d3d | 86 | create_lttng_session_uri $SESSION_NAME net://localhost |
e7716c6a JD |
87 | enable_channel_per_pid $SESSION_NAME "channel0" |
88 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" | |
89 | ||
3b33e9e7 | 90 | rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" "ust/pid/*/" 1 |
e7716c6a JD |
91 | } |
92 | ||
93 | function test_ust_local_pid () | |
94 | { | |
95 | diag "Test UST local with session rotation per PID" | |
96 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
97 | enable_channel_per_pid $SESSION_NAME "channel0" | |
98 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" | |
99 | ||
3b33e9e7 | 100 | rotate_ust_test "${TRACE_PATH}/archives" "ust/pid/*/" 1 |
e7716c6a JD |
101 | } |
102 | ||
3c4c3582 JR |
103 | function wait_until_app_unregistration () |
104 | { | |
105 | local pid=$1 | |
106 | local mi_output | |
107 | local value=1 | |
108 | ||
109 | mi_output=$(mktemp) | |
110 | ||
111 | while [ $value -ne 0 ]; do | |
112 | # Extract from lttng list tracepoint the registered apps. | |
113 | # This should give us enough guarantee since that if the app is not | |
114 | # present it is unregistered from lttng-sessiond point of view. | |
115 | LTTNG_BIN="lttng --mi xml" OUTPUT_DEST="$mi_output" list_lttng_notap -u | |
116 | if ! $MI_VALIDATE "$mi_output"; then | |
117 | return 1 | |
118 | fi | |
119 | ||
120 | value=$("$MI_VALIDATE" "$mi_output" "$XPATH_PID" | wc -l) | |
121 | if [ $value -ne 0 ]; then | |
122 | diag "At least one app is still registred from lttng-sessiond point of view" | |
123 | sleep 1 | |
124 | else | |
125 | # No app present on listing. | |
126 | break; | |
127 | fi | |
128 | done | |
129 | ||
130 | return 0 | |
131 | } | |
132 | ||
e7716c6a JD |
133 | function test_ust_local_timer_uid () |
134 | { | |
135 | diag "Test ust local with session rotation timer per-uid" | |
136 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
137 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME | |
138 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms | |
139 | start_lttng_tracing_ok $SESSION_NAME | |
140 | # We just want the app to register, no event generated | |
6c4a91d6 | 141 | $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1 |
e7716c6a | 142 | |
3b33e9e7 | 143 | rotate_timer_test "${TRACE_PATH}/archives" 0 |
e7716c6a JD |
144 | } |
145 | ||
146 | function test_ust_streaming_timer_uid () | |
147 | { | |
148 | diag "Test ust remote with session rotation timer per-uid" | |
f0d43d3d | 149 | create_lttng_session_uri $SESSION_NAME net://localhost |
e7716c6a JD |
150 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
151 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms | |
152 | start_lttng_tracing_ok $SESSION_NAME | |
153 | # We just want the app to register, no event generated | |
6c4a91d6 | 154 | $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1 |
e7716c6a | 155 | |
3b33e9e7 | 156 | rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" 0 |
e7716c6a JD |
157 | } |
158 | ||
159 | function test_ust_local_timer_pid () | |
160 | { | |
3c4c3582 JR |
161 | local app_pid |
162 | ||
e7716c6a JD |
163 | diag "Test ust local with session rotation timer per-pid" |
164 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
165 | enable_channel_per_pid $SESSION_NAME "channel0" | |
166 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" | |
e7716c6a | 167 | start_lttng_tracing_ok $SESSION_NAME |
3c4c3582 JR |
168 | |
169 | # We just want the app to register, no event generated. | |
170 | # But we want the pid for the app since we need to validate its | |
171 | # unregistration on lttng listing. | |
172 | $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1 & | |
173 | app_pid=$! | |
174 | wait $app_pid | |
175 | ||
176 | wait_until_app_unregistration $app_pid | |
177 | ok $? "App is un-registered" | |
178 | ||
179 | # Set the rotation after that the app is done and that it was | |
180 | # unregistered from lttng-sessiond. | |
181 | # This is necessary since the rotate_timer_test function expects the | |
182 | # second rotation archive to be empty. On slow machine it can take more | |
183 | # than 500ms for the lttng-sessiond to receive and handle an app | |
184 | # termination. This can lead to situation where the second rotation | |
185 | # archive still have the channels for the pid for the app since that | |
186 | # from the point of view of the lttng-sessiond/consumer the app is still | |
187 | # "alive" and "kicking". This is a problem only for per-pid testing. | |
188 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms | |
e7716c6a | 189 | |
3b33e9e7 | 190 | rotate_timer_test "${TRACE_PATH}/archives" 1 |
e7716c6a JD |
191 | } |
192 | ||
193 | function test_ust_streaming_timer_pid () | |
194 | { | |
195 | diag "Test ust remote with session rotation timer per-pid" | |
f0d43d3d | 196 | create_lttng_session_uri $SESSION_NAME net://localhost |
e7716c6a JD |
197 | enable_channel_per_pid $SESSION_NAME "channel0" |
198 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" | |
e7716c6a | 199 | start_lttng_tracing_ok $SESSION_NAME |
3c4c3582 JR |
200 | |
201 | # We just want the app to register, no event generated. | |
202 | # But we want the pid for the app since we need to validate its | |
203 | # unregistration on lttng listing. | |
204 | $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1 & | |
205 | app_pid=$! | |
206 | wait $app_pid | |
207 | ||
208 | wait_until_app_unregistration $app_pid | |
209 | ok $? "App is un-registered" | |
210 | ||
211 | # Set the rotation after that the app is done and that it was | |
212 | # unregistered from lttng-sessiond. | |
213 | # This is necessary since the rotate_timer_test function expects the | |
214 | # second rotation archive to be empty. On slow machine it can take more | |
215 | # than 500ms for the lttng-sessiond to receive and handle an app | |
216 | # termination. This can lead to situation where the second rotation | |
217 | # archive still have the channels for the pid for the app since that | |
218 | # from the point of view of the lttng-sessiond/consumer the app is still | |
219 | # "alive" and "kicking". This is a problem only for per-pid testing. | |
220 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms | |
e7716c6a | 221 | |
3b33e9e7 | 222 | rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" 1 |
e7716c6a JD |
223 | } |
224 | ||
225 | function test_incompatible_sessions () | |
226 | { | |
227 | diag "Check incompatible session types with rotation" | |
228 | ||
229 | diag "Live session with rotate timer" | |
230 | # Should not be able to enable a rotation timer with a live session | |
308a8946 | 231 | create_lttng_session_uri $SESSION_NAME net://localhost --live |
e7716c6a JD |
232 | lttng_enable_rotation_timer_fail $SESSION_NAME 500ms |
233 | destroy_lttng_session_ok $SESSION_NAME | |
234 | ||
235 | diag "Snapshot session with rotate timer" | |
236 | # Should not be able to enable a rotation timer with a snapshot session | |
308a8946 | 237 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot |
e7716c6a JD |
238 | lttng_enable_rotation_timer_fail $SESSION_NAME 500ms |
239 | destroy_lttng_session_ok $SESSION_NAME | |
240 | ||
241 | diag "Live session with rotate" | |
242 | # Should not be able to rotate a live session | |
308a8946 | 243 | create_lttng_session_uri $SESSION_NAME net://localhost --live |
e7716c6a JD |
244 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
245 | start_lttng_tracing_ok $SESSION_NAME | |
246 | rotate_session_fail $SESSION_NAME | |
247 | destroy_lttng_session_ok $SESSION_NAME | |
248 | ||
249 | diag "Snapshot session with rotate" | |
250 | # Should not be able to rotate a snapshot session | |
308a8946 | 251 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot |
e7716c6a JD |
252 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
253 | start_lttng_tracing_ok $SESSION_NAME | |
254 | rotate_session_fail $SESSION_NAME | |
255 | destroy_lttng_session_ok $SESSION_NAME | |
e7716c6a JD |
256 | } |
257 | ||
34764ec8 JG |
258 | function produce_n_events () |
259 | { | |
260 | local event_count=$1 | |
261 | ||
262 | $TESTAPP_BIN -i "$event_count" -w 0 > /dev/null 2>&1 | |
263 | } | |
264 | ||
56f80787 JG |
265 | function test_ust_local_size_uid () |
266 | { | |
267 | diag "Rotate uid local session every 2MiB" | |
268 | local size_threshold=$((2 * 1024 * 1024)) | |
269 | ||
270 | diag "Test ust local with size-based session rotation per-uid" | |
271 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
272 | enable_ust_lttng_channel_ok $SESSION_NAME "channel0" --buffers-uid | |
273 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" | |
274 | lttng_enable_rotation_size_ok $SESSION_NAME $size_threshold | |
275 | start_lttng_tracing_ok $SESSION_NAME | |
276 | ||
609996d5 JG |
277 | # Cutoff at 100 times the expected size |
278 | trace_until_n_archives produce_n_events "$TRACE_PATH" 5 $((5 * 100 * size_threshold)) | |
56f80787 | 279 | |
bf1e8411 JG |
280 | destroy_lttng_session_ok $SESSION_NAME |
281 | } | |
282 | ||
283 | function test_ust_local_size_pid () | |
284 | { | |
285 | diag "Rotate uid local session every 2MiB" | |
286 | local size_threshold=$((2 * 1024 * 1024)) | |
287 | ||
288 | diag "Test ust local with size-based session rotation per-pid" | |
289 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
290 | enable_ust_lttng_channel_ok $SESSION_NAME "channel0" --buffers-pid | |
291 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" | |
292 | lttng_enable_rotation_size_ok $SESSION_NAME $size_threshold | |
293 | start_lttng_tracing_ok $SESSION_NAME | |
56f80787 | 294 | |
609996d5 JG |
295 | # Cutoff at 100 times the expected size |
296 | trace_until_n_archives produce_n_events "$TRACE_PATH" 3 $((3 * 100 * size_threshold)) | |
56f80787 JG |
297 | |
298 | destroy_lttng_session_ok $SESSION_NAME | |
299 | } | |
300 | ||
e7716c6a JD |
301 | plan_tests $NUM_TESTS |
302 | ||
303 | print_test_banner "$TEST_DESC" | |
c125de8f | 304 | bail_out_if_no_babeltrace |
e7716c6a JD |
305 | |
306 | start_lttng_relayd "-o $TRACE_PATH" | |
307 | start_lttng_sessiond | |
308 | ||
309 | tests=( test_ust_streaming_uid test_ust_local_uid \ | |
310 | test_ust_streaming_pid test_ust_local_pid \ | |
311 | test_ust_local_timer_uid test_ust_streaming_timer_uid \ | |
312 | test_ust_local_timer_pid test_ust_streaming_timer_pid \ | |
bf1e8411 JG |
313 | test_ust_local_size_uid test_ust_local_size_pid \ |
314 | test_incompatible_sessions ) | |
e7716c6a JD |
315 | |
316 | for fct_test in ${tests[@]}; | |
317 | do | |
318 | SESSION_NAME=$(randstring 16 0) | |
319 | ${fct_test} | |
8f2d0517 | 320 | clean_path $TRACE_PATH |
e7716c6a JD |
321 | done |
322 | ||
323 | stop_lttng_sessiond | |
324 | stop_lttng_relayd | |
9dc506ae JR |
325 | |
326 | # Remove tmp dir | |
327 | rm -rf $TRACE_PATH |