3 # Copyright (C) - 2016 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
="Session creation based on template"
21 TESTDIR
=$CURDIR/..
/..
/..
/
22 SESSIOND_BIN
="lttng-sessiond"
23 RELAYD_BIN
="lttng-relayd"
25 export LTTNG_SESSION_CONFIG_XSD_PATH
=$
(readlink
-m ${TESTDIR}..
/src
/common
/config
/)
27 SESSION_NAME
="load-42"
29 DIR
=$
(readlink
-f $TESTDIR)
33 source $TESTDIR/utils
/utils.sh
35 LTTNG_BIN
="lttng --mi xml"
37 # MUST set TESTDIR before calling those functions
40 print_test_banner
"$TEST_DESC"
44 XPATH_SESSION_NAME
="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:name/text()"
45 XPATH_SESSION_PATH
="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:path/text()"
46 XPATH_SESSION_SNAPSHOT_MODE
="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:snapshot_mode/text()"
47 XPATH_SESSION_SNAPSHOT_CTRL_URL
="//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:ctrl_url/text()"
48 XPATH_SESSION_SNAPSHOT_DATA_URL
="//lttng:command/lttng:output/lttng:snapshot_action/lttng:output/lttng:session/lttng:snapshots/lttng:snapshot/lttng:data_url/text()"
49 XPATH_SESSION_LIVE_TIMER_INTERVAL
="//lttng:command/lttng:output/lttng:sessions/lttng:session/lttng:live_timer_interval/text()"
50 XPATH_SAVE_SESSION_SHM_PATH
="//sessions/session/shared_memory_path/text()"
52 TEMPLATE_DIR
="$CURDIR/sessions"
54 # TODO: note: most of these fuctions could have been tested via lttng save and
55 # diffing the original and the saved one. Might want to go this way...
57 function test_normal_local
()
59 diag
"Load from template a normal session with local consumer output"
60 local template_name
="normal_local.lttng"
61 local session_name
="normal_local"
62 local output_path
="/home/jonathan/lttng-traces/normal_local-20160606-132532"
64 local template_path
="$TEMPLATE_DIR/$template_name"
66 local mi_output_file
=$
(mktemp
)
72 create_lttng_session_template_ok
"$template_path"
74 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
77 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_NAME}")
78 if [[ $mi_result = "$session_name" ]]; then
79 ok
0 "Session names are the same"
81 fail
"Session names should be $session_name but value is $mi_result"
85 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
86 if [[ $mi_result = "$output_path" ]]; then
87 ok
0 "Output paths are the same"
89 fail
"Output paths should be $output_path but value is $mi_result"
92 destroy_lttng_session_ok
$session_name
95 function test_normal_no_output
()
97 diag
"Load from template a normal session with no output (--no-output)"
98 local template_name
="normal_no_output.lttng"
99 local session_name
="normal_no_output"
102 local template_path
="$TEMPLATE_DIR/$template_name"
104 local mi_output_file
=$
(mktemp
)
105 if [ $?
-ne 0 ]; then
110 create_lttng_session_template_ok
"$template_path"
112 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
115 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_NAME}")
116 if [[ $mi_result = "$session_name" ]]; then
117 ok
0 "Session names are the same"
119 fail
"Session names should be $session_name but value is $mi_result"
123 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
124 if [[ $mi_result = "$output_path" ]]; then
125 ok
0 "Output paths are the same"
127 fail
"Output paths should be empty but value is $mi_result"
130 destroy_lttng_session_ok
$session_name
133 function test_normal_net
()
135 diag
"Load from template a normal session with net output"
136 local template_name
="normal_net.lttng"
137 local session_name
="normal_net"
138 local output_path
="tcp4://127.0.0.1:5342/normal_net-20160606-132620 [data: 5343]"
140 local template_path
="$TEMPLATE_DIR/$template_name"
142 local mi_output_file
=$
(mktemp
)
143 if [ $?
-ne 0 ]; then
148 create_lttng_session_template_ok
"$template_path"
150 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
153 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_NAME}")
154 if [[ $mi_result = "$session_name" ]]; then
155 ok
0 "Session names are the same"
157 fail
"Session names should be $session_name but value is $mi_result"
161 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
162 if [[ $mi_result = "$output_path" ]]; then
163 ok
0 "Output paths are the same"
165 fail
"Output paths should be empty but value is $mi_result"
168 destroy_lttng_session_ok
$session_name
171 function test_snapshot_local
()
173 diag
"Load from template a snapshot session with local output"
174 local template_name
="snapshot_local.lttng"
175 local session_name
="snapshot_local"
177 local snapshot_ctrl_url
="/home/jonathan/lttng-traces/snapshot_local-20160606-132651"
178 local snapshot_data_url
=""
180 local template_path
="$TEMPLATE_DIR/$template_name"
182 local mi_output_file
=$
(mktemp
)
183 if [ $?
-ne 0 ]; then
188 create_lttng_session_template_ok
"$template_path"
190 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
193 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_MODE}")
194 if [[ $mi_result = "1" ]]; then
195 ok
0 "Session snapshot mode is enabled"
197 fail
"Session snapshot mode is invalid value is $mi_result"
201 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
202 if [[ $mi_result = "$output_path" ]]; then
203 ok
0 "Output paths are the same"
205 fail
"Output paths should be empty but value is $mi_result"
208 OUTPUT_DEST
="$mi_output_file" lttng_snapshot_list
$session_name
210 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
211 if [[ $mi_result = "$snapshot_ctrl_url" ]]; then
212 ok
0 "Ctrl urls for snapshot are the same"
214 fail
"Ctrl urls should be $snapshot_ctrl_url but value is $mi_result"
217 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
218 if [[ $mi_result = "$snapshot_data_url" ]]; then
219 ok
0 "Data urls for snapshot are the same"
221 fail
"Data urls should be $snapshot_data_url but value is $mi_result"
224 destroy_lttng_session_ok
$session_name
227 function test_snapshot_net
()
229 diag
"Load from template a snapshot session with net output"
230 local template_name
="snapshot_net.lttng"
231 local session_name
="snapshot_net"
233 local snapshot_ctrl_url
="tcp4://127.0.0.1:5342/"
234 local snapshot_data_url
="tcp4://127.0.0.1:5343/"
236 local template_path
="$TEMPLATE_DIR/$template_name"
238 local mi_output_file
=$
(mktemp
)
239 if [ $?
-ne 0 ]; then
243 create_lttng_session_template_ok
"$template_path"
245 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
248 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_MODE}")
249 if [[ $mi_result = "1" ]]; then
250 ok
0 "Session snapshot mode is enabled"
252 fail
"Session snapshot mode is invalid value is $mi_result"
256 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
257 if [[ $mi_result = "$output_path" ]]; then
258 ok
0 "Output paths are the same"
260 fail
"Output paths should be empty but value is $mi_result"
263 OUTPUT_DEST
="$mi_output_file" lttng_snapshot_list
$session_name
265 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
266 if [[ $mi_result = "$snapshot_ctrl_url" ]]; then
267 ok
0 "Ctrl urls for snapshot are the same"
269 fail
"Ctrl urls should be $snapshot_ctrl_url but value is $mi_result"
272 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
273 if [[ $mi_result = "$snapshot_data_url" ]]; then
274 ok
0 "Data urls for snapshot are the same"
276 fail
"Data urls should be $snapshot_data_url but value is $mi_result"
279 destroy_lttng_session_ok
$session_name
284 diag
"Load from template a live session"
285 local template_name
="live.lttng"
286 local session_name
="live"
287 local output_path
="tcp4://127.0.0.1:5342/ [data: 5343]"
288 local live_timer_interval
="1000000"
290 local template_path
="$TEMPLATE_DIR/$template_name"
292 local mi_output_file
=$
(mktemp
)
293 if [ $?
-ne 0 ]; then
298 create_lttng_session_template_ok
"$template_path"
300 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
303 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_NAME}")
304 if [[ $mi_result = "$session_name" ]]; then
305 ok
0 "Session names are the same"
307 fail
"Session names should be $session_name but value is $mi_result"
310 # Validate live timer
311 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_LIVE_TIMER_INTERVAL}")
312 if [[ $mi_result = "$live_timer_interval" ]]; then
313 ok
0 "Session live timer intervals are the same"
315 fail
"Session live timer should be $live_timer_interval but value is $mi_result"
319 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
320 if [[ $mi_result = "$output_path" ]]; then
321 ok
0 "Output paths are the same"
323 fail
"Output paths should be empty but value is $mi_result"
326 destroy_lttng_session_ok
$session_name
329 function test_shm_path
()
331 # Since lttng list do not expose the shm path save the session and check
333 diag
"Load from template a session with a shared memory path"
334 local template_name
="shm_path.lttng"
335 local session_name
="shm_path"
336 local shared_memory_path
="/tmp/shm_path-20160606-161801"
338 local template_path
="$TEMPLATE_DIR/$template_name"
340 local save_output_path
=$
(mktemp
-d)
341 local save_output_file
="${save_output_path}/$session_name.lttng"
342 if [ $?
-ne 0 ]; then
346 create_lttng_session_template_ok
"$template_path"
348 lttng_save
$session_name "-o ${save_output_path}"
351 save_result
=$
($CURDIR/..
/mi
/extract_xml
$save_output_file "${XPATH_SAVE_SESSION_SHM_PATH}")
352 if [[ $save_result = "$shared_memory_path" ]]; then
353 ok
0 "Session shared memory paths are the same"
355 fail
"Session shared memory path should be $shared_memory_path but value is $save_result"
359 rmdir $save_output_path
360 destroy_lttng_session_ok
$session_name
363 # Default data generation
364 function test_name_generation
()
366 diag
"Load from template a session with no name"
367 local template_name
="name_generation.lttng"
368 local template_path
="$TEMPLATE_DIR/$template_name"
370 # On session creation success a name must have been generated.
371 create_lttng_session_template_ok
"$template_path"
373 destroy_lttng_session_ok
$session_name
376 function test_normal_output_generation
()
378 diag
"Load from template a normal session with no consumer output defined"
379 local template_name
="normal_output_generation.lttng"
380 local session_name
="normal_output_generation"
381 local output_path
="/home/jonathan/lttng-traces/normal_local-20160606-132532"
383 local template_path
="$TEMPLATE_DIR/$template_name"
385 local mi_output_file
=$
(mktemp
)
386 if [ $?
-ne 0 ]; then
390 create_lttng_session_template_ok
"$template_path"
392 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
395 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
396 if [ ! -z "$mi_result" ]; then
397 ok
0 "Output path was generated"
399 fail
"Output path should not be empty $mi_result"
402 destroy_lttng_session_ok
$session_name
405 function test_snapshot_output_generation
()
407 diag
"Load from template a snapshot session with no local output defined"
408 local template_name
="snapshot_output_generation.lttng"
409 local session_name
="snapshot_output_generation"
411 local template_path
="$TEMPLATE_DIR/$template_name"
413 local mi_output_file
=$
(mktemp
)
414 if [ $?
-ne 0 ]; then
419 create_lttng_session_template_ok
"$template_path"
421 OUTPUT_DEST
="$mi_output_file" lttng_snapshot_list
$session_name
423 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
424 if [ ! -z "${mi_result}" ]; then
425 ok
0 "Local snapshot output was generated"
427 fail
"Local snapshot output is null"
430 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
431 if [ -z "${mi_result}" ]; then
432 ok
0 "Data url is empty as planned"
434 fail
"Data url should be null but value is : $mi_result"
437 destroy_lttng_session_ok
$session_name
440 function test_live_output_generation
()
442 diag
"Load from template a live session with no consumer output defined"
443 local template_name
="live_output_generation.lttng"
444 local session_name
="live_output_generation"
445 local output_path
="tcp4://127.0.0.1:5342/ [data: 5343]"
447 local template_path
="$TEMPLATE_DIR/$template_name"
449 local mi_output_file
=$
(mktemp
)
450 if [ $?
-ne 0 ]; then
454 create_lttng_session_template_ok
"$template_path"
456 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
459 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
460 if [[ $mi_result = "$output_path" ]]; then
461 ok
0 "Output path was generated and value is good: $mi_result"
463 fail
"Output path default is invalid: $mi_result"
466 destroy_lttng_session_ok
$session_name
470 function test_overwrite_live_timer
()
472 diag
"Load from template a live session - Overwrite live timer"
473 local template_name
="live.lttng"
474 local session_name
="live"
475 local output_path
="tcp4://127.0.0.1:5342/ [data: 5343]"
476 local live_timer_interval
="123456"
478 local template_path
="$TEMPLATE_DIR/$template_name"
480 local mi_output_file
=$
(mktemp
)
481 if [ $?
-ne 0 ]; then
485 create_lttng_session_template_ok
"$template_path" "--live=${live_timer_interval}"
487 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
489 # Validate live timer
490 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_LIVE_TIMER_INTERVAL}")
491 if [[ $mi_result = "$live_timer_interval" ]]; then
492 ok
0 "Session live timer intervals are the same: $mi_result == $live_timer_interval"
494 fail
"Session live timer should be $live_timer_interval but value is $mi_result"
497 destroy_lttng_session_ok
$session_name
500 function test_overwrite_shm_path
()
502 # Since lttng list do not expose the shm path save the session and check
504 diag
"Load from template a session with a shared memory path - Overwrite shm path"
505 local template_name
="shm_path.lttng"
506 local session_name
="shm_path"
507 local shared_memory_path
="/tmp/beer-run"
509 local template_path
="$TEMPLATE_DIR/$template_name"
511 local save_output_path
=$
(mktemp
-d)
512 local save_output_file
="${save_output_path}/$session_name.lttng"
513 if [ $?
-ne 0 ]; then
517 create_lttng_session_template_ok
"$template_path" "--shm-path=${shared_memory_path}"
519 lttng_save
$session_name "-o ${save_output_path}"
522 save_result
=$
($CURDIR/..
/mi
/extract_xml
$save_output_file "${XPATH_SAVE_SESSION_SHM_PATH}")
523 if [[ $
(dirname $save_result) = "$shared_memory_path" ]]; then
524 ok
0 "Session shared memory paths are the same"
526 fail
"Session shared memory path should be $shared_memory_path but value is $save_result"
530 rmdir $save_output_path
531 destroy_lttng_session_ok
$session_name
534 function test_overwrite_normal_net_to_local
()
536 diag
"Load from template a normal session with net output - Overwrite to local output"
537 local template_name
="normal_net.lttng"
538 local session_name
="normal_net"
539 local output_path
="/tmp/beer-run"
541 local template_path
="$TEMPLATE_DIR/$template_name"
543 local mi_output_file
=$
(mktemp
)
544 if [ $?
-ne 0 ]; then
548 create_lttng_session_template_ok
"$template_path" "--set-url=file://${output_path}"
550 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
553 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
554 if [[ $mi_result = "$output_path" ]]; then
555 ok
0 "Output paths are the same"
557 fail
"Output paths should be empty but value is $mi_result"
560 destroy_lttng_session_ok
$session_name
562 create_lttng_session_template_ok
"$template_path" "--output=${output_path}"
564 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
567 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
568 if [[ $mi_result = "$output_path" ]]; then
569 ok
0 "Output paths are the same"
571 fail
"Output paths should be empty but value is $mi_result"
574 destroy_lttng_session_ok
$session_name
578 function test_overwrite_snapshot_local_to_net
()
580 diag
"Load from template a snapshot session with local output"
581 local template_name
="snapshot_local.lttng"
582 local session_name
="snapshot_local"
584 local snapshot_ctrl_url
="tcp4://127.0.0.1:5342/"
585 local snapshot_data_url
="tcp4://127.0.0.1:5343/"
587 local template_path
="$TEMPLATE_DIR/$template_name"
589 local mi_output_file
=$
(mktemp
)
590 if [ $?
-ne 0 ]; then
594 create_lttng_session_template_ok
"$template_path" "--ctrl-url=${snapshot_ctrl_url} --data-url=${snapshot_data_url}"
596 OUTPUT_DEST
="$mi_output_file" lttng_snapshot_list
$session_name
598 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_CTRL_URL}")
599 if [[ $mi_result = "$snapshot_ctrl_url" ]]; then
600 ok
0 "Ctrl urls for snapshot are the same"
602 fail
"Ctrl urls should be $snapshot_ctrl_url but value is $mi_result"
605 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_SNAPSHOT_DATA_URL}")
606 if [[ $mi_result = "$snapshot_data_url" ]]; then
607 ok
0 "Data urls for snapshot are the same"
609 fail
"Data urls should be $snapshot_data_url but value is $mi_result"
612 destroy_lttng_session_ok
$session_name
615 function test_overwrite_live_net
()
617 diag
"Load from template a live session - Overwrite net output"
618 local template_name
="live.lttng"
619 local session_name
="live"
620 local ctrl_url
="tcp4://127.0.0.1:1000/"
621 local data_url
="tcp4://127.0.0.1:1001/"
622 local output_path
="tcp4://127.0.0.1:1000/ [data: 1001]"
624 local template_path
="$TEMPLATE_DIR/$template_name"
626 local mi_output_file
=$
(mktemp
)
627 if [ $?
-ne 0 ]; then
631 create_lttng_session_template_ok
"$template_path" "--ctrl-url=${ctrl_url} --data-url=${data_url}"
633 OUTPUT_DEST
="$mi_output_file" list_lttng_with_opts
$session_name
636 mi_result
=$
($CURDIR/..
/mi
/extract_xml
$mi_output_file "${XPATH_SESSION_PATH}")
637 if [[ $mi_result = "$output_path" ]]; then
638 ok
0 "Output paths are the same"
640 fail
"Output paths should be empty but value is $mi_result"
643 destroy_lttng_session_ok
$session_name
647 function test_full_load
()
649 # Since lttng list do not expose the shm path save the session and check
651 diag
"Load from template a complex session with henabled channel and events"
652 local template_name
="full_load.lttng"
653 local session_name
="full_load"
655 local template_path
="$TEMPLATE_DIR/$template_name"
657 local save_output_path
=$
(mktemp
-d)
658 local save_output_file
="${save_output_path}/$session_name.lttng"
659 if [ $?
-ne 0 ]; then
663 create_lttng_session_template_ok
"$template_path"
665 lttng_save
$session_name "-o ${save_output_path}"
668 save_result
=$
($CURDIR/..
/mi
/extract_xml
$save_output_file "${XPATH_SAVE_SESSION_SHM_PATH}")
669 if diff $template_path $save_output_path ; then
670 ok
0 "Session complex load"
672 fail
"Sessions results are different"
676 rmdir $save_output_path
677 destroy_lttng_session_ok
$session_name
682 test_normal_no_output
688 # Default data generation
690 test_normal_output_generation
691 test_snapshot_output_generation
692 test_live_output_generation
694 test_overwrite_live_timer
695 test_overwrite_shm_path
696 test_overwrite_normal_net_to_local
697 test_overwrite_snapshot_local_to_net
698 test_overwrite_live_net
706 for fct_test
in ${TESTS[@]};
709 if [ $?
-ne 0 ]; then
712 # Only delete if successful