Tests: Consider lttng mi namespace in test_mi
[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=222
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 opt=$2
136 local output_path=$1
137
138 $LTTNG version $opt > $1
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_ust_channel ()
250 {
251 local session_name="testsession"
252 local channel_name=("channelUst0"
253 "channelUst1"
254 "channelUst2")
255
256 OUTPUT_FILE="ust_channel.xml"
257
258 #Test buil up
259 OUTPUT_DEST=$DEVNULL
260 create_lttng_session_ok $session_name $OUTPUT_DIR
261
262 #Test the enable_channel command
263 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
264 enable_ust_lttng_channel_ok $session_name ${channel_name[0]}
265 $XML_VALIDATE $OUTPUT_DEST
266 ok $? "Mi test: enable ust channel xsd validation"
267 is_command_success $OUTPUT_DEST false
268
269 #Expect the command to fail
270 enable_ust_lttng_channel_fail $session_name ${channel_name[0]}
271 $XML_VALIDATE $OUTPUT_DEST
272 ok $? "Mi test: fail enable ust channel xsd validation"
273 is_command_success $OUTPUT_DEST true
274
275 #Create two ust channel to test multiple disable
276 for (( i = 1; i < 3; i++ )); do
277 enable_ust_lttng_channel_ok $session_name ${channel_name[$i]}
278 done
279
280 #Test the disable_channel command
281 disable_ust_lttng_channel $session_name ${channel_name[0]}
282 $XML_VALIDATE $OUTPUT_DEST
283 ok $? "Mi test: disable ust channel xsd validation"
284 is_command_success $OUTPUT_DEST false
285 #Check that we delete the good channel
286 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
287 test "$result" = "${channel_name[0]}"
288 ok $? "MI test: ${channel_name[0]} disabled"
289
290 #Test multiple disable_channel;
291 disable_ust_lttng_channel $session_name ${channel_name[1]},${channel_name[2]}
292 $XML_VALIDATE $OUTPUT_DEST
293 ok $? "Mi test: multiple disable ust channel xsd validation"
294 is_command_success $OUTPUT_DEST false
295
296 #Make sure we have two disabled channel
297 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
298 local num=$(echo "$result" | wc -l)
299 test "$num" = "2"
300 ok $? "Mi test: disabled ust channel $num/2"
301
302 #Teardown
303 OUTPUT_DEST=$DEVNULL
304 destroy_lttng_sessions
305
306 }
307
308 function test_ust_lttng_event ()
309 {
310 local session_name="testSession"
311 local channel_name="testChannel"
312 local event=("ev1" "ev2" "ev3")
313
314 OUTPUT_FILE="ust_event.xml"
315
316 #Test build up
317 OUTPUT_DEST=$DEVNULL
318 create_lttng_session_ok $session_name $OUTPUT_DIR
319 enable_ust_lttng_channel_ok $session_name $channel_name
320
321 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
322 #Test the enable event for ust domain
323 enable_ust_lttng_event_ok $session_name ${event[0]} $channel_name
324 $XML_VALIDATE $OUTPUT_DEST
325 ok $? "Mi test: Enable_event for ust domain xsd validation"
326 is_command_success $OUTPUT_DEST false
327
328 #Try to reenable an enabled event. Should fail
329 enable_ust_lttng_event_fail $session_name ${event[0]} $channel_name
330 $XML_VALIDATE $OUTPUT_DEST
331 ok $? "Mi test: Fail enable_event for ust domain xsd validation"
332 is_command_success $OUTPUT_DEST true
333
334 #Enable multiple event including the last one command will fail
335 #But 2 events should success
336
337 #Nice little hack, create a string ev,ev,ev
338 #IFS stand for Internal field separator
339 #Event[*] print all the element inside the array with the IFS in between
340 concat_event=$( IFS=$','; echo "${event[*]}" )
341
342 enable_ust_lttng_event_fail $session_name $concat_event $channel_name
343 $XML_VALIDATE $OUTPUT_DEST
344 ok $? "Mi test: Multiple enable ust event with inside fail xsd validation"
345
346 #Check for 2 success = true and 1 success = false
347 extract_xml $OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
348 num_ocur=$(grep -o "true" <<< "$result" | wc -l)
349 test "$num_ocur" -eq "2"
350 ok $? "Mi test: Enabled event on failing enable command $num_ocur_true/2"
351
352 extract_xml $OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result
353 num_ocur=$(grep -o "false" <<< "$result" | wc -l)
354 test "$num_ocur" -eq "1"
355 ok $? "Mi test: Enabled event on failing enable command $num_ocur_true/2"
356
357 #Disable the event
358 disable_ust_lttng_event $session_name ${event[0]} $channel_name
359 $XML_VALIDATE $OUTPUT_DEST
360 ok $? "Mi test: Disable ust event xsd validation"
361 is_command_success $OUTPUT_DEST false
362
363 #Disable the 3 event combined. Should pass
364 disable_ust_lttng_event $session_name $concat_event $channel_name
365 $XML_VALIDATE $OUTPUT_DEST
366 ok $? "Mi test: Disable multiple ust event xsd validation"
367 is_command_success $OUTPUT_DEST false
368
369 #Make sure we have 3 inner success
370 extract_xml $OUTPUT_DEST $XPATH_DISABLE_EVENT_SUCCESS result
371 num_ocur=$(grep -o "true" <<< "$result" | wc -l)
372 test "$num_ocur" -eq "3"
373 ok $? "Mi test: Disable multiple ust event success $num_ocur/3"
374
375 #Teardown
376 OUTPUT_DEST=$DEVNULL
377 destroy_lttng_sessions
378 }
379
380 function test_list_channel ()
381 {
382 local session_name="testSession"
383 local channel_name="testChannel"
384 local event=("ev1" "ev2" "ev3")
385
386 OUTPUT_FILE="list_channel.xml"
387
388 #Test buid up
389 OUTPUT_DEST=$DEVNULL
390 create_lttng_session_ok $session_name $OUTPUT_DIR
391 enable_ust_lttng_channel_ok $session_name $channel_name
392
393 #Enable ust and jul events
394 concat_event=$( IFS=$','; echo "${event[*]}" )
395 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
396
397 #Begin testing
398 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
399 list_lttng_with_opts "$session_name -c $channel_name"
400 $XML_VALIDATE $OUTPUT_DEST
401 ok $? "Mi test: list channel xsd validation"
402
403 #Expect 1 domain: UST
404 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
405 num=$(echo "$result" | wc -l)
406 test "$num" -eq "1"
407 ok $? "Mi test: $num / 1 domains discovered"
408
409 #Expect 1 channel: test
410 extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
411 num=$(echo "$result" | wc -l)
412 test "$num" -eq "1"
413 ok $? "Mi test: $num / 1 channel discovered"
414
415 test "$result" = "$channel_name"
416 ok $? "Mi test: expected channel: $channel_name found: $result"
417
418 #Add a channel and make sure we have 2 channel now
419 OUTPUT_DEST=$DEVNULL
420 enable_ust_lttng_channel_ok $session_name $channel_name"a"
421
422 #Teardown
423 OUTPUT_DEST=$DEVNULL
424 destroy_lttng_sessions
425 }
426
427 function test_list_domain ()
428 {
429 local session_name="testSession"
430 local channel_name="testChannel"
431 local event=("ev1" "ev2" "ev3")
432
433 OUTPUT_FILE="list_domain.xml"
434
435 #Test buid up
436 OUTPUT_DEST=$DEVNULL
437 create_lttng_session_ok $session_name $OUTPUT_DIR
438 enable_ust_lttng_channel_ok $session_name $channel_name
439
440 #Enable ust and jul events
441 concat_event=$( IFS=$','; echo "${event[*]}" )
442 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
443 enable_jul_lttng_event $session_name $concat_event $channel_name
444
445 #Begin testing
446 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
447 list_lttng_with_opts "$session_name -d"
448 $XML_VALIDATE $OUTPUT_DEST
449 ok $? "Mi test: list domain xsd validation"
450
451 #Expect 2 domain: Jul and UST
452 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
453 num=$(echo "$result" | wc -l)
454 test "$num" -eq "2"
455 ok $? "Mi test: $num / 2 domains discovered"
456
457 #Test for valid value
458 if [[ "$result" = *"JUL"* ]]; then
459 pass "Mi test: domains Jul is present"
460 else
461 fail "Mi test: domains Jul is absent"
462 fi
463
464 if [[ "$result" = *"UST"* ]]; then
465 pass "Mi test: domains UST is present"
466 else
467 fail "Mi test: domains UST is absent"
468 fi
469
470 #Teardown
471 OUTPUT_DEST=$DEVNULL
472 destroy_lttng_sessions
473 }
474
475 function test_list_session ()
476 {
477 local session_name="testSession"
478 local channel_name="testChannel"
479 local event=("ev1" "ev2" "ev3")
480
481 OUTPUT_FILE="list_session.xml"
482
483 #Test buid up
484 OUTPUT_DEST=$DEVNULL
485 create_lttng_session_ok $session_name $OUTPUT_DIR
486 enable_ust_lttng_channel_ok $session_name $channel_name
487
488 #Enable ust and jul events
489 concat_event=$( IFS=$','; echo "${event[*]}" )
490 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
491 enable_jul_lttng_event $session_name $concat_event $channel_name
492
493 #Begin testing
494 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
495 list_lttng_with_opts $session_name
496 $XML_VALIDATE $OUTPUT_DEST
497 ok $? "Mi test: list session xsd validation"
498
499 #Expect 2 domain: Jul and UST
500 extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/lttng:type/text()" result
501 num=$(echo "$result" | wc -l)
502 test "$num" -eq "2"
503 ok $? "Mi test: $num / 2 domains discovered"
504
505 #Expect 2 channel: test and lttng_jul_event
506 extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/lttng:name/text()" result
507 num=$(echo "$result" | wc -l)
508 test "$num" -eq "2"
509 ok $? "Mi test: $num / 2 channel discovered"
510
511 #Teardown
512 OUTPUT_DEST=$DEVNULL
513 destroy_lttng_sessions
514 }
515
516 function test_list_ust_event ()
517 {
518 local file_sync_after_first=$(mktemp -u)
519 local file_sync_before_last=$(mktemp -u)
520
521 OUTPUT_FILE="list_ust_event.xml"
522
523 #Test buid up
524 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
525
526 #Begin testing
527 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} & 2>/dev/null
528
529 while [ ! -f "${file_sync_after_first}" ]; do
530 sleep 0.5
531 done
532
533 list_lttng_with_opts "-u -f"
534
535 touch ${file_sync_before_last}
536
537 $XML_VALIDATE $OUTPUT_DEST
538 ok $? "Mi test: list ust event xsd validation"
539
540 #Extract events
541 extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/lttng:name/text()" result
542 num=$(echo "$result" | wc -l)
543
544 #Since the number of events is prone to change we only look for >= from a
545 #base number. An alternative would be to look for each events but this
546 #is complicated for nothing.
547 test "$num" -ge "5"
548 ok $? "Mi test: $num / 5 ust events discovered"
549
550 #Extract field from tp:tptest event. Expect >= to 12 because number of
551 #field is prone to change.
552 extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./lttng:name = 'tp:tptest']/lttng:event_fields/lttng:event_field/lttng:name/text()" result
553 num=$(echo "$result" | wc -l)
554 test "$num" -ge "12"
555 ok $? "Mi test: $num / 12 ust event fields discovered"
556
557 #Wait for all background processes
558 wait
559
560 rm -f ${file_sync_after_first}
561 rm -f ${file_sync_before_last}
562 }
563
564 function test_start_stop () {
565 local session_name="testStartStopSession"
566 local channel_name="startStopChannel"
567
568 OUTPUT_FILE="list_start_stop.xml"
569
570 #Test buid up
571 OUTPUT_DEST=$DEVNULL
572 create_lttng_session_ok $session_name $OUTPUT_DIR
573
574 #Test fail command
575 #No channel enable start command should return element success false
576 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
577 start_lttng_tracing_fail $session_name
578 $XML_VALIDATE $OUTPUT_DEST
579 ok $? "Mi test: failed start xsd validation"
580
581 #Expect a false element
582 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
583 test "$result" = "false"
584 ok $? "Mi test: mi report failure on start command as expected"
585
586 #Enable a channel to test success
587 OUTPUT_DEST=$DEVNULL
588 enable_ust_lttng_channel_ok $session_name $channel_name
589
590 #Start tracing
591 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
592 start_lttng_tracing_ok $session_name
593 $XML_VALIDATE $OUTPUT_DEST
594 ok $? "Mi test: start xsd validation"
595
596 #Expect a true element
597 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
598 test "$result" = "true"
599 ok $? "Mi test: mi report success on start command as expected"
600
601 #Extract session name from xml
602 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
603 test "$result" = "$session_name"
604 ok $? "Mi test: started $session_name"
605
606 #Extract enabled expect true
607 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
608 test "$result" = "true"
609 ok $? "Mi test: enabled element : $result expected: true"
610
611 #Test stop command
612 stop_lttng_tracing_ok $session_name
613 $XML_VALIDATE $OUTPUT_DEST
614 ok $? "Mi test: stop xsd validation"
615
616 #Extract session name from xml
617 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:name/text()" result
618 test "$result" = "$session_name"
619 ok $? "Mi test: stoped $session_name"
620
621 #Extract enabled expect false
622 extract_xml $OUTPUT_DEST $XPATH_SESSION"/lttng:enabled/text()" result
623 test "$result" = "false"
624 ok $? "Mi test: enabled element : $result expected: false"
625
626 #Test failing stop command
627 stop_lttng_tracing_fail $session_name
628 $XML_VALIDATE $OUTPUT_DEST
629 ok $? "Mi test: failed stop xsd validation"
630
631 #Expect a false element
632 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
633 test "$result" = "false"
634 ok $? "Mi test: mi report failure on start command as expected"
635
636 #Teardown
637 OUTPUT_DEST=$DEVNULL
638 destroy_lttng_sessions
639 }
640
641 function test_snapshot () {
642 local session_name="testSnapshotAdd"
643 local snapshot_path="$OUTPUT_DIR/snapshotoutput"
644 OUTPUT_FILE="snapshot.xml"
645
646
647 #Test buid up
648 OUTPUT_DEST=$DEVNULL
649 create_lttng_session_no_output $session_name
650
651 #Test fail command
652 #No channel enable start command should return element success false
653 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
654 lttng_snapshot_add_output_ok $session_name $snapshot_path
655 $XML_VALIDATE $OUTPUT_DEST
656 ok $? "Mi test: snapshot xsd validation"
657
658 #Expect a true element
659 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
660 test "$result" = "true"
661 ok $? "Mi test: add snapshot is a success"
662
663 #Get data
664 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:session_name/text()" result
665 test "$result" = "$session_name"
666 ok $? "Mi test: added snapshot for: $result expected $session_name"
667
668 #Get name of generated output and id
669 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:name/text()" snapshot_name
670 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/lttng:snapshot/lttng:id/text()" snapshot_id
671
672 #Test list output
673 lttng_snapshot_list $session_name
674 $XML_VALIDATE $OUTPUT_DEST
675 ok $? "Mi test: snapshot list xsd validation"
676
677 #Expect a true element
678 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
679 test "$result" = "true"
680 ok $? "Mi test: add snapshot is a success"
681
682 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/lttng:session[./lttng:name ='$session_name']/lttng:snapshots/lttng:snapshot/lttng:name/text()" result
683 test "$result" = "$snapshot_name"
684 ok $? "Mi test: snapshot list extracted snapshot: $result expected: $snapshot_name"
685
686 #Test del output
687 lttng_snapshot_del_output_ok $session_name $snapshot_id
688 $XML_VALIDATE $OUTPUT_DEST
689 ok $? "Mi test: snapshot delete xsd validation"
690
691 #Success ?
692 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
693 test "$result" = "true"
694 ok $? "Mi test: del snapshot is a success"
695
696 #Test data
697 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:id/text()" result
698 test "$result" = "$snapshot_id"
699 ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $snapshot_id"
700
701 extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/lttng:snapshot/lttng:session_name/text()" result
702 test "$result" = "$session_name"
703 ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $session_name"
704
705 #Test fail on delete command
706 lttng_snapshot_del_output_fail $session_name $snapshot_id
707 $XML_VALIDATE $OUTPUT_DEST
708 ok $? "Mi test: snapshot delete xsd validation"
709
710 #Success ?
711 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
712 test "$result" = "false"
713 ok $? "Mi test: del snapshot is a success"
714
715 OUTPUT_DEST=$DEVNULL
716 destroy_lttng_sessions
717 }
718
719 function test_track_untrack ()
720 {
721 diag "Test track/untrack pid"
722
723 local session_name="testTrack"
724 local snapshot_path="$OUTPUT_DIR/trackoutput"
725 local pid="1,2,3"
726 OUTPUT_FILE="track.xml"
727
728 #Test buid up
729 OUTPUT_DEST=$DEVNULL
730 create_lttng_session_no_output $session_name
731
732 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
733 lttng_track_ok "-p $pid -u"
734 $XML_VALIDATE $OUTPUT_DEST
735 ok $? "Mi test: track pid xsd validation"
736
737 #Expect a true element
738 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
739 test "$result" = "true"
740 ok $? "Mi test: track pid is a success"
741
742 #Verify that there is 3 process
743 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
744 num=$(echo "$result" | wc -l)
745 test "$num" -eq "3"
746 ok $? "Mi test: track pid expecting 3 processes got $num"
747
748 #Test the pid_tracker listing
749 list_lttng_with_opts $session_name
750 $XML_VALIDATE $OUTPUT_DEST
751 ok $? "Mi test: session list with pid_tracker validate"
752
753 #Check the good count
754 extract_xml $OUTPUT_DEST $XPATH_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result
755 num=$(echo "$result" | wc -l)
756 test "$num" -eq "3"
757 ok $? "Mi test: tracker pid listing expecting 3 target got $num"
758
759 #Untrack pid 2,3
760 lttng_untrack_ok "-p 2,3 -u"
761 $XML_VALIDATE $OUTPUT_DEST
762 ok $? "Mi test: untrack 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: untrack pid is a success"
768
769 #Verify that there is 2 untracked pids
770 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
771 num=$(echo "$result" | wc -l)
772 test "$num" -eq "2"
773 ok $? "Mi test: untrack pid expecting 2 process got $num"
774
775 #Check 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 "1"
784 ok $? "Mi test: tracker pid listing expecting 1 process got $num"
785
786 #Untrack all
787 lttng_untrack_ok "-p -u -a"
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 all pid is a success"
795
796 #Verify that there is 1 untracked pid
797 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
798 num=$(echo "$result" | wc -l)
799 test "$num" -eq "1"
800 ok $? "Mi test: untrack pid expecting 1 process got $num"
801
802 #Test if the id is * which represent the all argument
803 test "$result" = "*"
804 ok $? "Mi test: pid expected is * got $result"
805
806 #Test if pid_tracker is enabled as definied by pid_tracker
807 #behavior. If all pid are untrack than the pid_tracker is still
808 #enabled (pid_tracker node is present).
809 list_lttng_with_opts $session_name
810 $XML_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_PID_TRACKER"/lttng:targets/lttng:pid_target/lttng:pid" result
815 num=$(echo -n "$result" | wc -l)
816 test "$num" -eq "0"
817 ok $? "Mi test: tracker pid listing expecting 0 process got $num"
818
819 #Test track all
820 lttng_track_ok "-p -u -a"
821 $XML_VALIDATE $OUTPUT_DEST
822 ok $? "Mi test: track 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: track all pid is a success"
828
829 #Verify that there is 1 tracked process
830 extract_xml $OUTPUT_DEST $XPATH_TRACK_UNTRACK_PID"/lttng:pid" result
831 num=$(echo "$result" | wc -l)
832 test "$num" -eq "1"
833 ok $? "Mi test: track pid expecting 1 process got $num"
834
835 #Test if the id is * wich represent the all argument
836 test "$result" = "*"
837 ok $? "Mi test: pid expected is * got $result"
838
839 #Test if pid_tracker is enabled as definied by pid_tracker
840 #behavior. If all pid are untrack thant the pid_tracker is
841 #disabled (node pid_tracker do not exist)
842 list_lttng_with_opts $session_name
843 $XML_VALIDATE $OUTPUT_DEST
844 ok $? "Mi test: session list with pid_tracker validate"
845
846 node_check_xml $OUTPUT_DEST $XPATH_PID_TRACKER result
847 test "$result" = ""
848 ok $? "Mi test: Pid_tracker node is absent as defined"
849
850 OUTPUT_DEST=$DEVNULL
851 destroy_lttng_sessions
852 }
853
854 start_lttng_sessiond $FOO_LOAD_DIR
855 TESTS=(
856 test_version
857 test_create_session
858 test_destroy_session
859 test_list_sessions
860 test_ust_channel
861 test_ust_lttng_event
862 test_list_channel
863 test_list_domain
864 test_list_session
865 test_list_ust_event
866 test_start_stop
867 test_snapshot
868 test_track_untrack
869 )
870
871
872 echo $OUTPUT_DIR
873 for fct_test in ${TESTS[@]};
874 do
875 ${fct_test}
876 if [ $? -ne 0 ]; then
877 break;
878 fi
879 done
880 rm -rf $OUTPUT_DIR
881
882 OUTPUT_DEST=/dev/null 2>&1
883 stop_lttng_sessiond
This page took 0.108332 seconds and 4 git commands to generate.