3 # Copyright (C) - 2018 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 TEST_DESC
="LTTng relayd filesystem grouping - Userspace tracing"
21 TESTDIR
=$CURDIR/..
/..
/..
24 TESTAPP_PATH
="$TESTDIR/utils/testapp"
25 TESTAPP_NAME
="gen-ust-events"
26 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
27 EVENT_NAME
="tp:tptest"
29 XSD_PATH
=$TESTDIR/..
/src
/common
/mi-lttng-3.0.xsd
31 XML_VALIDATE
="$TESTDIR/regression/tools/mi/validate_xml $XSD_PATH"
32 XML_EXTRACT
="$TESTDIR/regression/tools/mi/extract_xml"
34 XPATH_CMD_OUTPUT
="//lttng:command/lttng:output"
35 XPATH_SESSION
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session"
37 TRACE_PATH
=$
(mktemp
-d)
41 source $TESTDIR/utils
/utils.sh
43 if [ ! -x "$TESTAPP_BIN" ]; then
44 BAIL_OUT
"No UST events binary detected."
47 function get_auto_session_name
()
51 LTTNG_BIN
="lttng --mi xml"
52 OUTPUT_DEST
=$
(mktemp
-u)
55 $XML_VALIDATE ${OUTPUT_DEST}
56 ok $?
"Valid lttng list XML"
58 value
=$
($XML_EXTRACT ${OUTPUT_DEST} ${XPATH_SESSION}/lttng
:name
/text\
(\
))
59 ok $?
"Extraction of session name"
63 eval $__result="'$value'"
66 function test_ust_uid_live_automatic_name
()
68 local session_name
="$1"
69 local channel_name
=$
(randstring
8 0)
70 local is_automatic_session
=false
72 if [ -z "$session_name" ]; then
73 is_automatic_session
=true
76 diag
"Test UST uid buffer live with session name"
78 create_lttng_session_uri
"$session_name" net
://localhost
--live
80 if [ "$is_automatic_session" = true
]; then
81 get_auto_session_name session_name
84 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
85 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
86 start_lttng_tracing_ok
$session_name
88 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
90 stop_lttng_tracing_ok
$session_name
91 destroy_lttng_session_ok
$session_name
93 # When session name is automatic, the actual directory is "auto", not
95 if [ "$is_automatic_session" = true
]; then
99 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
103 function test_ust_uid_live
()
105 local session_name
="$1"
106 local channel_name
=$
(randstring
8 0)
107 local is_automatic_session
=false
109 if [ -z "$session_name" ]; then
110 is_automatic_session
=true
113 diag
"Test UST uid buffer live with session name"
115 create_lttng_session_uri
"$session_name" net
://localhost
--live
116 if [ "$is_automatic_session" = true
]; then
117 get_auto_session_name session_name
120 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
121 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
122 start_lttng_tracing_ok
$session_name
124 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
126 stop_lttng_tracing_ok
$session_name
127 destroy_lttng_session_ok
$session_name
129 # When session name is automatic, the actual directory is "auto", not
131 if [ "$is_automatic_session" = true
]; then
134 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
137 function test_ust_pid_live
()
139 local session_name
="$1"
140 local channel_name
=$
(randstring
8 0)
141 local is_automatic_session
=false
143 if [ -z "$session_name" ]; then
144 is_automatic_session
=true
147 diag
"Test UST pid buffer live with session name"
149 create_lttng_session_uri
"$session_name" net
://localhost
--live
150 if [ "$is_automatic_session" = true
]; then
151 get_auto_session_name session_name
154 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
155 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
156 start_lttng_tracing_ok
$session_name
158 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
160 stop_lttng_tracing_ok
$session_name
161 destroy_lttng_session_ok
$session_name
163 # When session name is automatic, the actual directory is "auto", not
165 if [ "$is_automatic_session" = true
]; then
168 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
171 function test_ust_uid_live_custom_output
()
173 local session_name
="$1"
174 local channel_name
=$
(randstring
8 0)
175 local custom_output
="my_live_custom_output"
176 local is_automatic_session
=false
178 if [ -z "$session_name" ]; then
179 is_automatic_session
=true
182 diag
"Test UST uid buffer live with session name, custom output"
184 create_lttng_session_uri
"$session_name" net
://localhost
/$custom_output --live
185 if [ "$is_automatic_session" = true
]; then
186 get_auto_session_name session_name
189 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
190 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
191 start_lttng_tracing_ok
$session_name
193 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
195 stop_lttng_tracing_ok
$session_name
196 destroy_lttng_session_ok
$session_name
198 # When session name is automatic, the actual directory is "auto", not
200 if [ "$is_automatic_session" = true
]; then
203 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/$custom_output
206 function test_ust_uid_streaming
()
208 local session_name
="$1"
209 local channel_name
=$
(randstring
8 0)
210 local is_automatic_session
=false
212 if [ -z "$session_name" ]; then
213 is_automatic_session
=true
216 diag
"Test UST uid buffer streaming with session name"
218 create_lttng_session_uri
"$session_name" net
://localhost
219 if [ "$is_automatic_session" = true
]; then
220 get_auto_session_name session_name
223 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
224 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
225 start_lttng_tracing_ok
$session_name
227 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
229 stop_lttng_tracing_ok
$session_name
230 destroy_lttng_session_ok
$session_name
232 # When session name is automatic, the actual directory is "auto", not
234 if [ "$is_automatic_session" = true
]; then
237 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
240 function test_ust_pid_streaming
()
242 local session_name
="$1"
243 local channel_name
=$
(randstring
8 0)
244 local is_automatic_session
=false
246 if [ -z "$session_name" ]; then
247 is_automatic_session
=true
250 diag
"Test UST pid buffer streaming with session name"
252 create_lttng_session_uri
"$session_name" net
://localhost
253 if [ "$is_automatic_session" = true
]; then
254 get_auto_session_name session_name
257 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
258 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
259 start_lttng_tracing_ok
$session_name
261 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
263 stop_lttng_tracing_ok
$session_name
264 destroy_lttng_session_ok
$session_name
266 # When session name is automatic, the actual directory is "auto", not
268 if [ "$is_automatic_session" = true
]; then
271 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
274 function test_ust_uid_streaming_custom_output
()
276 local session_name
="$1"
277 local channel_name
=$
(randstring
8 0)
278 local custom_output
="custom_second_token"
279 local is_automatic_session
=false
281 if [ -z "$session_name" ]; then
282 is_automatic_session
=true
285 diag
"Test UST uid buffer streaming with session name, custom output"
287 create_lttng_session_uri
"$session_name" net
://localhost
/$custom_output
288 if [ "$is_automatic_session" = true
]; then
289 get_auto_session_name session_name
292 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
293 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
294 start_lttng_tracing_ok
$session_name
296 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
298 stop_lttng_tracing_ok
$session_name
299 destroy_lttng_session_ok
$session_name
301 # When session name is automatic, the actual directory is "auto", not
303 if [ "$is_automatic_session" = true
]; then
306 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/$custom_output
309 function test_ust_uid_streaming_rotate
()
311 local session_name
="$1"
312 local channel_name
=$
(randstring
8 0)
313 local is_automatic_session
=false
315 if [ -z "$session_name" ]; then
316 is_automatic_session
=true
319 diag
"Test UST uid buffer rotate with session name"
321 create_lttng_session_uri
"$session_name" net
://localhost
322 if [ "$is_automatic_session" = true
]; then
323 get_auto_session_name session_name
326 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
327 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
328 start_lttng_tracing_ok
$session_name
330 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
331 rotate_session_ok
$session_name
333 stop_lttng_tracing_ok
$session_name
334 destroy_lttng_session_ok
$session_name
336 # When session name is automatic, the actual directory is "auto", not
338 if [ "$is_automatic_session" = true
]; then
341 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
344 function test_ust_uid_streaming_rotate_custom_output
()
346 local session_name
="$1"
347 local channel_name
=$
(randstring
8 0)
348 local custom_output
="rotate_custom_path"
349 local is_automatic_session
=false
351 if [ -z "$session_name" ]; then
352 is_automatic_session
=true
355 diag
"Test UST uid buffer rotate with session name, custom output"
357 create_lttng_session_uri
"$session_name" net
://localhost
/$custom_output
358 if [ "$is_automatic_session" = true
]; then
359 get_auto_session_name session_name
362 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
363 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
364 start_lttng_tracing_ok
$session_name
366 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
367 rotate_session_ok
$session_name
370 stop_lttng_tracing_ok
$session_name
371 destroy_lttng_session_ok
$session_name
373 # When session name is automatic, the actual directory is "auto", not
375 if [ "$is_automatic_session" = true
]; then
378 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/$custom_output
381 function test_ust_pid_streaming_rotate
()
383 local session_name
="$1"
384 local channel_name
=$
(randstring
8 0)
385 local is_automatic_session
=false
387 if [ -z "$session_name" ]; then
388 is_automatic_session
=true
391 diag
"Test UST pid buffer rotate with session_name"
393 create_lttng_session_uri
"$session_name" net
://localhost
394 if [ "$is_automatic_session" = true
]; then
395 get_auto_session_name session_name
398 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
399 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
400 start_lttng_tracing_ok
$session_name
402 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
403 rotate_session_ok
$session_name
405 stop_lttng_tracing_ok
$session_name
406 destroy_lttng_session_ok
$session_name
408 # When session name is automatic, the actual directory is "auto", not
410 if [ "$is_automatic_session" = true
]; then
413 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
416 function test_ust_uid_streaming_snapshot
()
418 local session_name
="$1"
419 local channel_name
=$
(randstring
8 0)
420 local is_automatic_session
=false
422 if [ -z "$session_name" ]; then
423 is_automatic_session
=true
426 diag
"Test UST uid buffer snapshot streaming with session name using 'create --snapshot'"
428 create_lttng_session_uri
"$session_name" net
://localhost
--snapshot
429 if [ "$is_automatic_session" = true
]; then
430 get_auto_session_name session_name
433 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-uid"
434 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
435 start_lttng_tracing_ok
$session_name
437 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
438 lttng_snapshot_record
$session_name
440 stop_lttng_tracing_ok
$session_name
441 destroy_lttng_session_ok
$session_name
443 # When session name is automatic, the actual directory is "auto", not
445 if [ "$is_automatic_session" = true
]; then
448 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*
451 function test_ust_pid_streaming_snapshot
()
453 local session_name
="$1"
454 local channel_name
=$
(randstring
8 0)
455 local file_sync_after_first
=$
(mktemp
-u)
456 local file_sync_before_last
=$
(mktemp
-u)
457 local is_automatic_session
=false
459 if [ -z "$session_name" ]; then
460 is_automatic_session
=true
463 diag
"Test UST pid buffer snapshot streaming with session name using 'create --snapshot'"
465 create_lttng_session_uri
"$session_name" net
://localhost
--snapshot
466 if [ "$is_automatic_session" = true
]; then
467 get_auto_session_name session_name
470 enable_ust_lttng_channel_ok
$session_name $channel_name "--buffers-pid"
471 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
472 start_lttng_tracing_ok
$session_name
474 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev
/null
2>&1 &
476 while [ ! -f "${file_sync_after_first}" ]; do
480 lttng_snapshot_record
$session_name
482 touch ${file_sync_before_last}
485 stop_lttng_tracing_ok
$session_name
486 destroy_lttng_session_ok
$session_name
488 # When session name is automatic, the actual directory is "auto", not
490 if [ "$is_automatic_session" = true
]; then
493 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/snapshot-1
*
495 rm -rf ${file_sync_after_first}
496 rm -rf ${file_sync_before_last}
499 function test_ust_uid_streaming_snapshot_add_output_default_name
()
501 local session_name
="$1"
502 local channel_name
=$
(randstring
8 0)
503 local is_automatic_session
=false
505 if [ -z "$session_name" ]; then
506 is_automatic_session
=true
509 diag
"Test UST uid buffer snapshot using 'add-output' with default snapshot name"
511 create_lttng_session_no_output
"$session_name"
512 if [ "$is_automatic_session" = true
]; then
513 get_auto_session_name session_name
516 enable_lttng_mmap_overwrite_ust_channel
$session_name $channel_name
517 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
518 start_lttng_tracing_ok
$session_name
520 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
522 lttng_snapshot_add_output_ok
$session_name "net://localhost"
523 lttng_snapshot_record
$session_name
525 stop_lttng_tracing_ok
$session_name
526 destroy_lttng_session_ok
$session_name
528 # When session name is automatic, the actual directory is "auto", not
530 if [ "$is_automatic_session" = true
]; then
533 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/snapshot-1
*
536 function test_ust_uid_streaming_snapshot_add_output_custom_name
()
538 local session_name
="$1"
539 local channel_name
=$
(randstring
8 0)
540 local snapshot_name
="this_is_my_snapshot"
541 local is_automatic_session
=false
543 if [ -z "$session_name" ]; then
544 is_automatic_session
=true
547 diag
"Test UST uid buffer snapshot using 'add-output' with custom snapshot name"
549 create_lttng_session_no_output
"$session_name"
550 if [ "$is_automatic_session" = true
]; then
551 get_auto_session_name session_name
554 enable_lttng_mmap_overwrite_ust_channel
$session_name $channel_name
555 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
556 start_lttng_tracing_ok
$session_name
558 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
560 lttng_snapshot_add_output_ok
$session_name "net://localhost" "-n $snapshot_name"
561 lttng_snapshot_record
$session_name
563 stop_lttng_tracing_ok
$session_name
564 destroy_lttng_session_ok
$session_name
566 # When session name is automatic, the actual directory is "auto", not
568 if [ "$is_automatic_session" = true
]; then
571 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/$snapshot_name*
574 function test_ust_uid_streaming_snapshot_add_output_custom_name_custom_output
()
576 local session_name
="$1"
577 local channel_name
=$
(randstring
8 0)
578 local snapshot_name
="this_is_my_snapshot"
579 local custom_output
="this/is/my/custom/path"
580 local is_automatic_session
=false
582 if [ -z "$session_name" ]; then
583 is_automatic_session
=true
586 diag
"Test UST uid buffer snapshot using 'add-output' with custom snapshot name and custom output path"
588 create_lttng_session_no_output
"$session_name"
589 if [ "$is_automatic_session" = true
]; then
590 get_auto_session_name session_name
593 enable_lttng_mmap_overwrite_ust_channel
$session_name $channel_name
594 enable_ust_lttng_event_ok
$session_name $EVENT_NAME $channel_name
595 start_lttng_tracing_ok
$session_name
597 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
599 lttng_snapshot_add_output_ok
$session_name "net://localhost/$custom_output" "-n $snapshot_name"
600 lttng_snapshot_record
$session_name
602 stop_lttng_tracing_ok
$session_name
603 destroy_lttng_session_ok
$session_name
605 # When session name is automatic, the actual directory is "auto", not
607 if [ "$is_automatic_session" = true
]; then
610 validate_trace
$EVENT_NAME $TRACE_PATH/$session_name/$HOSTNAME*/$custom_output/$snapshot_name*
613 plan_tests
$NUM_TESTS
615 print_test_banner
"$TEST_DESC"
617 # Set the relayd in --group-output-by-session mode
618 start_lttng_relayd
"-o $TRACE_PATH --group-output-by-session"
624 test_ust_uid_live_custom_output
625 test_ust_uid_streaming
626 test_ust_pid_streaming
627 test_ust_uid_streaming_custom_output
628 # Rotation does not exist on stable 2.9
629 # test_ust_uid_streaming_rotate
630 # test_ust_uid_streaming_rotate_custom_output
631 # test_ust_pid_streaming_rotate
632 test_ust_uid_streaming_snapshot
633 test_ust_pid_streaming_snapshot
634 test_ust_uid_streaming_snapshot_add_output_default_name
635 test_ust_uid_streaming_snapshot_add_output_custom_name
636 test_ust_uid_streaming_snapshot_add_output_custom_name_custom_output
640 # Perform test when session name is generated by the client
641 for fct_test
in ${tests[@]};
644 rm -rf $TRACE_PATH/auto
/
645 count
=$
(ls -1 $TRACE_PATH/ |
wc -l)
646 is
$count "0" "LTTng-relayd output directory empty"
649 # Perform test when session name is given
650 for fct_test
in ${tests[@]};
652 name
=$
(randstring
16 0)
654 rm -rf $TRACE_PATH/$name/
655 count
=$
(ls -1 $TRACE_PATH/ |
wc -l)
656 is
$count "0" "LTTng-relayd output directory empty"