3 # Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Machine interface testing"
10 TESTDIR
=$CURDIR/..
/..
/..
/
12 #Test app for ust event
13 TESTAPP_PATH
="$TESTDIR/utils/testapp"
14 TESTAPP_NAME
="gen-ust-events"
15 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
20 OUTPUT_DIR
=$
(mktemp
--tmpdir -d tmp.test_mi_output_dir.XXXXXX
)
21 SESSIOND_LOAD_DIR
=$
(mktemp
--tmpdir -d tmp.test_mi_sessiond_load_dir.XXXXXX
)
22 OUTPUT_FILE
="default.xml"
24 XPATH_CMD_OUTPUT
="//lttng:command/lttng:output"
25 XPATH_COMMAND_SUCCESS
="/lttng:command/lttng:success/text()"
26 XPATH_SESSION
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session"
27 XPATH_ENABLE_CHANNEL_NAME
="$XPATH_CMD_OUTPUT/lttng:channels/lttng:channel/lttng:name/text()"
28 XPATH_ENABLE_EVENT_SUCCESS
="$XPATH_CMD_OUTPUT/lttng:events/lttng:event/lttng:success/text()"
29 XPATH_DISABLE_EVENT_SUCCESS
="$XPATH_CMD_OUTPUT/lttng:channel/lttng:events/lttng:event/lttng:success/text()"
30 XPATH_LIST_DOMAIN
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain"
31 XPATH_LIST_CHANNEL
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:channels/lttng:channel"
32 XPATH_LIST_UST_EVENT
="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type ='UST']/lttng:pids/lttng:pid/lttng:events/lttng:event"
33 XPATH_SNAPSHOT_ADD_SNAPSHOT
="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'add-output']/lttng:output"
34 XPATH_SNAPSHOT_LIST
="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'list-output']/lttng:output"
35 XPATH_SNAPSHOT_DEL
="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'del-output']/lttng:output"
36 XPATH_TRACK_UNTRACK_VPID
="$XPATH_CMD_OUTPUT/lttng:process_attr_trackers/lttng:vpid_process_attr_tracker/lttng:process_attr_values/lttng:vpid/lttng:type"
37 XPATH_VPID_TRACKER
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:process_attr_trackers/lttng:vpid_process_attr_tracker"
39 DEVNULL
=/dev
/null
2>&1
41 DIR
=$
(readlink
-f $TESTDIR)
45 source $TESTDIR/utils
/utils.sh
47 #Overwrite the lttng_bin to get mi output
48 LTTNG_BIN
="lttng --mi xml"
50 #Global declaration for simplification
51 LTTNG
=$TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN
53 #Overwrite the default output for utils.sh command
55 #MUST set TESTDIR before calling those functions
58 print_test_banner
"$TEST_DESC"
60 function extract_xml
()
66 output
=$
($XML_EXTRACT $xml "$xpath")
67 ok $?
"Extraction of xpath $xpath"
68 eval $__result="'$output'"
71 function node_check_xml
()
77 output
=$
($XML_NODE_CHECK $xml "$xpath")
78 ok $?
"Check of node existence with xpath $xpath"
79 eval $__result="'$output'"
82 # Arg1 is path to xml file
84 # is true if we expected the success element to be false
88 function is_command_success
()
93 local xpath
=$XPATH_COMMAND_SUCCESS
95 #Extract the success element
97 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
98 if [[ $expect_false = "true" ]]; then
99 if [[ $result ]]; then
100 pass
"Mi test: $xml command failed as expected"
102 fail
"Mi test: $xml command did not fail as expected"
105 if [[ $result ]]; then
106 pass
"Mi test: $xml command success"
108 fail
"Mi test: $xml command failed"
113 function mi_print_version
()
118 $LTTNG version
$opt > $output_path
119 ok $?
"MI test: Lttng version"
123 function test_version
()
125 OUTPUT_FILE
="version.xml"
126 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
127 mi_print_version
$OUTPUT_DEST
128 $MI_VALIDATE $OUTPUT_DEST
129 ok $?
"MI test: Version xsd validation"
132 function test_create_session
()
134 diag
"Test create session"
136 local session_name
="testSession"
138 OUTPUT_FILE
="create_session.xml"
139 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
140 create_lttng_session_ok
$session_name $OUTPUT_DIR
141 $MI_VALIDATE $OUTPUT_DEST
142 ok $?
"MI test: create session xsd validation"
144 #try to recreate a session. Expecting it to fail
145 create_lttng_session_fail
$session_name $OUTPUT_DIR
146 $MI_VALIDATE $OUTPUT_DEST
147 ok $?
"MI test: expecting fail create session xsd validation"
148 is_command_success
$OUTPUT_DEST true
151 destroy_lttng_session_ok
$session_name
154 function test_destroy_session
()
156 diag
"Test destroy session"
163 OUTPUT_FILE
="destroy_session.xml"
167 for (( i
= 0; i
< 3; i
++ )); do
168 create_lttng_session_ok
${session_name[$i]} $OUTPUT_DIR
171 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
172 destroy_lttng_session_ok
${session_name[0]}
173 $MI_VALIDATE $OUTPUT_DEST
174 ok $?
"MI test: destroy session ${session_name[0]} xsd validation"
176 #Verify that we destroyed the good session
177 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
178 test "$result" = "${session_name[0]}"
179 ok $?
"Mi test: deleted session: $result expected: ${session_name[0]}"
181 #Destroy all and count:should be 2
182 destroy_lttng_sessions
183 $MI_VALIDATE $OUTPUT_DEST
184 ok $?
"MI test: destroy all session xsd validation"
186 #Verify that we destroyed 2 sessions
187 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
188 num
=$
(echo "$result" |
wc -l)
190 ok $?
"Mi test: $num / 2 sessions discovered"
192 #Verify that if no session is present command fail and mi report it.
193 destroy_lttng_session_fail
${session_name[0]}
194 $MI_VALIDATE $OUTPUT_DEST
195 ok $?
"MI test: failing destroy session ${session_name[0]} xsd validation"
196 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
197 test "$result" = "false"
198 ok $?
"Mi test: destroy command on ${session_name[0]} failed as expected"
202 function test_list_sessions
()
204 diag
"Test list sessions"
211 OUTPUT_FILE
="list_sessions.xml"
215 for (( i
= 0; i
< 3; i
++ )); do
216 create_lttng_session_ok
${session_name[$i]} $OUTPUT_DIR
219 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
221 $MI_VALIDATE $OUTPUT_DEST
222 ok $?
"Mi test: list sessions xsd validation"
224 #We should have 3 session
225 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
226 num
=$
(echo "$result" |
wc -l)
228 ok $?
"Mi test: $num / 3 sessions discovered"
232 destroy_lttng_sessions
235 function test_list_session_long_path
()
237 diag
"Test list session long path"
239 local session_name
="session_long_path"
241 output_basedir
=$OUTPUT_DIR/$
(randstring
254 0)
242 mkdir
-p ${output_basedir}
244 OUTPUT_FILE
="list_sessions.xml"
248 create_lttng_session_ok
$session_name ${output_basedir}
250 OUTPUT_DEST
=${output_basedir}/$OUTPUT_FILE
252 $MI_VALIDATE $OUTPUT_DEST
253 ok $?
"Mi test: list session with long path xsd validation"
257 destroy_lttng_sessions
259 function test_ust_channel
()
261 diag
"Test UST channel"
263 local session_name
="testsession"
264 local channel_name
=("channelUst0" "channelUst1" "channelUst2")
266 OUTPUT_FILE
="ust_channel.xml"
270 create_lttng_session_ok
$session_name $OUTPUT_DIR
272 #Test the enable_channel command
273 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
274 enable_ust_lttng_channel_ok
$session_name ${channel_name[0]}
275 $MI_VALIDATE $OUTPUT_DEST
276 ok $?
"Mi test: enable ust channel xsd validation"
277 is_command_success
$OUTPUT_DEST false
279 #Expect the command to fail
280 enable_ust_lttng_channel_fail
$session_name ${channel_name[0]}
281 $MI_VALIDATE $OUTPUT_DEST
282 ok $?
"Mi test: fail enable ust channel xsd validation"
283 is_command_success
$OUTPUT_DEST true
285 #Create two ust channel to test multiple disable
286 for (( i
= 1; i
< 3; i
++ )); do
287 enable_ust_lttng_channel_ok
$session_name ${channel_name[$i]}
290 #Test the disable_channel command
291 disable_ust_lttng_channel
$session_name ${channel_name[0]}
292 $MI_VALIDATE $OUTPUT_DEST
293 ok $?
"Mi test: disable ust channel xsd validation"
294 is_command_success
$OUTPUT_DEST false
295 #Check that we delete the good channel
296 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
297 test "$result" = "${channel_name[0]}"
298 ok $?
"MI test: ${channel_name[0]} disabled"
300 #Test multiple disable_channel;
301 disable_ust_lttng_channel
$session_name ${channel_name[1]},${channel_name[2]}
302 $MI_VALIDATE $OUTPUT_DEST
303 ok $?
"Mi test: multiple disable ust channel xsd validation"
304 is_command_success
$OUTPUT_DEST false
306 #Make sure we have two disabled channel
307 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
308 local num
=$
(echo "$result" |
wc -l)
310 ok $?
"Mi test: disabled ust channel $num/2"
314 destroy_lttng_sessions
318 function test_ust_lttng_event
()
320 diag
"Test UST event"
322 local session_name
="testSession"
323 local channel_name
="testChannel"
324 local event
=("ev1" "ev2" "ev3")
326 OUTPUT_FILE
="ust_event.xml"
330 create_lttng_session_ok
$session_name $OUTPUT_DIR
331 enable_ust_lttng_channel_ok
$session_name $channel_name
333 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
334 #Test the enable event for ust domain
335 enable_ust_lttng_event_ok
$session_name ${event[0]} $channel_name
336 $MI_VALIDATE $OUTPUT_DEST
337 ok $?
"Mi test: Enable_event for ust domain xsd validation"
338 is_command_success
$OUTPUT_DEST false
340 #Try to reenable an enabled event. Should fail
341 enable_ust_lttng_event_fail
$session_name ${event[0]} $channel_name
342 $MI_VALIDATE $OUTPUT_DEST
343 ok $?
"Mi test: Fail enable_event for ust domain xsd validation"
344 is_command_success
$OUTPUT_DEST true
346 #Enable multiple event including the last one command will fail
347 #But 2 events should success
349 #Nice little hack, create a string ev,ev,ev
350 #IFS stand for Internal field separator
351 #Event[*] print all the element inside the array with the IFS in between
352 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
354 enable_ust_lttng_event_fail
$session_name $concat_event $channel_name
355 $MI_VALIDATE $OUTPUT_DEST
356 ok $?
"Mi test: Multiple enable ust event with inside fail xsd validation"
358 #Check for 2 success = true and 1 success = false
359 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
360 num_ocur
=$
(grep -o "true" <<< "$result" |
wc -l)
361 test "$num_ocur" -eq "2"
362 ok $?
"Mi test: Enabled event on failing enable command $num_ocur_true/2"
364 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
365 num_ocur
=$
(grep -o "false" <<< "$result" |
wc -l)
366 test "$num_ocur" -eq "1"
367 ok $?
"Mi test: Enabled event on failing enable command $num_ocur_true/2"
370 disable_ust_lttng_event
$session_name ${event[0]} $channel_name
371 $MI_VALIDATE $OUTPUT_DEST
372 ok $?
"Mi test: Disable ust event xsd validation"
373 is_command_success
$OUTPUT_DEST false
375 #Disable the 3 event combined. Should pass
376 disable_ust_lttng_event
$session_name $concat_event $channel_name
377 $MI_VALIDATE $OUTPUT_DEST
378 ok $?
"Mi test: Disable multiple ust event xsd validation"
379 is_command_success
$OUTPUT_DEST false
381 #Make sure we have 3 inner success
382 extract_xml
$OUTPUT_DEST $XPATH_DISABLE_EVENT_SUCCESS result
383 num_ocur
=$
(grep -o "true" <<< "$result" |
wc -l)
384 test "$num_ocur" -eq "3"
385 ok $?
"Mi test: Disable multiple ust event success $num_ocur/3"
389 destroy_lttng_sessions
392 function test_list_channel
()
394 diag
"Test list channel"
396 local session_name
="testSession"
397 local channel_name
="testChannel"
398 local event
=("ev1" "ev2" "ev3")
400 OUTPUT_FILE
="list_channel.xml"
404 create_lttng_session_ok
$session_name $OUTPUT_DIR
405 enable_ust_lttng_channel_ok
$session_name $channel_name
407 #Enable ust and jul events
408 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
409 enable_ust_lttng_event_ok
$session_name $concat_event $channel_name
412 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
413 list_lttng_ok
"$session_name -c $channel_name"
414 $MI_VALIDATE $OUTPUT_DEST
415 ok $?
"Mi test: list channel xsd validation"
417 #Expect 1 domain: UST
418 extract_xml
$OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
419 num
=$
(echo "$result" |
wc -l)
421 ok $?
"Mi test: $num / 1 domains discovered"
423 #Expect 1 channel: test
424 extract_xml
$OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
425 num
=$
(echo "$result" |
wc -l)
427 ok $?
"Mi test: $num / 1 channel discovered"
429 test "$result" = "$channel_name"
430 ok $?
"Mi test: expected channel: $channel_name found: $result"
432 #Add a channel and make sure we have 2 channel now
434 enable_ust_lttng_channel_ok
$session_name $channel_name"a"
438 destroy_lttng_sessions
441 function test_list_domain
()
443 diag
"Test list domain"
445 local session_name
="testSession"
446 local channel_name
="testChannel"
447 local event
=("ev1" "ev2" "ev3")
449 OUTPUT_FILE
="list_domain.xml"
453 create_lttng_session_ok
$session_name $OUTPUT_DIR
454 enable_ust_lttng_channel_ok
$session_name $channel_name
456 #Enable ust and jul events
457 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
458 enable_ust_lttng_event_ok
$session_name $concat_event $channel_name
459 enable_jul_lttng_event
$session_name $concat_event $channel_name
462 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
463 list_lttng_ok
"$session_name -d"
464 $MI_VALIDATE $OUTPUT_DEST
465 ok $?
"Mi test: list domain xsd validation"
467 #Expect 2 domain: Jul and UST
468 extract_xml
$OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
469 num
=$
(echo "$result" |
wc -l)
471 ok $?
"Mi test: $num / 2 domains discovered"
473 #Test for valid value
474 if [[ "$result" = *"JUL"* ]]; then
475 pass
"Mi test: domains Jul is present"
477 fail
"Mi test: domains Jul is absent"
480 if [[ "$result" = *"UST"* ]]; then
481 pass
"Mi test: domains UST is present"
483 fail
"Mi test: domains UST is absent"
488 destroy_lttng_sessions
491 function test_list_session
()
493 diag
"Test list session"
495 local session_name
="testSession"
496 local channel_name
="testChannel"
497 local event
=("ev1" "ev2" "ev3")
499 OUTPUT_FILE
="list_session.xml"
504 create_lttng_session_ok
$session_name $OUTPUT_DIR
505 enable_ust_lttng_channel_ok
$session_name $channel_name
507 #Enable ust and jul events
508 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
509 enable_ust_lttng_event_ok
$session_name $concat_event $channel_name
510 enable_jul_lttng_event
$session_name $concat_event $channel_name
513 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
514 list_lttng_ok
$session_name
515 $MI_VALIDATE $OUTPUT_DEST
516 ok $?
"Mi test: list session xsd validation"
518 #Expect 2 domain: Jul and UST
519 extract_xml
$OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
520 num
=$
(echo "$result" |
wc -l)
522 ok $?
"Mi test: $num / 2 domains discovered"
524 #Expect 2 channel: test and lttng_jul_event
525 extract_xml
$OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
526 num
=$
(echo "$result" |
wc -l)
528 ok $?
"Mi test: $num / 2 channel discovered"
532 destroy_lttng_sessions
535 function test_list_ust_event
()
537 diag
"Test list ust event"
539 local file_sync_after_first
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
540 local file_sync_before_last
=$
(mktemp
--tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
542 OUTPUT_FILE
="list_ust_event.xml"
545 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
548 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
549 --sync-after-first-event ${file_sync_after_first} \
550 --sync-before-last-event ${file_sync_before_last} & 2>/dev
/null
552 while [ ! -f "${file_sync_after_first}" ]; do
556 list_lttng_ok
"-u -f"
558 touch ${file_sync_before_last}
560 $MI_VALIDATE $OUTPUT_DEST
561 ok $?
"Mi test: list ust event xsd validation"
564 extract_xml
$OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/lttng:name/text()" result
565 num
=$
(echo "$result" |
wc -l)
567 #Since the number of events is prone to change we only look for >= from a
568 #base number. An alternative would be to look for each events but this
569 #is complicated for nothing.
571 ok $?
"Mi test: $num / 5 ust events discovered"
573 #Extract field from tp:tptest event. Expect >= to 12 because number of
574 #field is prone to change.
575 extract_xml
$OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./lttng:name = 'tp:tptest']/lttng:event_fields/lttng:event_field/lttng:name/text()" result
576 num
=$
(echo "$result" |
wc -l)
578 ok $?
"Mi test: $num / 12 ust event fields discovered"
580 #Wait for all background processes
583 rm -f ${file_sync_after_first}
584 rm -f ${file_sync_before_last}
587 function test_start_stop
()
589 diag
"Test start-stop"
591 local session_name
="testStartStopSession"
592 local channel_name
="startStopChannel"
594 OUTPUT_FILE
="list_start_stop.xml"
599 create_lttng_session_ok
$session_name $OUTPUT_DIR
602 #No channel enable start command should return element success false
603 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
604 start_lttng_tracing_fail
$session_name
605 $MI_VALIDATE $OUTPUT_DEST
606 ok $?
"Mi test: failed start xsd validation"
608 #Expect a false element
609 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
610 test "$result" = "false"
611 ok $?
"Mi test: mi report failure on start command as expected"
613 #Enable a channel to test success
615 enable_ust_lttng_channel_ok
$session_name $channel_name
618 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
619 start_lttng_tracing_ok
$session_name
620 $MI_VALIDATE $OUTPUT_DEST
621 ok $?
"Mi test: start xsd validation"
623 #Expect a true element
624 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
625 test "$result" = "true"
626 ok $?
"Mi test: mi report success on start command as expected"
628 #Extract session name from xml
629 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
630 test "$result" = "$session_name"
631 ok $?
"Mi test: started $session_name"
633 #Extract enabled expect true
634 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
635 test "$result" = "true"
636 ok $?
"Mi test: enabled element : $result expected: true"
638 #Test metadata regenerate command
639 regenerate_metadata_ok
$session_name
640 $MI_VALIDATE $OUTPUT_DEST
641 ok $?
"Mi test: regenerate metadata"
644 stop_lttng_tracing_ok
$session_name
645 $MI_VALIDATE $OUTPUT_DEST
646 ok $?
"Mi test: stop xsd validation"
648 #Extract session name from xml
649 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
650 test "$result" = "$session_name"
651 ok $?
"Mi test: stopped $session_name"
653 #Extract enabled expect false
654 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
655 test "$result" = "false"
656 ok $?
"Mi test: enabled element : $result expected: false"
658 #Test failing stop command
659 stop_lttng_tracing_fail
$session_name
660 $MI_VALIDATE $OUTPUT_DEST
661 ok $?
"Mi test: failed stop xsd validation"
663 #Expect a false element
664 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
665 test "$result" = "false"
666 ok $?
"Mi test: mi report failure on start command as expected"
670 destroy_lttng_sessions
673 function test_snapshot
()
677 local session_name
="testSnapshotAdd"
678 local snapshot_path
="$OUTPUT_DIR/snapshotoutput"
679 OUTPUT_FILE
="snapshot.xml"
683 create_lttng_session_no_output
$session_name
686 #No channel enable start command should return element success false
687 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
688 lttng_snapshot_add_output_ok
$session_name file://$snapshot_path
689 $MI_VALIDATE $OUTPUT_DEST
690 ok $?
"Mi test: snapshot xsd validation"
692 #Expect a true element
693 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
694 test "$result" = "true"
695 ok $?
"Mi test: add snapshot is a success"
698 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:session_name/text()" result
699 test "$result" = "$session_name"
700 ok $?
"Mi test: added snapshot for: $result expected $session_name"
702 #Get name of generated output and id
703 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:name/text()" snapshot_name
704 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:id/text()" snapshot_id
707 lttng_snapshot_list
$session_name
708 $MI_VALIDATE $OUTPUT_DEST
709 ok $?
"Mi test: snapshot list xsd validation"
711 #Expect a true element
712 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
713 test "$result" = "true"
714 ok $?
"Mi test: add snapshot is a success"
716 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/lttng:session[./lttng:name ='$session_name']/lttng:snapshots/lttng:snapshot/lttng:name/text()" result
717 test "$result" = "$snapshot_name"
718 ok $?
"Mi test: snapshot list extracted snapshot: $result expected: $snapshot_name"
721 lttng_snapshot_del_output_ok
$session_name $snapshot_id
722 $MI_VALIDATE $OUTPUT_DEST
723 ok $?
"Mi test: snapshot delete xsd validation"
726 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
727 test "$result" = "true"
728 ok $?
"Mi test: del snapshot is a success"
731 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:id/text()" result
732 test "$result" = "$snapshot_id"
733 ok $?
"Mi test: snapshot del extracted snapshot id: $result expected: $snapshot_id"
735 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:session_name/text()" result
736 test "$result" = "$session_name"
737 ok $?
"Mi test: snapshot del extracted snapshot id: $result expected: $session_name"
739 #Test fail on delete command
740 lttng_snapshot_del_output_fail
$session_name $snapshot_id
741 $MI_VALIDATE $OUTPUT_DEST
742 ok $?
"Mi test: snapshot delete xsd validation"
745 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
746 test "$result" = "false"
747 ok $?
"Mi test: del snapshot is a success"
750 destroy_lttng_sessions
753 function test_track_untrack
()
755 diag
"Test track/untrack pid"
757 local session_name
="testTrack"
759 OUTPUT_FILE
="track.xml"
763 create_lttng_session_no_output
$session_name
765 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
766 lttng_track_ok
"-p $pid -u"
767 $MI_VALIDATE $OUTPUT_DEST
768 ok $?
"Mi test: track pid xsd validation"
770 #Expect a true element
771 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
772 test "$result" = "true"
773 ok $?
"Mi test: track pid is a success"
775 #Verify that there is 3 process
776 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:id" result
777 num
=$
(echo "$result" |
wc -l)
779 ok $?
"Mi test: track pid expecting 3 processes got $num"
781 #Test the pid_tracker listing
782 list_lttng_ok
$session_name
783 $MI_VALIDATE $OUTPUT_DEST
784 ok $?
"Mi test: session list with pid_tracker validate"
786 #Check the good count
787 extract_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER"/lttng:process_attr_values/lttng:vpid/lttng:type/lttng:id" result
788 num
=$
(echo "$result" |
wc -l)
790 ok $?
"Mi test: tracker pid listing expecting 3 target got $num"
793 lttng_untrack_ok
"-p 2,3 -u"
794 $MI_VALIDATE $OUTPUT_DEST
795 ok $?
"Mi test: untrack pid xsd validation"
797 #Expect a true element
798 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
799 test "$result" = "true"
800 ok $?
"Mi test: untrack pid is a success"
802 #Verify that there is 2 untracked pids
803 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:id" result
804 num
=$
(echo "$result" |
wc -l)
806 ok $?
"Mi test: untrack pid expecting 2 process got $num"
808 #Check pid_tracker listing
809 list_lttng_ok
$session_name
810 $MI_VALIDATE $OUTPUT_DEST
811 ok $?
"Mi test: session list with pid_tracker validate"
813 #Check the good count
814 extract_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER"/lttng:targets/lttng:vpid_target/lttng:type/lttng:pid" result
815 num
=$
(echo "$result" |
wc -l)
817 ok $?
"Mi test: tracker pid listing expecting 1 process got $num"
820 lttng_untrack_ok
"-p -u -a"
821 $MI_VALIDATE $OUTPUT_DEST
822 ok $?
"Mi test: untrack pid xsd validation"
824 #Expect a true element
825 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
826 test "$result" = "true"
827 ok $?
"Mi test: untrack all pid is a success"
829 #Verify that there is 1 untracked pid
830 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:all" result
831 num
=$
(echo "$result" |
wc -l)
833 ok $?
"Mi test: untrack pid expecting 1 process got $num"
835 #Test if type "all" is "true" which represent the all argument
836 test "$result" = "true"
837 ok $?
"Mi test: pid expected is true got $result"
839 #Test if pid_tracker is enabled as definied by pid_tracker
840 #behavior. If all pid are untrack than the pid_tracker is still
841 #enabled (pid_tracker node is present).
842 list_lttng_ok
$session_name
843 $MI_VALIDATE $OUTPUT_DEST
844 ok $?
"Mi test: session list with pid_tracker validate"
846 #Check the good count
847 extract_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER"/lttng:targets/lttng:vpid_target/lttng:type/lttng:pid" result
848 num
=$
(echo -n "$result" |
wc -l)
850 ok $?
"Mi test: tracker pid listing expecting 0 process got $num"
853 lttng_track_ok
"-p -u -a"
854 $MI_VALIDATE $OUTPUT_DEST
855 ok $?
"Mi test: track pid xsd validation"
857 #Expect a true element
858 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
859 test "$result" = "true"
860 ok $?
"Mi test: track all pid is a success"
862 #Verify that there is 1 tracked process
863 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:all" result
864 num
=$
(echo "$result" |
wc -l)
866 ok $?
"Mi test: track pid expecting 1 process got $num"
868 #Test if the id is true wich represent the all argument
869 test "$result" = "true"
870 ok $?
"Mi test: pid expected is true got $result"
872 #Test if pid_tracker is enabled as definied by pid_tracker
873 #behavior. If all pid are untrack thant the pid_tracker is
874 #disabled (node pid_tracker do not exist)
875 list_lttng_ok
$session_name
876 $MI_VALIDATE $OUTPUT_DEST
877 ok $?
"Mi test: session list with pid_tracker validate"
879 node_check_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER result
881 ok $?
"Mi test: VPID_tracker node is absent as defined"
884 destroy_lttng_sessions
887 function test_add_context_list
()
889 diag
"Test context listing"
891 OUTPUT_FILE
="list-context.xml"
892 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
893 lttng_add_context_list
895 $MI_VALIDATE $OUTPUT_DEST
896 ok $?
"Mi test: context listing validation"
899 function test_clear_session
()
901 diag
"Test clear session"
903 # Since the session are not started there is no real clear done.
904 # We are testing the MI output only here.
910 OUTPUT_FILE
="clear_session.xml"
914 for (( i
= 0; i
< 3; i
++ )); do
915 create_lttng_session_ok
${session_name[$i]} $OUTPUT_DIR
918 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
919 lttng_clear_session_ok
${session_name[0]}
920 $MI_VALIDATE $OUTPUT_DEST
921 ok $?
"MI test: clear session ${session_name[0]} xsd validation"
923 #Verify that we cleared the good session
924 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
925 test "$result" = "${session_name[0]}"
926 ok $?
"Mi test: cleared session: $result expected: ${session_name[0]}"
928 #Destroy all and count:should be 3
930 $MI_VALIDATE $OUTPUT_DEST
931 ok $?
"MI test: clear all session xsd validation"
933 #Verify that we cleared 3 sessions
934 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
935 num
=$
(echo "$result" |
wc -l)
937 ok $?
"Mi test: $num / 3 sessions discovered"
939 destroy_lttng_sessions
941 #Verify that if no session is present command fail and mi report it.
942 lttng_clear_session_fail
${session_name[0]}
943 $MI_VALIDATE $OUTPUT_DEST
944 ok $?
"MI test: failing clear session ${session_name[0]} xsd validation"
945 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
946 test "$result" = "false"
947 ok $?
"Mi test: clear command on ${session_name[0]} failed as expected"
951 start_lttng_sessiond
$SESSIOND_LOAD_DIR
966 test_list_session_long_path
967 test_add_context_list
973 for fct_test
in ${TESTS[@]};
976 if [ $?
-ne 0 ]; then
981 rm -rf $SESSIOND_LOAD_DIR
983 OUTPUT_DEST
=/dev
/null
2>&1