Cleanup: tests: name all temporary files to better identify leakage
[lttng-tools.git] / tests / regression / tools / clear / test_ust
CommitLineData
c28fcefd
JR
1#!/bin/bash
2#
4942c256 3# Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
c28fcefd 4#
9d16b343 5# SPDX-License-Identifier: LGPL-2.1-only
c28fcefd
JR
6
7TEST_DESC="Clear - UST tracing"
8
9CURDIR=$(dirname $0)/
10TESTDIR=$CURDIR/../../..
11EVENT_NAME="tp:tptest"
bc3c79ae
JG
12EVENT_STATE_DUMP_START="lttng_ust_statedump:start"
13EVENT_STATE_DUMP_END="lttng_ust_statedump:end"
c28fcefd
JR
14SESSION_NAME=""
15TESTAPP_PATH="$TESTDIR/utils/testapp"
16TESTAPP_NAME="gen-ust-events"
17TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
18
bc3c79ae 19NUM_TESTS=2071
c28fcefd
JR
20
21PAGE_SIZE=$(getconf PAGE_SIZE)
33e55711 22TRACE_PATH=$(mktemp --tmpdir -d tmp.test_clear_ust_trace_path.XXXXXX)
c28fcefd
JR
23
24source $TESTDIR/utils/utils.sh
25
26if [ ! -x "$TESTAPP_BIN" ]; then
27 BAIL_OUT "No UST events binary detected."
28fi
29
30function clean_path ()
31{
32 local trace_path=$1
33 set -u
061cde02 34 rm -rf $trace_path
c28fcefd
JR
35 set +u
36}
37
38function 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
48function 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
58function 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
85function 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
69ebf37e
JR
118function 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
c28fcefd
JR
143function 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
176function 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
209function 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
94360c17
FD
228 if [[ "$buffer_type" == "uid" ]]; then
229 validate_trace_empty $local_path
230 else # pid
231 validate_directory_empty $local_path
232 fi
c28fcefd
JR
233
234 destroy_lttng_session_ok $SESSION_NAME
235}
236
237#no clear
238function 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"
33e55711
FD
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)
c28fcefd
JR
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
bc3c79ae 278 diag "Waiting for application to exit"
c28fcefd
JR
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
290function 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"
33e55711 299 local bt_output_path=$(mktemp --tmpdir -u tmp.test_${FUNCNAME[0]}_bt_output_path.XXXXXX)
c28fcefd
JR
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
bc3c79ae
JG
329function 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"
bc3c79ae 338
33e55711
FD
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")
bc3c79ae
JG
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"
a8cf8647 411 rm -f "$file_sync_before_exit"
bc3c79ae
JG
412}
413
c28fcefd
JR
414function 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
94360c17
FD
439
440 # The sessiond always created a `ust/ directory
441 # whenever the UST domain is active
442 validate_directory_empty $TRACE_PATH/ust/
c28fcefd
JR
443 fi
444 fi
445
446 destroy_lttng_session_ok $SESSION_NAME
447}
448
69ebf37e
JR
449function 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
c28fcefd
JR
473function 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
505function 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
537function 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
581function 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
596function 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.
613function 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"
33e55711
FD
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")
c28fcefd
JR
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
691function 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
738function 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
782function 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
802plan_tests $NUM_TESTS
803
804print_test_banner "$TEST_DESC"
805
806streaming_tests=(test_ust_streaming
807 test_ust_streaming_rotate_clear
808 test_ust_streaming_clear_rotate
809 test_ust_streaming_tracefile_rotation
810 test_ust_streaming_tracefile_rotation_overwrite_files
69ebf37e 811 test_ust_streaming_no_event
c28fcefd
JR
812)
813
814live_tests=(test_ust_streaming_live
815 test_ust_basic_streaming_live_viewer
816 test_ust_streaming_live_viewer
bc3c79ae 817 test_ust_streaming_live_viewer_new_metadata_after_clear
c28fcefd
JR
818)
819
820local_tests=(test_ust_local
821 test_ust_local_rotate_clear
822 test_ust_local_clear_rotate
69ebf37e 823 test_ust_local_no_event
c28fcefd
JR
824)
825
826snapshot_uid_tests=(test_ust_streaming_snapshot
827 test_ust_local_snapshot
828)
829
830snapshot_pid_tests=(test_ust_local_snapshot_per_pid)
831
832start_lttng_relayd "-o $TRACE_PATH"
833start_lttng_sessiond
834
835# Per-UID buffers
836
837# Clear with tracing active, clear once
838for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
839do
840 SESSION_NAME=$(randstring 16 0)
841 ${fct_test} 1 0 0 0 uid
842 clean_path $TRACE_PATH
843done
844
845# Clear with tracing active, clear twice
846for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
847do
848 SESSION_NAME=$(randstring 16 0)
849 ${fct_test} 1 1 0 0 uid
850 clean_path $TRACE_PATH
851done
852
853# Clear with tracing inactive, clear once
854for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
855do
856 SESSION_NAME=$(randstring 16 0)
857 ${fct_test} 0 0 0 0 uid
858 clean_path $TRACE_PATH
859done
860
861# Clear with tracing inactive, clear twice
862for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_uid_tests[@]};
863do
864 SESSION_NAME=$(randstring 16 0)
865 ${fct_test} 0 1 0 0 uid
866 clean_path $TRACE_PATH
867done
868
869# Clear with tracing inactive, rotate-clear once
870for fct_test in ${streaming_tests[@]} ${local_tests[@]};
871do
872 SESSION_NAME=$(randstring 16 0)
873 ${fct_test} 0 0 1 0 uid
874 clean_path $TRACE_PATH
875done
876
877# Clear with tracing inactive, clear once-rotate(fail)
878for fct_test in ${streaming_tests[@]} ${local_tests[@]};
879do
880 SESSION_NAME=$(randstring 16 0)
881 ${fct_test} 0 0 0 1 uid
882 clean_path $TRACE_PATH
883done
884
885
886# Per-PID buffers.
887
888# Clear with tracing active, clear once
889for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
890do
891 SESSION_NAME=$(randstring 16 0)
892 ${fct_test} 1 0 0 0 pid
893 clean_path $TRACE_PATH
894done
895
896# Clear with tracing active, clear twice
897for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
898do
899 SESSION_NAME=$(randstring 16 0)
900 ${fct_test} 1 1 0 0 pid
901 clean_path $TRACE_PATH
902done
903
904# Clear with tracing inactive, clear once
905for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
906do
907 SESSION_NAME=$(randstring 16 0)
908 ${fct_test} 0 0 0 0 pid
909 clean_path $TRACE_PATH
910done
911
912# Clear with tracing inactive, clear twice
913for fct_test in ${streaming_tests[@]} ${live_tests[@]} ${local_tests[@]} ${snapshot_pid_tests[@]};
914do
915 SESSION_NAME=$(randstring 16 0)
916 ${fct_test} 0 1 0 0 pid
917 clean_path $TRACE_PATH
918done
919
920# Clear with tracing inactive, rotate-clear once
921for fct_test in ${streaming_tests[@]} ${local_tests[@]};
922do
923 SESSION_NAME=$(randstring 16 0)
924 ${fct_test} 0 0 1 0 pid
925 clean_path $TRACE_PATH
926done
927
928# Clear with tracing inactive, clear once-rotate(fail)
929for fct_test in ${streaming_tests[@]} ${local_tests[@]};
930do
931 SESSION_NAME=$(randstring 16 0)
932 ${fct_test} 0 0 0 1 pid
933 clean_path $TRACE_PATH
934done
935
936stop_lttng_sessiond
937stop_lttng_relayd
938
939test_ust_disallow_clear
This page took 0.070049 seconds and 4 git commands to generate.