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