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