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