MI: Implement event context schema change
[lttng-tools.git] / tests / regression / tools / mi / test_mi
CommitLineData
312dabc3
JRJ
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
18TEST_DESC="Machine interface testing"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../../
654f9f5e 22XSD_PATH=$TESTDIR/../src/common/mi-lttng-3.0.xsd
312dabc3
JRJ
23SESSIOND_BIN="lttng-sessiond"
24RELAYD_BIN="lttng-relayd"
25
01513c3e
JRJ
26#Test app for ust event
27TESTAPP_PATH="$TESTDIR/utils/testapp"
28TESTAPP_NAME="gen-ust-events"
29TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
1c240f7e
MD
30NR_USEC_WAIT=0
31NR_ITER=10000
312dabc3
JRJ
32
33#Temp file output
01513c3e 34OUTPUT_DIR=$(mktemp -d)
8d51ddbc 35FOO_LOAD_DIR=$(mktemp -d)
312dabc3
JRJ
36OUTPUT_FILE="default.xml"
37
38#Path to custom xml utilities
39XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH"
40XML_EXTRACT="$CURDIR/extract_xml"
e83a8bdb 41XML_NODE_CHECK="$CURDIR/extract_xml -e"
312dabc3 42
01513c3e 43XPATH_CMD_OUTPUT="//command/output"
312dabc3 44XPATH_COMMAND_SUCCESS="/command/success/text()"
01513c3e
JRJ
45XPATH_SESSION="$XPATH_CMD_OUTPUT/sessions/session"
46XPATH_ENABLE_CHANNEL_NAME="$XPATH_CMD_OUTPUT/channels/channel/name/text()"
47XPATH_ENABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/events/event/success/text()"
48XPATH_DISABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/channel/events/event/success/text()"
49XPATH_LIST_DOMAIN="$XPATH_CMD_OUTPUT/sessions/session/domains/domain"
50XPATH_LIST_CHANNEL="$XPATH_CMD_OUTPUT/sessions/session/domains/domain/channels/channel"
bf239d4c 51XPATH_LIST_UST_EVENT="$XPATH_CMD_OUTPUT/domains/domain[./type ='UST']/pids/pid/events/event"
01513c3e
JRJ
52XPATH_SNAPSHOT_ADD_SNAPSHOT="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'add-output']/output"
53XPATH_SNAPSHOT_LIST="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'list-output']/output"
54XPATH_SNAPSHOT_DEL="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'del-output']/output"
e83a8bdb
JR
55XPATH_TRACK_UNTRACK_PID="$XPATH_CMD_OUTPUT/targets/pid_target"
56XPATH_PID_TRACKER="$XPATH_CMD_OUTPUT/sessions/session/domains/domain/trackers/pid_tracker"
312dabc3
JRJ
57
58DEVNULL=/dev/null 2>&1
59
60DIR=$(readlink -f $TESTDIR)
61
4f3c38db 62NUM_TESTS=222
312dabc3
JRJ
63
64source $TESTDIR/utils/utils.sh
65
66#Overwrite the lttng_bin to get mi output
67LTTNG_BIN="lttng --mi xml"
68
6bad3253 69#Global declaration for simplification
312dabc3
JRJ
70LTTNG=$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
75plan_tests $NUM_TESTS
76
77print_test_banner "$TEST_DESC"
78
79function extract_xml ()
80{
81 local xml=$1
82 local xpath=$2
83 local __result=$3
01513c3e
JRJ
84 local output
85 output=$($XML_EXTRACT $xml "$xpath")
312dabc3
JRJ
86 ok $? "Extraction of xpath $xpath"
87 eval $__result="'$output'"
88}
89
e83a8bdb
JR
90function 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
312dabc3
JRJ
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
107function 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
01513c3e 117 if [[ $expect_false = "true" ]]; then
312dabc3
JRJ
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
312dabc3 125 pass "Mi test: $xml command success"
01513c3e
JRJ
126 else
127 fail "Mi test: $xml command failed"
312dabc3
JRJ
128 fi
129 fi
130}
131
132function 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
142function 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
151function test_create_session ()
152{
153 local session_name="testSession"
154
155 OUTPUT_FILE="create_session.xml"
156 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
bf6ae429 157 create_lttng_session_ok $session_name $OUTPUT_DIR
312dabc3
JRJ
158 $XML_VALIDATE $OUTPUT_DEST
159 ok $? "MI test: create session xsd validation"
160
161 #try to recreate a session. Expecting it to fail
bf6ae429 162 create_lttng_session_fail $session_name $OUTPUT_DIR
312dabc3
JRJ
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
67b4c664 168 destroy_lttng_session_ok $session_name
312dabc3
JRJ
169}
170
171function 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
bf6ae429 183 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
312dabc3
JRJ
184 done
185
186 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
67b4c664 187 destroy_lttng_session_ok ${session_name[0]}
312dabc3
JRJ
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
01513c3e
JRJ
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]}"
312dabc3
JRJ
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
01513c3e 202 extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result
312dabc3
JRJ
203 num=$(echo "$result" | wc -l)
204 test "$num" -eq "2"
205 ok $? "Mi test: $num / 2 sessions discovered"
01513c3e
JRJ
206
207 #Verify that if no session is present command fail and mi report it.
67b4c664 208 destroy_lttng_session_fail ${session_name[0]}
01513c3e
JRJ
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
312dabc3
JRJ
215}
216
217function 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
bf6ae429 229 create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR
312dabc3
JRJ
230 done
231
232 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
233 list_lttng_with_opts
234 $XML_VALIDATE $OUTPUT_DEST
01513c3e 235 ok $? "Mi test: list sessions xsd validation"
312dabc3
JRJ
236
237 #We should have 3 session
01513c3e 238 extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result
312dabc3
JRJ
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
248function 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
bf6ae429 259 create_lttng_session_ok $session_name $OUTPUT_DIR
312dabc3
JRJ
260
261 #Test the enable_channel command
262 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
827caf52 263 enable_ust_lttng_channel_ok $session_name ${channel_name[0]}
312dabc3
JRJ
264 $XML_VALIDATE $OUTPUT_DEST
265 ok $? "Mi test: enable ust channel xsd validation"
01513c3e 266 is_command_success $OUTPUT_DEST false
312dabc3
JRJ
267
268 #Expect the command to fail
827caf52 269 enable_ust_lttng_channel_fail $session_name ${channel_name[0]}
312dabc3
JRJ
270 $XML_VALIDATE $OUTPUT_DEST
271 ok $? "Mi test: fail enable ust channel xsd validation"
01513c3e 272 is_command_success $OUTPUT_DEST true
312dabc3
JRJ
273
274 #Create two ust channel to test multiple disable
275 for (( i = 1; i < 3; i++ )); do
827caf52 276 enable_ust_lttng_channel_ok $session_name ${channel_name[$i]}
312dabc3
JRJ
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"
01513c3e 283 is_command_success $OUTPUT_DEST false
312dabc3
JRJ
284 #Check that we delete the good channel
285 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
01513c3e 286 test "$result" = "${channel_name[0]}"
312dabc3
JRJ
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"
01513c3e 293 is_command_success $OUTPUT_DEST false
312dabc3
JRJ
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)
01513c3e 298 test "$num" = "2"
312dabc3
JRJ
299 ok $? "Mi test: disabled ust channel $num/2"
300
301 #Teardown
302 OUTPUT_DEST=$DEVNULL
303 destroy_lttng_sessions
304
305}
306
01513c3e
JRJ
307function 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
bf6ae429 317 create_lttng_session_ok $session_name $OUTPUT_DIR
827caf52 318 enable_ust_lttng_channel_ok $session_name $channel_name
01513c3e
JRJ
319
320 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
321 #Test the enable event for ust domain
c4926bb5 322 enable_ust_lttng_event_ok $session_name ${event[0]} $channel_name
01513c3e
JRJ
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
c4926bb5 328 enable_ust_lttng_event_fail $session_name ${event[0]} $channel_name
01513c3e
JRJ
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
c4926bb5 341 enable_ust_lttng_event_fail $session_name $concat_event $channel_name
01513c3e
JRJ
342 $XML_VALIDATE $OUTPUT_DEST
343 ok $? "Mi test: Multiple enable ust event with inside fail xsd validation"
344
4e1b4b38 345 #Check for 2 success = true and 1 success = false
01513c3e
JRJ
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
379function 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
bf6ae429 389 create_lttng_session_ok $session_name $OUTPUT_DIR
827caf52 390 enable_ust_lttng_channel_ok $session_name $channel_name
01513c3e
JRJ
391
392 #Enable ust and jul events
393 concat_event=$( IFS=$','; echo "${event[*]}" )
c4926bb5 394 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
01513c3e
JRJ
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
827caf52 419 enable_ust_lttng_channel_ok $session_name $channel_name"a"
01513c3e
JRJ
420
421 #Teardown
422 OUTPUT_DEST=$DEVNULL
423 destroy_lttng_sessions
424}
425
426function 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
bf6ae429 436 create_lttng_session_ok $session_name $OUTPUT_DIR
827caf52 437 enable_ust_lttng_channel_ok $session_name $channel_name
01513c3e
JRJ
438
439 #Enable ust and jul events
440 concat_event=$( IFS=$','; echo "${event[*]}" )
c4926bb5 441 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
01513c3e
JRJ
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
474function 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
bf6ae429 484 create_lttng_session_ok $session_name $OUTPUT_DIR
827caf52 485 enable_ust_lttng_channel_ok $session_name $channel_name
01513c3e
JRJ
486
487 #Enable ust and jul events
488 concat_event=$( IFS=$','; echo "${event[*]}" )
c4926bb5 489 enable_ust_lttng_event_ok $session_name $concat_event $channel_name
01513c3e
JRJ
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
515function test_list_ust_event ()
516{
1c240f7e
MD
517 local file_sync_after_first=$(mktemp -u)
518 local file_sync_before_last=$(mktemp -u)
519
01513c3e
JRJ
520 OUTPUT_FILE="list_ust_event.xml"
521
522 #Test buid up
523 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
524
525 #Begin testing
1c240f7e
MD
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
01513c3e 532 list_lttng_with_opts "-u -f"
1c240f7e
MD
533
534 touch ${file_sync_before_last}
535
01513c3e
JRJ
536 $XML_VALIDATE $OUTPUT_DEST
537 ok $? "Mi test: list ust event xsd validation"
538
4e1b4b38 539 #Extract events
01513c3e
JRJ
540 extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/name/text()" result
541 num=$(echo "$result" | wc -l)
4e1b4b38
JR
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"
50a74617 547 ok $? "Mi test: $num / 5 ust events discovered"
01513c3e 548
4e1b4b38
JR
549 #Extract field from tp:tptest event. Expect >= to 12 because number of
550 #field is prone to change.
01513c3e
JRJ
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)
4e1b4b38 553 test "$num" -ge "12"
01513c3e
JRJ
554 ok $? "Mi test: $num / 12 ust event fields discovered"
555
5402fe87
MD
556 #Wait for all background processes
557 wait
1c240f7e
MD
558
559 rm -f ${file_sync_after_first}
560 rm -f ${file_sync_before_last}
01513c3e
JRJ
561}
562
563function 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
bf6ae429 571 create_lttng_session_ok $session_name $OUTPUT_DIR
01513c3e
JRJ
572
573 #Test fail command
574 #No channel enable start command should return element success false
575 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
e563bbdb 576 start_lttng_tracing_fail $session_name
01513c3e
JRJ
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
827caf52 587 enable_ust_lttng_channel_ok $session_name $channel_name
01513c3e
JRJ
588
589 #Start tracing
590 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
e563bbdb 591 start_lttng_tracing_ok $session_name
01513c3e
JRJ
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
96340a01 611 stop_lttng_tracing_ok $session_name
01513c3e
JRJ
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
96340a01 626 stop_lttng_tracing_fail $session_name
01513c3e
JRJ
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
01513c3e
JRJ
638}
639
640function 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
b5633831 653 lttng_snapshot_add_output_ok $session_name $snapshot_path
01513c3e
JRJ
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
31580dc7 686 lttng_snapshot_del_output_ok $session_name $snapshot_id
01513c3e
JRJ
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
31580dc7 705 lttng_snapshot_del_output_fail $session_name $snapshot_id
01513c3e
JRJ
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
e83a8bdb
JR
718function 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
e83a8bdb
JR
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
e83a8bdb
JR
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
8d51ddbc 853start_lttng_sessiond $FOO_LOAD_DIR
312dabc3
JRJ
854TESTS=(
855 test_version
856 test_create_session
857 test_destroy_session
858 test_list_sessions
859 test_ust_channel
01513c3e
JRJ
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
e83a8bdb 867 test_track_untrack
312dabc3
JRJ
868)
869
01513c3e 870
312dabc3
JRJ
871echo $OUTPUT_DIR
872for fct_test in ${TESTS[@]};
873do
312dabc3
JRJ
874 ${fct_test}
875 if [ $? -ne 0 ]; then
876 break;
877 fi
312dabc3 878done
01513c3e 879rm -rf $OUTPUT_DIR
312dabc3
JRJ
880
881OUTPUT_DEST=/dev/null 2>&1
882stop_lttng_sessiond
This page took 0.062628 seconds and 4 git commands to generate.