Commit | Line | Data |
---|---|---|
10a8a223 | 1 | #!/src/bin/bash |
d3e8f6bb DG |
2 | # |
3 | # Copyright (C) - 2012 David Goulet <dgoulet@efficios.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 | SESSIOND_BIN="lttng-sessiond" | |
f7613992 | 19 | CONSUMERD_BIN="lttng-consumerd" |
f4e40ab6 | 20 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
21 | LTTNG_BIN="lttng" |
22 | BABELTRACE_BIN="babeltrace" | |
873c2aae | 23 | OUTPUT_DEST=/dev/null 2>&1 |
d3e8f6bb | 24 | |
fd4dfcec DG |
25 | # Minimal kernel version supported for session daemon tests |
26 | KERNEL_MAJOR_VERSION=2 | |
27 | KERNEL_MINOR_VERSION=6 | |
28 | KERNEL_PATCHLEVEL_VERSION=27 | |
29 | ||
629b9335 MD |
30 | # We set the default UST register timeout to "wait forever", so that |
31 | # basic tests don't have to worry about hitting timeouts on busy | |
32 | # systems. Specialized tests should test those corner-cases. | |
33 | export LTTNG_UST_REGISTER_TIMEOUT=-1 | |
34 | ||
29655db7 CB |
35 | source $TESTDIR/utils/tap/tap.sh |
36 | ||
fec81a7e CB |
37 | function print_ok () |
38 | { | |
39 | # Check if we are a terminal | |
40 | if [ -t 1 ]; then | |
41 | echo -e "\e[1;32mOK\e[0m" | |
42 | else | |
43 | echo -e "OK" | |
44 | fi | |
45 | } | |
46 | ||
47 | function print_fail () | |
48 | { | |
49 | # Check if we are a terminal | |
50 | if [ -t 1 ]; then | |
51 | echo -e "\e[1;31mFAIL\e[0m" | |
52 | else | |
53 | echo -e "FAIL" | |
54 | fi | |
55 | } | |
56 | ||
57 | function print_test_banner () | |
58 | { | |
7d0ad314 | 59 | local desc="$1" |
29655db7 | 60 | diag "$desc" |
fec81a7e CB |
61 | } |
62 | ||
fd4dfcec DG |
63 | function validate_kernel_version () |
64 | { | |
7d0ad314 | 65 | local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) |
fd4dfcec DG |
66 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then |
67 | return 0 | |
68 | fi | |
69 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
70 | return 0 | |
71 | fi | |
72 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
73 | return 0 | |
74 | fi | |
75 | return 1 | |
76 | } | |
77 | ||
9ac429ef | 78 | # Generate a random string |
f4e40ab6 DG |
79 | # $1 = number of characters; defaults to 16 |
80 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 81 | function randstring() |
f4e40ab6 DG |
82 | { |
83 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
84 | cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16} | |
85 | echo | |
86 | } | |
87 | ||
f4e40ab6 DG |
88 | function lttng_enable_kernel_event |
89 | { | |
7d0ad314 JRJ |
90 | local sess_name=$1 |
91 | local event_name=$2 | |
92 | local channel_name=$3 | |
f4e40ab6 DG |
93 | |
94 | if [ -z $event_name ]; then | |
95 | # Enable all event if no event name specified | |
29655db7 | 96 | event_name="-a" |
f4e40ab6 DG |
97 | fi |
98 | ||
07b86b52 JD |
99 | if [ -z $channel_name ]; then |
100 | # default channel if none specified | |
101 | chan="" | |
102 | else | |
103 | chan="-c $channel_name" | |
104 | fi | |
105 | ||
873c2aae | 106 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k >$OUTPUT_DEST |
29655db7 | 107 | ok $? "Enable kernel event $event_name for session $sess_name" |
f4e40ab6 DG |
108 | } |
109 | ||
8cfcd41c MD |
110 | function lttng_enable_kernel_syscall() |
111 | { | |
112 | local expected_to_fail=$1 | |
113 | local sess_name=$2 | |
114 | local syscall_name=$3 | |
115 | local channel_name=$4 | |
116 | ||
117 | if [ -z $syscall_name ]; then | |
118 | # Enable all event if no syscall name specified | |
119 | syscall_name="-a" | |
120 | fi | |
121 | ||
122 | if [ -z $channel_name ]; then | |
123 | # default channel if none specified | |
124 | chan="" | |
125 | else | |
126 | chan="-c $channel_name" | |
127 | fi | |
128 | ||
129 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST | |
130 | ret=$? | |
131 | if [[ $expected_to_fail -eq "1" ]]; then | |
132 | test $ret -ne "0" | |
133 | ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" | |
134 | else | |
135 | ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
136 | fi | |
137 | } | |
138 | ||
139 | function lttng_enable_kernel_syscall_ok() | |
140 | { | |
141 | lttng_enable_kernel_syscall 0 ${*} | |
142 | } | |
143 | ||
144 | function lttng_enable_kernel_syscall_fail() | |
145 | { | |
146 | lttng_enable_kernel_syscall 1 ${*} | |
147 | } | |
148 | ||
149 | function lttng_disable_kernel_syscall() | |
150 | { | |
151 | local expected_to_fail=$1 | |
152 | local sess_name=$2 | |
153 | local syscall_name=$3 | |
154 | local channel_name=$4 | |
155 | ||
156 | if [ -z $syscall_name ]; then | |
157 | # Enable all event if no syscall name specified | |
158 | syscall_name="-a" | |
159 | fi | |
160 | ||
161 | if [ -z $channel_name ]; then | |
162 | # default channel if none specified | |
163 | chan="" | |
164 | else | |
165 | chan="-c $channel_name" | |
166 | fi | |
167 | ||
168 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k >$OUTPUT_DEST | |
169 | ||
170 | ret=$? | |
171 | if [[ $expected_to_fail -eq "1" ]]; then | |
172 | test $ret -ne "0" | |
173 | ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" | |
174 | else | |
175 | ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
176 | fi | |
177 | } | |
178 | ||
179 | function lttng_disable_kernel_syscall_ok() | |
180 | { | |
181 | lttng_disable_kernel_syscall 0 ${*} | |
182 | } | |
183 | ||
184 | function lttng_disable_kernel_syscall_fail() | |
185 | { | |
186 | lttng_disable_kernel_syscall 1 ${*} | |
187 | } | |
188 | ||
d96f6315 MD |
189 | function lttng_enable_kernel_channel() |
190 | { | |
191 | local expected_to_fail=$1 | |
192 | local sess_name=$2 | |
193 | local channel_name=$3 | |
194 | ||
195 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name >$OUTPUT_DEST | |
196 | ret=$? | |
197 | if [[ $expected_to_fail -eq "1" ]]; then | |
198 | test "$ret" -ne "0" | |
199 | ok $? "Expected failure on kernel channel creation $channel_name in $sess_name" | |
200 | else | |
201 | ok $ret "Enable channel $channel_name for session $sess_name" | |
202 | fi | |
203 | } | |
204 | ||
205 | function lttng_enable_kernel_channel_ok() | |
206 | { | |
207 | lttng_enable_kernel_channel 0 ${*} | |
208 | } | |
209 | ||
210 | function lttng_enable_kernel_channel_fail() | |
211 | { | |
212 | lttng_enable_kernel_channel 1 ${*} | |
213 | } | |
214 | ||
215 | function lttng_disable_kernel_channel() | |
216 | { | |
217 | local expected_to_fail=$1 | |
218 | local sess_name=$2 | |
219 | local channel_name=$3 | |
220 | ||
221 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name >$OUTPUT_DEST | |
222 | ret=$? | |
223 | if [[ $expected_to_fail -eq "1" ]]; then | |
224 | test "$ret" -ne "0" | |
225 | ok $? "Expected failure on kernel channel creation $channel_name in $sess_name" | |
226 | else | |
227 | ok $ret "disable channel $channel_name for session $sess_name" | |
228 | fi | |
229 | } | |
230 | ||
231 | function lttng_disable_kernel_channel_ok() | |
232 | { | |
233 | lttng_disable_kernel_channel 0 ${*} | |
234 | } | |
235 | ||
236 | function lttng_disable_kernel_channel_fail() | |
237 | { | |
238 | lttng_disable_kernel_channel 1 ${*} | |
239 | } | |
240 | ||
fb3268e3 | 241 | function start_lttng_relayd |
f4e40ab6 | 242 | { |
198e7caf | 243 | local opt=$1 |
173af62f | 244 | |
f4e40ab6 DG |
245 | DIR=$(readlink -f $TESTDIR) |
246 | ||
247 | if [ -z $(pidof lt-$RELAYD_BIN) ]; then | |
873c2aae | 248 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt >$OUTPUT_DEST |
25a818af | 249 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
f4e40ab6 | 250 | if [ $? -eq 1 ]; then |
29655db7 | 251 | fail "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
252 | return 1 |
253 | else | |
29655db7 | 254 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
255 | fi |
256 | else | |
29655db7 | 257 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
258 | fi |
259 | } | |
260 | ||
1fb23888 | 261 | function stop_lttng_relayd_nocheck |
f4e40ab6 DG |
262 | { |
263 | PID_RELAYD=`pidof lt-$RELAYD_BIN` | |
264 | ||
1fb23888 | 265 | diag "Killing lttng-relayd (pid: $PID_RELAYD)" |
873c2aae | 266 | kill $PID_RELAYD >$OUTPUT_DEST |
1fb23888 | 267 | retval=$? |
29655db7 | 268 | |
1fb23888 | 269 | if [ $retval -eq 1 ]; then |
f4e40ab6 DG |
270 | out=1 |
271 | while [ -n "$out" ]; do | |
272 | out=$(pidof lt-$RELAYD_BIN) | |
273 | sleep 0.5 | |
274 | done | |
1fb23888 MD |
275 | fi |
276 | return $retval | |
277 | } | |
278 | ||
279 | function stop_lttng_relayd | |
280 | { | |
281 | stop_lttng_relayd_nocheck | |
282 | ||
283 | if [ $? -eq 1 ]; then | |
284 | fail "Killed lttng-relayd (pid: $PID_RELAYD)" | |
285 | return 1 | |
286 | else | |
287 | pass "Killed lttng-relayd (pid: $PID_RELAYD)" | |
f4e40ab6 DG |
288 | return 0 |
289 | fi | |
290 | } | |
291 | ||
8d51ddbc | 292 | #First argument: load path for automatic loading |
fb3268e3 | 293 | function start_lttng_sessiond() |
355f483d | 294 | { |
8d51ddbc JRJ |
295 | |
296 | local load_path="$1" | |
355f483d DG |
297 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
298 | # Env variable requested no session daemon | |
299 | return | |
300 | fi | |
301 | ||
29655db7 CB |
302 | validate_kernel_version |
303 | if [ $? -ne 0 ]; then | |
304 | fail "Start session daemon" | |
305 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
306 | fi |
307 | ||
29655db7 | 308 | DIR=$(readlink -f $TESTDIR) |
d3d97763 JG |
309 | : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/} |
310 | export LTTNG_SESSION_CONFIG_XSD_PATH | |
29655db7 CB |
311 | |
312 | if [ -z $(pidof lt-$SESSIOND_BIN) ]; then | |
8d51ddbc JRJ |
313 | # Have a load path ? |
314 | if [ -n "$1" ]; then | |
315 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$1" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
316 | else | |
317 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
318 | fi | |
0fc2834c | 319 | #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --verbose-consumer >>/tmp/sessiond.log 2>&1 |
29655db7 | 320 | status=$? |
29655db7 CB |
321 | ok $status "Start session daemon" |
322 | fi | |
355f483d DG |
323 | } |
324 | ||
fb3268e3 | 325 | function stop_lttng_sessiond () |
d3e8f6bb | 326 | { |
355f483d DG |
327 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
328 | # Env variable requested no session daemon | |
329 | return | |
330 | fi | |
331 | ||
d3e8f6bb DG |
332 | PID_SESSIOND=`pidof lt-$SESSIOND_BIN` |
333 | ||
873c2aae | 334 | kill $PID_SESSIOND >$OUTPUT_DEST |
29655db7 | 335 | |
d3e8f6bb | 336 | if [ $? -eq 1 ]; then |
29655db7 | 337 | fail "Kill sessions daemon" |
d3e8f6bb DG |
338 | return 1 |
339 | else | |
5fa32580 DG |
340 | out=1 |
341 | while [ -n "$out" ]; do | |
342 | out=$(pidof lt-$SESSIOND_BIN) | |
343 | sleep 0.5 | |
344 | done | |
f7613992 MD |
345 | out=1 |
346 | while [ -n "$out" ]; do | |
347 | out=$(pidof $CONSUMERD_BIN) | |
348 | sleep 0.5 | |
349 | done | |
29655db7 | 350 | pass "Kill session daemon" |
d3e8f6bb DG |
351 | fi |
352 | } | |
353 | ||
873c2aae JRJ |
354 | function list_lttng_with_opts () |
355 | { | |
7d0ad314 | 356 | local opts=$1 |
312dabc3 | 357 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts >$OUTPUT_DEST |
873c2aae JRJ |
358 | ok $? "Lttng-tool list command with option $opts" |
359 | } | |
360 | ||
07b86b52 JD |
361 | function create_lttng_session_no_output () |
362 | { | |
7d0ad314 | 363 | local sess_name=$1 |
07b86b52 | 364 | |
873c2aae | 365 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output >$OUTPUT_DEST |
07b86b52 JD |
366 | ok $? "Create session $sess_name in no-output mode" |
367 | } | |
368 | ||
d3e8f6bb DG |
369 | function create_lttng_session () |
370 | { | |
bf6ae429 JR |
371 | local expected_to_fail=$1 |
372 | local sess_name=$2 | |
373 | local trace_path=$3 | |
d3e8f6bb | 374 | |
873c2aae JRJ |
375 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST |
376 | ret=$? | |
bf6ae429 | 377 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e JRJ |
378 | test "$ret" -ne "0" |
379 | ok $? "Expected fail on session creation $sess_name in $trace_path" | |
873c2aae JRJ |
380 | else |
381 | ok $ret "Create session $sess_name in $trace_path" | |
382 | fi | |
d4018451 DG |
383 | } |
384 | ||
bf6ae429 JR |
385 | function create_lttng_session_ok () |
386 | { | |
387 | create_lttng_session 0 "$@" | |
388 | } | |
389 | ||
390 | function create_lttng_session_fail () | |
391 | { | |
392 | create_lttng_session 1 "$@" | |
393 | } | |
394 | ||
395 | ||
827caf52 | 396 | function enable_ust_lttng_channel () |
d4018451 | 397 | { |
827caf52 JR |
398 | local expect_fail=$1 |
399 | local sess_name=$2 | |
400 | local channel_name=$3 | |
d4018451 | 401 | |
873c2aae | 402 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST |
312dabc3 | 403 | ret=$? |
827caf52 | 404 | if [[ $expect_fail -eq "1" ]]; then |
01513c3e JRJ |
405 | test "$ret" -ne "0" |
406 | ok $? "Expected fail on ust channel creation $channel_name in $sess_name" | |
312dabc3 JRJ |
407 | else |
408 | ok $ret "Enable channel $channel_name for session $sess_name" | |
409 | fi | |
d4018451 DG |
410 | } |
411 | ||
827caf52 JR |
412 | function enable_ust_lttng_channel_ok () |
413 | { | |
414 | enable_ust_lttng_channel 0 "$@" | |
415 | } | |
416 | ||
417 | function enable_ust_lttng_channel_fail () | |
418 | { | |
419 | enable_ust_lttng_channel 1 "$@" | |
420 | } | |
421 | ||
29655db7 | 422 | function disable_ust_lttng_channel() |
d4018451 | 423 | { |
7d0ad314 JRJ |
424 | local sess_name=$1 |
425 | local channel_name=$2 | |
d4018451 | 426 | |
873c2aae | 427 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST |
29655db7 | 428 | ok $? "Disable channel $channel_name for session $sess_name" |
d3e8f6bb DG |
429 | } |
430 | ||
07b86b52 JD |
431 | function enable_lttng_mmap_overwrite_kernel_channel() |
432 | { | |
7d0ad314 JRJ |
433 | local sess_name=$1 |
434 | local channel_name=$2 | |
07b86b52 | 435 | |
873c2aae | 436 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite >$OUTPUT_DEST |
07b86b52 JD |
437 | ok $? "Enable channel $channel_name for session $sess_name" |
438 | } | |
439 | ||
ebaaaf5e JD |
440 | function enable_lttng_mmap_overwrite_ust_channel() |
441 | { | |
7d0ad314 JRJ |
442 | local sess_name=$1 |
443 | local channel_name=$2 | |
ebaaaf5e | 444 | |
873c2aae | 445 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite >$OUTPUT_DEST |
ebaaaf5e JD |
446 | ok $? "Enable channel $channel_name for session $sess_name" |
447 | } | |
448 | ||
d3e8f6bb DG |
449 | function enable_ust_lttng_event () |
450 | { | |
c4926bb5 JR |
451 | local expected_to_fail=$1 |
452 | local sess_name=$2 | |
453 | local event_name="$3" | |
454 | local channel_name=$4 | |
ebaaaf5e JD |
455 | |
456 | if [ -z $channel_name ]; then | |
457 | # default channel if none specified | |
458 | chan="" | |
459 | else | |
460 | chan="-c $channel_name" | |
461 | fi | |
d3e8f6bb | 462 | |
873c2aae | 463 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u >$OUTPUT_DEST |
01513c3e | 464 | ret=$? |
c4926bb5 | 465 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e JRJ |
466 | test $ret -ne "0" |
467 | ok $? "Enable ust event $event_name for session $session_name on channel $channel_name failed as expected" | |
468 | else | |
469 | ok $ret "Enable event $event_name for session $sess_name" | |
470 | fi | |
26b53d3b DG |
471 | } |
472 | ||
c4926bb5 JR |
473 | function enable_ust_lttng_event_ok () |
474 | { | |
475 | enable_ust_lttng_event 0 "$@" | |
476 | } | |
477 | ||
478 | function enable_ust_lttng_event_fail () | |
479 | { | |
480 | enable_ust_lttng_event 1 "$@" | |
481 | } | |
482 | ||
37175ce4 DG |
483 | function enable_jul_lttng_event() |
484 | { | |
485 | sess_name=$1 | |
486 | event_name="$2" | |
487 | channel_name=$3 | |
488 | ||
489 | if [ -z $channel_name ]; then | |
490 | # default channel if none specified | |
491 | chan="" | |
492 | else | |
493 | chan="-c $channel_name" | |
494 | fi | |
495 | ||
873c2aae | 496 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST |
37175ce4 DG |
497 | ok $? "Enable JUL event $event_name for session $sess_name" |
498 | } | |
499 | ||
b2064f54 DG |
500 | function enable_jul_lttng_event_loglevel() |
501 | { | |
7d0ad314 JRJ |
502 | local sess_name=$1 |
503 | local event_name="$2" | |
504 | local loglevel=$3 | |
505 | local channel_name=$4 | |
b2064f54 DG |
506 | |
507 | if [ -z $channel_name ]; then | |
508 | # default channel if none specified | |
509 | chan="" | |
510 | else | |
511 | chan="-c $channel_name" | |
512 | fi | |
513 | ||
873c2aae | 514 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST |
b2064f54 DG |
515 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
516 | } | |
517 | ||
504d4ace DG |
518 | function enable_log4j_lttng_event() |
519 | { | |
520 | sess_name=$1 | |
521 | event_name="$2" | |
522 | channel_name=$3 | |
523 | ||
524 | if [ -z $channel_name ]; then | |
525 | # default channel if none specified | |
526 | chan="" | |
527 | else | |
528 | chan="-c $channel_name" | |
529 | fi | |
530 | ||
531 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST | |
532 | ok $? "Enable LOG4J event $event_name for session $sess_name" | |
533 | } | |
534 | ||
535 | function enable_log4j_lttng_event_loglevel() | |
536 | { | |
537 | local sess_name=$1 | |
538 | local event_name="$2" | |
539 | local loglevel=$3 | |
540 | local channel_name=$4 | |
541 | ||
542 | if [ -z $channel_name ]; then | |
543 | # default channel if none specified | |
544 | chan="" | |
545 | else | |
546 | chan="-c $channel_name" | |
547 | fi | |
548 | ||
549 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l >$OUTPUT_DEST | |
550 | ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel" | |
551 | } | |
552 | ||
0e115563 DG |
553 | function enable_python_lttng_event() |
554 | { | |
555 | sess_name=$1 | |
556 | event_name="$2" | |
557 | channel_name=$3 | |
558 | ||
559 | if [ -z $channel_name ]; then | |
560 | # default channel if none specified | |
561 | chan="" | |
562 | else | |
563 | chan="-c $channel_name" | |
564 | fi | |
565 | ||
566 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST | |
567 | ok $? "Enable Python event $event_name for session $sess_name" | |
568 | } | |
569 | ||
570 | function enable_python_lttng_event_loglevel() | |
571 | { | |
572 | local sess_name=$1 | |
573 | local event_name="$2" | |
574 | local loglevel=$3 | |
575 | local channel_name=$4 | |
576 | ||
577 | if [ -z $channel_name ]; then | |
578 | # default channel if none specified | |
579 | chan="" | |
580 | else | |
581 | chan="-c $channel_name" | |
582 | fi | |
583 | ||
584 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p >$OUTPUT_DEST | |
585 | ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel" | |
586 | } | |
587 | ||
26b53d3b DG |
588 | function enable_ust_lttng_event_filter() |
589 | { | |
7d0ad314 JRJ |
590 | local sess_name="$1" |
591 | local event_name="$2" | |
592 | local filter="$3" | |
26b53d3b | 593 | |
873c2aae | 594 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST |
29655db7 | 595 | ok $? "Enable event $event_name with filtering for session $sess_name" |
26b53d3b DG |
596 | } |
597 | ||
598 | function enable_ust_lttng_event_loglevel() | |
599 | { | |
7d0ad314 JRJ |
600 | local sess_name="$1" |
601 | local event_name="$2" | |
602 | local loglevel="$3" | |
26b53d3b | 603 | |
873c2aae | 604 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST |
29655db7 | 605 | ok $? "Enable event $event_name with loglevel $loglevel" |
26b53d3b DG |
606 | } |
607 | ||
608 | function enable_ust_lttng_event_loglevel_only() | |
609 | { | |
7d0ad314 JRJ |
610 | local sess_name="$1" |
611 | local event_name="$2" | |
612 | local loglevel="$3" | |
26b53d3b | 613 | |
873c2aae | 614 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST |
29655db7 | 615 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
26b53d3b DG |
616 | } |
617 | ||
618 | function disable_ust_lttng_event () | |
619 | { | |
7d0ad314 JRJ |
620 | local sess_name="$1" |
621 | local event_name="$2" | |
01513c3e | 622 | local channel_name="$3" |
26b53d3b | 623 | |
01513c3e JRJ |
624 | if [ -z $channel_name ]; then |
625 | # default channel if none specified | |
626 | chan="" | |
627 | else | |
628 | chan="-c $channel_name" | |
629 | fi | |
630 | ||
631 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u >$OUTPUT_DEST | |
29655db7 | 632 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
633 | } |
634 | ||
1d842d5a DG |
635 | function disable_jul_lttng_event () |
636 | { | |
637 | local sess_name="$1" | |
638 | local event_name="$2" | |
639 | ||
640 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
641 | ok $? "Disable JUL event $event_name for session $sess_name" | |
642 | } | |
643 | ||
504d4ace DG |
644 | function disable_log4j_lttng_event () |
645 | { | |
646 | local sess_name="$1" | |
647 | local event_name="$2" | |
648 | ||
649 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1 | |
650 | ok $? "Disable LOG4J event $event_name for session $sess_name" | |
651 | } | |
652 | ||
0e115563 DG |
653 | function disable_python_lttng_event () |
654 | { | |
655 | local sess_name="$1" | |
656 | local event_name="$2" | |
657 | ||
658 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p >$OUTPUT_DEST | |
659 | ok $? "Disable Python event $event_name for session $sess_name" | |
660 | } | |
661 | ||
fb3268e3 | 662 | function start_lttng_tracing () |
d3e8f6bb | 663 | { |
e563bbdb JR |
664 | local expected_to_fail=$1 |
665 | local sess_name=$2 | |
d3e8f6bb | 666 | |
873c2aae | 667 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >$OUTPUT_DEST |
01513c3e | 668 | ret=$? |
e563bbdb | 669 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e JRJ |
670 | test "$ret" -ne "0" |
671 | ok $? "Expected fail on start tracing for session: $sess_name" | |
672 | else | |
673 | ok $ret "Start tracing for session $sess_name" | |
674 | fi | |
d3e8f6bb DG |
675 | } |
676 | ||
e563bbdb JR |
677 | function start_lttng_tracing_ok () |
678 | { | |
679 | start_lttng_tracing 0 "$@" | |
680 | } | |
681 | ||
682 | function start_lttng_tracing_fail () | |
683 | { | |
684 | start_lttng_tracing 1 "$@" | |
685 | } | |
686 | ||
fb3268e3 | 687 | function stop_lttng_tracing () |
d3e8f6bb | 688 | { |
96340a01 JR |
689 | local expected_to_fail=$1 |
690 | local sess_name=$2 | |
d3e8f6bb | 691 | |
873c2aae | 692 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >$OUTPUT_DEST |
01513c3e | 693 | ret=$? |
96340a01 | 694 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e JRJ |
695 | test "$ret" -ne "0" |
696 | ok $? "Expected fail on stop tracing for session: $sess_name" | |
697 | else | |
698 | ok $ret "Stop lttng tracing for session $sess_name" | |
699 | fi | |
d3e8f6bb DG |
700 | } |
701 | ||
96340a01 JR |
702 | function stop_lttng_tracing_ok () |
703 | { | |
704 | stop_lttng_tracing 0 "$@" | |
705 | } | |
706 | ||
707 | function stop_lttng_tracing_fail () | |
708 | { | |
709 | stop_lttng_tracing 1 "$@" | |
710 | } | |
711 | ||
d3e8f6bb DG |
712 | function destroy_lttng_session () |
713 | { | |
67b4c664 JR |
714 | local expected_to_fail=$1 |
715 | local sess_name=$2 | |
d3e8f6bb | 716 | |
873c2aae | 717 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >$OUTPUT_DEST |
01513c3e | 718 | ret=$? |
96340a01 | 719 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e JRJ |
720 | test "$ret" -ne "0" |
721 | ok $? "Expected fail on session deletion $sess_name" | |
722 | else | |
723 | ok $ret "Destroy session $sess_name" | |
724 | fi | |
d3e8f6bb DG |
725 | } |
726 | ||
67b4c664 JR |
727 | function destroy_lttng_session_ok () |
728 | { | |
729 | destroy_lttng_session 0 "$@" | |
730 | ||
731 | } | |
732 | ||
733 | function destroy_lttng_session_fail () | |
734 | { | |
735 | destroy_lttng_session 1 "$@" | |
736 | } | |
737 | ||
738 | ||
873c2aae JRJ |
739 | function destroy_lttng_sessions () |
740 | { | |
741 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all >$OUTPUT_DEST | |
742 | ok $? "Destroy all lttng sessions" | |
743 | } | |
744 | ||
07b86b52 JD |
745 | function lttng_snapshot_add_output () |
746 | { | |
7d0ad314 JRJ |
747 | local sess_name=$1 |
748 | local trace_path=$2 | |
01513c3e | 749 | local expected_to_fail=$3 |
07b86b52 | 750 | |
873c2aae | 751 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path >$OUTPUT_DEST |
01513c3e JRJ |
752 | ret=$? |
753 | if [[ $expected_to_fail ]]; then | |
754 | test "$ret" -ne "0" | |
755 | ok $? "Failed to add a snapshot output file://$trace_path as expected" | |
756 | else | |
757 | ok $ret "Added snapshot output file://$trace_path" | |
758 | fi | |
07b86b52 JD |
759 | } |
760 | ||
26402e0c DG |
761 | function lttng_snapshot_del_output () |
762 | { | |
763 | local sess_name=$1 | |
764 | local id=$2 | |
01513c3e | 765 | local expected_to_fail=$3 |
26402e0c | 766 | |
873c2aae | 767 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id >$OUTPUT_DEST |
01513c3e JRJ |
768 | ret=$? |
769 | if [[ $expected_to_fail ]]; then | |
770 | test "$ret" -ne "0" | |
771 | ok $? "Expect fail on deletion of snapshot output id $id" | |
772 | else | |
773 | ok $ret "Deleted snapshot output id $id" | |
774 | fi | |
26402e0c DG |
775 | } |
776 | ||
07b86b52 JD |
777 | function lttng_snapshot_record () |
778 | { | |
7d0ad314 JRJ |
779 | local sess_name=$1 |
780 | local trace_path=$2 | |
07b86b52 | 781 | |
873c2aae | 782 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name >$OUTPUT_DEST |
07b86b52 JD |
783 | ok $? "Snapshot recorded" |
784 | } | |
785 | ||
01513c3e JRJ |
786 | function lttng_snapshot_list () |
787 | { | |
788 | local sess_name=$1 | |
789 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name >$OUTPUT_DEST | |
790 | ok $? "Snapshot list" | |
791 | } | |
792 | ||
e02b109b DG |
793 | function lttng_save() |
794 | { | |
795 | local sess_name=$1 | |
796 | local opts=$2 | |
797 | ||
873c2aae | 798 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >$OUTPUT_DEST |
e02b109b DG |
799 | ok $? "Session successfully saved" |
800 | } | |
801 | ||
802 | function lttng_load() | |
803 | { | |
804 | local opts=$1 | |
805 | ||
873c2aae | 806 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts >$OUTPUT_DEST |
e02b109b DG |
807 | ok $? "Load command successful" |
808 | } | |
809 | ||
d3e8f6bb DG |
810 | function trace_matches () |
811 | { | |
7d0ad314 JRJ |
812 | local event_name=$1 |
813 | local nr_iter=$2 | |
814 | local trace_path=$3 | |
d3e8f6bb | 815 | |
317eef93 | 816 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 817 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb | 818 | |
7d0ad314 | 819 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
29655db7 | 820 | |
d3e8f6bb | 821 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 CB |
822 | fail "Trace match" |
823 | diag "$count events found in trace" | |
d3e8f6bb | 824 | else |
29655db7 | 825 | pass "Trace match" |
d3e8f6bb DG |
826 | fi |
827 | } | |
f4e40ab6 | 828 | |
d53addeb DG |
829 | function trace_match_only() |
830 | { | |
831 | local event_name=$1 | |
832 | local nr_iter=$2 | |
833 | local trace_path=$3 | |
834 | ||
835 | which $BABELTRACE_BIN >/dev/null | |
836 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
837 | ||
838 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
839 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
840 | ||
841 | if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then | |
842 | pass "Trace match with $total event $event_name" | |
843 | else | |
844 | fail "Trace match" | |
845 | diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" | |
846 | fi | |
847 | } | |
848 | ||
f4e40ab6 DG |
849 | function validate_trace |
850 | { | |
7d0ad314 JRJ |
851 | local event_name=$1 |
852 | local trace_path=$2 | |
f4e40ab6 DG |
853 | |
854 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
855 | if [ $? -ne 0 ]; then |
856 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
857 | fi |
858 | ||
07b86b52 JD |
859 | OLDIFS=$IFS |
860 | IFS="," | |
861 | for i in $event_name; do | |
862 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
863 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 864 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
865 | else |
866 | fail "Validate trace for event $i" | |
867 | diag "Found $traced occurences of $i" | |
868 | fi | |
869 | done | |
870 | ret=$? | |
871 | IFS=$OLDIFS | |
872 | return $ret | |
f4e40ab6 | 873 | } |
8cfcd41c MD |
874 | |
875 | function validate_trace_exp() | |
876 | { | |
877 | local event_exp=$1 | |
878 | local trace_path=$2 | |
879 | ||
880 | which $BABELTRACE_BIN >/dev/null | |
881 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation" | |
882 | ||
883 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l) | |
884 | if [ "$traced" -ne 0 ]; then | |
885 | pass "Validate trace for expression '${event_exp}', $traced events" | |
886 | else | |
887 | fail "Validate trace for expression '${event_exp}'" | |
888 | diag "Found $traced occurences of '${event_exp}'" | |
889 | fi | |
890 | ret=$? | |
891 | return $ret | |
892 | } | |
893 | ||
894 | function validate_trace_only_exp() | |
895 | { | |
896 | local event_exp=$1 | |
897 | local trace_path=$2 | |
898 | ||
899 | which $BABELTRACE_BIN >/dev/null | |
900 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
901 | ||
902 | local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l) | |
903 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
904 | ||
905 | if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then | |
906 | pass "Trace match with $total for expression '${event_exp}" | |
907 | else | |
908 | fail "Trace match" | |
909 | diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" | |
910 | fi | |
911 | ret=$? | |
912 | return $ret | |
913 | } | |
914 | ||
915 | function validate_trace_empty() | |
916 | { | |
917 | local trace_path=$1 | |
918 | ||
919 | which $BABELTRACE_BIN >/dev/null | |
920 | if [ $? -ne 0 ]; then | |
921 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
922 | fi | |
923 | ||
924 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l) | |
925 | if [ "$traced" -eq 0 ]; then | |
926 | pass "Validate empty trace" | |
927 | else | |
928 | fail "Validate empty trace" | |
929 | diag "Found $traced events in trace" | |
930 | fi | |
931 | ret=$? | |
932 | return $ret | |
933 | } |