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