Fix: tests: app unregistering is not guaranteed by app lifetime
[lttng-tools.git] / tests / regression / tools / mi / test_mi
1 #!/bin/bash
2 #
3 # Copyright (C) 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Machine interface testing"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../../
11
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"
16 NR_USEC_WAIT=0
17 NR_ITER=10000
18
19 #Temp file output
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"
23
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"
38
39 DEVNULL=/dev/null 2>&1
40
41 DIR=$(readlink -f $TESTDIR)
42
43 NUM_TESTS=246
44
45 source $TESTDIR/utils/utils.sh
46
47 #Overwrite the lttng_bin to get mi output
48 LTTNG_BIN="lttng --mi xml"
49
50 #Global declaration for simplification
51 LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN
52
53 #Overwrite the default output for utils.sh command
54
55 #MUST set TESTDIR before calling those functions
56 plan_tests $NUM_TESTS
57
58 print_test_banner "$TEST_DESC"
59
60 function extract_xml ()
61 {
62 local xml=$1
63 local xpath=$2
64 local __result=$3
65 local output
66 output=$($XML_EXTRACT $xml "$xpath")
67 ok $? "Extraction of xpath $xpath"
68 eval $__result="'$output'"
69 }
70
71 function node_check_xml ()
72 {
73 local xml=$1
74 local xpath=$2
75 local __result=$3
76 local output
77 output=$($XML_NODE_CHECK $xml "$xpath")
78 ok $? "Check of node existence with xpath $xpath"
79 eval $__result="'$output'"
80 }
81
82 # Arg1 is path to xml file
83 # Arg2:
84 # is true if we expected the success element to be false
85 # else
86 # passe false
87
88 function is_command_success ()
89 {
90 local xml=$1
91 local expect_false=$2
92
93 local xpath=$XPATH_COMMAND_SUCCESS
94
95 #Extract the success element
96 #expect false
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"
101 else
102 fail "Mi test: $xml command did not fail as expected"
103 fi
104 else
105 if [[ $result ]]; then
106 pass "Mi test: $xml command success"
107 else
108 fail "Mi test: $xml command failed"
109 fi
110 fi
111 }
112
113 function mi_print_version ()
114 {
115 local output_path=$1
116 local opt=$2
117
118 $LTTNG version $opt > $output_path
119 ok $? "MI test: Lttng version"
120
121 }
122
123 function test_version ()
124 {
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"
130 }
131
132 function test_create_session ()
133 {
134 diag "Test create session"
135
136 local session_name="testSession"
137
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"
143
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
149
150 OUTPUT_DEST=$DEVNULL
151 destroy_lttng_session_ok $session_name
152 }
153
154 function test_destroy_session ()
155 {
156 diag "Test destroy session"
157
158 local session_name=(
159 "testSession1"
160 "testSession2"
161 "testSession3")
162
163 OUTPUT_FILE="destroy_session.xml"
164
165 #Test build up
166 OUTPUT_DEST=$DEVNULL
167 for (( i = 0; i < 3; i++ )); do
168 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
169 done
170
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"
175
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]}"
180
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"
185
186 #Verify that we destroyed 2 sessions
187 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
188 num=$(echo "$result" | wc -l)
189 test "$num" -eq "2"
190 ok $? "Mi test: $num / 2 sessions discovered"
191
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"
199
200 }
201
202 function test_list_sessions ()
203 {
204 diag "Test list sessions"
205
206 local session_name=(
207 "testSession1"
208 "testSession2"
209 "testSession3")
210
211 OUTPUT_FILE="list_sessions.xml"
212
213 #Test buid up
214 OUTPUT_DEST=$DEVNULL
215 for (( i = 0; i < 3; i++ )); do
216 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
217 done
218
219 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
220 list_lttng_ok
221 $MI_VALIDATE $OUTPUT_DEST
222 ok $? "Mi test: list sessions xsd validation"
223
224 #We should have 3 session
225 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
226 num=$(echo "$result" | wc -l)
227 test "$num" -eq "3"
228 ok $? "Mi test: $num / 3 sessions discovered"
229
230 #Teardown
231 OUTPUT_DEST=$DEVNULL
232 destroy_lttng_sessions
233 }
234
235 function test_list_session_long_path ()
236 {
237 diag "Test list session long path"
238
239 local session_name="session_long_path"
240
241 output_basedir=$OUTPUT_DIR/$(randstring 254 0)
242 mkdir -p ${output_basedir}
243
244 OUTPUT_FILE="list_sessions.xml"
245
246 #Test build up
247 OUTPUT_DEST=$DEVNULL
248 create_lttng_session_ok $session_name ${output_basedir}
249
250 OUTPUT_DEST=${output_basedir}/$OUTPUT_FILE
251 list_lttng_ok
252 $MI_VALIDATE $OUTPUT_DEST
253 ok $? "Mi test: list session with long path xsd validation"
254
255 #Teardown
256 OUTPUT_DEST=$DEVNULL
257 destroy_lttng_sessions
258 }
259 function test_ust_channel ()
260 {
261 diag "Test UST channel"
262
263 local session_name="testsession"
264 local channel_name=("channelUst0" "channelUst1" "channelUst2")
265
266 OUTPUT_FILE="ust_channel.xml"
267
268 #Test buil up
269 OUTPUT_DEST=$DEVNULL
270 create_lttng_session_ok $session_name $OUTPUT_DIR
271
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
278
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
284
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]}
288 done
289
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"
299
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
305
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)
309 test "$num" = "2"
310 ok $? "Mi test: disabled ust channel $num/2"
311
312 #Teardown
313 OUTPUT_DEST=$DEVNULL
314 destroy_lttng_sessions
315
316 }
317
318 function test_ust_lttng_event ()
319 {
320 diag "Test UST event"
321
322 local session_name="testSession"
323 local channel_name="testChannel"
324 local event=("ev1" "ev2" "ev3")
325
326 OUTPUT_FILE="ust_event.xml"
327
328 #Test build up
329 OUTPUT_DEST=$DEVNULL
330 create_lttng_session_ok $session_name $OUTPUT_DIR
331 enable_ust_lttng_channel_ok $session_name $channel_name
332
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
339
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
345
346 #Enable multiple event including the last one command will fail
347 #But 2 events should success
348
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[*]}" )
353
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"
357
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"
363
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"
368
369 #Disable the event
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
374
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
380
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"
386
387 #Teardown
388 OUTPUT_DEST=$DEVNULL
389 destroy_lttng_sessions
390 }
391
392 function test_list_channel ()
393 {
394 diag "Test list channel"
395
396 local session_name="testSession"
397 local channel_name="testChannel"
398 local event=("ev1" "ev2" "ev3")
399
400 OUTPUT_FILE="list_channel.xml"
401
402 #Test buid up
403 OUTPUT_DEST=$DEVNULL
404 create_lttng_session_ok $session_name $OUTPUT_DIR
405 enable_ust_lttng_channel_ok $session_name $channel_name
406
407 #Enable ust and jul events
408 concat_event=$( IFS=$','; echo "${event[*]}" )
409 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
410
411 #Begin testing
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"
416
417 #Expect 1 domain: UST
418 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
419 num=$(echo "$result" | wc -l)
420 test "$num" -eq "1"
421 ok $? "Mi test: $num / 1 domains discovered"
422
423 #Expect 1 channel: test
424 extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
425 num=$(echo "$result" | wc -l)
426 test "$num" -eq "1"
427 ok $? "Mi test: $num / 1 channel discovered"
428
429 test "$result" = "$channel_name"
430 ok $? "Mi test: expected channel: $channel_name found: $result"
431
432 #Add a channel and make sure we have 2 channel now
433 OUTPUT_DEST=$DEVNULL
434 enable_ust_lttng_channel_ok $session_name $channel_name"a"
435
436 #Teardown
437 OUTPUT_DEST=$DEVNULL
438 destroy_lttng_sessions
439 }
440
441 function test_list_domain ()
442 {
443 diag "Test list domain"
444
445 local session_name="testSession"
446 local channel_name="testChannel"
447 local event=("ev1" "ev2" "ev3")
448
449 OUTPUT_FILE="list_domain.xml"
450
451 #Test buid up
452 OUTPUT_DEST=$DEVNULL
453 create_lttng_session_ok $session_name $OUTPUT_DIR
454 enable_ust_lttng_channel_ok $session_name $channel_name
455
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
460
461 #Begin testing
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"
466
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)
470 test "$num" -eq "2"
471 ok $? "Mi test: $num / 2 domains discovered"
472
473 #Test for valid value
474 if [[ "$result" = *"JUL"* ]]; then
475 pass "Mi test: domains Jul is present"
476 else
477 fail "Mi test: domains Jul is absent"
478 fi
479
480 if [[ "$result" = *"UST"* ]]; then
481 pass "Mi test: domains UST is present"
482 else
483 fail "Mi test: domains UST is absent"
484 fi
485
486 #Teardown
487 OUTPUT_DEST=$DEVNULL
488 destroy_lttng_sessions
489 }
490
491 function test_list_session ()
492 {
493 diag "Test list session"
494
495 local session_name="testSession"
496 local channel_name="testChannel"
497 local event=("ev1" "ev2" "ev3")
498
499 OUTPUT_FILE="list_session.xml"
500
501 #Test buid up
502 OUTPUT_DEST=$DEVNULL
503
504 create_lttng_session_ok $session_name $OUTPUT_DIR
505 enable_ust_lttng_channel_ok $session_name $channel_name
506
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
511
512 #Begin testing
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"
517
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)
521 test "$num" -eq "2"
522 ok $? "Mi test: $num / 2 domains discovered"
523
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)
527 test "$num" -eq "2"
528 ok $? "Mi test: $num / 2 channel discovered"
529
530 #Teardown
531 OUTPUT_DEST=$DEVNULL
532 destroy_lttng_sessions
533 }
534
535 function test_list_ust_event ()
536 {
537 diag "Test list ust event"
538
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")
541
542 OUTPUT_FILE="list_ust_event.xml"
543
544 #Test buid up
545 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
546
547 #Begin testing
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
551
552 while [ ! -f "${file_sync_after_first}" ]; do
553 sleep 0.5
554 done
555
556 list_lttng_ok "-u -f"
557
558 touch ${file_sync_before_last}
559
560 $MI_VALIDATE $OUTPUT_DEST
561 ok $? "Mi test: list ust event xsd validation"
562
563 #Extract events
564 extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/lttng:name/text()" result
565 num=$(echo "$result" | wc -l)
566
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.
570 test "$num" -ge "5"
571 ok $? "Mi test: $num / 5 ust events discovered"
572
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)
577 test "$num" -ge "12"
578 ok $? "Mi test: $num / 12 ust event fields discovered"
579
580 #Wait for all background processes
581 wait
582
583 rm -f ${file_sync_after_first}
584 rm -f ${file_sync_before_last}
585 }
586
587 function test_start_stop ()
588 {
589 diag "Test start-stop"
590
591 local session_name="testStartStopSession"
592 local channel_name="startStopChannel"
593
594 OUTPUT_FILE="list_start_stop.xml"
595
596 #Test buid up
597 OUTPUT_DEST=$DEVNULL
598
599 create_lttng_session_ok $session_name $OUTPUT_DIR
600
601 #Test fail command
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"
607
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"
612
613 #Enable a channel to test success
614 OUTPUT_DEST=$DEVNULL
615 enable_ust_lttng_channel_ok $session_name $channel_name
616
617 #Start tracing
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"
622
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"
627
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"
632
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"
637
638 #Test metadata regenerate command
639 regenerate_metadata_ok $session_name
640 $MI_VALIDATE $OUTPUT_DEST
641 ok $? "Mi test: regenerate metadata"
642
643 #Test stop command
644 stop_lttng_tracing_ok $session_name
645 $MI_VALIDATE $OUTPUT_DEST
646 ok $? "Mi test: stop xsd validation"
647
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"
652
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"
657
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"
662
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"
667
668 #Teardown
669 OUTPUT_DEST=$DEVNULL
670 destroy_lttng_sessions
671 }
672
673 function test_snapshot ()
674 {
675 diag "Test snapshot"
676
677 local session_name="testSnapshotAdd"
678 local snapshot_path="$OUTPUT_DIR/snapshotoutput"
679 OUTPUT_FILE="snapshot.xml"
680
681 #Test buid up
682 OUTPUT_DEST=$DEVNULL
683 create_lttng_session_no_output $session_name
684
685 #Test fail command
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"
691
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"
696
697 #Get data
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"
701
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
705
706 #Test list output
707 lttng_snapshot_list $session_name
708 $MI_VALIDATE $OUTPUT_DEST
709 ok $? "Mi test: snapshot list xsd validation"
710
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"
715
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"
719
720 #Test del output
721 lttng_snapshot_del_output_ok $session_name $snapshot_id
722 $MI_VALIDATE $OUTPUT_DEST
723 ok $? "Mi test: snapshot delete xsd validation"
724
725 #Success ?
726 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
727 test "$result" = "true"
728 ok $? "Mi test: del snapshot is a success"
729
730 #Test data
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"
734
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"
738
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"
743
744 #Success ?
745 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
746 test "$result" = "false"
747 ok $? "Mi test: del snapshot is a success"
748
749 OUTPUT_DEST=$DEVNULL
750 destroy_lttng_sessions
751 }
752
753 function test_track_untrack ()
754 {
755 diag "Test track/untrack pid"
756
757 local session_name="testTrack"
758 local pid="1,2,3"
759 OUTPUT_FILE="track.xml"
760
761 #Test buid up
762 OUTPUT_DEST=$DEVNULL
763 create_lttng_session_no_output $session_name
764
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"
769
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"
774
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)
778 test "$num" -eq "3"
779 ok $? "Mi test: track pid expecting 3 processes got $num"
780
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"
785
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)
789 test "$num" -eq "3"
790 ok $? "Mi test: tracker pid listing expecting 3 target got $num"
791
792 #Untrack pid 2,3
793 lttng_untrack_ok "-p 2,3 -u"
794 $MI_VALIDATE $OUTPUT_DEST
795 ok $? "Mi test: untrack pid xsd validation"
796
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"
801
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)
805 test "$num" -eq "2"
806 ok $? "Mi test: untrack pid expecting 2 process got $num"
807
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"
812
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)
816 test "$num" -eq "1"
817 ok $? "Mi test: tracker pid listing expecting 1 process got $num"
818
819 #Untrack all
820 lttng_untrack_ok "-p -u -a"
821 $MI_VALIDATE $OUTPUT_DEST
822 ok $? "Mi test: untrack pid xsd validation"
823
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"
828
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)
832 test "$num" -eq "1"
833 ok $? "Mi test: untrack pid expecting 1 process got $num"
834
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"
838
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"
845
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)
849 test "$num" -eq "0"
850 ok $? "Mi test: tracker pid listing expecting 0 process got $num"
851
852 #Test track all
853 lttng_track_ok "-p -u -a"
854 $MI_VALIDATE $OUTPUT_DEST
855 ok $? "Mi test: track pid xsd validation"
856
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"
861
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)
865 test "$num" -eq "1"
866 ok $? "Mi test: track pid expecting 1 process got $num"
867
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"
871
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"
878
879 node_check_xml $OUTPUT_DEST $XPATH_VPID_TRACKER result
880 test "$result" = ""
881 ok $? "Mi test: VPID_tracker node is absent as defined"
882
883 OUTPUT_DEST=$DEVNULL
884 destroy_lttng_sessions
885 }
886
887 function test_add_context_list()
888 {
889 diag "Test context listing"
890
891 OUTPUT_FILE="list-context.xml"
892 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
893 lttng_add_context_list
894
895 $MI_VALIDATE $OUTPUT_DEST
896 ok $? "Mi test: context listing validation"
897 }
898
899 function test_clear_session ()
900 {
901 diag "Test clear session"
902
903 # Since the session are not started there is no real clear done.
904 # We are testing the MI output only here.
905 local session_name=(
906 "testSession1"
907 "testSession2"
908 "testSession3")
909
910 OUTPUT_FILE="clear_session.xml"
911
912 #Test build up
913 OUTPUT_DEST=$DEVNULL
914 for (( i = 0; i < 3; i++ )); do
915 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
916 done
917
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"
922
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]}"
927
928 #Destroy all and count:should be 3
929 lttng_clear_all
930 $MI_VALIDATE $OUTPUT_DEST
931 ok $? "MI test: clear all session xsd validation"
932
933 #Verify that we cleared 3 sessions
934 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
935 num=$(echo "$result" | wc -l)
936 test "$num" -eq "3"
937 ok $? "Mi test: $num / 3 sessions discovered"
938
939 destroy_lttng_sessions
940
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"
948
949 }
950
951 start_lttng_sessiond $SESSIOND_LOAD_DIR
952 TESTS=(
953 test_version
954 test_create_session
955 test_destroy_session
956 test_list_sessions
957 test_ust_channel
958 test_ust_lttng_event
959 test_list_channel
960 test_list_domain
961 test_list_session
962 test_list_ust_event
963 test_start_stop
964 test_snapshot
965 test_track_untrack
966 test_list_session_long_path
967 test_add_context_list
968 test_clear_session
969 )
970
971
972 echo $OUTPUT_DIR
973 for fct_test in ${TESTS[@]};
974 do
975 ${fct_test}
976 if [ $? -ne 0 ]; then
977 break;
978 fi
979 done
980 rm -rf $OUTPUT_DIR
981 rm -rf $SESSIOND_LOAD_DIR
982
983 OUTPUT_DEST=/dev/null 2>&1
984 stop_lttng_sessiond
This page took 0.074555 seconds and 4 git commands to generate.