Tests: clear: remove test workspace directory
[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)
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 -u)
248 local file_sync_before_exit=$(mktemp -u)
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 -d)/bt-output.txt
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 local bt_output_path
339 local bt_error_path
340 local file_sync_before_exit
341
342 bt_output_path=$(mktemp -d)/bt-output.txt
343 bt_error_path=$(mktemp -d)/bt-output.err
344 file_sync_before_exit=$(mktemp -u)
345
346 diag "Test ust streaming live clear with viewer with new metadata after clear"
347 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
348 create_lttng_session_uri "$SESSION_NAME" net://localhost "--live"
349 enable_ust_lttng_channel_ok "$SESSION_NAME" $channel_name "--buffers-$buffer_type"
350
351 # The vpid context is added to filter events based on the vpid of the
352 # test application as state dump events are used. Regenerating a
353 # state dump will cause other instrumented application on the system
354 # to trigger a state dump which would throw off checks that rely on an
355 # event count.
356 add_context_ust_ok "$SESSION_NAME" $channel_name "vpid"
357 enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $channel_name
358 start_lttng_tracing_ok "$SESSION_NAME"
359
360 wait_live_trace_ready net://localhost
361
362 # Connect a live viewer
363 $BABELTRACE_BIN -i lttng-live "net://localhost/host/$remote_trace_path" 1> "$bt_output_path" 2> "$bt_error_path" &
364 local viewer_pid=$!
365
366 wait_live_viewer_connect net://localhost
367
368 $TESTAPP_BIN -i 10 --sync-before-exit "$file_sync_before_exit" &
369 local app_pid=$!
370
371 diag "Wait until viewer sees all 10 expected events"
372 local evcount=0
373 while [ $evcount -ne 10 ]; do
374 evcount=$(wc -l < "$bt_output_path")
375 sleep 0.5
376 done
377 pass "Live viewer read $evcount events, expect 10"
378
379 do_clear_session "$SESSION_NAME" "$tracing_active" "$clear_twice" 0 0
380
381 # Enable new events which will add their descriptions to the metadata
382 # file. This validates that, following a clear, the relay daemon rotates
383 # the metadata viewer stream to the new metadata file.
384 enable_ust_lttng_event_filter "$SESSION_NAME" $EVENT_STATE_DUMP_START "\$ctx.vpid == $app_pid" $channel_name
385 enable_ust_lttng_event_filter "$SESSION_NAME" $EVENT_STATE_DUMP_END "\$ctx.vpid == $app_pid" $channel_name
386
387 # Forcing a state dump to produce the two events enabled above
388 regenerate_statedump_ok "$SESSION_NAME"
389
390 diag "Wait until viewer sees all 12 expected events"
391 local evcount=0
392 while [ $evcount -ne 12 ]; do
393 evcount=$(wc -l < "$bt_output_path")
394 sleep 0.5
395 done
396 pass "Live viewer read $evcount events, expect 12"
397
398 stop_lttng_tracing_ok "$SESSION_NAME"
399
400 destroy_lttng_session_ok "$SESSION_NAME"
401
402 touch "$file_sync_before_exit"
403 diag "Waiting for application to exit"
404 wait $app_pid
405 pass "Wait for application to exit"
406
407 diag "Wait for viewer to exit"
408 wait $viewer_pid
409 ok $? "Babeltrace succeeds"
410 pass "Wait for viewer to exit"
411
412 clean_path "$bt_output_path"
413 clean_path "$bt_error_path"
414 }
415
416 function test_ust_local ()
417 {
418 local tracing_active=$1
419 local clear_twice=$2
420 local rotate_before=$3
421 local rotate_after=$4
422 local buffer_type=$5
423 local channel_name="chan"
424
425 diag "Test ust local"
426 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
427 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
428 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
429 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
430 start_lttng_tracing_ok $SESSION_NAME
431 $TESTAPP_BIN -i 10
432 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
433 stop_lttng_tracing_ok $SESSION_NAME
434
435 if [[ $rotate_before -eq 1 ]]; then
436 validate_trace_count $EVENT_NAME $TRACE_PATH 10
437 else
438 if [[ "$buffer_type" == "uid" ]]; then
439 validate_trace_empty $TRACE_PATH
440 else # pid
441
442 # The sessiond always created a `ust/ directory
443 # whenever the UST domain is active
444 validate_directory_empty $TRACE_PATH/ust/
445 fi
446 fi
447
448 destroy_lttng_session_ok $SESSION_NAME
449 }
450
451 function test_ust_local_no_event ()
452 {
453 local tracing_active=$1
454 local clear_twice=$2
455 #local rotate_before=$3 ignored
456 #local rotate_after=$4 ignored
457 local buffer_type=$5
458 local channel_name="chan"
459
460 diag "Test ust local no event"
461 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
462 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
463 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name "--buffers-$buffer_type"
464 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
465 start_lttng_tracing_ok $SESSION_NAME
466
467 do_clear_session $SESSION_NAME "$tracing_active" "$clear_twice" "$rotate_before" "$rotate_after"
468 stop_lttng_tracing_ok $SESSION_NAME
469
470 validate_directory_empty "$TRACE_PATH"
471
472 destroy_lttng_session_ok $SESSION_NAME
473 }
474
475 function test_ust_local_rotate_clear ()
476 {
477 local tracing_active=$1
478 local clear_twice=$2
479 local rotate_before=$3
480 local rotate_after=$4
481 local buffer_type=$5
482 local channel_name="chan"
483
484 diag "Test ust local rotate-clear"
485 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
486 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
487 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
488 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
489 start_lttng_tracing_ok $SESSION_NAME
490 $TESTAPP_BIN -i 1
491 rotate_session_ok $SESSION_NAME
492 $TESTAPP_BIN -i 2
493 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
494 $TESTAPP_BIN -i 3
495 stop_lttng_tracing_ok $SESSION_NAME
496
497 if [[ $rotate_before -eq 1 ]]; then
498 local expect_count=6
499 else
500 local expect_count=4
501 fi
502 validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count
503
504 destroy_lttng_session_ok $SESSION_NAME
505 }
506
507 function test_ust_local_clear_rotate ()
508 {
509 local tracing_active=$1
510 local clear_twice=$2
511 local rotate_before=$3
512 local rotate_after=$4
513 local buffer_type=$5
514 local channel_name="chan"
515
516 diag "Test ust local clear-rotate"
517 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
518 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
519 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
520 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
521 start_lttng_tracing_ok $SESSION_NAME
522 $TESTAPP_BIN -i 1
523 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
524 $TESTAPP_BIN -i 2
525 rotate_session_ok $SESSION_NAME
526 $TESTAPP_BIN -i 3
527 stop_lttng_tracing_ok $SESSION_NAME
528
529 if [[ $rotate_before -eq 1 ]]; then
530 local expect_count=6
531 else
532 local expect_count=5
533 fi
534 validate_trace_count $EVENT_NAME $TRACE_PATH $expect_count
535
536 destroy_lttng_session_ok $SESSION_NAME
537 }
538
539 function do_ust_snapshot ()
540 {
541 local session_name=$1
542 local trace_path=$2
543 local tracing_active=$3
544 local clear_twice=$4
545 local buffer_type=$5
546 local channel_name="snapshot"
547
548 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
549 enable_ust_lttng_event_ok $session_name $EVENT_NAME $channel_name
550 start_lttng_tracing_ok $session_name
551
552 # Generate 10 events that will sit in the buffers.
553 $TESTAPP_BIN -i 10
554
555 # Take a first snapshot and validate that the events are present.
556 lttng_snapshot_record $session_name
557 stop_lttng_tracing_ok $session_name
558 validate_trace_count $EVENT_NAME $trace_path 10
559
560 # Clean the output path
561 clean_path $trace_path
562 start_lttng_tracing_ok $session_name
563
564 do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0
565
566 # Make sure the subsequent snapshot is empty and valid.
567 lttng_snapshot_record $session_name
568 stop_lttng_tracing_ok $session_name
569 validate_trace_empty $trace_path
570
571 # Clean the output path
572 clean_path $trace_path
573 start_lttng_tracing_ok $session_name
574
575 # Make sure that everything still works, generate events and take a
576 # snapshot.
577 $TESTAPP_BIN -i 10
578 lttng_snapshot_record $session_name
579 stop_lttng_tracing_ok $session_name
580 validate_trace_count $EVENT_NAME $trace_path 10
581 }
582
583 function test_ust_streaming_snapshot ()
584 {
585 local tracing_active=$1
586 local clear_twice=$2
587 # 3, 4 unused.
588 local buffer_type=$5
589
590 diag "Test ust streaming snapshot clear"
591 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
592
593 create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot"
594 do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type
595 destroy_lttng_session_ok $SESSION_NAME
596 }
597
598 function test_ust_local_snapshot ()
599 {
600 local tracing_active=$1
601 local clear_twice=$2
602 # 3, 4 unused.
603 local buffer_type=$5
604
605 diag "Test ust local snapshot clear"
606 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
607
608 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
609 do_ust_snapshot $SESSION_NAME $TRACE_PATH $tracing_active $clear_twice $buffer_type
610 destroy_lttng_session_ok $SESSION_NAME
611 }
612
613 # snapshot for per-pid is tested independently of the "buffer type" parameter
614 # because an application needs to be live to appear in a snapshot.
615 function test_ust_local_snapshot_per_pid ()
616 {
617 local tracing_active=$1
618 local clear_twice=$2
619 # 3, 4 unused.
620 local buffer_type=$5
621 local channel_name="channel0"
622 local file_sync_before_last=$(mktemp -u)
623 local file_sync_before_last_touch=$(mktemp -u)
624 local file_sync_before_exit=$(mktemp -u)
625 local file_sync_before_exit_touch=$(mktemp -u)
626
627 diag "Test ust local snapshot clear per pid"
628 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, buffer_type=$buffer_type"
629
630 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
631 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-$buffer_type
632 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
633 start_lttng_tracing_ok $SESSION_NAME
634
635 # Generate 10 events that will sit in the buffers.
636 $TESTAPP_BIN -i 10 -w 0 \
637 --sync-before-last-event ${file_sync_before_last} \
638 --sync-before-last-event-touch ${file_sync_before_last_touch} \
639 --sync-before-exit ${file_sync_before_exit} \
640 --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev/null 2>&1 &
641
642 # Continue only when there is only the last event remaining.
643 while [ ! -f "${file_sync_before_last_touch}" ]; do
644 sleep 0.5
645 done
646
647 # Take a first snapshot and validate that the events are present.
648 lttng_snapshot_record $SESSION_NAME
649 stop_lttng_tracing_ok $SESSION_NAME
650 validate_trace_count $EVENT_NAME $TRACE_PATH 9
651
652 # Clean the output path
653 clean_path $TRACE_PATH
654 start_lttng_tracing_ok $SESSION_NAME
655
656 do_clear_session $SESSION_NAME $tracing_active $clear_twice 0 0
657
658 # Make sure the subsequent snapshot is empty and valid.
659 lttng_snapshot_record $SESSION_NAME
660 stop_lttng_tracing_ok $SESSION_NAME
661 validate_trace_empty $TRACE_PATH
662
663 # Validate that tracing still works and subsequent snapshots are valid.
664 # Clean the output path.
665 clean_path $TRACE_PATH
666 start_lttng_tracing_ok $SESSION_NAME
667
668 # Continue over the last event.
669 touch ${file_sync_before_last}
670
671 # Wait for the before exit sync point. This ensure that we went over the
672 # last tracepoint.
673 while [ ! -f "${file_sync_before_exit_touch}" ]; do
674 sleep 0.5
675 done
676
677 # Make sure the snapshot contains the last event.
678 lttng_snapshot_record $SESSION_NAME
679 stop_lttng_tracing_ok $SESSION_NAME
680 validate_trace_count $EVENT_NAME $TRACE_PATH 1
681
682 # Release the application.
683 touch ${file_sync_before_exit}
684 wait
685 destroy_lttng_session_ok $SESSION_NAME
686
687 rm -f ${file_sync_before_last}
688 rm -f ${file_sync_before_last_touch}
689 rm -f ${file_sync_before_exit}
690 rm -f ${file_sync_before_exit_touch}
691 }
692
693 function test_ust_streaming_tracefile_rotation ()
694 {
695 local tracing_active=$1
696 local clear_twice=$2
697 local rotate_before=$3
698 local rotate_after=$4
699 local buffer_type=$5
700 local channel_name="rotchan"
701 local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
702
703 diag "Test ust streaming clear with tracefile rotation"
704 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
705 create_lttng_session_uri $SESSION_NAME net://localhost
706 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
707 --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type
708 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
709 start_lttng_tracing_ok $SESSION_NAME
710 $TESTAPP_BIN -i 10
711 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
712 stop_lttng_tracing_ok $SESSION_NAME
713
714 if [[ $rotate_before -eq 1 ]]; then
715 validate_trace_count $EVENT_NAME $local_path 10
716 else
717 if [[ "$buffer_type" == "uid" ]]; then
718 validate_trace_empty $local_path
719 else # pid
720 validate_directory_empty $local_path
721 fi
722 fi
723
724 start_lttng_tracing_ok $SESSION_NAME
725 $TESTAPP_BIN -i 20
726 stop_lttng_tracing_ok
727
728 if [[ $rotate_before -eq 1 ]]; then
729 validate_trace_count $EVENT_NAME $local_path 30
730 else
731 validate_trace_count $EVENT_NAME $local_path 20
732 fi
733
734 destroy_lttng_session_ok $SESSION_NAME
735 }
736
737 # With 1 byte per event (as strict minimum), generating 200000 events
738 # guarantees filling up 2 files of 64k in size, which is the maximum
739 # page size known on Linux
740 function test_ust_streaming_tracefile_rotation_overwrite_files ()
741 {
742 local tracing_active=$1
743 local clear_twice=$2
744 local rotate_before=$3
745 local rotate_after=$4
746 local buffer_type=$5
747 local channel_name="rotchan"
748 local local_path="${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*"
749
750 diag "Test ust streaming clear with tracefile rotation, overwrite files"
751 diag "Parameters: tracing_active=$tracing_active, clear_twice=$clear_twice, rotate_before=$rotate_before, rotate_after=$rotate_after, buffer_type=$buffer_type"
752 create_lttng_session_uri $SESSION_NAME net://localhost
753 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --subbuf-size=$PAGE_SIZE \
754 --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type
755 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
756 start_lttng_tracing_ok $SESSION_NAME
757 taskset -c 0 $TESTAPP_BIN -i 200000
758 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after
759 stop_lttng_tracing_ok $SESSION_NAME
760
761 if [[ $rotate_before -eq 1 ]]; then
762 validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000
763 else
764 if [[ "$buffer_type" == "uid" ]]; then
765 validate_trace_empty $local_path
766 else # pid
767 validate_directory_empty $local_path
768 fi
769 fi
770
771 start_lttng_tracing_ok $SESSION_NAME
772 taskset -c 0 $TESTAPP_BIN -i 400000
773 stop_lttng_tracing_ok
774
775 if [[ $rotate_before -eq 1 ]]; then
776 validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 600000
777 else
778 validate_trace_count_range_incl_min_excl_max $EVENT_NAME $local_path 1 200000
779 fi
780
781 destroy_lttng_session_ok $SESSION_NAME
782 }
783
784 function test_ust_disallow_clear ()
785 {
786 diag "Test ust disallow clear on relay daemon"
787 SESSION_NAME=$(randstring 16 0)
788
789 LTTNG_RELAYD_DISALLOW_CLEAR=1 start_lttng_relayd "-o $TRACE_PATH"
790
791 start_lttng_sessiond
792
793 create_lttng_session_uri $SESSION_NAME net://localhost
794 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
795 start_lttng_tracing_ok $SESSION_NAME
796 lttng_clear_session_fail $SESSION_NAME
797 destroy_lttng_session_ok $SESSION_NAME
798
799 stop_lttng_sessiond
800 stop_lttng_relayd
801 clean_path $TRACE_PATH
802 }
803
804 plan_tests $NUM_TESTS
805
806 print_test_banner "$TEST_DESC"
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
This page took 0.050706 seconds and 5 git commands to generate.