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