Commit | Line | Data |
---|---|---|
c28fcefd JR |
1 | #!/bin/bash |
2 | # | |
9e3c8d58 | 3 | # Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
c28fcefd | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: LGPL-2.1-only |
c28fcefd JR |
6 | |
7 | TEST_DESC="Clear - UST tracing" | |
8 | ||
9 | CURDIR=$(dirname $0)/ | |
10 | TESTDIR=$CURDIR/../../.. | |
11 | EVENT_NAME="tp:tptest" | |
60ef7bf7 JG |
12 | EVENT_STATE_DUMP_START="lttng_ust_statedump:start" |
13 | EVENT_STATE_DUMP_END="lttng_ust_statedump:end" | |
c28fcefd JR |
14 | SESSION_NAME="" |
15 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
16 | TESTAPP_NAME="gen-ust-events" | |
17 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
18 | ||
60ef7bf7 | 19 | NUM_TESTS=2071 |
c28fcefd JR |
20 | |
21 | PAGE_SIZE=$(getconf PAGE_SIZE) | |
22 | TRACE_PATH=$(mktemp -d) | |
23 | ||
fe1c64c5 OD |
24 | # shellcheck source=../utils/utils.sh |
25 | source "$TESTDIR/utils/utils.sh" | |
c28fcefd JR |
26 | |
27 | if [ ! -x "$TESTAPP_BIN" ]; then | |
28 | BAIL_OUT "No UST events binary detected." | |
29 | fi | |
30 | ||
31 | function clean_path () | |
32 | { | |
33 | local trace_path=$1 | |
34 | set -u | |
35 | rm -rf $trace_path/* | |
36 | set +u | |
37 | } | |
38 | ||
39 | function cond_start_tracing () | |
40 | { | |
41 | local session_name=$1 | |
42 | local tracing_active=$2 | |
43 | ||
44 | if [[ $tracing_active -ne 1 ]]; then | |
45 | start_lttng_tracing_ok $session_name | |
46 | fi | |
47 | } | |
48 | ||
49 | function cond_stop_tracing () | |
50 | { | |
51 | local session_name=$1 | |
52 | local tracing_active=$2 | |
53 | ||
54 | if [[ $tracing_active -ne 1 ]]; then | |
55 | stop_lttng_tracing_ok $session_name | |
56 | fi | |
57 | } | |
58 | ||
59 | function do_clear_session () | |
60 | { | |
61 | local session_name=$1 | |
62 | local tracing_active=$2 | |
63 | local clear_twice=$3 | |
64 | local rotate_before=$4 | |
65 | local rotate_after=$5 | |
66 | ||
67 | cond_stop_tracing $session_name $tracing_active | |
68 | if [[ $rotate_before -eq 1 ]]; then | |
69 | rotate_session_ok $SESSION_NAME | |
70 | fi | |
71 | lttng_clear_session_ok $SESSION_NAME | |
72 | if [[ $clear_twice -eq 1 ]]; then | |
73 | lttng_clear_session_ok $SESSION_NAME | |
74 | fi | |
75 | if [[ $rotate_after -eq 1 ]]; then | |
76 | if [[ $tracing_active -eq 1 ]]; then | |
77 | rotate_session_ok $SESSION_NAME | |
78 | else | |
79 | # Expect failure | |
80 | rotate_session_fail $SESSION_NAME | |
81 | fi | |
82 | fi | |
83 | cond_start_tracing $session_name $tracing_active | |
84 | } | |
85 | ||
86 | function test_ust_streaming () | |
87 | { | |
88 | local tracing_active=$1 | |
89 | local clear_twice=$2 | |
90 | local rotate_before=$3 | |
91 | local rotate_after=$4 | |
92 | local buffer_type=$5 | |
93 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
94 | local channel_name="chan" | |
95 | ||
96 | diag "Test ust streaming clear" | |
97 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
98 | create_lttng_session_uri $SESSION_NAME net://localhost | |
99 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
100 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
101 | start_lttng_tracing_ok $SESSION_NAME | |
102 | $TESTAPP_BIN -i 10 | |
103 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
104 | stop_lttng_tracing_ok $SESSION_NAME | |
105 | ||
106 | if [[ $rotate_before -eq 1 ]]; then | |
107 | validate_trace_count $EVENT_NAME $local_path 10 | |
108 | else | |
109 | if [[ "$buffer_type" == "uid" ]]; then | |
110 | validate_trace_empty $local_path | |
111 | else # pid | |
112 | validate_directory_empty $local_path | |
113 | fi | |
114 | fi | |
115 | ||
116 | destroy_lttng_session_ok $SESSION_NAME | |
117 | } | |
118 | ||
27d444d3 JR |
119 | function test_ust_streaming_no_event () |
120 | { | |
121 | local tracing_active=$1 | |
122 | local clear_twice=$2 | |
123 | #local rotate_before=$3 ignored | |
124 | #local rotate_after=$4 | |
125 | local buffer_type=uid | |
126 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
127 | local channel_name="chan" | |
128 | ||
129 | diag "Test ust streaming clear no event" | |
130 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
131 | create_lttng_session_uri $SESSION_NAME net://localhost | |
132 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
133 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
134 | start_lttng_tracing_ok $SESSION_NAME | |
135 | ||
136 | do_clear_session $SESSION_NAME "$tracing_active" "$clear_twice" "$rotate_before" "$rotate_after" | |
137 | stop_lttng_tracing_ok $SESSION_NAME | |
138 | ||
139 | validate_directory_empty "$local_path" | |
140 | ||
141 | destroy_lttng_session_ok $SESSION_NAME | |
142 | } | |
143 | ||
c28fcefd JR |
144 | function test_ust_streaming_rotate_clear () |
145 | { | |
146 | local tracing_active=$1 | |
147 | local clear_twice=$2 | |
148 | local rotate_before=$3 | |
149 | local rotate_after=$4 | |
150 | local buffer_type=$5 | |
151 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
152 | local channel_name="chan" | |
153 | ||
154 | diag "Test ust streaming rotate-clear" | |
155 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
156 | create_lttng_session_uri $SESSION_NAME net://localhost | |
157 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
158 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
159 | start_lttng_tracing_ok $SESSION_NAME | |
160 | $TESTAPP_BIN -i 1 | |
161 | rotate_session_ok $SESSION_NAME | |
162 | $TESTAPP_BIN -i 2 | |
163 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
164 | $TESTAPP_BIN -i 3 | |
165 | stop_lttng_tracing_ok $SESSION_NAME | |
166 | ||
167 | if [[ $rotate_before -eq 1 ]]; then | |
168 | local expect_count=6 | |
169 | else | |
170 | local expect_count=4 | |
171 | fi | |
172 | validate_trace_count $EVENT_NAME $local_path $expect_count | |
173 | ||
174 | destroy_lttng_session_ok $SESSION_NAME | |
175 | } | |
176 | ||
177 | function test_ust_streaming_clear_rotate () | |
178 | { | |
179 | local tracing_active=$1 | |
180 | local clear_twice=$2 | |
181 | local rotate_before=$3 | |
182 | local rotate_after=$4 | |
183 | local buffer_type=$5 | |
184 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
185 | local channel_name="chan" | |
186 | ||
187 | diag "Test ust streaming clear-rotate" | |
188 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
189 | create_lttng_session_uri $SESSION_NAME net://localhost | |
190 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
191 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
192 | start_lttng_tracing_ok $SESSION_NAME | |
193 | $TESTAPP_BIN -i 1 | |
194 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
195 | $TESTAPP_BIN -i 2 | |
196 | rotate_session_ok $SESSION_NAME | |
197 | $TESTAPP_BIN -i 3 | |
198 | stop_lttng_tracing_ok $SESSION_NAME | |
199 | ||
200 | if [[ $rotate_before -eq 1 ]]; then | |
201 | local expect_count=6 | |
202 | else | |
203 | local expect_count=5 | |
204 | fi | |
205 | validate_trace_count $EVENT_NAME $local_path $expect_count | |
206 | ||
207 | destroy_lttng_session_ok $SESSION_NAME | |
208 | } | |
209 | ||
210 | function test_ust_streaming_live () | |
211 | { | |
212 | local tracing_active=$1 | |
213 | local clear_twice=$2 | |
214 | # 3, 4 unused | |
215 | local buffer_type=$5 | |
216 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
217 | local channel_name="chan" | |
218 | ||
219 | diag "Test ust streaming live clear" | |
220 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
221 | create_lttng_session_uri $SESSION_NAME net://localhost "--live" | |
222 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
223 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
224 | start_lttng_tracing_ok $SESSION_NAME | |
225 | $TESTAPP_BIN -i 10 | |
226 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 | |
227 | stop_lttng_tracing_ok $SESSION_NAME | |
228 | ||
f2489409 FD |
229 | if [[ "$buffer_type" == "uid" ]]; then |
230 | validate_trace_empty $local_path | |
231 | else # pid | |
232 | validate_directory_empty $local_path | |
233 | fi | |
c28fcefd JR |
234 | |
235 | destroy_lttng_session_ok $SESSION_NAME | |
236 | } | |
237 | ||
238 | #no clear | |
239 | function test_ust_basic_streaming_live_viewer () | |
240 | { | |
241 | local tracing_active=$1 | |
242 | local clear_twice=$2 | |
243 | # 3, 4 unused | |
244 | local buffer_type=$5 | |
245 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
246 | local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" | |
247 | local channel_name="chan" | |
248 | local bt_output_path=$(mktemp -u) | |
249 | local file_sync_before_exit=$(mktemp -u) | |
250 | ||
251 | diag "Test ust basic streaming live with viewer" | |
252 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
253 | create_lttng_session_uri $SESSION_NAME net://localhost "--live" | |
254 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
255 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
256 | start_lttng_tracing_ok $SESSION_NAME | |
257 | ||
258 | wait_live_trace_ready net://localhost | |
259 | ||
260 | # Connect a live viewer | |
261 | $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & | |
262 | local viewer_pid=$! | |
263 | ||
264 | wait_live_viewer_connect net://localhost | |
265 | ||
266 | $TESTAPP_BIN -i 10 --sync-before-exit $file_sync_before_exit & | |
267 | local app_pid=$! | |
268 | ||
269 | diag "Wait until viewer sees all 10 expected events" | |
270 | local evcount=0 | |
271 | while [ $evcount -ne 10 ]; do | |
272 | evcount=$(cat $bt_output_path | wc -l) | |
273 | sleep 0.5 | |
274 | done | |
275 | pass "Live viewer read $evcount events, expect 10" | |
276 | ||
277 | destroy_lttng_session_ok $SESSION_NAME | |
278 | touch $file_sync_before_exit | |
60ef7bf7 | 279 | diag "Waiting for application to exit" |
c28fcefd JR |
280 | wait $app_pid |
281 | pass "Wait for application to exit" | |
282 | diag "Wait for viewer to exit" | |
283 | wait $viewer_pid | |
284 | ok $? "Babeltrace succeeds" | |
285 | pass "Wait for viewer to exit" | |
286 | ||
287 | rm -f $bt_output_path | |
288 | rm -f $file_sync_before_exit | |
289 | } | |
290 | ||
291 | function test_ust_streaming_live_viewer () | |
292 | { | |
293 | local tracing_active=$1 | |
294 | local clear_twice=$2 | |
295 | # 3, 4 unused | |
296 | local buffer_type=$5 | |
297 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
298 | local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" | |
299 | local channel_name="chan" | |
300 | local bt_output_path=$(mktemp -d)/bt-output.txt | |
301 | ||
302 | diag "Test ust streaming live clear with viewer" | |
303 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
304 | create_lttng_session_uri $SESSION_NAME net://localhost "--live" | |
305 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
306 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
307 | start_lttng_tracing_ok $SESSION_NAME | |
308 | ||
309 | wait_live_trace_ready net://localhost | |
310 | ||
311 | # Connect a live viewer | |
312 | $BABELTRACE_BIN -i lttng-live net://localhost/host/$remote_trace_path > $bt_output_path & | |
313 | local viewer_pid=$! | |
314 | ||
315 | wait_live_viewer_connect net://localhost | |
316 | ||
317 | $TESTAPP_BIN -i 10 | |
318 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 | |
319 | stop_lttng_tracing_ok $SESSION_NAME | |
320 | ||
321 | destroy_lttng_session_ok $SESSION_NAME | |
322 | diag "Wait for viewer to exit" | |
323 | wait $viewer_pid | |
324 | ok $? "Babeltrace succeeds" | |
325 | pass "Wait for viewer to exit" | |
326 | ||
327 | clean_path $bt_output_path | |
328 | } | |
329 | ||
60ef7bf7 JG |
330 | function test_ust_streaming_live_viewer_new_metadata_after_clear () |
331 | { | |
332 | local tracing_active=$1 | |
333 | local clear_twice=$2 | |
334 | # 3, 4 unused | |
335 | local buffer_type=$5 | |
336 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
337 | local remote_trace_path="${HOSTNAME}/${SESSION_NAME}" | |
338 | local channel_name="chan" | |
339 | local bt_output_path | |
340 | local bt_error_path | |
341 | local file_sync_before_exit | |
342 | ||
343 | bt_output_path=$(mktemp -d)/bt-output.txt | |
344 | bt_error_path=$(mktemp -d)/bt-output.err | |
345 | file_sync_before_exit=$(mktemp -u) | |
346 | ||
347 | diag "Test ust streaming live clear with viewer with new metadata after clear" | |
348 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
349 | create_lttng_session_uri "$SESSION_NAME" net://localhost "--live" | |
350 | enable_ust_lttng_channel_ok "$SESSION_NAME" $channel_name "--buffers-$buffer_type" | |
351 | ||
352 | # The vpid context is added to filter events based on the vpid of the | |
353 | # test application as state dump events are used. Regenerating a | |
354 | # state dump will cause other instrumented application on the system | |
355 | # to trigger a state dump which would throw off checks that rely on an | |
356 | # event count. | |
357 | add_context_ust_ok "$SESSION_NAME" $channel_name "vpid" | |
358 | enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $channel_name | |
359 | start_lttng_tracing_ok "$SESSION_NAME" | |
360 | ||
361 | wait_live_trace_ready net://localhost | |
362 | ||
363 | # Connect a live viewer | |
364 | $BABELTRACE_BIN -i lttng-live "net://localhost/host/$remote_trace_path" 1> "$bt_output_path" 2> "$bt_error_path" & | |
365 | local viewer_pid=$! | |
366 | ||
367 | wait_live_viewer_connect net://localhost | |
368 | ||
369 | $TESTAPP_BIN -i 10 --sync-before-exit "$file_sync_before_exit" & | |
370 | local app_pid=$! | |
371 | ||
372 | diag "Wait until viewer sees all 10 expected events" | |
373 | local evcount=0 | |
374 | while [ $evcount -ne 10 ]; do | |
375 | evcount=$(wc -l < "$bt_output_path") | |
376 | sleep 0.5 | |
377 | done | |
378 | pass "Live viewer read $evcount events, expect 10" | |
379 | ||
380 | do_clear_session "$SESSION_NAME" "$tracing_active" "$clear_twice" 0 0 | |
381 | ||
382 | # Enable new events which will add their descriptions to the metadata | |
383 | # file. This validates that, following a clear, the relay daemon rotates | |
384 | # the metadata viewer stream to the new metadata file. | |
385 | enable_ust_lttng_event_filter "$SESSION_NAME" $EVENT_STATE_DUMP_START "\$ctx.vpid == $app_pid" $channel_name | |
386 | enable_ust_lttng_event_filter "$SESSION_NAME" $EVENT_STATE_DUMP_END "\$ctx.vpid == $app_pid" $channel_name | |
387 | ||
388 | # Forcing a state dump to produce the two events enabled above | |
389 | regenerate_statedump_ok "$SESSION_NAME" | |
390 | ||
391 | diag "Wait until viewer sees all 12 expected events" | |
392 | local evcount=0 | |
393 | while [ $evcount -ne 12 ]; do | |
394 | evcount=$(wc -l < "$bt_output_path") | |
395 | sleep 0.5 | |
396 | done | |
397 | pass "Live viewer read $evcount events, expect 12" | |
398 | ||
399 | stop_lttng_tracing_ok "$SESSION_NAME" | |
400 | ||
401 | destroy_lttng_session_ok "$SESSION_NAME" | |
402 | ||
403 | touch "$file_sync_before_exit" | |
404 | diag "Waiting for application to exit" | |
405 | wait $app_pid | |
406 | pass "Wait for application to exit" | |
407 | ||
408 | diag "Wait for viewer to exit" | |
409 | wait $viewer_pid | |
410 | ok $? "Babeltrace succeeds" | |
411 | pass "Wait for viewer to exit" | |
412 | ||
413 | clean_path "$bt_output_path" | |
414 | clean_path "$bt_error_path" | |
415 | } | |
416 | ||
c28fcefd JR |
417 | function test_ust_local () |
418 | { | |
419 | local tracing_active=$1 | |
420 | local clear_twice=$2 | |
421 | local rotate_before=$3 | |
422 | local rotate_after=$4 | |
423 | local buffer_type=$5 | |
424 | local channel_name="chan" | |
425 | ||
426 | diag "Test ust local" | |
427 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
428 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
429 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
430 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
431 | start_lttng_tracing_ok $SESSION_NAME | |
432 | $TESTAPP_BIN -i 10 | |
433 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
434 | stop_lttng_tracing_ok $SESSION_NAME | |
435 | ||
436 | if [[ $rotate_before -eq 1 ]]; then | |
437 | validate_trace_count $EVENT_NAME $TRACE_PATH 10 | |
438 | else | |
439 | if [[ "$buffer_type" == "uid" ]]; then | |
440 | validate_trace_empty $TRACE_PATH | |
441 | else # pid | |
f2489409 FD |
442 | |
443 | # The sessiond always created a `ust/ directory | |
444 | # whenever the UST domain is active | |
445 | validate_directory_empty $TRACE_PATH/ust/ | |
c28fcefd JR |
446 | fi |
447 | fi | |
448 | ||
449 | destroy_lttng_session_ok $SESSION_NAME | |
450 | } | |
451 | ||
27d444d3 JR |
452 | function test_ust_local_no_event () |
453 | { | |
454 | local tracing_active=$1 | |
455 | local clear_twice=$2 | |
456 | #local rotate_before=$3 ignored | |
457 | #local rotate_after=$4 ignored | |
458 | local buffer_type=$5 | |
459 | local channel_name="chan" | |
460 | ||
461 | diag "Test ust local no event" | |
462 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
463 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" | |
464 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name "--buffers-$buffer_type" | |
465 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
466 | start_lttng_tracing_ok $SESSION_NAME | |
467 | ||
468 | do_clear_session $SESSION_NAME "$tracing_active" "$clear_twice" "$rotate_before" "$rotate_after" | |
469 | stop_lttng_tracing_ok $SESSION_NAME | |
470 | ||
471 | validate_directory_empty "$TRACE_PATH" | |
472 | ||
473 | destroy_lttng_session_ok $SESSION_NAME | |
474 | } | |
475 | ||
c28fcefd JR |
476 | function test_ust_local_rotate_clear () |
477 | { | |
478 | local tracing_active=$1 | |
479 | local clear_twice=$2 | |
480 | local rotate_before=$3 | |
481 | local rotate_after=$4 | |
482 | local buffer_type=$5 | |
483 | local channel_name="chan" | |
484 | ||
485 | diag "Test ust local rotate-clear" | |
486 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
487 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
488 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
489 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
490 | start_lttng_tracing_ok $SESSION_NAME | |
491 | $TESTAPP_BIN -i 1 | |
492 | rotate_session_ok $SESSION_NAME | |
493 | $TESTAPP_BIN -i 2 | |
494 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
495 | $TESTAPP_BIN -i 3 | |
496 | stop_lttng_tracing_ok $SESSION_NAME | |
497 | ||
498 | if [[ $rotate_before -eq 1 ]]; then | |
499 | local expect_count=6 | |
500 | else | |
501 | local expect_count=4 | |
502 | fi | |
503 | validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count | |
504 | ||
505 | destroy_lttng_session_ok $SESSION_NAME | |
506 | } | |
507 | ||
508 | function test_ust_local_clear_rotate () | |
509 | { | |
510 | local tracing_active=$1 | |
511 | local clear_twice=$2 | |
512 | local rotate_before=$3 | |
513 | local rotate_after=$4 | |
514 | local buffer_type=$5 | |
515 | local channel_name="chan" | |
516 | ||
517 | diag "Test ust local clear-rotate" | |
518 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
519 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH | |
520 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
521 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
522 | start_lttng_tracing_ok $SESSION_NAME | |
523 | $TESTAPP_BIN -i 1 | |
524 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
525 | $TESTAPP_BIN -i 2 | |
526 | rotate_session_ok $SESSION_NAME | |
527 | $TESTAPP_BIN -i 3 | |
528 | stop_lttng_tracing_ok $SESSION_NAME | |
529 | ||
530 | if [[ $rotate_before -eq 1 ]]; then | |
531 | local expect_count=6 | |
532 | else | |
533 | local expect_count=5 | |
534 | fi | |
535 | validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count | |
536 | ||
537 | destroy_lttng_session_ok $SESSION_NAME | |
538 | } | |
539 | ||
540 | function do_ust_snapshot () | |
541 | { | |
542 | local session_name=$1 | |
543 | local trace_path=$2 | |
544 | local tracing_active=$3 | |
545 | local clear_twice=$4 | |
546 | local buffer_type=$5 | |
547 | local channel_name="snapshot" | |
548 | ||
549 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
550 | enable_ust_lttng_event_ok $session_name $EVENT_NAME $channel_name | |
551 | start_lttng_tracing_ok $session_name | |
552 | ||
553 | # Generate 10 events that will sit in the buffers. | |
554 | $TESTAPP_BIN -i 10 | |
555 | ||
556 | # Take a first snapshot and validate that the events are present. | |
557 | lttng_snapshot_record $session_name | |
558 | stop_lttng_tracing_ok $session_name | |
559 | validate_trace_count $EVENT_NAME $trace_path 10 | |
560 | ||
561 | # Clean the output path | |
562 | clean_path $trace_path | |
563 | start_lttng_tracing_ok $session_name | |
564 | ||
565 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 | |
566 | ||
567 | # Make sure the subsequent snapshot is empty and valid. | |
568 | lttng_snapshot_record $session_name | |
569 | stop_lttng_tracing_ok $session_name | |
570 | validate_trace_empty $trace_path | |
571 | ||
572 | # Clean the output path | |
573 | clean_path $trace_path | |
574 | start_lttng_tracing_ok $session_name | |
575 | ||
576 | # Make sure that everything still works, generate events and take a | |
577 | # snapshot. | |
578 | $TESTAPP_BIN -i 10 | |
579 | lttng_snapshot_record $session_name | |
580 | stop_lttng_tracing_ok $session_name | |
581 | validate_trace_count $EVENT_NAME $trace_path 10 | |
582 | } | |
583 | ||
584 | function test_ust_streaming_snapshot () | |
585 | { | |
586 | local tracing_active=$1 | |
587 | local clear_twice=$2 | |
588 | # 3, 4 unused. | |
589 | local buffer_type=$5 | |
590 | ||
591 | diag "Test ust streaming snapshot clear" | |
592 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
593 | ||
594 | create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot" | |
595 | do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type | |
596 | destroy_lttng_session_ok $SESSION_NAME | |
597 | } | |
598 | ||
599 | function test_ust_local_snapshot () | |
600 | { | |
601 | local tracing_active=$1 | |
602 | local clear_twice=$2 | |
603 | # 3, 4 unused. | |
604 | local buffer_type=$5 | |
605 | ||
606 | diag "Test ust local snapshot clear" | |
607 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
608 | ||
609 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" | |
610 | do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type | |
611 | destroy_lttng_session_ok $SESSION_NAME | |
612 | } | |
613 | ||
614 | # snapshot for per-pid is tested independently of the "buffer type" parameter | |
615 | # because an application needs to be live to appear in a snapshot. | |
616 | function test_ust_local_snapshot_per_pid () | |
617 | { | |
618 | local tracing_active=$1 | |
619 | local clear_twice=$2 | |
620 | # 3, 4 unused. | |
621 | local buffer_type=$5 | |
622 | local channel_name="channel0" | |
623 | local file_sync_before_last=$(mktemp -u) | |
624 | local file_sync_before_last_touch=$(mktemp -u) | |
625 | local file_sync_before_exit=$(mktemp -u) | |
626 | local file_sync_before_exit_touch=$(mktemp -u) | |
627 | ||
628 | diag "Test ust local snapshot clear per pid" | |
629 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type" | |
630 | ||
631 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot" | |
632 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type | |
633 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
634 | start_lttng_tracing_ok $SESSION_NAME | |
635 | ||
636 | # Generate 10 events that will sit in the buffers. | |
637 | $TESTAPP_BIN -i 10 -w 0 \ | |
638 | --sync-before-last-event ${file_sync_before_last} \ | |
639 | --sync-before-last-event-touch ${file_sync_before_last_touch} \ | |
640 | --sync-before-exit ${file_sync_before_exit} \ | |
641 | --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev/null 2>&1 & | |
c03a0ff4 | 642 | local app_pid="${!}" |
c28fcefd JR |
643 | |
644 | # Continue only when there is only the last event remaining. | |
645 | while [ ! -f "${file_sync_before_last_touch}" ]; do | |
646 | sleep 0.5 | |
647 | done | |
648 | ||
649 | # Take a first snapshot and validate that the events are present. | |
650 | lttng_snapshot_record $SESSION_NAME | |
651 | stop_lttng_tracing_ok $SESSION_NAME | |
652 | validate_trace_count $EVENT_NAME $TRACE_PATH 9 | |
653 | ||
654 | # Clean the output path | |
655 | clean_path $TRACE_PATH | |
656 | start_lttng_tracing_ok $SESSION_NAME | |
657 | ||
658 | do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0 | |
659 | ||
660 | # Make sure the subsequent snapshot is empty and valid. | |
661 | lttng_snapshot_record $SESSION_NAME | |
662 | stop_lttng_tracing_ok $SESSION_NAME | |
663 | validate_trace_empty $TRACE_PATH | |
664 | ||
665 | # Validate that tracing still works and subsequent snapshots are valid. | |
666 | # Clean the output path. | |
667 | clean_path $TRACE_PATH | |
668 | start_lttng_tracing_ok $SESSION_NAME | |
669 | ||
670 | # Continue over the last event. | |
671 | touch ${file_sync_before_last} | |
672 | ||
673 | # Wait for the before exit sync point. This ensure that we went over the | |
674 | # last tracepoint. | |
675 | while [ ! -f "${file_sync_before_exit_touch}" ]; do | |
676 | sleep 0.5 | |
677 | done | |
678 | ||
679 | # Make sure the snapshot contains the last event. | |
680 | lttng_snapshot_record $SESSION_NAME | |
681 | stop_lttng_tracing_ok $SESSION_NAME | |
682 | validate_trace_count $EVENT_NAME $TRACE_PATH 1 | |
683 | ||
684 | # Release the application. | |
685 | touch ${file_sync_before_exit} | |
c03a0ff4 | 686 | wait "${app_pid}" |
c28fcefd JR |
687 | destroy_lttng_session_ok $SESSION_NAME |
688 | ||
689 | rm -f ${file_sync_before_last} | |
690 | rm -f ${file_sync_before_last_touch} | |
691 | rm -f ${file_sync_before_exit} | |
692 | rm -f ${file_sync_before_exit_touch} | |
693 | } | |
694 | ||
695 | function test_ust_streaming_tracefile_rotation () | |
696 | { | |
697 | local tracing_active=$1 | |
698 | local clear_twice=$2 | |
699 | local rotate_before=$3 | |
700 | local rotate_after=$4 | |
701 | local buffer_type=$5 | |
702 | local channel_name="rotchan" | |
703 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
704 | ||
705 | diag "Test ust streaming clear with tracefile rotation" | |
706 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
707 | create_lttng_session_uri $SESSION_NAME net://localhost | |
708 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ | |
709 | --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type | |
710 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
711 | start_lttng_tracing_ok $SESSION_NAME | |
712 | $TESTAPP_BIN -i 10 | |
713 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after | |
714 | stop_lttng_tracing_ok $SESSION_NAME | |
715 | ||
716 | if [[ $rotate_before -eq 1 ]]; then | |
717 | validate_trace_count $EVENT_NAME $local_path 10 | |
718 | else | |
719 | if [[ "$buffer_type" == "uid" ]]; then | |
720 | validate_trace_empty $local_path | |
721 | else # pid | |
722 | validate_directory_empty $local_path | |
723 | fi | |
724 | fi | |
725 | ||
726 | start_lttng_tracing_ok $SESSION_NAME | |
727 | $TESTAPP_BIN -i 20 | |
728 | stop_lttng_tracing_ok | |
729 | ||
730 | if [[ $rotate_before -eq 1 ]]; then | |
731 | validate_trace_count $EVENT_NAME $local_path 30 | |
732 | else | |
733 | validate_trace_count $EVENT_NAME $local_path 20 | |
734 | fi | |
735 | ||
736 | destroy_lttng_session_ok $SESSION_NAME | |
737 | } | |
738 | ||
739 | # With 1 byte per event (as strict minimum), generating 200000 events | |
740 | # guarantees filling up 2 files of 64k in size, which is the maximum | |
741 | # page size known on Linux | |
742 | function test_ust_streaming_tracefile_rotation_overwrite_files () | |
743 | { | |
744 | local tracing_active=$1 | |
745 | local clear_twice=$2 | |
746 | local rotate_before=$3 | |
747 | local rotate_after=$4 | |
748 | local buffer_type=$5 | |
749 | local channel_name="rotchan" | |
750 | local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" | |
751 | ||
752 | diag "Test ust streaming clear with tracefile rotation, overwrite files" | |
753 | diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type" | |
754 | create_lttng_session_uri $SESSION_NAME net://localhost | |
755 | enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \ | |
756 | --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type | |
757 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name | |
758 | start_lttng_tracing_ok $SESSION_NAME | |
fe1c64c5 | 759 | taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i 200000 |
c28fcefd JR |
760 | do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after |
761 | stop_lttng_tracing_ok $SESSION_NAME | |
762 | ||
763 | if [[ $rotate_before -eq 1 ]]; then | |
764 | validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 | |
765 | else | |
766 | if [[ "$buffer_type" == "uid" ]]; then | |
767 | validate_trace_empty $local_path | |
768 | else # pid | |
769 | validate_directory_empty $local_path | |
770 | fi | |
771 | fi | |
772 | ||
773 | start_lttng_tracing_ok $SESSION_NAME | |
fe1c64c5 | 774 | taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i 400000 |
c28fcefd JR |
775 | stop_lttng_tracing_ok |
776 | ||
777 | if [[ $rotate_before -eq 1 ]]; then | |
778 | validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 600000 | |
779 | else | |
780 | validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000 | |
781 | fi | |
782 | ||
783 | destroy_lttng_session_ok $SESSION_NAME | |
784 | } | |
785 | ||
786 | function test_ust_disallow_clear () | |
787 | { | |
788 | diag "Test ust disallow clear on relay daemon" | |
789 | SESSION_NAME=$(randstring 16 0) | |
790 | ||
791 | LTTNG_RELAYD_DISALLOW_CLEAR=1 start_lttng_relayd "-o $TRACE_PATH" | |
792 | ||
793 | start_lttng_sessiond | |
794 | ||
795 | create_lttng_session_uri $SESSION_NAME net://localhost | |
796 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME | |
797 | start_lttng_tracing_ok $SESSION_NAME | |
798 | lttng_clear_session_fail $SESSION_NAME | |
799 | destroy_lttng_session_ok $SESSION_NAME | |
800 | ||
801 | stop_lttng_sessiond | |
802 | stop_lttng_relayd | |
803 | clean_path $TRACE_PATH | |
804 | } | |
805 | ||
806 | plan_tests $NUM_TESTS | |
807 | ||
808 | print_test_banner "$TEST_DESC" | |
809 | ||
810 | streaming_tests=(test_ust_streaming | |
811 | test_ust_streaming_rotate_clear | |
812 | test_ust_streaming_clear_rotate | |
813 | test_ust_streaming_tracefile_rotation | |
814 | test_ust_streaming_tracefile_rotation_overwrite_files | |
27d444d3 | 815 | test_ust_streaming_no_event |
c28fcefd JR |
816 | ) |
817 | ||
818 | live_tests=(test_ust_streaming_live | |
819 | test_ust_basic_streaming_live_viewer | |
820 | test_ust_streaming_live_viewer | |
60ef7bf7 | 821 | test_ust_streaming_live_viewer_new_metadata_after_clear |
c28fcefd JR |
822 | ) |
823 | ||
824 | local_tests=(test_ust_local | |
825 | test_ust_local_rotate_clear | |
826 | test_ust_local_clear_rotate | |
27d444d3 | 827 | test_ust_local_no_event |
c28fcefd JR |
828 | ) |
829 | ||
830 | snapshot_uid_tests=(test_ust_streaming_snapshot | |
831 | test_ust_local_snapshot | |
832 | ) | |
833 | ||
834 | snapshot_pid_tests=(test_ust_local_snapshot_per_pid) | |
835 | ||
836 | start_lttng_relayd "-o $TRACE_PATH" | |
837 | start_lttng_sessiond | |
838 | ||
839 | # Per-UID buffers | |
840 | ||
841 | # Clear with tracing active, clear once | |
842 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; | |
843 | do | |
844 | SESSION_NAME=$(randstring 16 0) | |
845 | ${fct_test} 1 0 0 0 uid | |
846 | clean_path $TRACE_PATH | |
847 | done | |
848 | ||
849 | # Clear with tracing active, clear twice | |
850 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; | |
851 | do | |
852 | SESSION_NAME=$(randstring 16 0) | |
853 | ${fct_test} 1 1 0 0 uid | |
854 | clean_path $TRACE_PATH | |
855 | done | |
856 | ||
857 | # Clear with tracing inactive, clear once | |
858 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; | |
859 | do | |
860 | SESSION_NAME=$(randstring 16 0) | |
861 | ${fct_test} 0 0 0 0 uid | |
862 | clean_path $TRACE_PATH | |
863 | done | |
864 | ||
865 | # Clear with tracing inactive, clear twice | |
866 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]}; | |
867 | do | |
868 | SESSION_NAME=$(randstring 16 0) | |
869 | ${fct_test} 0 1 0 0 uid | |
870 | clean_path $TRACE_PATH | |
871 | done | |
872 | ||
873 | # Clear with tracing inactive, rotate-clear once | |
874 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; | |
875 | do | |
876 | SESSION_NAME=$(randstring 16 0) | |
877 | ${fct_test} 0 0 1 0 uid | |
878 | clean_path $TRACE_PATH | |
879 | done | |
880 | ||
881 | # Clear with tracing inactive, clear once-rotate(fail) | |
882 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; | |
883 | do | |
884 | SESSION_NAME=$(randstring 16 0) | |
885 | ${fct_test} 0 0 0 1 uid | |
886 | clean_path $TRACE_PATH | |
887 | done | |
888 | ||
889 | ||
890 | # Per-PID buffers. | |
891 | ||
892 | # Clear with tracing active, clear once | |
893 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; | |
894 | do | |
895 | SESSION_NAME=$(randstring 16 0) | |
896 | ${fct_test} 1 0 0 0 pid | |
897 | clean_path $TRACE_PATH | |
898 | done | |
899 | ||
900 | # Clear with tracing active, clear twice | |
901 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; | |
902 | do | |
903 | SESSION_NAME=$(randstring 16 0) | |
904 | ${fct_test} 1 1 0 0 pid | |
905 | clean_path $TRACE_PATH | |
906 | done | |
907 | ||
908 | # Clear with tracing inactive, clear once | |
909 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; | |
910 | do | |
911 | SESSION_NAME=$(randstring 16 0) | |
912 | ${fct_test} 0 0 0 0 pid | |
913 | clean_path $TRACE_PATH | |
914 | done | |
915 | ||
916 | # Clear with tracing inactive, clear twice | |
917 | for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]}; | |
918 | do | |
919 | SESSION_NAME=$(randstring 16 0) | |
920 | ${fct_test} 0 1 0 0 pid | |
921 | clean_path $TRACE_PATH | |
922 | done | |
923 | ||
924 | # Clear with tracing inactive, rotate-clear once | |
925 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; | |
926 | do | |
927 | SESSION_NAME=$(randstring 16 0) | |
928 | ${fct_test} 0 0 1 0 pid | |
929 | clean_path $TRACE_PATH | |
930 | done | |
931 | ||
932 | # Clear with tracing inactive, clear once-rotate(fail) | |
933 | for fct_test in ${streaming_tests[@]} ${local_tests[@]}; | |
934 | do | |
935 | SESSION_NAME=$(randstring 16 0) | |
936 | ${fct_test} 0 0 0 1 pid | |
937 | clean_path $TRACE_PATH | |
938 | done | |
939 | ||
940 | stop_lttng_sessiond | |
941 | stop_lttng_relayd | |
942 | ||
943 | test_ust_disallow_clear |