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