Commit | Line | Data |
---|---|---|
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 | ||
18 | TEST_DESC="Machine interface testing" | |
19 | ||
20 | CURDIR=$(dirname $0)/ | |
21 | TESTDIR=$CURDIR/../../../ | |
22 | XSD_PATH=$TESTDIR/../src/common/mi_lttng.xsd | |
23 | SESSIOND_BIN="lttng-sessiond" | |
24 | RELAYD_BIN="lttng-relayd" | |
25 | ||
01513c3e JRJ |
26 | #Test app for ust event |
27 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
28 | TESTAPP_NAME="gen-ust-events" | |
29 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
30 | NR_USEC_WAIT=10000 | |
31 | ||
312dabc3 JRJ |
32 | |
33 | #Temp file output | |
01513c3e | 34 | OUTPUT_DIR=$(mktemp -d) |
8d51ddbc | 35 | FOO_LOAD_DIR=$(mktemp -d) |
312dabc3 JRJ |
36 | OUTPUT_FILE="default.xml" |
37 | ||
38 | #Path to custom xml utilities | |
39 | XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH" | |
40 | XML_EXTRACT="$CURDIR/extract_xml" | |
41 | ||
01513c3e | 42 | XPATH_CMD_OUTPUT="//command/output" |
312dabc3 | 43 | XPATH_COMMAND_SUCCESS="/command/success/text()" |
01513c3e JRJ |
44 | XPATH_SESSION="$XPATH_CMD_OUTPUT/sessions/session" |
45 | XPATH_ENABLE_CHANNEL_NAME="$XPATH_CMD_OUTPUT/channels/channel/name/text()" | |
46 | XPATH_ENABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/events/event/success/text()" | |
47 | XPATH_DISABLE_EVENT_SUCCESS="$XPATH_CMD_OUTPUT/channel/events/event/success/text()" | |
48 | XPATH_LIST_DOMAIN="$XPATH_CMD_OUTPUT/sessions/session/domains/domain" | |
49 | XPATH_LIST_CHANNEL="$XPATH_CMD_OUTPUT/sessions/session/domains/domain/channels/channel" | |
50 | XPATH_LIST_UST_EVENT="$XPATH_CMD_OUTPUT/domains/domain[./type = 'UST']/pids/pid/events/event" | |
51 | XPATH_SNAPSHOT_ADD_SNAPSHOT="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'add-output']/output" | |
52 | XPATH_SNAPSHOT_LIST="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'list-output']/output" | |
53 | XPATH_SNAPSHOT_DEL="$XPATH_CMD_OUTPUT/snapshot_action[./name = 'del-output']/output" | |
312dabc3 JRJ |
54 | |
55 | DEVNULL=/dev/null 2>&1 | |
56 | ||
57 | DIR=$(readlink -f $TESTDIR) | |
58 | ||
01513c3e | 59 | NUM_TESTS=178 |
312dabc3 JRJ |
60 | |
61 | source $TESTDIR/utils/utils.sh | |
62 | ||
63 | #Overwrite the lttng_bin to get mi output | |
64 | LTTNG_BIN="lttng --mi xml" | |
65 | ||
6bad3253 | 66 | #Global declaration for simplification |
312dabc3 JRJ |
67 | LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN |
68 | ||
69 | #Overwrite the default output for utils.sh command | |
70 | ||
71 | #MUST set TESTDIR before calling those functions | |
72 | plan_tests $NUM_TESTS | |
73 | ||
74 | print_test_banner "$TEST_DESC" | |
75 | ||
76 | function extract_xml () | |
77 | { | |
78 | local xml=$1 | |
79 | local xpath=$2 | |
80 | local __result=$3 | |
01513c3e JRJ |
81 | local output |
82 | output=$($XML_EXTRACT $xml "$xpath") | |
312dabc3 JRJ |
83 | ok $? "Extraction of xpath $xpath" |
84 | eval $__result="'$output'" | |
85 | } | |
86 | ||
87 | # Arg1 is path to xml file | |
88 | # Arg2: | |
89 | # is true if we expected the success element to be false | |
90 | # else | |
91 | # passe false | |
92 | ||
93 | function is_command_success () | |
94 | { | |
95 | local xml=$1 | |
96 | local expect_false=$2 | |
97 | ||
98 | local xpath=$XPATH_COMMAND_SUCCESS | |
99 | ||
100 | #Extract the success element | |
101 | #expect false | |
102 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
01513c3e | 103 | if [[ $expect_false = "true" ]]; then |
312dabc3 JRJ |
104 | if [[ $result ]]; then |
105 | pass "Mi test: $xml command failed as expected" | |
106 | else | |
107 | fail "Mi test: $xml command did not fail as expected" | |
108 | fi | |
109 | else | |
110 | if [[ $result ]]; then | |
312dabc3 | 111 | pass "Mi test: $xml command success" |
01513c3e JRJ |
112 | else |
113 | fail "Mi test: $xml command failed" | |
312dabc3 JRJ |
114 | fi |
115 | fi | |
116 | } | |
117 | ||
118 | function mi_print_version () | |
119 | { | |
120 | local opt=$2 | |
121 | local output_path=$1 | |
122 | ||
123 | $LTTNG version $opt > $1 | |
124 | ok $? "MI test: Lttng version" | |
125 | ||
126 | } | |
127 | ||
128 | function test_version () | |
129 | { | |
130 | OUTPUT_FILE="version.xml" | |
131 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
132 | mi_print_version $OUTPUT_DEST | |
133 | $XML_VALIDATE $OUTPUT_DEST | |
134 | ok $? "MI test: Version xsd validation" | |
135 | } | |
136 | ||
137 | function test_create_session () | |
138 | { | |
139 | local session_name="testSession" | |
140 | ||
141 | OUTPUT_FILE="create_session.xml" | |
142 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
bf6ae429 | 143 | create_lttng_session_ok $session_name $OUTPUT_DIR |
312dabc3 JRJ |
144 | $XML_VALIDATE $OUTPUT_DEST |
145 | ok $? "MI test: create session xsd validation" | |
146 | ||
147 | #try to recreate a session. Expecting it to fail | |
bf6ae429 | 148 | create_lttng_session_fail $session_name $OUTPUT_DIR |
312dabc3 JRJ |
149 | $XML_VALIDATE $OUTPUT_DEST |
150 | ok $? "MI test: expecting fail create session xsd validation" | |
151 | is_command_success $OUTPUT_DEST true | |
152 | ||
153 | OUTPUT_DEST=$DEVNULL | |
67b4c664 | 154 | destroy_lttng_session_ok $session_name |
312dabc3 JRJ |
155 | } |
156 | ||
157 | function test_destroy_session () | |
158 | { | |
159 | local session_name=( | |
160 | "testSession1" | |
161 | "testSession2" | |
162 | "testSession3") | |
163 | ||
164 | OUTPUT_FILE="destroy_session.xml" | |
165 | ||
166 | #Test build up | |
167 | OUTPUT_DEST=$DEVNULL | |
168 | for (( i = 0; i < 3; i++ )); do | |
bf6ae429 | 169 | create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR |
312dabc3 JRJ |
170 | done |
171 | ||
172 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
67b4c664 | 173 | destroy_lttng_session_ok ${session_name[0]} |
312dabc3 JRJ |
174 | $XML_VALIDATE $OUTPUT_DEST |
175 | ok $? "MI test: destroy session ${session_name[0]} xsd validation" | |
176 | ||
177 | #Verify that we destroyed the good session | |
01513c3e JRJ |
178 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result |
179 | test "$result" = "${session_name[0]}" | |
180 | ok $? "Mi test: deleted session: $result expected: ${session_name[0]}" | |
312dabc3 JRJ |
181 | |
182 | #Destroy all and count:should be 2 | |
183 | destroy_lttng_sessions | |
184 | $XML_VALIDATE $OUTPUT_DEST | |
185 | ok $? "MI test: destroy all session xsd validation" | |
186 | ||
187 | #Verify that we destroyed 2 sessions | |
01513c3e | 188 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result |
312dabc3 JRJ |
189 | num=$(echo "$result" | wc -l) |
190 | test "$num" -eq "2" | |
191 | ok $? "Mi test: $num / 2 sessions discovered" | |
01513c3e JRJ |
192 | |
193 | #Verify that if no session is present command fail and mi report it. | |
67b4c664 | 194 | destroy_lttng_session_fail ${session_name[0]} |
01513c3e JRJ |
195 | $XML_VALIDATE $OUTPUT_DEST |
196 | ok $? "MI test: failing destroy session ${session_name[0]} xsd validation" | |
197 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
198 | test "$result" = "false" | |
199 | ok $? "Mi test: destroy command on ${session_name[0]} failed as expected" | |
200 | ||
312dabc3 JRJ |
201 | } |
202 | ||
203 | function test_list_sessions () | |
204 | { | |
205 | local session_name=( | |
206 | "testSession1" | |
207 | "testSession2" | |
208 | "testSession3") | |
209 | ||
210 | OUTPUT_FILE="list_sessions.xml" | |
211 | ||
212 | #Test buid up | |
213 | OUTPUT_DEST=$DEVNULL | |
214 | for (( i = 0; i < 3; i++ )); do | |
bf6ae429 | 215 | create_lttng_session_ok ${session_name[$i]} $OUTPUT_DIR |
312dabc3 JRJ |
216 | done |
217 | ||
218 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
219 | list_lttng_with_opts | |
220 | $XML_VALIDATE $OUTPUT_DEST | |
01513c3e | 221 | ok $? "Mi test: list sessions xsd validation" |
312dabc3 JRJ |
222 | |
223 | #We should have 3 session | |
01513c3e | 224 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result |
312dabc3 JRJ |
225 | num=$(echo "$result" | wc -l) |
226 | test "$num" -eq "3" | |
227 | ok $? "Mi test: $num / 3 sessions discovered" | |
228 | ||
229 | #Teardown | |
230 | OUTPUT_DEST=$DEVNULL | |
231 | destroy_lttng_sessions | |
232 | } | |
233 | ||
234 | function test_ust_channel () | |
235 | { | |
236 | local session_name="testsession" | |
237 | local channel_name=("channelUst0" | |
238 | "channelUst1" | |
239 | "channelUst2") | |
240 | ||
241 | OUTPUT_FILE="ust_channel.xml" | |
242 | ||
243 | #Test buil up | |
244 | OUTPUT_DEST=$DEVNULL | |
bf6ae429 | 245 | create_lttng_session_ok $session_name $OUTPUT_DIR |
312dabc3 JRJ |
246 | |
247 | #Test the enable_channel command | |
248 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
827caf52 | 249 | enable_ust_lttng_channel_ok $session_name ${channel_name[0]} |
312dabc3 JRJ |
250 | $XML_VALIDATE $OUTPUT_DEST |
251 | ok $? "Mi test: enable ust channel xsd validation" | |
01513c3e | 252 | is_command_success $OUTPUT_DEST false |
312dabc3 JRJ |
253 | |
254 | #Expect the command to fail | |
827caf52 | 255 | enable_ust_lttng_channel_fail $session_name ${channel_name[0]} |
312dabc3 JRJ |
256 | $XML_VALIDATE $OUTPUT_DEST |
257 | ok $? "Mi test: fail enable ust channel xsd validation" | |
01513c3e | 258 | is_command_success $OUTPUT_DEST true |
312dabc3 JRJ |
259 | |
260 | #Create two ust channel to test multiple disable | |
261 | for (( i = 1; i < 3; i++ )); do | |
827caf52 | 262 | enable_ust_lttng_channel_ok $session_name ${channel_name[$i]} |
312dabc3 JRJ |
263 | done |
264 | ||
265 | #Test the disable_channel command | |
266 | disable_ust_lttng_channel $session_name ${channel_name[0]} | |
267 | $XML_VALIDATE $OUTPUT_DEST | |
268 | ok $? "Mi test: disable ust channel xsd validation" | |
01513c3e | 269 | is_command_success $OUTPUT_DEST false |
312dabc3 JRJ |
270 | #Check that we delete the good channel |
271 | extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result | |
01513c3e | 272 | test "$result" = "${channel_name[0]}" |
312dabc3 JRJ |
273 | ok $? "MI test: ${channel_name[0]} disabled" |
274 | ||
275 | #Test multiple disable_channel; | |
276 | disable_ust_lttng_channel $session_name ${channel_name[1]},${channel_name[2]} | |
277 | $XML_VALIDATE $OUTPUT_DEST | |
278 | ok $? "Mi test: multiple disable ust channel xsd validation" | |
01513c3e | 279 | is_command_success $OUTPUT_DEST false |
312dabc3 JRJ |
280 | |
281 | #Make sure we have two disabled channel | |
282 | extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result | |
283 | local num=$(echo "$result" | wc -l) | |
01513c3e | 284 | test "$num" = "2" |
312dabc3 JRJ |
285 | ok $? "Mi test: disabled ust channel $num/2" |
286 | ||
287 | #Teardown | |
288 | OUTPUT_DEST=$DEVNULL | |
289 | destroy_lttng_sessions | |
290 | ||
291 | } | |
292 | ||
01513c3e JRJ |
293 | function test_ust_lttng_event () |
294 | { | |
295 | local session_name="testSession" | |
296 | local channel_name="testChannel" | |
297 | local event=("ev1" "ev2" "ev3") | |
298 | ||
299 | OUTPUT_FILE="ust_event.xml" | |
300 | ||
301 | #Test build up | |
302 | OUTPUT_DEST=$DEVNULL | |
bf6ae429 | 303 | create_lttng_session_ok $session_name $OUTPUT_DIR |
827caf52 | 304 | enable_ust_lttng_channel_ok $session_name $channel_name |
01513c3e JRJ |
305 | |
306 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
307 | #Test the enable event for ust domain | |
c4926bb5 | 308 | enable_ust_lttng_event_ok $session_name ${event[0]} $channel_name |
01513c3e JRJ |
309 | $XML_VALIDATE $OUTPUT_DEST |
310 | ok $? "Mi test: Enable_event for ust domain xsd validation" | |
311 | is_command_success $OUTPUT_DEST false | |
312 | ||
313 | #Try to reenable an enabled event. Should fail | |
c4926bb5 | 314 | enable_ust_lttng_event_fail $session_name ${event[0]} $channel_name |
01513c3e JRJ |
315 | $XML_VALIDATE $OUTPUT_DEST |
316 | ok $? "Mi test: Fail enable_event for ust domain xsd validation" | |
317 | is_command_success $OUTPUT_DEST true | |
318 | ||
319 | #Enable multiple event including the last one command will fail | |
320 | #But 2 events should success | |
321 | ||
322 | #Nice little hack, create a string ev,ev,ev | |
323 | #IFS stand for Internal field separator | |
324 | #Event[*] print all the element inside the array with the IFS in between | |
325 | concat_event=$( IFS=$','; echo "${event[*]}" ) | |
326 | ||
c4926bb5 | 327 | enable_ust_lttng_event_fail $session_name $concat_event $channel_name |
01513c3e JRJ |
328 | $XML_VALIDATE $OUTPUT_DEST |
329 | ok $? "Mi test: Multiple enable ust event with inside fail xsd validation" | |
330 | ||
4e1b4b38 | 331 | #Check for 2 success = true and 1 success = false |
01513c3e JRJ |
332 | extract_xml $OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result |
333 | num_ocur=$(grep -o "true" <<< "$result" | wc -l) | |
334 | test "$num_ocur" -eq "2" | |
335 | ok $? "Mi test: Enabled event on failing enable command $num_ocur_true/2" | |
336 | ||
337 | extract_xml $OUTPUT_DEST $XPATH_ENABLE_EVENT_SUCCESS result | |
338 | num_ocur=$(grep -o "false" <<< "$result" | wc -l) | |
339 | test "$num_ocur" -eq "1" | |
340 | ok $? "Mi test: Enabled event on failing enable command $num_ocur_true/2" | |
341 | ||
342 | #Disable the event | |
343 | disable_ust_lttng_event $session_name ${event[0]} $channel_name | |
344 | $XML_VALIDATE $OUTPUT_DEST | |
345 | ok $? "Mi test: Disable ust event xsd validation" | |
346 | is_command_success $OUTPUT_DEST false | |
347 | ||
348 | #Disable the 3 event combined. Should pass | |
349 | disable_ust_lttng_event $session_name $concat_event $channel_name | |
350 | $XML_VALIDATE $OUTPUT_DEST | |
351 | ok $? "Mi test: Disable multiple ust event xsd validation" | |
352 | is_command_success $OUTPUT_DEST false | |
353 | ||
354 | #Make sure we have 3 inner success | |
355 | extract_xml $OUTPUT_DEST $XPATH_DISABLE_EVENT_SUCCESS result | |
356 | num_ocur=$(grep -o "true" <<< "$result" | wc -l) | |
357 | test "$num_ocur" -eq "3" | |
358 | ok $? "Mi test: Disable multiple ust event success $num_ocur/3" | |
359 | ||
360 | #Teardown | |
361 | OUTPUT_DEST=$DEVNULL | |
362 | destroy_lttng_sessions | |
363 | } | |
364 | ||
365 | function test_list_channel () | |
366 | { | |
367 | local session_name="testSession" | |
368 | local channel_name="testChannel" | |
369 | local event=("ev1" "ev2" "ev3") | |
370 | ||
371 | OUTPUT_FILE="list_channel.xml" | |
372 | ||
373 | #Test buid up | |
374 | OUTPUT_DEST=$DEVNULL | |
bf6ae429 | 375 | create_lttng_session_ok $session_name $OUTPUT_DIR |
827caf52 | 376 | enable_ust_lttng_channel_ok $session_name $channel_name |
01513c3e JRJ |
377 | |
378 | #Enable ust and jul events | |
379 | concat_event=$( IFS=$','; echo "${event[*]}" ) | |
c4926bb5 | 380 | enable_ust_lttng_event_ok $session_name $concat_event $channel_name |
01513c3e JRJ |
381 | |
382 | #Begin testing | |
383 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
384 | list_lttng_with_opts "$session_name -c $channel_name" | |
385 | $XML_VALIDATE $OUTPUT_DEST | |
386 | ok $? "Mi test: list channel xsd validation" | |
387 | ||
388 | #Expect 1 domain: UST | |
389 | extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/type/text()" result | |
390 | num=$(echo "$result" | wc -l) | |
391 | test "$num" -eq "1" | |
392 | ok $? "Mi test: $num / 1 domains discovered" | |
393 | ||
394 | #Expect 1 channel: test | |
395 | extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/name/text()" result | |
396 | num=$(echo "$result" | wc -l) | |
397 | test "$num" -eq "1" | |
398 | ok $? "Mi test: $num / 1 channel discovered" | |
399 | ||
400 | test "$result" = "$channel_name" | |
401 | ok $? "Mi test: expected channel: $channel_name found: $result" | |
402 | ||
403 | #Add a channel and make sure we have 2 channel now | |
404 | OUTPUT_DEST=$DEVNULL | |
827caf52 | 405 | enable_ust_lttng_channel_ok $session_name $channel_name"a" |
01513c3e JRJ |
406 | |
407 | #Teardown | |
408 | OUTPUT_DEST=$DEVNULL | |
409 | destroy_lttng_sessions | |
410 | } | |
411 | ||
412 | function test_list_domain () | |
413 | { | |
414 | local session_name="testSession" | |
415 | local channel_name="testChannel" | |
416 | local event=("ev1" "ev2" "ev3") | |
417 | ||
418 | OUTPUT_FILE="list_domain.xml" | |
419 | ||
420 | #Test buid up | |
421 | OUTPUT_DEST=$DEVNULL | |
bf6ae429 | 422 | create_lttng_session_ok $session_name $OUTPUT_DIR |
827caf52 | 423 | enable_ust_lttng_channel_ok $session_name $channel_name |
01513c3e JRJ |
424 | |
425 | #Enable ust and jul events | |
426 | concat_event=$( IFS=$','; echo "${event[*]}" ) | |
c4926bb5 | 427 | enable_ust_lttng_event_ok $session_name $concat_event $channel_name |
01513c3e JRJ |
428 | enable_jul_lttng_event $session_name $concat_event $channel_name |
429 | ||
430 | #Begin testing | |
431 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
432 | list_lttng_with_opts "$session_name -d" | |
433 | $XML_VALIDATE $OUTPUT_DEST | |
434 | ok $? "Mi test: list domain xsd validation" | |
435 | ||
436 | #Expect 2 domain: Jul and UST | |
437 | extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/type/text()" result | |
438 | num=$(echo "$result" | wc -l) | |
439 | test "$num" -eq "2" | |
440 | ok $? "Mi test: $num / 2 domains discovered" | |
441 | ||
442 | #Test for valid value | |
443 | if [[ "$result" = *"JUL"* ]]; then | |
444 | pass "Mi test: domains Jul is present" | |
445 | else | |
446 | fail "Mi test: domains Jul is absent" | |
447 | fi | |
448 | ||
449 | if [[ "$result" = *"UST"* ]]; then | |
450 | pass "Mi test: domains UST is present" | |
451 | else | |
452 | fail "Mi test: domains UST is absent" | |
453 | fi | |
454 | ||
455 | #Teardown | |
456 | OUTPUT_DEST=$DEVNULL | |
457 | destroy_lttng_sessions | |
458 | } | |
459 | ||
460 | function test_list_session () | |
461 | { | |
462 | local session_name="testSession" | |
463 | local channel_name="testChannel" | |
464 | local event=("ev1" "ev2" "ev3") | |
465 | ||
466 | OUTPUT_FILE="list_session.xml" | |
467 | ||
468 | #Test buid up | |
469 | OUTPUT_DEST=$DEVNULL | |
bf6ae429 | 470 | create_lttng_session_ok $session_name $OUTPUT_DIR |
827caf52 | 471 | enable_ust_lttng_channel_ok $session_name $channel_name |
01513c3e JRJ |
472 | |
473 | #Enable ust and jul events | |
474 | concat_event=$( IFS=$','; echo "${event[*]}" ) | |
c4926bb5 | 475 | enable_ust_lttng_event_ok $session_name $concat_event $channel_name |
01513c3e JRJ |
476 | enable_jul_lttng_event $session_name $concat_event $channel_name |
477 | ||
478 | #Begin testing | |
479 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
480 | list_lttng_with_opts $session_name | |
481 | $XML_VALIDATE $OUTPUT_DEST | |
482 | ok $? "Mi test: list session xsd validation" | |
483 | ||
484 | #Expect 2 domain: Jul and UST | |
485 | extract_xml $OUTPUT_DEST $XPATH_LIST_DOMAIN"/type/text()" result | |
486 | num=$(echo "$result" | wc -l) | |
487 | test "$num" -eq "2" | |
488 | ok $? "Mi test: $num / 2 domains discovered" | |
489 | ||
490 | #Expect 2 channel: test and lttng_jul_event | |
491 | extract_xml $OUTPUT_DEST $XPATH_LIST_CHANNEL"/name/text()" result | |
492 | num=$(echo "$result" | wc -l) | |
493 | test "$num" -eq "2" | |
494 | ok $? "Mi test: $num / 2 channel discovered" | |
495 | ||
496 | #Teardown | |
497 | OUTPUT_DEST=$DEVNULL | |
498 | destroy_lttng_sessions | |
499 | } | |
500 | ||
501 | function test_list_ust_event () | |
502 | { | |
503 | OUTPUT_FILE="list_ust_event.xml" | |
504 | ||
505 | #Test buid up | |
506 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
507 | ||
508 | #Begin testing | |
509 | $TESTAPP_BIN $NR_USEC_WAIT & 2>/dev/null | |
510 | list_lttng_with_opts "-u -f" | |
511 | $XML_VALIDATE $OUTPUT_DEST | |
512 | ok $? "Mi test: list ust event xsd validation" | |
513 | ||
4e1b4b38 | 514 | #Extract events |
01513c3e JRJ |
515 | extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""/name/text()" result |
516 | num=$(echo "$result" | wc -l) | |
4e1b4b38 JR |
517 | |
518 | #Since the number of events is prone to change we only look for >= from a | |
519 | #base number. An alternative would be to look for each events but this | |
520 | #is complicated for nothing. | |
521 | test "$num" -ge "5" | |
50a74617 | 522 | ok $? "Mi test: $num / 5 ust events discovered" |
01513c3e | 523 | |
4e1b4b38 JR |
524 | #Extract field from tp:tptest event. Expect >= to 12 because number of |
525 | #field is prone to change. | |
01513c3e JRJ |
526 | extract_xml $OUTPUT_DEST "$XPATH_LIST_UST_EVENT""[./name = 'tp:tptest']/event_fields/event_field/name/text()" result |
527 | num=$(echo "$result" | wc -l) | |
4e1b4b38 | 528 | test "$num" -ge "12" |
01513c3e JRJ |
529 | ok $? "Mi test: $num / 12 ust event fields discovered" |
530 | ||
5402fe87 MD |
531 | #Wait for all background processes |
532 | wait | |
01513c3e JRJ |
533 | } |
534 | ||
535 | function test_start_stop () { | |
536 | local session_name="testStartStopSession" | |
537 | local channel_name="startStopChannel" | |
538 | ||
539 | OUTPUT_FILE="list_start_stop.xml" | |
540 | ||
541 | #Test buid up | |
542 | OUTPUT_DEST=$DEVNULL | |
bf6ae429 | 543 | create_lttng_session_ok $session_name $OUTPUT_DIR |
01513c3e JRJ |
544 | |
545 | #Test fail command | |
546 | #No channel enable start command should return element success false | |
547 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
e563bbdb | 548 | start_lttng_tracing_fail $session_name |
01513c3e JRJ |
549 | $XML_VALIDATE $OUTPUT_DEST |
550 | ok $? "Mi test: failed start xsd validation" | |
551 | ||
552 | #Expect a false element | |
553 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
554 | test "$result" = "false" | |
555 | ok $? "Mi test: mi report failure on start command as expected" | |
556 | ||
557 | #Enable a channel to test success | |
558 | OUTPUT_DEST=$DEVNULL | |
827caf52 | 559 | enable_ust_lttng_channel_ok $session_name $channel_name |
01513c3e JRJ |
560 | |
561 | #Start tracing | |
562 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
e563bbdb | 563 | start_lttng_tracing_ok $session_name |
01513c3e JRJ |
564 | $XML_VALIDATE $OUTPUT_DEST |
565 | ok $? "Mi test: start xsd validation" | |
566 | ||
567 | #Expect a true element | |
568 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
569 | test "$result" = "true" | |
570 | ok $? "Mi test: mi report success on start command as expected" | |
571 | ||
572 | #Extract session name from xml | |
573 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result | |
574 | test "$result" = "$session_name" | |
575 | ok $? "Mi test: started $session_name" | |
576 | ||
577 | #Extract enabled expect true | |
578 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/enabled/text()" result | |
579 | test "$result" = "true" | |
580 | ok $? "Mi test: enabled element : $result expected: true" | |
581 | ||
582 | #Test stop command | |
96340a01 | 583 | stop_lttng_tracing_ok $session_name |
01513c3e JRJ |
584 | $XML_VALIDATE $OUTPUT_DEST |
585 | ok $? "Mi test: stop xsd validation" | |
586 | ||
587 | #Extract session name from xml | |
588 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/name/text()" result | |
589 | test "$result" = "$session_name" | |
590 | ok $? "Mi test: stoped $session_name" | |
591 | ||
592 | #Extract enabled expect false | |
593 | extract_xml $OUTPUT_DEST $XPATH_SESSION"/enabled/text()" result | |
594 | test "$result" = "false" | |
595 | ok $? "Mi test: enabled element : $result expected: false" | |
596 | ||
597 | #Test failing stop command | |
96340a01 | 598 | stop_lttng_tracing_fail $session_name |
01513c3e JRJ |
599 | $XML_VALIDATE $OUTPUT_DEST |
600 | ok $? "Mi test: failed stop xsd validation" | |
601 | ||
602 | #Expect a false element | |
603 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
604 | test "$result" = "false" | |
605 | ok $? "Mi test: mi report failure on start command as expected" | |
606 | ||
607 | #Teardown | |
608 | OUTPUT_DEST=$DEVNULL | |
609 | destroy_lttng_sessions | |
01513c3e JRJ |
610 | } |
611 | ||
612 | function test_snapshot () { | |
613 | local session_name="testSnapshotAdd" | |
614 | local snapshot_path="$OUTPUT_DIR/snapshotoutput" | |
615 | OUTPUT_FILE="snapshot.xml" | |
616 | ||
617 | ||
618 | #Test buid up | |
619 | OUTPUT_DEST=$DEVNULL | |
620 | create_lttng_session_no_output $session_name | |
621 | ||
622 | #Test fail command | |
623 | #No channel enable start command should return element success false | |
624 | OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE | |
b5633831 | 625 | lttng_snapshot_add_output_ok $session_name $snapshot_path |
01513c3e JRJ |
626 | $XML_VALIDATE $OUTPUT_DEST |
627 | ok $? "Mi test: snapshot xsd validation" | |
628 | ||
629 | #Expect a true element | |
630 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
631 | test "$result" = "true" | |
632 | ok $? "Mi test: add snapshot is a success" | |
633 | ||
634 | #Get data | |
635 | extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/snapshot/session_name/text()" result | |
636 | test "$result" = "$session_name" | |
637 | ok $? "Mi test: added snapshot for: $result expected $session_name" | |
638 | ||
639 | #Get name of generated output and id | |
640 | extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/snapshot/name/text()" snapshot_name | |
641 | extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_ADD_SNAPSHOT""/snapshot/id/text()" snapshot_id | |
642 | ||
643 | #Test list output | |
644 | lttng_snapshot_list $session_name | |
645 | $XML_VALIDATE $OUTPUT_DEST | |
646 | ok $? "Mi test: snapshot list xsd validation" | |
647 | ||
648 | #Expect a true element | |
649 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
650 | test "$result" = "true" | |
651 | ok $? "Mi test: add snapshot is a success" | |
652 | ||
653 | extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_LIST""/session[./name ='$session_name']/snapshots/snapshot/name/text()" result | |
654 | test "$result" = "$snapshot_name" | |
655 | ok $? "Mi test: snapshot list extracted snapshot: $result expected: $snapshot_name" | |
656 | ||
657 | #Test del output | |
31580dc7 | 658 | lttng_snapshot_del_output_ok $session_name $snapshot_id |
01513c3e JRJ |
659 | $XML_VALIDATE $OUTPUT_DEST |
660 | ok $? "Mi test: snapshot delete xsd validation" | |
661 | ||
662 | #Success ? | |
663 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
664 | test "$result" = "true" | |
665 | ok $? "Mi test: del snapshot is a success" | |
666 | ||
667 | #Test data | |
668 | extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/snapshot/id/text()" result | |
669 | test "$result" = "$snapshot_id" | |
670 | ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $snapshot_id" | |
671 | ||
672 | extract_xml $OUTPUT_DEST "$XPATH_SNAPSHOT_DEL""/snapshot/session_name/text()" result | |
673 | test "$result" = "$session_name" | |
674 | ok $? "Mi test: snapshot del extracted snapshot id: $result expected: $session_name" | |
675 | ||
676 | #Test fail on delete command | |
31580dc7 | 677 | lttng_snapshot_del_output_fail $session_name $snapshot_id |
01513c3e JRJ |
678 | $XML_VALIDATE $OUTPUT_DEST |
679 | ok $? "Mi test: snapshot delete xsd validation" | |
680 | ||
681 | #Success ? | |
682 | extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result | |
683 | test "$result" = "false" | |
684 | ok $? "Mi test: del snapshot is a success" | |
685 | ||
686 | OUTPUT_DEST=$DEVNULL | |
687 | destroy_lttng_sessions | |
688 | } | |
689 | ||
8d51ddbc | 690 | start_lttng_sessiond $FOO_LOAD_DIR |
312dabc3 JRJ |
691 | TESTS=( |
692 | test_version | |
693 | test_create_session | |
694 | test_destroy_session | |
695 | test_list_sessions | |
696 | test_ust_channel | |
01513c3e JRJ |
697 | test_ust_lttng_event |
698 | test_list_channel | |
699 | test_list_domain | |
700 | test_list_session | |
701 | test_list_ust_event | |
702 | test_start_stop | |
703 | test_snapshot | |
312dabc3 JRJ |
704 | ) |
705 | ||
01513c3e | 706 | |
312dabc3 JRJ |
707 | echo $OUTPUT_DIR |
708 | for fct_test in ${TESTS[@]}; | |
709 | do | |
312dabc3 JRJ |
710 | ${fct_test} |
711 | if [ $? -ne 0 ]; then | |
712 | break; | |
713 | fi | |
312dabc3 | 714 | done |
01513c3e | 715 | rm -rf $OUTPUT_DIR |
312dabc3 JRJ |
716 | |
717 | OUTPUT_DEST=/dev/null 2>&1 | |
718 | stop_lttng_sessiond |