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/..
/..
/..
/
11 XSD_PATH
=$TESTDIR/..
/src
/common
/mi-lttng-4.0.xsd
13 #Test app for ust event
14 TESTAPP_PATH
="$TESTDIR/utils/testapp"
15 TESTAPP_NAME
="gen-ust-events"
16 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
21 OUTPUT_DIR
=$
(mktemp
-d)
22 SESSIOND_LOAD_DIR
=$
(mktemp
-d)
23 OUTPUT_FILE
="default.xml"
25 #Path to custom xml utilities
26 XML_VALIDATE
="$CURDIR/validate_xml $XSD_PATH"
27 XML_EXTRACT
="$CURDIR/extract_xml"
28 XML_NODE_CHECK
="$CURDIR/extract_xml -e"
30 XPATH_CMD_OUTPUT
="//lttng:command/lttng:output"
31 XPATH_COMMAND_SUCCESS
="/lttng:command/lttng:success/text()"
32 XPATH_SESSION
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session"
33 XPATH_ENABLE_CHANNEL_NAME
="$XPATH_CMD_OUTPUT/lttng:channels/lttng:channel/lttng:name/text()"
34 XPATH_ENABLE_EVENT_SUCCESS
="$XPATH_CMD_OUTPUT/lttng:events/lttng:event/lttng:success/text()"
35 XPATH_DISABLE_EVENT_SUCCESS
="$XPATH_CMD_OUTPUT/lttng:channel/lttng:events/lttng:event/lttng:success/text()"
36 XPATH_LIST_DOMAIN
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain"
37 XPATH_LIST_CHANNEL
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:channels/lttng:channel"
38 XPATH_LIST_UST_EVENT
="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type ='UST']/lttng:pids/lttng:pid/lttng:events/lttng:event"
39 XPATH_SNAPSHOT_ADD_SNAPSHOT
="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'add-output']/lttng:output"
40 XPATH_SNAPSHOT_LIST
="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'list-output']/lttng:output"
41 XPATH_SNAPSHOT_DEL
="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'del-output']/lttng:output"
42 XPATH_TRACK_UNTRACK_VPID
="$XPATH_CMD_OUTPUT/lttng:process_attr_trackers/lttng:vpid_process_attr_tracker/lttng:process_attr_values/lttng:vpid/lttng:type"
43 XPATH_VPID_TRACKER
="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:process_attr_trackers/lttng:vpid_process_attr_tracker"
45 DEVNULL
=/dev
/null
2>&1
47 DIR
=$
(readlink
-f $TESTDIR)
51 source $TESTDIR/utils
/utils.sh
53 #Overwrite the lttng_bin to get mi output
54 LTTNG_BIN
="lttng --mi xml"
56 #Global declaration for simplification
57 LTTNG
=$TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN
59 #Overwrite the default output for utils.sh command
61 #MUST set TESTDIR before calling those functions
64 print_test_banner
"$TEST_DESC"
66 function extract_xml
()
72 output
=$
($XML_EXTRACT $xml "$xpath")
73 ok $?
"Extraction of xpath $xpath"
74 eval $__result="'$output'"
77 function node_check_xml
()
83 output
=$
($XML_NODE_CHECK $xml "$xpath")
84 ok $?
"Check of node existence with xpath $xpath"
85 eval $__result="'$output'"
88 # Arg1 is path to xml file
90 # is true if we expected the success element to be false
94 function is_command_success
()
99 local xpath
=$XPATH_COMMAND_SUCCESS
102 #Extract the success element
104 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
105 if [[ $expect_false = "true" ]]; then
106 if [[ $result ]]; then
107 pass
"Mi test: $xml command failed as expected"
109 fail
"Mi test: $xml command did not fail as expected"
112 if [[ $result ]]; then
113 pass
"Mi test: $xml command success"
115 fail
"Mi test: $xml command failed"
120 function mi_print_version
()
125 $LTTNG version
$opt > $output_path
126 ok $?
"MI test: Lttng version"
130 function test_version
()
132 OUTPUT_FILE
="version.xml"
133 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
134 mi_print_version
$OUTPUT_DEST
135 $XML_VALIDATE $OUTPUT_DEST
136 ok $?
"MI test: Version xsd validation"
139 function test_create_session
()
141 local session_name
="testSession"
143 OUTPUT_FILE
="create_session.xml"
144 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
145 create_lttng_session_ok
$session_name $OUTPUT_DIR
146 $XML_VALIDATE $OUTPUT_DEST
147 ok $?
"MI test: create session xsd validation"
149 #try to recreate a session. Expecting it to fail
150 create_lttng_session_fail
$session_name $OUTPUT_DIR
151 $XML_VALIDATE $OUTPUT_DEST
152 ok $?
"MI test: expecting fail create session xsd validation"
153 is_command_success
$OUTPUT_DEST true
156 destroy_lttng_session_ok
$session_name
159 function test_destroy_session
()
166 OUTPUT_FILE
="destroy_session.xml"
170 for (( i
= 0; i
< 3; i
++ )); do
171 create_lttng_session_ok
${session_name[$i]} $OUTPUT_DIR
174 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
175 destroy_lttng_session_ok
${session_name[0]}
176 $XML_VALIDATE $OUTPUT_DEST
177 ok $?
"MI test: destroy session ${session_name[0]} xsd validation"
179 #Verify that we destroyed the good session
180 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
181 test "$result" = "${session_name[0]}"
182 ok $?
"Mi test: deleted session: $result expected: ${session_name[0]}"
184 #Destroy all and count:should be 2
185 destroy_lttng_sessions
186 $XML_VALIDATE $OUTPUT_DEST
187 ok $?
"MI test: destroy all session xsd validation"
189 #Verify that we destroyed 2 sessions
190 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
191 num
=$
(echo "$result" |
wc -l)
193 ok $?
"Mi test: $num / 2 sessions discovered"
195 #Verify that if no session is present command fail and mi report it.
196 destroy_lttng_session_fail
${session_name[0]}
197 $XML_VALIDATE $OUTPUT_DEST
198 ok $?
"MI test: failing destroy session ${session_name[0]} xsd validation"
199 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
200 test "$result" = "false"
201 ok $?
"Mi test: destroy command on ${session_name[0]} failed as expected"
205 function test_list_sessions
()
212 OUTPUT_FILE
="list_sessions.xml"
216 for (( i
= 0; i
< 3; i
++ )); do
217 create_lttng_session_ok
${session_name[$i]} $OUTPUT_DIR
220 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
222 $XML_VALIDATE $OUTPUT_DEST
223 ok $?
"Mi test: list sessions xsd validation"
225 #We should have 3 session
226 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
227 num
=$
(echo "$result" |
wc -l)
229 ok $?
"Mi test: $num / 3 sessions discovered"
233 destroy_lttng_sessions
236 function test_list_session_long_path
()
238 local session_name
="session_long_path"
240 output_basedir
=$OUTPUT_DIR/$
(randstring
254 0)
241 mkdir
-p ${output_basedir}
243 OUTPUT_FILE
="list_sessions.xml"
247 create_lttng_session_ok
$session_name ${output_basedir}
249 OUTPUT_DEST
=${output_basedir}/$OUTPUT_FILE
251 $XML_VALIDATE $OUTPUT_DEST
252 ok $?
"Mi test: list session with long path xsd validation"
256 destroy_lttng_sessions
258 function test_ust_channel
()
260 local session_name
="testsession"
261 local channel_name
=("channelUst0"
265 OUTPUT_FILE
="ust_channel.xml"
269 create_lttng_session_ok
$session_name $OUTPUT_DIR
271 #Test the enable_channel command
272 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
273 enable_ust_lttng_channel_ok
$session_name ${channel_name[0]}
274 $XML_VALIDATE $OUTPUT_DEST
275 ok $?
"Mi test: enable ust channel xsd validation"
276 is_command_success
$OUTPUT_DEST false
278 #Expect the command to fail
279 enable_ust_lttng_channel_fail
$session_name ${channel_name[0]}
280 $XML_VALIDATE $OUTPUT_DEST
281 ok $?
"Mi test: fail enable ust channel xsd validation"
282 is_command_success
$OUTPUT_DEST true
284 #Create two ust channel to test multiple disable
285 for (( i
= 1; i
< 3; i
++ )); do
286 enable_ust_lttng_channel_ok
$session_name ${channel_name[$i]}
289 #Test the disable_channel command
290 disable_ust_lttng_channel
$session_name ${channel_name[0]}
291 $XML_VALIDATE $OUTPUT_DEST
292 ok $?
"Mi test: disable ust channel xsd validation"
293 is_command_success
$OUTPUT_DEST false
294 #Check that we delete the good channel
295 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
296 test "$result" = "${channel_name[0]}"
297 ok $?
"MI test: ${channel_name[0]} disabled"
299 #Test multiple disable_channel;
300 disable_ust_lttng_channel
$session_name ${channel_name[1]},${channel_name[2]}
301 $XML_VALIDATE $OUTPUT_DEST
302 ok $?
"Mi test: multiple disable ust channel xsd validation"
303 is_command_success
$OUTPUT_DEST false
305 #Make sure we have two disabled channel
306 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
307 local num
=$
(echo "$result" |
wc -l)
309 ok $?
"Mi test: disabled ust channel $num/2"
313 destroy_lttng_sessions
317 function test_ust_lttng_event
()
319 local session_name
="testSession"
320 local channel_name
="testChannel"
321 local event
=("ev1" "ev2" "ev3")
323 OUTPUT_FILE
="ust_event.xml"
327 create_lttng_session_ok
$session_name $OUTPUT_DIR
328 enable_ust_lttng_channel_ok
$session_name $channel_name
330 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
331 #Test the enable event for ust domain
332 enable_ust_lttng_event_ok
$session_name ${event[0]} $channel_name
333 $XML_VALIDATE $OUTPUT_DEST
334 ok $?
"Mi test: Enable_event for ust domain xsd validation"
335 is_command_success
$OUTPUT_DEST false
337 #Try to reenable an enabled event. Should fail
338 enable_ust_lttng_event_fail
$session_name ${event[0]} $channel_name
339 $XML_VALIDATE $OUTPUT_DEST
340 ok $?
"Mi test: Fail enable_event for ust domain xsd validation"
341 is_command_success
$OUTPUT_DEST true
343 #Enable multiple event including the last one command will fail
344 #But 2 events should success
346 #Nice little hack, create a string ev,ev,ev
347 #IFS stand for Internal field separator
348 #Event[*] print all the element inside the array with the IFS in between
349 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
351 enable_ust_lttng_event_fail
$session_name $concat_event $channel_name
352 $XML_VALIDATE $OUTPUT_DEST
353 ok $?
"Mi test: Multiple enable ust event with inside fail xsd validation"
355 #Check for 2 success = true and 1 success = false
356 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
357 num_ocur
=$
(grep -o "true" <<< "$result" |
wc -l)
358 test "$num_ocur" -eq "2"
359 ok $?
"Mi test: Enabled event on failing enable command $num_ocur_true/2"
361 extract_xml
$OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
362 num_ocur
=$
(grep -o "false" <<< "$result" |
wc -l)
363 test "$num_ocur" -eq "1"
364 ok $?
"Mi test: Enabled event on failing enable command $num_ocur_true/2"
367 disable_ust_lttng_event
$session_name ${event[0]} $channel_name
368 $XML_VALIDATE $OUTPUT_DEST
369 ok $?
"Mi test: Disable ust event xsd validation"
370 is_command_success
$OUTPUT_DEST false
372 #Disable the 3 event combined. Should pass
373 disable_ust_lttng_event
$session_name $concat_event $channel_name
374 $XML_VALIDATE $OUTPUT_DEST
375 ok $?
"Mi test: Disable multiple ust event xsd validation"
376 is_command_success
$OUTPUT_DEST false
378 #Make sure we have 3 inner success
379 extract_xml
$OUTPUT_DEST $XPATH_DISABLE_EVENT_SUCCESS result
380 num_ocur
=$
(grep -o "true" <<< "$result" |
wc -l)
381 test "$num_ocur" -eq "3"
382 ok $?
"Mi test: Disable multiple ust event success $num_ocur/3"
386 destroy_lttng_sessions
389 function test_list_channel
()
391 local session_name
="testSession"
392 local channel_name
="testChannel"
393 local event
=("ev1" "ev2" "ev3")
395 OUTPUT_FILE
="list_channel.xml"
399 create_lttng_session_ok
$session_name $OUTPUT_DIR
400 enable_ust_lttng_channel_ok
$session_name $channel_name
402 #Enable ust and jul events
403 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
404 enable_ust_lttng_event_ok
$session_name $concat_event $channel_name
407 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
408 list_lttng_with_opts
"$session_name -c $channel_name"
409 $XML_VALIDATE $OUTPUT_DEST
410 ok $?
"Mi test: list channel xsd validation"
412 #Expect 1 domain: UST
413 extract_xml
$OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
414 num
=$
(echo "$result" |
wc -l)
416 ok $?
"Mi test: $num / 1 domains discovered"
418 #Expect 1 channel: test
419 extract_xml
$OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
420 num
=$
(echo "$result" |
wc -l)
422 ok $?
"Mi test: $num / 1 channel discovered"
424 test "$result" = "$channel_name"
425 ok $?
"Mi test: expected channel: $channel_name found: $result"
427 #Add a channel and make sure we have 2 channel now
429 enable_ust_lttng_channel_ok
$session_name $channel_name"a"
433 destroy_lttng_sessions
436 function test_list_domain
()
438 local session_name
="testSession"
439 local channel_name
="testChannel"
440 local event
=("ev1" "ev2" "ev3")
442 OUTPUT_FILE
="list_domain.xml"
446 create_lttng_session_ok
$session_name $OUTPUT_DIR
447 enable_ust_lttng_channel_ok
$session_name $channel_name
449 #Enable ust and jul events
450 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
451 enable_ust_lttng_event_ok
$session_name $concat_event $channel_name
452 enable_jul_lttng_event
$session_name $concat_event $channel_name
455 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
456 list_lttng_with_opts
"$session_name -d"
457 $XML_VALIDATE $OUTPUT_DEST
458 ok $?
"Mi test: list domain xsd validation"
460 #Expect 2 domain: Jul and UST
461 extract_xml
$OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
462 num
=$
(echo "$result" |
wc -l)
464 ok $?
"Mi test: $num / 2 domains discovered"
466 #Test for valid value
467 if [[ "$result" = *"JUL"* ]]; then
468 pass
"Mi test: domains Jul is present"
470 fail
"Mi test: domains Jul is absent"
473 if [[ "$result" = *"UST"* ]]; then
474 pass
"Mi test: domains UST is present"
476 fail
"Mi test: domains UST is absent"
481 destroy_lttng_sessions
484 function test_list_session
()
486 local session_name
="testSession"
487 local channel_name
="testChannel"
488 local event
=("ev1" "ev2" "ev3")
490 OUTPUT_FILE
="list_session.xml"
494 create_lttng_session_ok
$session_name $OUTPUT_DIR
495 enable_ust_lttng_channel_ok
$session_name $channel_name
497 #Enable ust and jul events
498 concat_event
=$
( IFS
=$
','; echo "${event[*]}" )
499 enable_ust_lttng_event_ok
$session_name $concat_event $channel_name
500 enable_jul_lttng_event
$session_name $concat_event $channel_name
503 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
504 list_lttng_with_opts
$session_name
505 $XML_VALIDATE $OUTPUT_DEST
506 ok $?
"Mi test: list session xsd validation"
508 #Expect 2 domain: Jul and UST
509 extract_xml
$OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
510 num
=$
(echo "$result" |
wc -l)
512 ok $?
"Mi test: $num / 2 domains discovered"
514 #Expect 2 channel: test and lttng_jul_event
515 extract_xml
$OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
516 num
=$
(echo "$result" |
wc -l)
518 ok $?
"Mi test: $num / 2 channel discovered"
522 destroy_lttng_sessions
525 function test_list_ust_event
()
527 local file_sync_after_first
=$
(mktemp
-u)
528 local file_sync_before_last
=$
(mktemp
-u)
530 OUTPUT_FILE
="list_ust_event.xml"
533 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
536 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
537 --sync-after-first-event ${file_sync_after_first} \
538 --sync-before-last-event ${file_sync_before_last} & 2>/dev
/null
540 while [ ! -f "${file_sync_after_first}" ]; do
544 list_lttng_with_opts
"-u -f"
546 touch ${file_sync_before_last}
548 $XML_VALIDATE $OUTPUT_DEST
549 ok $?
"Mi test: list ust event xsd validation"
552 extract_xml
$OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/lttng:name/text()" result
553 num
=$
(echo "$result" |
wc -l)
555 #Since the number of events is prone to change we only look for >= from a
556 #base number. An alternative would be to look for each events but this
557 #is complicated for nothing.
559 ok $?
"Mi test: $num / 5 ust events discovered"
561 #Extract field from tp:tptest event. Expect >= to 12 because number of
562 #field is prone to change.
563 extract_xml
$OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./lttng:name = 'tp:tptest']/lttng:event_fields/lttng:event_field/lttng:name/text()" result
564 num
=$
(echo "$result" |
wc -l)
566 ok $?
"Mi test: $num / 12 ust event fields discovered"
568 #Wait for all background processes
571 rm -f ${file_sync_after_first}
572 rm -f ${file_sync_before_last}
575 function test_start_stop
() {
576 local session_name
="testStartStopSession"
577 local channel_name
="startStopChannel"
579 OUTPUT_FILE
="list_start_stop.xml"
583 create_lttng_session_ok
$session_name $OUTPUT_DIR
586 #No channel enable start command should return element success false
587 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
588 start_lttng_tracing_fail
$session_name
589 $XML_VALIDATE $OUTPUT_DEST
590 ok $?
"Mi test: failed start xsd validation"
592 #Expect a false element
593 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
594 test "$result" = "false"
595 ok $?
"Mi test: mi report failure on start command as expected"
597 #Enable a channel to test success
599 enable_ust_lttng_channel_ok
$session_name $channel_name
602 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
603 start_lttng_tracing_ok
$session_name
604 $XML_VALIDATE $OUTPUT_DEST
605 ok $?
"Mi test: start xsd validation"
607 #Expect a true element
608 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
609 test "$result" = "true"
610 ok $?
"Mi test: mi report success on start command as expected"
612 #Extract session name from xml
613 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
614 test "$result" = "$session_name"
615 ok $?
"Mi test: started $session_name"
617 #Extract enabled expect true
618 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
619 test "$result" = "true"
620 ok $?
"Mi test: enabled element : $result expected: true"
622 #Test metadata regenerate command
623 regenerate_metadata_ok
$session_name
624 $XML_VALIDATE $OUTPUT_DEST
625 ok $?
"Mi test: regenerate metadata"
628 stop_lttng_tracing_ok
$session_name
629 $XML_VALIDATE $OUTPUT_DEST
630 ok $?
"Mi test: stop xsd validation"
632 #Extract session name from xml
633 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
634 test "$result" = "$session_name"
635 ok $?
"Mi test: stopped $session_name"
637 #Extract enabled expect false
638 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
639 test "$result" = "false"
640 ok $?
"Mi test: enabled element : $result expected: false"
642 #Test failing stop command
643 stop_lttng_tracing_fail
$session_name
644 $XML_VALIDATE $OUTPUT_DEST
645 ok $?
"Mi test: failed stop xsd validation"
647 #Expect a false element
648 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
649 test "$result" = "false"
650 ok $?
"Mi test: mi report failure on start command as expected"
654 destroy_lttng_sessions
657 function test_snapshot
() {
658 local session_name
="testSnapshotAdd"
659 local snapshot_path
="$OUTPUT_DIR/snapshotoutput"
660 OUTPUT_FILE
="snapshot.xml"
665 create_lttng_session_no_output
$session_name
668 #No channel enable start command should return element success false
669 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
670 lttng_snapshot_add_output_ok
$session_name file://$snapshot_path
671 $XML_VALIDATE $OUTPUT_DEST
672 ok $?
"Mi test: snapshot xsd validation"
674 #Expect a true element
675 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
676 test "$result" = "true"
677 ok $?
"Mi test: add snapshot is a success"
680 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:session_name/text()" result
681 test "$result" = "$session_name"
682 ok $?
"Mi test: added snapshot for: $result expected $session_name"
684 #Get name of generated output and id
685 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:name/text()" snapshot_name
686 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:id/text()" snapshot_id
689 lttng_snapshot_list
$session_name
690 $XML_VALIDATE $OUTPUT_DEST
691 ok $?
"Mi test: snapshot list xsd validation"
693 #Expect a true element
694 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
695 test "$result" = "true"
696 ok $?
"Mi test: add snapshot is a success"
698 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/lttng:session[./lttng:name ='$session_name']/lttng:snapshots/lttng:snapshot/lttng:name/text()" result
699 test "$result" = "$snapshot_name"
700 ok $?
"Mi test: snapshot list extracted snapshot: $result expected: $snapshot_name"
703 lttng_snapshot_del_output_ok
$session_name $snapshot_id
704 $XML_VALIDATE $OUTPUT_DEST
705 ok $?
"Mi test: snapshot delete xsd validation"
708 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
709 test "$result" = "true"
710 ok $?
"Mi test: del snapshot is a success"
713 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:id/text()" result
714 test "$result" = "$snapshot_id"
715 ok $?
"Mi test: snapshot del extracted snapshot id: $result expected: $snapshot_id"
717 extract_xml
$OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:session_name/text()" result
718 test "$result" = "$session_name"
719 ok $?
"Mi test: snapshot del extracted snapshot id: $result expected: $session_name"
721 #Test fail on delete command
722 lttng_snapshot_del_output_fail
$session_name $snapshot_id
723 $XML_VALIDATE $OUTPUT_DEST
724 ok $?
"Mi test: snapshot delete xsd validation"
727 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
728 test "$result" = "false"
729 ok $?
"Mi test: del snapshot is a success"
732 destroy_lttng_sessions
735 function test_track_untrack
()
737 diag
"Test track/untrack pid"
739 local session_name
="testTrack"
741 OUTPUT_FILE
="track.xml"
745 create_lttng_session_no_output
$session_name
747 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
748 lttng_track_ok
"-p $pid -u"
749 $XML_VALIDATE $OUTPUT_DEST
750 ok $?
"Mi test: track pid xsd validation"
752 #Expect a true element
753 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
754 test "$result" = "true"
755 ok $?
"Mi test: track pid is a success"
757 #Verify that there is 3 process
758 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:id" result
759 num
=$
(echo "$result" |
wc -l)
761 ok $?
"Mi test: track pid expecting 3 processes got $num"
763 #Test the pid_tracker listing
764 list_lttng_with_opts
$session_name
765 $XML_VALIDATE $OUTPUT_DEST
766 ok $?
"Mi test: session list with pid_tracker validate"
768 #Check the good count
769 extract_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER"/lttng:process_attr_values/lttng:vpid/lttng:type/lttng:id" result
770 num
=$
(echo "$result" |
wc -l)
772 ok $?
"Mi test: tracker pid listing expecting 3 target got $num"
775 lttng_untrack_ok
"-p 2,3 -u"
776 $XML_VALIDATE $OUTPUT_DEST
777 ok $?
"Mi test: untrack pid xsd validation"
779 #Expect a true element
780 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
781 test "$result" = "true"
782 ok $?
"Mi test: untrack pid is a success"
784 #Verify that there is 2 untracked pids
785 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:id" result
786 num
=$
(echo "$result" |
wc -l)
788 ok $?
"Mi test: untrack pid expecting 2 process got $num"
790 #Check pid_tracker listing
791 list_lttng_with_opts
$session_name
792 $XML_VALIDATE $OUTPUT_DEST
793 ok $?
"Mi test: session list with pid_tracker validate"
795 #Check the good count
796 extract_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER"/lttng:targets/lttng:vpid_target/lttng:type/lttng:pid" result
797 num
=$
(echo "$result" |
wc -l)
799 ok $?
"Mi test: tracker pid listing expecting 1 process got $num"
802 lttng_untrack_ok
"-p -u -a"
803 $XML_VALIDATE $OUTPUT_DEST
804 ok $?
"Mi test: untrack pid xsd validation"
806 #Expect a true element
807 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
808 test "$result" = "true"
809 ok $?
"Mi test: untrack all pid is a success"
811 #Verify that there is 1 untracked pid
812 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:all" result
813 num
=$
(echo "$result" |
wc -l)
815 ok $?
"Mi test: untrack pid expecting 1 process got $num"
817 #Test if type "all" is "true" which represent the all argument
818 test "$result" = "true"
819 ok $?
"Mi test: pid expected is true got $result"
821 #Test if pid_tracker is enabled as definied by pid_tracker
822 #behavior. If all pid are untrack than the pid_tracker is still
823 #enabled (pid_tracker node is present).
824 list_lttng_with_opts
$session_name
825 $XML_VALIDATE $OUTPUT_DEST
826 ok $?
"Mi test: session list with pid_tracker validate"
828 #Check the good count
829 extract_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER"/lttng:targets/lttng:vpid_target/lttng:type/lttng:pid" result
830 num
=$
(echo -n "$result" |
wc -l)
832 ok $?
"Mi test: tracker pid listing expecting 0 process got $num"
835 lttng_track_ok
"-p -u -a"
836 $XML_VALIDATE $OUTPUT_DEST
837 ok $?
"Mi test: track pid xsd validation"
839 #Expect a true element
840 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
841 test "$result" = "true"
842 ok $?
"Mi test: track all pid is a success"
844 #Verify that there is 1 tracked process
845 extract_xml
$OUTPUT_DEST $XPATH_TRACK_UNTRACK_VPID"/lttng:all" result
846 num
=$
(echo "$result" |
wc -l)
848 ok $?
"Mi test: track pid expecting 1 process got $num"
850 #Test if the id is true wich represent the all argument
851 test "$result" = "true"
852 ok $?
"Mi test: pid expected is true got $result"
854 #Test if pid_tracker is enabled as definied by pid_tracker
855 #behavior. If all pid are untrack thant the pid_tracker is
856 #disabled (node pid_tracker do not exist)
857 list_lttng_with_opts
$session_name
858 $XML_VALIDATE $OUTPUT_DEST
859 ok $?
"Mi test: session list with pid_tracker validate"
861 node_check_xml
$OUTPUT_DEST $XPATH_VPID_TRACKER result
863 ok $?
"Mi test: VPID_tracker node is absent as defined"
866 destroy_lttng_sessions
869 function test_add_context_list
()
871 diag
"Test context listing"
873 OUTPUT_FILE
="list-context.xml"
874 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
875 lttng_add_context_list
877 $XML_VALIDATE $OUTPUT_DEST
878 ok $?
"Mi test: context listing validation"
881 function test_clear_session
()
883 # Since the session are not started there is no real clear done.
884 # We are testing the MI output only here.
890 OUTPUT_FILE
="clear_session.xml"
894 for (( i
= 0; i
< 3; i
++ )); do
895 create_lttng_session_ok
${session_name[$i]} $OUTPUT_DIR
898 OUTPUT_DEST
=$OUTPUT_DIR/$OUTPUT_FILE
899 lttng_clear_session_ok
${session_name[0]}
900 $XML_VALIDATE $OUTPUT_DEST
901 ok $?
"MI test: clear session ${session_name[0]} xsd validation"
903 #Verify that we cleared the good session
904 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
905 test "$result" = "${session_name[0]}"
906 ok $?
"Mi test: cleared session: $result expected: ${session_name[0]}"
908 #Destroy all and count:should be 3
910 $XML_VALIDATE $OUTPUT_DEST
911 ok $?
"MI test: clear all session xsd validation"
913 #Verify that we cleared 3 sessions
914 extract_xml
$OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
915 num
=$
(echo "$result" |
wc -l)
917 ok $?
"Mi test: $num / 3 sessions discovered"
919 destroy_lttng_sessions
921 #Verify that if no session is present command fail and mi report it.
922 lttng_clear_session_fail
${session_name[0]}
923 $XML_VALIDATE $OUTPUT_DEST
924 ok $?
"MI test: failing clear session ${session_name[0]} xsd validation"
925 extract_xml
$OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
926 test "$result" = "false"
927 ok $?
"Mi test: clear command on ${session_name[0]} failed as expected"
931 start_lttng_sessiond
$SESSIOND_LOAD_DIR
946 test_list_session_long_path
947 test_add_context_list
953 for fct_test
in ${TESTS[@]};
956 if [ $?
-ne 0 ]; then
963 OUTPUT_DEST
=/dev
/null
2>&1