Fix: Don't override user variables within the build system
[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 # 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.
8 #
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
12 # details.
13 #
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
17
18 TEST_DESC="Machine interface testing"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../../
22 XSD_PATH=$TESTDIR/../src/common/mi-lttng-3.0.xsd
23 SESSIOND_BIN="lttng-sessiond"
24 RELAYD_BIN="lttng-relayd"
25
26 #Test app for ust event
27 TESTAPP_PATH="$TESTDIR/utils/testapp"
28 TESTAPP_NAME="gen-ust-events"
29 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
30 NR_USEC_WAIT=0
31 NR_ITER=10000
32
33 #Temp file output
34 OUTPUT_DIR=$(mktemp -d)
35 FOO_LOAD_DIR=$(mktemp -d)
36 OUTPUT_FILE="default.xml"
37
38 #Path to custom xml utilities
39 XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH"
40 XML_EXTRACT="$CURDIR/extract_xml"
41 XML_NODE_CHECK="$CURDIR/extract_xml -e"
42
43 XPATH_CMD_OUTPUT="//lttng:command/lttng:output"
44 XPATH_COMMAND_SUCCESS="/lttng:command/lttng:success/text()"
45 XPATH_SESSION="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session"
46 XPATH_ENABLE_CHANNEL_NAME="$XPATH_CMD_OUTPUT/lttng:channels/lttng:channel/lttng:name/text()"
47 XPATH_ENABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/lttng:events/lttng:event/lttng:success/text()"
48 XPATH_DISABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/lttng:channel/lttng:events/lttng:event/lttng:success/text()"
49 XPATH_LIST_DOMAIN="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain"
50 XPATH_LIST_CHANNEL="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:channels/lttng:channel"
51 XPATH_LIST_UST_EVENT="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type ='UST']/lttng:pids/lttng:pid/lttng:events/lttng:event"
52 XPATH_SNAPSHOT_ADD_SNAPSHOT="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'add-output']/lttng:output"
53 XPATH_SNAPSHOT_LIST="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'list-output']/lttng:output"
54 XPATH_SNAPSHOT_DEL="$XPATH_CMD_OUTPUT/lttng:snapshot_action[./lttng:name = 'del-output']/lttng:output"
55 XPATH_TRACK_UNTRACK_PID="$XPATH_CMD_OUTPUT/lttng:targets/lttng:pid_target"
56 XPATH_PID_TRACKER="$XPATH_CMD_OUTPUT/lttng:sessions/lttng:session/lttng:domains/lttng:domain/lttng:trackers/lttng:pid_tracker"
57
58 DEVNULL=/dev/null 2>&1
59
60 DIR=$(readlink -f $TESTDIR)
61
62 NUM_TESTS=228
63
64 source $TESTDIR/utils/utils.sh
65
66 #Overwrite the lttng_bin to get mi output
67 LTTNG_BIN="lttng --mi xml"
68
69 #Global declaration for simplification
70 LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN
71
72 #Overwrite the default output for utils.sh command
73
74 #MUST set TESTDIR before calling those functions
75 plan_tests $NUM_TESTS
76
77 print_test_banner "$TEST_DESC"
78
79 function extract_xml ()
80 {
81 local xml=$1
82 local xpath=$2
83 local __result=$3
84 local output
85 output=$($XML_EXTRACT $xml "$xpath")
86 ok $? "Extraction of xpath $xpath"
87 eval $__result="'$output'"
88 }
89
90 function node_check_xml ()
91 {
92 local xml=$1
93 local xpath=$2
94 local __result=$3
95 local output
96 output=$($XML_NODE_CHECK $xml "$xpath")
97 ok $? "Check of node existence with xpath $xpath"
98 eval $__result="'$output'"
99 }
100
101 # Arg1 is path to xml file
102 # Arg2:
103 # is true if we expected the success element to be false
104 # else
105 # passe false
106
107 function is_command_success ()
108 {
109 local xml=$1
110 local expect_false=$2
111
112 local xpath=$XPATH_COMMAND_SUCCESS
113
114 echo $xml
115 #Extract the success element
116 #expect false
117 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
118 if [[ $expect_false = "true" ]]; then
119 if [[ $result ]]; then
120 pass "Mi test: $xml command failed as expected"
121 else
122 fail "Mi test: $xml command did not fail as expected"
123 fi
124 else
125 if [[ $result ]]; then
126 pass "Mi test: $xml command success"
127 else
128 fail "Mi test: $xml command failed"
129 fi
130 fi
131 }
132
133 function mi_print_version ()
134 {
135 local output_path=$1
136 local opt=$2
137
138 $LTTNG version $opt > $output_path
139 ok $? "MI test: Lttng version"
140
141 }
142
143 function test_version ()
144 {
145 OUTPUT_FILE="version.xml"
146 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
147 mi_print_version $OUTPUT_DEST
148 $XML_VALIDATE $OUTPUT_DEST
149 ok $? "MI test: Version xsd validation"
150 }
151
152 function test_create_session ()
153 {
154 local session_name="testSession"
155
156 OUTPUT_FILE="create_session.xml"
157 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
158 create_lttng_session_ok $session_name $OUTPUT_DIR
159 $XML_VALIDATE $OUTPUT_DEST
160 ok $? "MI test: create session xsd validation"
161
162 #try to recreate a session. Expecting it to fail
163 create_lttng_session_fail $session_name $OUTPUT_DIR
164 $XML_VALIDATE $OUTPUT_DEST
165 ok $? "MI test: expecting fail create session xsd validation"
166 is_command_success $OUTPUT_DEST true
167
168 OUTPUT_DEST=$DEVNULL
169 destroy_lttng_session_ok $session_name
170 }
171
172 function test_destroy_session ()
173 {
174 local session_name=(
175 "testSession1"
176 "testSession2"
177 "testSession3")
178
179 OUTPUT_FILE="destroy_session.xml"
180
181 #Test build up
182 OUTPUT_DEST=$DEVNULL
183 for (( i = 0; i < 3; i++ )); do
184 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
185 done
186
187 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
188 destroy_lttng_session_ok ${session_name[0]}
189 $XML_VALIDATE $OUTPUT_DEST
190 ok $? "MI test: destroy session ${session_name[0]} xsd validation"
191
192 #Verify that we destroyed the good session
193 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
194 test "$result" = "${session_name[0]}"
195 ok $? "Mi test: deleted session: $result expected: ${session_name[0]}"
196
197 #Destroy all and count:should be 2
198 destroy_lttng_sessions
199 $XML_VALIDATE $OUTPUT_DEST
200 ok $? "MI test: destroy all session xsd validation"
201
202 #Verify that we destroyed 2 sessions
203 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
204 num=$(echo "$result" | wc -l)
205 test "$num" -eq "2"
206 ok $? "Mi test: $num / 2 sessions discovered"
207
208 #Verify that if no session is present command fail and mi report it.
209 destroy_lttng_session_fail ${session_name[0]}
210 $XML_VALIDATE $OUTPUT_DEST
211 ok $? "MI test: failing destroy session ${session_name[0]} xsd validation"
212 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
213 test "$result" = "false"
214 ok $? "Mi test: destroy command on ${session_name[0]} failed as expected"
215
216 }
217
218 function test_list_sessions ()
219 {
220 local session_name=(
221 "testSession1"
222 "testSession2"
223 "testSession3")
224
225 OUTPUT_FILE="list_sessions.xml"
226
227 #Test buid up
228 OUTPUT_DEST=$DEVNULL
229 for (( i = 0; i < 3; i++ )); do
230 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
231 done
232
233 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
234 list_lttng_with_opts
235 $XML_VALIDATE $OUTPUT_DEST
236 ok $? "Mi test: list sessions xsd validation"
237
238 #We should have 3 session
239 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
240 num=$(echo "$result" | wc -l)
241 test "$num" -eq "3"
242 ok $? "Mi test: $num / 3 sessions discovered"
243
244 #Teardown
245 OUTPUT_DEST=$DEVNULL
246 destroy_lttng_sessions
247 }
248
249 function test_list_session_long_path ()
250 {
251 local session_name="session_long_path"
252
253 output_basedir=$OUTPUT_DIR/$(randstring 254 0)
254 mkdir -p ${output_basedir}
255
256 OUTPUT_FILE="list_sessions.xml"
257
258 #Test build up
259 OUTPUT_DEST=$DEVNULL
260 create_lttng_session_ok $session_name ${output_basedir}
261
262 OUTPUT_DEST=${output_basedir}/$OUTPUT_FILE
263 list_lttng_with_opts
264 $XML_VALIDATE $OUTPUT_DEST
265 ok $? "Mi test: list session with long path xsd validation"
266
267 #Teardown
268 OUTPUT_DEST=$DEVNULL
269 destroy_lttng_sessions
270 }
271 function test_ust_channel ()
272 {
273 local session_name="testsession"
274 local channel_name=("channelUst0"
275 "channelUst1"
276 "channelUst2")
277
278 OUTPUT_FILE="ust_channel.xml"
279
280 #Test buil up
281 OUTPUT_DEST=$DEVNULL
282 create_lttng_session_ok $session_name $OUTPUT_DIR
283
284 #Test the enable_channel command
285 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
286 enable_ust_lttng_channel_ok $session_name ${channel_name[0]}
287 $XML_VALIDATE $OUTPUT_DEST
288 ok $? "Mi test: enable ust channel xsd validation"
289 is_command_success $OUTPUT_DEST false
290
291 #Expect the command to fail
292 enable_ust_lttng_channel_fail $session_name ${channel_name[0]}
293 $XML_VALIDATE $OUTPUT_DEST
294 ok $? "Mi test: fail enable ust channel xsd validation"
295 is_command_success $OUTPUT_DEST true
296
297 #Create two ust channel to test multiple disable
298 for (( i = 1; i < 3; i++ )); do
299 enable_ust_lttng_channel_ok $session_name ${channel_name[$i]}
300 done
301
302 #Test the disable_channel command
303 disable_ust_lttng_channel $session_name ${channel_name[0]}
304 $XML_VALIDATE $OUTPUT_DEST
305 ok $? "Mi test: disable ust channel xsd validation"
306 is_command_success $OUTPUT_DEST false
307 #Check that we delete the good channel
308 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
309 test "$result" = "${channel_name[0]}"
310 ok $? "MI test: ${channel_name[0]} disabled"
311
312 #Test multiple disable_channel;
313 disable_ust_lttng_channel $session_name ${channel_name[1]},${channel_name[2]}
314 $XML_VALIDATE $OUTPUT_DEST
315 ok $? "Mi test: multiple disable ust channel xsd validation"
316 is_command_success $OUTPUT_DEST false
317
318 #Make sure we have two disabled channel
319 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
320 local num=$(echo "$result" | wc -l)
321 test "$num" = "2"
322 ok $? "Mi test: disabled ust channel $num/2"
323
324 #Teardown
325 OUTPUT_DEST=$DEVNULL
326 destroy_lttng_sessions
327
328 }
329
330 function test_ust_lttng_event ()
331 {
332 local session_name="testSession"
333 local channel_name="testChannel"
334 local event=("ev1" "ev2" "ev3")
335
336 OUTPUT_FILE="ust_event.xml"
337
338 #Test build up
339 OUTPUT_DEST=$DEVNULL
340 create_lttng_session_ok $session_name $OUTPUT_DIR
341 enable_ust_lttng_channel_ok $session_name $channel_name
342
343 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
344 #Test the enable event for ust domain
345 enable_ust_lttng_event_ok $session_name ${event[0]} $channel_name
346 $XML_VALIDATE $OUTPUT_DEST
347 ok $? "Mi test: Enable_event for ust domain xsd validation"
348 is_command_success $OUTPUT_DEST false
349
350 #Try to reenable an enabled event. Should fail
351 enable_ust_lttng_event_fail $session_name ${event[0]} $channel_name
352 $XML_VALIDATE $OUTPUT_DEST
353 ok $? "Mi test: Fail enable_event for ust domain xsd validation"
354 is_command_success $OUTPUT_DEST true
355
356 #Enable multiple event including the last one command will fail
357 #But 2 events should success
358
359 #Nice little hack, create a string ev,ev,ev
360 #IFS stand for Internal field separator
361 #Event[*] print all the element inside the array with the IFS in between
362 concat_event=$( IFS=$','; echo "${event[*]}" )
363
364 enable_ust_lttng_event_fail $session_name $concat_event $channel_name
365 $XML_VALIDATE $OUTPUT_DEST
366 ok $? "Mi test: Multiple enable ust event with inside fail xsd validation"
367
368 #Check for 2 success = true and 1 success = false
369 extract_xml $OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
370 num_ocur=$(grep -o "true" <<< "$result" | wc -l)
371 test "$num_ocur" -eq "2"
372 ok $? "Mi test: Enabled event on failing enable command $num_ocur_true/2"
373
374 extract_xml $OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
375 num_ocur=$(grep -o "false" <<< "$result" | wc -l)
376 test "$num_ocur" -eq "1"
377 ok $? "Mi test: Enabled event on failing enable command $num_ocur_true/2"
378
379 #Disable the event
380 disable_ust_lttng_event $session_name ${event[0]} $channel_name
381 $XML_VALIDATE $OUTPUT_DEST
382 ok $? "Mi test: Disable ust event xsd validation"
383 is_command_success $OUTPUT_DEST false
384
385 #Disable the 3 event combined. Should pass
386 disable_ust_lttng_event $session_name $concat_event $channel_name
387 $XML_VALIDATE $OUTPUT_DEST
388 ok $? "Mi test: Disable multiple ust event xsd validation"
389 is_command_success $OUTPUT_DEST false
390
391 #Make sure we have 3 inner success
392 extract_xml $OUTPUT_DEST $XPATH_DISABLE_EVENT_SUCCESS result
393 num_ocur=$(grep -o "true" <<< "$result" | wc -l)
394 test "$num_ocur" -eq "3"
395 ok $? "Mi test: Disable multiple ust event success $num_ocur/3"
396
397 #Teardown
398 OUTPUT_DEST=$DEVNULL
399 destroy_lttng_sessions
400 }
401
402 function test_list_channel ()
403 {
404 local session_name="testSession"
405 local channel_name="testChannel"
406 local event=("ev1" "ev2" "ev3")
407
408 OUTPUT_FILE="list_channel.xml"
409
410 #Test buid up
411 OUTPUT_DEST=$DEVNULL
412 create_lttng_session_ok $session_name $OUTPUT_DIR
413 enable_ust_lttng_channel_ok $session_name $channel_name
414
415 #Enable ust and jul events
416 concat_event=$( IFS=$','; echo "${event[*]}" )
417 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
418
419 #Begin testing
420 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
421 list_lttng_with_opts "$session_name -c $channel_name"
422 $XML_VALIDATE $OUTPUT_DEST
423 ok $? "Mi test: list channel xsd validation"
424
425 #Expect 1 domain: UST
426 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
427 num=$(echo "$result" | wc -l)
428 test "$num" -eq "1"
429 ok $? "Mi test: $num / 1 domains discovered"
430
431 #Expect 1 channel: test
432 extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
433 num=$(echo "$result" | wc -l)
434 test "$num" -eq "1"
435 ok $? "Mi test: $num / 1 channel discovered"
436
437 test "$result" = "$channel_name"
438 ok $? "Mi test: expected channel: $channel_name found: $result"
439
440 #Add a channel and make sure we have 2 channel now
441 OUTPUT_DEST=$DEVNULL
442 enable_ust_lttng_channel_ok $session_name $channel_name"a"
443
444 #Teardown
445 OUTPUT_DEST=$DEVNULL
446 destroy_lttng_sessions
447 }
448
449 function test_list_domain ()
450 {
451 local session_name="testSession"
452 local channel_name="testChannel"
453 local event=("ev1" "ev2" "ev3")
454
455 OUTPUT_FILE="list_domain.xml"
456
457 #Test buid up
458 OUTPUT_DEST=$DEVNULL
459 create_lttng_session_ok $session_name $OUTPUT_DIR
460 enable_ust_lttng_channel_ok $session_name $channel_name
461
462 #Enable ust and jul events
463 concat_event=$( IFS=$','; echo "${event[*]}" )
464 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
465 enable_jul_lttng_event $session_name $concat_event $channel_name
466
467 #Begin testing
468 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
469 list_lttng_with_opts "$session_name -d"
470 $XML_VALIDATE $OUTPUT_DEST
471 ok $? "Mi test: list domain xsd validation"
472
473 #Expect 2 domain: Jul and UST
474 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
475 num=$(echo "$result" | wc -l)
476 test "$num" -eq "2"
477 ok $? "Mi test: $num / 2 domains discovered"
478
479 #Test for valid value
480 if [[ "$result" = *"JUL"* ]]; then
481 pass "Mi test: domains Jul is present"
482 else
483 fail "Mi test: domains Jul is absent"
484 fi
485
486 if [[ "$result" = *"UST"* ]]; then
487 pass "Mi test: domains UST is present"
488 else
489 fail "Mi test: domains UST is absent"
490 fi
491
492 #Teardown
493 OUTPUT_DEST=$DEVNULL
494 destroy_lttng_sessions
495 }
496
497 function test_list_session ()
498 {
499 local session_name="testSession"
500 local channel_name="testChannel"
501 local event=("ev1" "ev2" "ev3")
502
503 OUTPUT_FILE="list_session.xml"
504
505 #Test buid up
506 OUTPUT_DEST=$DEVNULL
507 create_lttng_session_ok $session_name $OUTPUT_DIR
508 enable_ust_lttng_channel_ok $session_name $channel_name
509
510 #Enable ust and jul events
511 concat_event=$( IFS=$','; echo "${event[*]}" )
512 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
513 enable_jul_lttng_event $session_name $concat_event $channel_name
514
515 #Begin testing
516 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
517 list_lttng_with_opts $session_name
518 $XML_VALIDATE $OUTPUT_DEST
519 ok $? "Mi test: list session xsd validation"
520
521 #Expect 2 domain: Jul and UST
522 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
523 num=$(echo "$result" | wc -l)
524 test "$num" -eq "2"
525 ok $? "Mi test: $num / 2 domains discovered"
526
527 #Expect 2 channel: test and lttng_jul_event
528 extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
529 num=$(echo "$result" | wc -l)
530 test "$num" -eq "2"
531 ok $? "Mi test: $num / 2 channel discovered"
532
533 #Teardown
534 OUTPUT_DEST=$DEVNULL
535 destroy_lttng_sessions
536 }
537
538 function test_list_ust_event ()
539 {
540 local file_sync_after_first=$(mktemp -u)
541 local file_sync_before_last=$(mktemp -u)
542
543 OUTPUT_FILE="list_ust_event.xml"
544
545 #Test buid up
546 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
547
548 #Begin testing
549 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} & 2>/dev/null
550
551 while [ ! -f "${file_sync_after_first}" ]; do
552 sleep 0.5
553 done
554
555 list_lttng_with_opts "-u -f"
556
557 touch ${file_sync_before_last}
558
559 $XML_VALIDATE $OUTPUT_DEST
560 ok $? "Mi test: list ust event xsd validation"
561
562 #Extract events
563 extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/lttng:name/text()" result
564 num=$(echo "$result" | wc -l)
565
566 #Since the number of events is prone to change we only look for >= from a
567 #base number. An alternative would be to look for each events but this
568 #is complicated for nothing.
569 test "$num" -ge "5"
570 ok $? "Mi test: $num / 5 ust events discovered"
571
572 #Extract field from tp:tptest event. Expect >= to 12 because number of
573 #field is prone to change.
574 extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./lttng:name = 'tp:tptest']/lttng:event_fields/lttng:event_field/lttng:name/text()" result
575 num=$(echo "$result" | wc -l)
576 test "$num" -ge "12"
577 ok $? "Mi test: $num / 12 ust event fields discovered"
578
579 #Wait for all background processes
580 wait
581
582 rm -f ${file_sync_after_first}
583 rm -f ${file_sync_before_last}
584 }
585
586 function test_start_stop () {
587 local session_name="testStartStopSession"
588 local channel_name="startStopChannel"
589
590 OUTPUT_FILE="list_start_stop.xml"
591
592 #Test buid up
593 OUTPUT_DEST=$DEVNULL
594 create_lttng_session_ok $session_name $OUTPUT_DIR
595
596 #Test fail command
597 #No channel enable start command should return element success false
598 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
599 start_lttng_tracing_fail $session_name
600 $XML_VALIDATE $OUTPUT_DEST
601 ok $? "Mi test: failed start xsd validation"
602
603 #Expect a false element
604 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
605 test "$result" = "false"
606 ok $? "Mi test: mi report failure on start command as expected"
607
608 #Enable a channel to test success
609 OUTPUT_DEST=$DEVNULL
610 enable_ust_lttng_channel_ok $session_name $channel_name
611
612 #Start tracing
613 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
614 start_lttng_tracing_ok $session_name
615 $XML_VALIDATE $OUTPUT_DEST
616 ok $? "Mi test: start xsd validation"
617
618 #Expect a true element
619 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
620 test "$result" = "true"
621 ok $? "Mi test: mi report success on start command as expected"
622
623 #Extract session name from xml
624 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
625 test "$result" = "$session_name"
626 ok $? "Mi test: started $session_name"
627
628 #Extract enabled expect true
629 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
630 test "$result" = "true"
631 ok $? "Mi test: enabled element : $result expected: true"
632
633 #Test metadata regenerate command
634 regenerate_metadata_ok $session_name
635 $XML_VALIDATE $OUTPUT_DEST
636 ok $? "Mi test: regenerate metadata"
637
638 #Test stop command
639 stop_lttng_tracing_ok $session_name
640 $XML_VALIDATE $OUTPUT_DEST
641 ok $? "Mi test: stop xsd validation"
642
643 #Extract session name from xml
644 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
645 test "$result" = "$session_name"
646 ok $? "Mi test: stopped $session_name"
647
648 #Extract enabled expect false
649 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
650 test "$result" = "false"
651 ok $? "Mi test: enabled element : $result expected: false"
652
653 #Test failing stop command
654 stop_lttng_tracing_fail $session_name
655 $XML_VALIDATE $OUTPUT_DEST
656 ok $? "Mi test: failed stop xsd validation"
657
658 #Expect a false element
659 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
660 test "$result" = "false"
661 ok $? "Mi test: mi report failure on start command as expected"
662
663 #Teardown
664 OUTPUT_DEST=$DEVNULL
665 destroy_lttng_sessions
666 }
667
668 function test_snapshot () {
669 local session_name="testSnapshotAdd"
670 local snapshot_path="$OUTPUT_DIR/snapshotoutput"
671 OUTPUT_FILE="snapshot.xml"
672
673
674 #Test buid up
675 OUTPUT_DEST=$DEVNULL
676 create_lttng_session_no_output $session_name
677
678 #Test fail command
679 #No channel enable start command should return element success false
680 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
681 lttng_snapshot_add_output_ok $session_name $snapshot_path
682 $XML_VALIDATE $OUTPUT_DEST
683 ok $? "Mi test: snapshot xsd validation"
684
685 #Expect a true element
686 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
687 test "$result" = "true"
688 ok $? "Mi test: add snapshot is a success"
689
690 #Get data
691 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:session_name/text()" result
692 test "$result" = "$session_name"
693 ok $? "Mi test: added snapshot for: $result expected $session_name"
694
695 #Get name of generated output and id
696 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:name/text()" snapshot_name
697 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:id/text()" snapshot_id
698
699 #Test list output
700 lttng_snapshot_list $session_name
701 $XML_VALIDATE $OUTPUT_DEST
702 ok $? "Mi test: snapshot list xsd validation"
703
704 #Expect a true element
705 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
706 test "$result" = "true"
707 ok $? "Mi test: add snapshot is a success"
708
709 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/lttng:session[./lttng:name ='$session_name']/lttng:snapshots/lttng:snapshot/lttng:name/text()" result
710 test "$result" = "$snapshot_name"
711 ok $? "Mi test: snapshot list extracted snapshot: $result expected: $snapshot_name"
712
713 #Test del output
714 lttng_snapshot_del_output_ok $session_name $snapshot_id
715 $XML_VALIDATE $OUTPUT_DEST
716 ok $? "Mi test: snapshot delete xsd validation"
717
718 #Success ?
719 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
720 test "$result" = "true"
721 ok $? "Mi test: del snapshot is a success"
722
723 #Test data
724 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:id/text()" result
725 test "$result" = "$snapshot_id"
726 ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $snapshot_id"
727
728 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:session_name/text()" result
729 test "$result" = "$session_name"
730 ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $session_name"
731
732 #Test fail on delete command
733 lttng_snapshot_del_output_fail $session_name $snapshot_id
734 $XML_VALIDATE $OUTPUT_DEST
735 ok $? "Mi test: snapshot delete xsd validation"
736
737 #Success ?
738 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
739 test "$result" = "false"
740 ok $? "Mi test: del snapshot is a success"
741
742 OUTPUT_DEST=$DEVNULL
743 destroy_lttng_sessions
744 }
745
746 function test_track_untrack ()
747 {
748 diag "Test track/untrack pid"
749
750 local session_name="testTrack"
751 local snapshot_path="$OUTPUT_DIR/trackoutput"
752 local pid="1,2,3"
753 OUTPUT_FILE="track.xml"
754
755 #Test buid up
756 OUTPUT_DEST=$DEVNULL
757 create_lttng_session_no_output $session_name
758
759 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
760 lttng_track_ok "-p $pid -u"
761 $XML_VALIDATE $OUTPUT_DEST
762 ok $? "Mi test: track pid xsd validation"
763
764 #Expect a true element
765 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
766 test "$result" = "true"
767 ok $? "Mi test: track pid is a success"
768
769 #Verify that there is 3 process
770 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
771 num=$(echo "$result" | wc -l)
772 test "$num" -eq "3"
773 ok $? "Mi test: track pid expecting 3 processes got $num"
774
775 #Test the pid_tracker listing
776 list_lttng_with_opts $session_name
777 $XML_VALIDATE $OUTPUT_DEST
778 ok $? "Mi test: session list with pid_tracker validate"
779
780 #Check the good count
781 extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result
782 num=$(echo "$result" | wc -l)
783 test "$num" -eq "3"
784 ok $? "Mi test: tracker pid listing expecting 3 target got $num"
785
786 #Untrack pid 2,3
787 lttng_untrack_ok "-p 2,3 -u"
788 $XML_VALIDATE $OUTPUT_DEST
789 ok $? "Mi test: untrack pid xsd validation"
790
791 #Expect a true element
792 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
793 test "$result" = "true"
794 ok $? "Mi test: untrack pid is a success"
795
796 #Verify that there is 2 untracked pids
797 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
798 num=$(echo "$result" | wc -l)
799 test "$num" -eq "2"
800 ok $? "Mi test: untrack pid expecting 2 process got $num"
801
802 #Check pid_tracker listing
803 list_lttng_with_opts $session_name
804 $XML_VALIDATE $OUTPUT_DEST
805 ok $? "Mi test: session list with pid_tracker validate"
806
807 #Check the good count
808 extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result
809 num=$(echo "$result" | wc -l)
810 test "$num" -eq "1"
811 ok $? "Mi test: tracker pid listing expecting 1 process got $num"
812
813 #Untrack all
814 lttng_untrack_ok "-p -u -a"
815 $XML_VALIDATE $OUTPUT_DEST
816 ok $? "Mi test: untrack pid xsd validation"
817
818 #Expect a true element
819 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
820 test "$result" = "true"
821 ok $? "Mi test: untrack all pid is a success"
822
823 #Verify that there is 1 untracked pid
824 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
825 num=$(echo "$result" | wc -l)
826 test "$num" -eq "1"
827 ok $? "Mi test: untrack pid expecting 1 process got $num"
828
829 #Test if the id is * which represent the all argument
830 test "$result" = "*"
831 ok $? "Mi test: pid expected is * got $result"
832
833 #Test if pid_tracker is enabled as definied by pid_tracker
834 #behavior. If all pid are untrack than the pid_tracker is still
835 #enabled (pid_tracker node is present).
836 list_lttng_with_opts $session_name
837 $XML_VALIDATE $OUTPUT_DEST
838 ok $? "Mi test: session list with pid_tracker validate"
839
840 #Check the good count
841 extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result
842 num=$(echo -n "$result" | wc -l)
843 test "$num" -eq "0"
844 ok $? "Mi test: tracker pid listing expecting 0 process got $num"
845
846 #Test track all
847 lttng_track_ok "-p -u -a"
848 $XML_VALIDATE $OUTPUT_DEST
849 ok $? "Mi test: track pid xsd validation"
850
851 #Expect a true element
852 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
853 test "$result" = "true"
854 ok $? "Mi test: track all pid is a success"
855
856 #Verify that there is 1 tracked process
857 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
858 num=$(echo "$result" | wc -l)
859 test "$num" -eq "1"
860 ok $? "Mi test: track pid expecting 1 process got $num"
861
862 #Test if the id is * wich represent the all argument
863 test "$result" = "*"
864 ok $? "Mi test: pid expected is * got $result"
865
866 #Test if pid_tracker is enabled as definied by pid_tracker
867 #behavior. If all pid are untrack thant the pid_tracker is
868 #disabled (node pid_tracker do not exist)
869 list_lttng_with_opts $session_name
870 $XML_VALIDATE $OUTPUT_DEST
871 ok $? "Mi test: session list with pid_tracker validate"
872
873 node_check_xml $OUTPUT_DEST $XPATH_PID_TRACKER result
874 test "$result" = ""
875 ok $? "Mi test: Pid_tracker node is absent as defined"
876
877 OUTPUT_DEST=$DEVNULL
878 destroy_lttng_sessions
879 }
880
881 start_lttng_sessiond $FOO_LOAD_DIR
882 TESTS=(
883 test_version
884 test_create_session
885 test_destroy_session
886 test_list_sessions
887 test_ust_channel
888 test_ust_lttng_event
889 test_list_channel
890 test_list_domain
891 test_list_session
892 test_list_ust_event
893 test_start_stop
894 test_snapshot
895 test_track_untrack
896 test_list_session_long_path
897 )
898
899
900 echo $OUTPUT_DIR
901 for fct_test in ${TESTS[@]};
902 do
903 ${fct_test}
904 if [ $? -ne 0 ]; then
905 break;
906 fi
907 done
908 rm -rf $OUTPUT_DIR
909
910 OUTPUT_DEST=/dev/null 2>&1
911 stop_lttng_sessiond
This page took 0.062413 seconds and 4 git commands to generate.