Fix: Tests that assume CPU 0 is present
[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 -d -t tmp.test_clear_ust_trace_path.XXXXXX)
23
24 # shellcheck source=../utils/utils.sh
25 source "$TESTDIR/utils/utils.sh"
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
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
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
229 if [[ "$buffer_type" == "uid" ]]; then
230 validate_trace_empty $local_path
231 else # pid
232 validate_directory_empty $local_path
233 fi
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 -t tmp.test_${FUNCNAME[0]}_bt_output_path.XXXXXX)
249 local file_sync_before_exit=$(mktemp -u -t tmp.test_${FUNCNAME[0]}_sync_before_exit.XXXXXX)
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
279 diag "Waiting for application to exit"
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 -u -t tmp.test_${FUNCNAME[0]}_bt_output_path.XXXXXX)
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
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
340 local bt_output_path=$(mktemp -t "tmp.${FUNCNAME[0]}_bt_output.XXXXXX")
341 local bt_error_path=$(mktemp -t "tmp.${FUNCNAME[0]}_bt_error.XXXXXX")
342 local file_sync_before_exit=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit.XXXXXX")
343
344 diag "Test ust streaming live clear with viewer with new metadata after clear"
345 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
346 create_lttng_session_uri "$SESSION_NAME" net://localhost "--live"
347 enable_ust_lttng_channel_ok "$SESSION_NAME" $channel_name "--buffers-$buffer_type"
348
349 # The vpid context is added to filter events based on the vpid of the
350 # test application as state dump events are used. Regenerating a
351 # state dump will cause other instrumented application on the system
352 # to trigger a state dump which would throw off checks that rely on an
353 # event count.
354 add_context_ust_ok "$SESSION_NAME" $channel_name "vpid"
355 enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $channel_name
356 start_lttng_tracing_ok "$SESSION_NAME"
357
358 wait_live_trace_ready net://localhost
359
360 # Connect a live viewer
361 $BABELTRACE_BIN -i lttng-live "net://localhost/host/$remote_trace_path" 1> "$bt_output_path" 2> "$bt_error_path" &
362 local viewer_pid=$!
363
364 wait_live_viewer_connect net://localhost
365
366 $TESTAPP_BIN -i 10 --sync-before-exit "$file_sync_before_exit" &
367 local app_pid=$!
368
369 diag "Wait until viewer sees all 10 expected events"
370 local evcount=0
371 while [ $evcount -ne 10 ]; do
372 evcount=$(wc -l < "$bt_output_path")
373 sleep 0.5
374 done
375 pass "Live viewer read $evcount events, expect 10"
376
377 do_clear_session "$SESSION_NAME" "$tracing_active" "$clear_twice" 0 0
378
379 # Enable new events which will add their descriptions to the metadata
380 # file. This validates that, following a clear, the relay daemon rotates
381 # the metadata viewer stream to the new metadata file.
382 enable_ust_lttng_event_filter "$SESSION_NAME" $EVENT_STATE_DUMP_START "\$ctx.vpid == $app_pid" $channel_name
383 enable_ust_lttng_event_filter "$SESSION_NAME" $EVENT_STATE_DUMP_END "\$ctx.vpid == $app_pid" $channel_name
384
385 # Forcing a state dump to produce the two events enabled above
386 regenerate_statedump_ok "$SESSION_NAME"
387
388 diag "Wait until viewer sees all 12 expected events"
389 local evcount=0
390 while [ $evcount -ne 12 ]; do
391 evcount=$(wc -l < "$bt_output_path")
392 sleep 0.5
393 done
394 pass "Live viewer read $evcount events, expect 12"
395
396 stop_lttng_tracing_ok "$SESSION_NAME"
397
398 destroy_lttng_session_ok "$SESSION_NAME"
399
400 touch "$file_sync_before_exit"
401 diag "Waiting for application to exit"
402 wait $app_pid
403 pass "Wait for application to exit"
404
405 diag "Wait for viewer to exit"
406 wait $viewer_pid
407 ok $? "Babeltrace succeeds"
408 pass "Wait for viewer to exit"
409
410 clean_path "$bt_output_path"
411 clean_path "$bt_error_path"
412 rm -f "$file_sync_before_exit"
413 }
414
415 function test_ust_local ()
416 {
417 local tracing_active=$1
418 local clear_twice=$2
419 local rotate_before=$3
420 local rotate_after=$4
421 local buffer_type=$5
422 local channel_name="chan"
423
424 diag "Test ust local"
425 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
426 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
427 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
428 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
429 start_lttng_tracing_ok $SESSION_NAME
430 $TESTAPP_BIN -i 10
431 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
432 stop_lttng_tracing_ok $SESSION_NAME
433
434 if [[ $rotate_before -eq 1 ]]; then
435 validate_trace_count $EVENT_NAME $TRACE_PATH 10
436 else
437 if [[ "$buffer_type" == "uid" ]]; then
438 validate_trace_empty $TRACE_PATH
439 else # pid
440
441 # The sessiond always created a `ust/ directory
442 # whenever the UST domain is active
443 validate_directory_empty $TRACE_PATH/ust/
444 fi
445 fi
446
447 destroy_lttng_session_ok $SESSION_NAME
448 }
449
450 function test_ust_local_no_event ()
451 {
452 local tracing_active=$1
453 local clear_twice=$2
454 #local rotate_before=$3 ignored
455 #local rotate_after=$4 ignored
456 local buffer_type=$5
457 local channel_name="chan"
458
459 diag "Test ust local no event"
460 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
461 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
462 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name "--buffers-$buffer_type"
463 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
464 start_lttng_tracing_ok $SESSION_NAME
465
466 do_clear_session $SESSION_NAME "$tracing_active" "$clear_twice" "$rotate_before" "$rotate_after"
467 stop_lttng_tracing_ok $SESSION_NAME
468
469 validate_directory_empty "$TRACE_PATH"
470
471 destroy_lttng_session_ok $SESSION_NAME
472 }
473
474 function test_ust_local_rotate_clear ()
475 {
476 local tracing_active=$1
477 local clear_twice=$2
478 local rotate_before=$3
479 local rotate_after=$4
480 local buffer_type=$5
481 local channel_name="chan"
482
483 diag "Test ust local rotate-clear"
484 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
485 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
486 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
487 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
488 start_lttng_tracing_ok $SESSION_NAME
489 $TESTAPP_BIN -i 1
490 rotate_session_ok $SESSION_NAME
491 $TESTAPP_BIN -i 2
492 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
493 $TESTAPP_BIN -i 3
494 stop_lttng_tracing_ok $SESSION_NAME
495
496 if [[ $rotate_before -eq 1 ]]; then
497 local expect_count=6
498 else
499 local expect_count=4
500 fi
501 validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count
502
503 destroy_lttng_session_ok $SESSION_NAME
504 }
505
506 function test_ust_local_clear_rotate ()
507 {
508 local tracing_active=$1
509 local clear_twice=$2
510 local rotate_before=$3
511 local rotate_after=$4
512 local buffer_type=$5
513 local channel_name="chan"
514
515 diag "Test ust local clear-rotate"
516 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
517 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
518 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
519 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
520 start_lttng_tracing_ok $SESSION_NAME
521 $TESTAPP_BIN -i 1
522 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
523 $TESTAPP_BIN -i 2
524 rotate_session_ok $SESSION_NAME
525 $TESTAPP_BIN -i 3
526 stop_lttng_tracing_ok $SESSION_NAME
527
528 if [[ $rotate_before -eq 1 ]]; then
529 local expect_count=6
530 else
531 local expect_count=5
532 fi
533 validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count
534
535 destroy_lttng_session_ok $SESSION_NAME
536 }
537
538 function do_ust_snapshot ()
539 {
540 local session_name=$1
541 local trace_path=$2
542 local tracing_active=$3
543 local clear_twice=$4
544 local buffer_type=$5
545 local channel_name="snapshot"
546
547 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
548 enable_ust_lttng_event_ok $session_name $EVENT_NAME $channel_name
549 start_lttng_tracing_ok $session_name
550
551 # Generate 10 events that will sit in the buffers.
552 $TESTAPP_BIN -i 10
553
554 # Take a first snapshot and validate that the events are present.
555 lttng_snapshot_record $session_name
556 stop_lttng_tracing_ok $session_name
557 validate_trace_count $EVENT_NAME $trace_path 10
558
559 # Clean the output path
560 clean_path $trace_path
561 start_lttng_tracing_ok $session_name
562
563 do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0
564
565 # Make sure the subsequent snapshot is empty and valid.
566 lttng_snapshot_record $session_name
567 stop_lttng_tracing_ok $session_name
568 validate_trace_empty $trace_path
569
570 # Clean the output path
571 clean_path $trace_path
572 start_lttng_tracing_ok $session_name
573
574 # Make sure that everything still works, generate events and take a
575 # snapshot.
576 $TESTAPP_BIN -i 10
577 lttng_snapshot_record $session_name
578 stop_lttng_tracing_ok $session_name
579 validate_trace_count $EVENT_NAME $trace_path 10
580 }
581
582 function test_ust_streaming_snapshot ()
583 {
584 local tracing_active=$1
585 local clear_twice=$2
586 # 3, 4 unused.
587 local buffer_type=$5
588
589 diag "Test ust streaming snapshot clear"
590 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
591
592 create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot"
593 do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type
594 destroy_lttng_session_ok $SESSION_NAME
595 }
596
597 function test_ust_local_snapshot ()
598 {
599 local tracing_active=$1
600 local clear_twice=$2
601 # 3, 4 unused.
602 local buffer_type=$5
603
604 diag "Test ust local snapshot clear"
605 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
606
607 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
608 do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type
609 destroy_lttng_session_ok $SESSION_NAME
610 }
611
612 # snapshot for per-pid is tested independently of the "buffer type" parameter
613 # because an application needs to be live to appear in a snapshot.
614 function test_ust_local_snapshot_per_pid ()
615 {
616 local tracing_active=$1
617 local clear_twice=$2
618 # 3, 4 unused.
619 local buffer_type=$5
620 local channel_name="channel0"
621 local file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
622 local file_sync_before_last_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last_touch.XXXXXX")
623 local file_sync_before_exit=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit.XXXXXX")
624 local file_sync_before_exit_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX")
625
626 diag "Test ust local snapshot clear per pid"
627 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
628
629 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
630 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
631 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
632 start_lttng_tracing_ok $SESSION_NAME
633
634 # Generate 10 events that will sit in the buffers.
635 $TESTAPP_BIN -i 10 -w 0 \
636 --sync-before-last-event ${file_sync_before_last} \
637 --sync-before-last-event-touch ${file_sync_before_last_touch} \
638 --sync-before-exit ${file_sync_before_exit} \
639 --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev/null 2>&1 &
640
641 # Continue only when there is only the last event remaining.
642 while [ ! -f "${file_sync_before_last_touch}" ]; do
643 sleep 0.5
644 done
645
646 # Take a first snapshot and validate that the events are present.
647 lttng_snapshot_record $SESSION_NAME
648 stop_lttng_tracing_ok $SESSION_NAME
649 validate_trace_count $EVENT_NAME $TRACE_PATH 9
650
651 # Clean the output path
652 clean_path $TRACE_PATH
653 start_lttng_tracing_ok $SESSION_NAME
654
655 do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0
656
657 # Make sure the subsequent snapshot is empty and valid.
658 lttng_snapshot_record $SESSION_NAME
659 stop_lttng_tracing_ok $SESSION_NAME
660 validate_trace_empty $TRACE_PATH
661
662 # Validate that tracing still works and subsequent snapshots are valid.
663 # Clean the output path.
664 clean_path $TRACE_PATH
665 start_lttng_tracing_ok $SESSION_NAME
666
667 # Continue over the last event.
668 touch ${file_sync_before_last}
669
670 # Wait for the before exit sync point. This ensure that we went over the
671 # last tracepoint.
672 while [ ! -f "${file_sync_before_exit_touch}" ]; do
673 sleep 0.5
674 done
675
676 # Make sure the snapshot contains the last event.
677 lttng_snapshot_record $SESSION_NAME
678 stop_lttng_tracing_ok $SESSION_NAME
679 validate_trace_count $EVENT_NAME $TRACE_PATH 1
680
681 # Release the application.
682 touch ${file_sync_before_exit}
683 wait
684 destroy_lttng_session_ok $SESSION_NAME
685
686 rm -f ${file_sync_before_last}
687 rm -f ${file_sync_before_last_touch}
688 rm -f ${file_sync_before_exit}
689 rm -f ${file_sync_before_exit_touch}
690 }
691
692 function test_ust_streaming_tracefile_rotation ()
693 {
694 local tracing_active=$1
695 local clear_twice=$2
696 local rotate_before=$3
697 local rotate_after=$4
698 local buffer_type=$5
699 local channel_name="rotchan"
700 local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
701
702 diag "Test ust streaming clear with tracefile rotation"
703 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
704 create_lttng_session_uri $SESSION_NAME net://localhost
705 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
706 --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type
707 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
708 start_lttng_tracing_ok $SESSION_NAME
709 $TESTAPP_BIN -i 10
710 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
711 stop_lttng_tracing_ok $SESSION_NAME
712
713 if [[ $rotate_before -eq 1 ]]; then
714 validate_trace_count $EVENT_NAME $local_path 10
715 else
716 if [[ "$buffer_type" == "uid" ]]; then
717 validate_trace_empty $local_path
718 else # pid
719 validate_directory_empty $local_path
720 fi
721 fi
722
723 start_lttng_tracing_ok $SESSION_NAME
724 $TESTAPP_BIN -i 20
725 stop_lttng_tracing_ok
726
727 if [[ $rotate_before -eq 1 ]]; then
728 validate_trace_count $EVENT_NAME $local_path 30
729 else
730 validate_trace_count $EVENT_NAME $local_path 20
731 fi
732
733 destroy_lttng_session_ok $SESSION_NAME
734 }
735
736 # With 1 byte per event (as strict minimum), generating 200000 events
737 # guarantees filling up 2 files of 64k in size, which is the maximum
738 # page size known on Linux
739 function test_ust_streaming_tracefile_rotation_overwrite_files ()
740 {
741 local tracing_active=$1
742 local clear_twice=$2
743 local rotate_before=$3
744 local rotate_after=$4
745 local buffer_type=$5
746 local channel_name="rotchan"
747 local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
748
749 diag "Test ust streaming clear with tracefile rotation, overwrite files"
750 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
751 create_lttng_session_uri $SESSION_NAME net://localhost
752 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
753 --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type
754 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
755 start_lttng_tracing_ok $SESSION_NAME
756 taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i 200000
757 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
758 stop_lttng_tracing_ok $SESSION_NAME
759
760 if [[ $rotate_before -eq 1 ]]; then
761 validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000
762 else
763 if [[ "$buffer_type" == "uid" ]]; then
764 validate_trace_empty $local_path
765 else # pid
766 validate_directory_empty $local_path
767 fi
768 fi
769
770 start_lttng_tracing_ok $SESSION_NAME
771 taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i 400000
772 stop_lttng_tracing_ok
773
774 if [[ $rotate_before -eq 1 ]]; then
775 validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 600000
776 else
777 validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000
778 fi
779
780 destroy_lttng_session_ok $SESSION_NAME
781 }
782
783 function test_ust_disallow_clear ()
784 {
785 diag "Test ust disallow clear on relay daemon"
786 SESSION_NAME=$(randstring 16 0)
787
788 LTTNG_RELAYD_DISALLOW_CLEAR=1 start_lttng_relayd "-o $TRACE_PATH"
789
790 start_lttng_sessiond
791
792 create_lttng_session_uri $SESSION_NAME net://localhost
793 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
794 start_lttng_tracing_ok $SESSION_NAME
795 lttng_clear_session_fail $SESSION_NAME
796 destroy_lttng_session_ok $SESSION_NAME
797
798 stop_lttng_sessiond
799 stop_lttng_relayd
800 clean_path $TRACE_PATH
801 }
802
803 plan_tests $NUM_TESTS
804
805 print_test_banner "$TEST_DESC"
806
807 bail_out_if_no_babeltrace
808
809 streaming_tests=(test_ust_streaming
810 test_ust_streaming_rotate_clear
811 test_ust_streaming_clear_rotate
812 test_ust_streaming_tracefile_rotation
813 test_ust_streaming_tracefile_rotation_overwrite_files
814 test_ust_streaming_no_event
815 )
816
817 live_tests=(test_ust_streaming_live
818 test_ust_basic_streaming_live_viewer
819 test_ust_streaming_live_viewer
820 test_ust_streaming_live_viewer_new_metadata_after_clear
821 )
822
823 local_tests=(test_ust_local
824 test_ust_local_rotate_clear
825 test_ust_local_clear_rotate
826 test_ust_local_no_event
827 )
828
829 snapshot_uid_tests=(test_ust_streaming_snapshot
830 test_ust_local_snapshot
831 )
832
833 snapshot_pid_tests=(test_ust_local_snapshot_per_pid)
834
835 start_lttng_relayd "-o $TRACE_PATH"
836 start_lttng_sessiond
837
838 # Per-UID buffers
839
840 # Clear with tracing active, clear once
841 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
842 do
843 SESSION_NAME=$(randstring 16 0)
844 ${fct_test} 1 0 0 0 uid
845 clean_path $TRACE_PATH
846 done
847
848 # Clear with tracing active, clear twice
849 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
850 do
851 SESSION_NAME=$(randstring 16 0)
852 ${fct_test} 1 1 0 0 uid
853 clean_path $TRACE_PATH
854 done
855
856 # Clear with tracing inactive, clear once
857 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
858 do
859 SESSION_NAME=$(randstring 16 0)
860 ${fct_test} 0 0 0 0 uid
861 clean_path $TRACE_PATH
862 done
863
864 # Clear with tracing inactive, clear twice
865 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
866 do
867 SESSION_NAME=$(randstring 16 0)
868 ${fct_test} 0 1 0 0 uid
869 clean_path $TRACE_PATH
870 done
871
872 # Clear with tracing inactive, rotate-clear once
873 for fct_test in ${streaming_tests[@]} ${local_tests[@]};
874 do
875 SESSION_NAME=$(randstring 16 0)
876 ${fct_test} 0 0 1 0 uid
877 clean_path $TRACE_PATH
878 done
879
880 # Clear with tracing inactive, clear once-rotate(fail)
881 for fct_test in ${streaming_tests[@]} ${local_tests[@]};
882 do
883 SESSION_NAME=$(randstring 16 0)
884 ${fct_test} 0 0 0 1 uid
885 clean_path $TRACE_PATH
886 done
887
888
889 # Per-PID buffers.
890
891 # Clear with tracing active, clear once
892 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
893 do
894 SESSION_NAME=$(randstring 16 0)
895 ${fct_test} 1 0 0 0 pid
896 clean_path $TRACE_PATH
897 done
898
899 # Clear with tracing active, clear twice
900 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
901 do
902 SESSION_NAME=$(randstring 16 0)
903 ${fct_test} 1 1 0 0 pid
904 clean_path $TRACE_PATH
905 done
906
907 # Clear with tracing inactive, clear once
908 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
909 do
910 SESSION_NAME=$(randstring 16 0)
911 ${fct_test} 0 0 0 0 pid
912 clean_path $TRACE_PATH
913 done
914
915 # Clear with tracing inactive, clear twice
916 for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
917 do
918 SESSION_NAME=$(randstring 16 0)
919 ${fct_test} 0 1 0 0 pid
920 clean_path $TRACE_PATH
921 done
922
923 # Clear with tracing inactive, rotate-clear once
924 for fct_test in ${streaming_tests[@]} ${local_tests[@]};
925 do
926 SESSION_NAME=$(randstring 16 0)
927 ${fct_test} 0 0 1 0 pid
928 clean_path $TRACE_PATH
929 done
930
931 # Clear with tracing inactive, clear once-rotate(fail)
932 for fct_test in ${streaming_tests[@]} ${local_tests[@]};
933 do
934 SESSION_NAME=$(randstring 16 0)
935 ${fct_test} 0 0 0 1 pid
936 clean_path $TRACE_PATH
937 done
938
939 stop_lttng_sessiond
940 stop_lttng_relayd
941
942 test_ust_disallow_clear
943
944 rm -rf "$TRACE_PATH"
This page took 0.049157 seconds and 4 git commands to generate.