Commit | Line | Data |
---|---|---|
9d16b343 | 1 | # Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
d3e8f6bb | 2 | # |
9d16b343 | 3 | # SPDX-License-Identifier: LGPL-2.1-only |
d3e8f6bb | 4 | # |
d3e8f6bb DG |
5 | |
6 | SESSIOND_BIN="lttng-sessiond" | |
725f658e | 7 | SESSIOND_MATCH=".*lttng-sess.*" |
19356f3a | 8 | RUNAS_BIN="lttng-runas" |
725f658e | 9 | RUNAS_MATCH=".*lttng-runas.*" |
f7613992 | 10 | CONSUMERD_BIN="lttng-consumerd" |
725f658e | 11 | CONSUMERD_MATCH=".*lttng-consumerd.*" |
f4e40ab6 | 12 | RELAYD_BIN="lttng-relayd" |
725f658e | 13 | RELAYD_MATCH=".*lttng-relayd.*" |
d3e8f6bb DG |
14 | LTTNG_BIN="lttng" |
15 | BABELTRACE_BIN="babeltrace" | |
2cf48300 JR |
16 | OUTPUT_DEST=/dev/null |
17 | ERROR_OUTPUT_DEST=/dev/null | |
d3e8f6bb | 18 | |
fd4dfcec DG |
19 | # Minimal kernel version supported for session daemon tests |
20 | KERNEL_MAJOR_VERSION=2 | |
21 | KERNEL_MINOR_VERSION=6 | |
22 | KERNEL_PATCHLEVEL_VERSION=27 | |
23 | ||
651b8bb3 JG |
24 | # We set the default UST register timeout and network and app socket timeout to |
25 | # "wait forever", so that basic tests don't have to worry about hitting | |
26 | # timeouts on busy systems. Specialized tests should test those corner-cases. | |
629b9335 | 27 | export LTTNG_UST_REGISTER_TIMEOUT=-1 |
651b8bb3 JG |
28 | export LTTNG_NETWORK_SOCKET_TIMEOUT=-1 |
29 | export LTTNG_APP_SOCKET_TIMEOUT=-1 | |
629b9335 | 30 | |
fd7fe1a8 JR |
31 | # We set the default lttng-sessiond path to /bin/true to prevent the spawning |
32 | # of a daemonized sessiond. This is necessary since 'lttng create' will spawn | |
33 | # its own sessiond if none is running. It also ensures that 'lttng create' | |
34 | # fails when no sessiond is running. | |
35 | export LTTNG_SESSIOND_PATH="/bin/true" | |
36 | ||
29655db7 CB |
37 | source $TESTDIR/utils/tap/tap.sh |
38 | ||
529bb942 MD |
39 | if [ -z $LTTNG_TEST_TEARDOWN_TIMEOUT ]; then |
40 | LTTNG_TEST_TEARDOWN_TIMEOUT=60 | |
41 | fi | |
42 | ||
1c362dc7 JR |
43 | function full_cleanup () |
44 | { | |
529bb942 MD |
45 | # Try to kill daemons gracefully |
46 | stop_lttng_relayd_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT | |
47 | stop_lttng_sessiond_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT | |
48 | ||
49 | # If daemons are still present, forcibly kill them | |
50 | stop_lttng_relayd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
51 | stop_lttng_sessiond_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
52 | stop_lttng_consumerd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
1c362dc7 JR |
53 | |
54 | # Disable trap for SIGTERM since the following kill to the | |
55 | # pidgroup will be SIGTERM. Otherwise it loops. | |
56 | # The '-' before the pid number ($$) indicates 'kill' to signal the | |
57 | # whole process group. | |
58 | trap - SIGTERM && kill -- -$$ | |
4e8ea4fa | 59 | exit 1 |
1c362dc7 JR |
60 | } |
61 | ||
27b667f7 MD |
62 | function null_pipes () |
63 | { | |
64 | exec 0>/dev/null | |
65 | exec 1>/dev/null | |
66 | exec 2>/dev/null | |
67 | } | |
1c362dc7 JR |
68 | |
69 | trap full_cleanup SIGINT SIGTERM | |
70 | ||
27b667f7 MD |
71 | # perl prove closes its child pipes before giving it a chance to run its |
72 | # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught | |
73 | # to allow those trap handlers to proceed. | |
74 | ||
75 | trap null_pipes SIGPIPE | |
76 | ||
fec81a7e CB |
77 | function print_ok () |
78 | { | |
79 | # Check if we are a terminal | |
80 | if [ -t 1 ]; then | |
81 | echo -e "\e[1;32mOK\e[0m" | |
82 | else | |
83 | echo -e "OK" | |
84 | fi | |
85 | } | |
86 | ||
87 | function print_fail () | |
88 | { | |
89 | # Check if we are a terminal | |
90 | if [ -t 1 ]; then | |
91 | echo -e "\e[1;31mFAIL\e[0m" | |
92 | else | |
93 | echo -e "FAIL" | |
94 | fi | |
95 | } | |
96 | ||
97 | function print_test_banner () | |
98 | { | |
7d0ad314 | 99 | local desc="$1" |
29655db7 | 100 | diag "$desc" |
fec81a7e CB |
101 | } |
102 | ||
fd4dfcec DG |
103 | function validate_kernel_version () |
104 | { | |
7d0ad314 | 105 | local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) |
fd4dfcec DG |
106 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then |
107 | return 0 | |
108 | fi | |
109 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
110 | return 0 | |
111 | fi | |
112 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
113 | return 0 | |
114 | fi | |
115 | return 1 | |
116 | } | |
117 | ||
9ac429ef | 118 | # Generate a random string |
f4e40ab6 DG |
119 | # $1 = number of characters; defaults to 16 |
120 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 121 | function randstring() |
f4e40ab6 DG |
122 | { |
123 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
b89c3a68 | 124 | cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null |
f4e40ab6 DG |
125 | echo |
126 | } | |
127 | ||
9e136324 JG |
128 | # Return the number of _configured_ CPUs. |
129 | function conf_proc_count() | |
130 | { | |
131 | getconf _NPROCESSORS_CONF | |
132 | if [ $? -ne 0 ]; then | |
133 | diag "Failed to get the number of configured CPUs" | |
134 | fi | |
135 | echo | |
136 | } | |
137 | ||
9c8a3964 JR |
138 | # Check if base lttng-modules are present. |
139 | # Bail out on failure | |
140 | function validate_lttng_modules_present () | |
141 | { | |
142 | modprobe -n lttng-tracer 2>/dev/null | |
143 | if [ $? -ne 0 ]; then | |
144 | BAIL_OUT "LTTng modules not detected." | |
145 | fi | |
146 | } | |
147 | ||
4a180d9f | 148 | function enable_kernel_lttng_event |
f4e40ab6 | 149 | { |
854382b8 JR |
150 | local withtap="$1" |
151 | local expected_to_fail="$2" | |
152 | local sess_name="$3" | |
153 | local event_name="$4" | |
154 | local channel_name="$5" | |
f4e40ab6 | 155 | |
4a180d9f | 156 | if [ -z "$event_name" ]; then |
f4e40ab6 | 157 | # Enable all event if no event name specified |
29655db7 | 158 | event_name="-a" |
f4e40ab6 DG |
159 | fi |
160 | ||
4a180d9f | 161 | if [ -z "$channel_name" ]; then |
07b86b52 JD |
162 | # default channel if none specified |
163 | chan="" | |
164 | else | |
165 | chan="-c $channel_name" | |
166 | fi | |
167 | ||
2cf48300 | 168 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
4a180d9f MD |
169 | ret=$? |
170 | if [[ $expected_to_fail -eq "1" ]]; then | |
171 | test $ret -ne "0" | |
854382b8 JR |
172 | ret=$? |
173 | if [ $withtap -eq "1" ]; then | |
174 | ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected" | |
175 | fi | |
4a180d9f | 176 | else |
854382b8 JR |
177 | if [ $withtap -eq "1" ]; then |
178 | ok $ret "Enable kernel event $event_name for session $sess_name" | |
179 | fi | |
4a180d9f MD |
180 | fi |
181 | } | |
182 | ||
183 | function enable_kernel_lttng_event_ok () | |
184 | { | |
854382b8 | 185 | enable_kernel_lttng_event 1 0 "$@" |
4a180d9f MD |
186 | } |
187 | ||
188 | function enable_kernel_lttng_event_fail () | |
189 | { | |
854382b8 JR |
190 | enable_kernel_lttng_event 1 1 "$@" |
191 | } | |
192 | ||
193 | function enable_kernel_lttng_event_notap () | |
194 | { | |
195 | enable_kernel_lttng_event 0 0 "$@" | |
4a180d9f MD |
196 | } |
197 | ||
198 | # Old interface | |
199 | function lttng_enable_kernel_event | |
200 | { | |
201 | enable_kernel_lttng_event_ok "$@" | |
f4e40ab6 DG |
202 | } |
203 | ||
8cfcd41c MD |
204 | function lttng_enable_kernel_syscall() |
205 | { | |
206 | local expected_to_fail=$1 | |
207 | local sess_name=$2 | |
208 | local syscall_name=$3 | |
209 | local channel_name=$4 | |
210 | ||
211 | if [ -z $syscall_name ]; then | |
212 | # Enable all event if no syscall name specified | |
213 | syscall_name="-a" | |
214 | fi | |
215 | ||
216 | if [ -z $channel_name ]; then | |
217 | # default channel if none specified | |
218 | chan="" | |
219 | else | |
220 | chan="-c $channel_name" | |
221 | fi | |
222 | ||
2cf48300 | 223 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
8cfcd41c MD |
224 | ret=$? |
225 | if [[ $expected_to_fail -eq "1" ]]; then | |
226 | test $ret -ne "0" | |
227 | ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" | |
228 | else | |
229 | ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
230 | fi | |
231 | } | |
232 | ||
233 | function lttng_enable_kernel_syscall_ok() | |
234 | { | |
421b83dc | 235 | lttng_enable_kernel_syscall 0 "$@" |
8cfcd41c MD |
236 | } |
237 | ||
238 | function lttng_enable_kernel_syscall_fail() | |
239 | { | |
421b83dc | 240 | lttng_enable_kernel_syscall 1 "$@" |
8cfcd41c MD |
241 | } |
242 | ||
243 | function lttng_disable_kernel_syscall() | |
244 | { | |
245 | local expected_to_fail=$1 | |
246 | local sess_name=$2 | |
247 | local syscall_name=$3 | |
248 | local channel_name=$4 | |
249 | ||
250 | if [ -z $syscall_name ]; then | |
251 | # Enable all event if no syscall name specified | |
252 | syscall_name="-a" | |
253 | fi | |
254 | ||
255 | if [ -z $channel_name ]; then | |
256 | # default channel if none specified | |
257 | chan="" | |
258 | else | |
259 | chan="-c $channel_name" | |
260 | fi | |
261 | ||
2cf48300 | 262 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
8cfcd41c MD |
263 | |
264 | ret=$? | |
265 | if [[ $expected_to_fail -eq "1" ]]; then | |
266 | test $ret -ne "0" | |
34ab15c5 | 267 | ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected" |
8cfcd41c MD |
268 | else |
269 | ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
270 | fi | |
271 | } | |
272 | ||
273 | function lttng_disable_kernel_syscall_ok() | |
274 | { | |
421b83dc | 275 | lttng_disable_kernel_syscall 0 "$@" |
8cfcd41c MD |
276 | } |
277 | ||
278 | function lttng_disable_kernel_syscall_fail() | |
279 | { | |
421b83dc | 280 | lttng_disable_kernel_syscall 1 "$@" |
8cfcd41c MD |
281 | } |
282 | ||
a9c2df2b FD |
283 | function lttng_enable_kernel_userspace_probe_event () |
284 | { | |
285 | local expected_to_fail="$1" | |
286 | local sess_name="$2" | |
287 | local target="$3" | |
288 | local event_name="$4" | |
289 | ||
290 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" | |
291 | ret=$? | |
292 | if [[ $expected_to_fail -eq "1" ]]; then | |
293 | test $ret -ne "0" | |
294 | ok $? "Enable kernel userspace probe event for session $sess_name failed as expected" | |
295 | else | |
296 | ok $ret "Enable kernel userspace probe event for session $sess_name" | |
297 | fi | |
298 | } | |
299 | ||
300 | function lttng_enable_kernel_userspace_probe_event_fail () | |
301 | { | |
302 | lttng_enable_kernel_userspace_probe_event 1 "$@" | |
303 | } | |
304 | ||
305 | function lttng_enable_kernel_userspace_probe_event_ok () | |
306 | { | |
307 | lttng_enable_kernel_userspace_probe_event 0 "$@" | |
308 | } | |
309 | ||
310 | function disable_kernel_lttng_userspace_probe_event_ok () | |
311 | { | |
312 | local sess_name="$1" | |
313 | local event_name="$2" | |
314 | ||
315 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" | |
316 | ok $? "Disable kernel event $target for session $sess_name" | |
317 | } | |
d96f6315 MD |
318 | function lttng_enable_kernel_channel() |
319 | { | |
854382b8 JR |
320 | local withtap=$1 |
321 | local expected_to_fail=$2 | |
322 | local sess_name=$3 | |
323 | local channel_name=$4 | |
c28fcefd | 324 | local opts="${@:5}" |
d96f6315 | 325 | |
c28fcefd | 326 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
d96f6315 MD |
327 | ret=$? |
328 | if [[ $expected_to_fail -eq "1" ]]; then | |
329 | test "$ret" -ne "0" | |
854382b8 JR |
330 | ret=$? |
331 | if [ $withtap -eq "1" ]; then | |
332 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" | |
333 | fi | |
d96f6315 | 334 | else |
854382b8 JR |
335 | if [ $withtap -eq "1" ]; then |
336 | ok $ret "Enable channel $channel_name for session $sess_name" | |
337 | fi | |
d96f6315 MD |
338 | fi |
339 | } | |
340 | ||
341 | function lttng_enable_kernel_channel_ok() | |
342 | { | |
854382b8 | 343 | lttng_enable_kernel_channel 1 0 "$@" |
d96f6315 MD |
344 | } |
345 | ||
346 | function lttng_enable_kernel_channel_fail() | |
347 | { | |
854382b8 JR |
348 | lttng_enable_kernel_channel 1 1 "$@" |
349 | } | |
350 | ||
351 | function lttng_enable_kernel_channel_notap() | |
352 | { | |
353 | lttng_enable_kernel_channel 0 0 "$@" | |
354 | } | |
355 | ||
356 | function enable_kernel_lttng_channel_ok() | |
357 | { | |
358 | lttng_enable_kernel_channel 1 0 "$@" | |
d96f6315 MD |
359 | } |
360 | ||
361 | function lttng_disable_kernel_channel() | |
362 | { | |
363 | local expected_to_fail=$1 | |
364 | local sess_name=$2 | |
365 | local channel_name=$3 | |
366 | ||
2cf48300 | 367 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
d96f6315 MD |
368 | ret=$? |
369 | if [[ $expected_to_fail -eq "1" ]]; then | |
370 | test "$ret" -ne "0" | |
34ab15c5 | 371 | ok $? "Disable channel $channel_name for session $sess_name failed as expected" |
d96f6315 | 372 | else |
34ab15c5 | 373 | ok $ret "Disable channel $channel_name for session $sess_name" |
d96f6315 MD |
374 | fi |
375 | } | |
376 | ||
377 | function lttng_disable_kernel_channel_ok() | |
378 | { | |
421b83dc | 379 | lttng_disable_kernel_channel 0 "$@" |
d96f6315 MD |
380 | } |
381 | ||
382 | function lttng_disable_kernel_channel_fail() | |
383 | { | |
421b83dc | 384 | lttng_disable_kernel_channel 1 "$@" |
d96f6315 MD |
385 | } |
386 | ||
05aa48da | 387 | function start_lttng_relayd_opt() |
f4e40ab6 | 388 | { |
05aa48da | 389 | local withtap=$1 |
f3630ec4 JR |
390 | local process_mode=$2 |
391 | local opt=$3 | |
173af62f | 392 | |
529bb942 | 393 | DIR=$(readlink -f "$TESTDIR") |
f4e40ab6 | 394 | |
f3630ec4 | 395 | if [ -z $(pgrep $RELAYD_MATCH) ]; then |
529bb942 | 396 | # shellcheck disable=SC2086 |
f3630ec4 JR |
397 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
398 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & | |
f4e40ab6 | 399 | if [ $? -eq 1 ]; then |
f3630ec4 JR |
400 | if [ $withtap -eq "1" ]; then |
401 | fail "Start lttng-relayd (process mode: $process_mode opt: $opt)" | |
05aa48da | 402 | fi |
f4e40ab6 DG |
403 | return 1 |
404 | else | |
f3630ec4 JR |
405 | if [ $withtap -eq "1" ]; then |
406 | pass "Start lttng-relayd (process mode: $process_mode opt: $opt)" | |
05aa48da | 407 | fi |
f4e40ab6 DG |
408 | fi |
409 | else | |
29655db7 | 410 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
411 | fi |
412 | } | |
413 | ||
05aa48da | 414 | function start_lttng_relayd() |
f4e40ab6 | 415 | { |
f3630ec4 | 416 | start_lttng_relayd_opt 1 "-b" "$@" |
05aa48da MD |
417 | } |
418 | ||
419 | function start_lttng_relayd_notap() | |
420 | { | |
f3630ec4 | 421 | start_lttng_relayd_opt 0 "-b" "$@" |
05aa48da MD |
422 | } |
423 | ||
424 | function stop_lttng_relayd_opt() | |
425 | { | |
426 | local withtap=$1 | |
529bb942 | 427 | local signal=$2 |
05aa48da | 428 | |
529bb942 MD |
429 | if [ -z "$signal" ]; then |
430 | signal="SIGTERM" | |
05aa48da | 431 | fi |
29655db7 | 432 | |
529bb942 MD |
433 | local timeout_s=$3 |
434 | local dtimeleft_s= | |
435 | ||
436 | # Multiply time by 2 to simplify integer arithmetic | |
437 | if [ -n "$timeout_s" ]; then | |
438 | dtimeleft_s=$((timeout_s * 2)) | |
439 | fi | |
440 | ||
441 | local retval=0 | |
442 | local pids= | |
443 | ||
444 | pids=$(pgrep "$RELAYD_MATCH") | |
445 | if [ -z "$pids" ]; then | |
446 | if [ "$withtap" -eq "1" ]; then | |
447 | pass "No relay daemon to kill" | |
448 | fi | |
449 | return 0 | |
450 | fi | |
451 | ||
452 | diag "Killing (signal $signal) lttng-relayd (pid: $pids)" | |
453 | ||
454 | # shellcheck disable=SC2086 | |
455 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
456 | retval=1 | |
457 | if [ "$withtap" -eq "1" ]; then | |
05aa48da MD |
458 | fail "Kill relay daemon" |
459 | fi | |
05aa48da | 460 | else |
f4e40ab6 DG |
461 | out=1 |
462 | while [ -n "$out" ]; do | |
529bb942 MD |
463 | out=$(pgrep "$RELAYD_MATCH") |
464 | if [ -n "$dtimeleft_s" ]; then | |
465 | if [ $dtimeleft_s -lt 0 ]; then | |
466 | out= | |
467 | retval=1 | |
468 | fi | |
469 | dtimeleft_s=$((dtimeleft_s - 1)) | |
470 | fi | |
f4e40ab6 DG |
471 | sleep 0.5 |
472 | done | |
529bb942 MD |
473 | if [ "$withtap" -eq "1" ]; then |
474 | if [ "$retval" -eq "0" ]; then | |
475 | pass "Wait after kill relay daemon" | |
476 | else | |
477 | fail "Wait after kill relay daemon" | |
478 | fi | |
05aa48da | 479 | fi |
1fb23888 MD |
480 | fi |
481 | return $retval | |
482 | } | |
483 | ||
05aa48da | 484 | function stop_lttng_relayd() |
1fb23888 | 485 | { |
05aa48da MD |
486 | stop_lttng_relayd_opt 1 "$@" |
487 | } | |
1fb23888 | 488 | |
05aa48da MD |
489 | function stop_lttng_relayd_notap() |
490 | { | |
491 | stop_lttng_relayd_opt 0 "$@" | |
f4e40ab6 DG |
492 | } |
493 | ||
05aa48da MD |
494 | #First arg: show tap output |
495 | #Second argument: load path for automatic loading | |
496 | function start_lttng_sessiond_opt() | |
355f483d | 497 | { |
05aa48da MD |
498 | local withtap=$1 |
499 | local load_path=$2 | |
8d51ddbc | 500 | |
4b01971f | 501 | local env_vars="" |
b916da6b | 502 | local consumerd="" |
b916da6b | 503 | |
529bb942 MD |
504 | local long_bit_value= |
505 | long_bit_value=$(getconf LONG_BIT) | |
506 | ||
507 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
355f483d DG |
508 | # Env variable requested no session daemon |
509 | return | |
510 | fi | |
511 | ||
529bb942 | 512 | DIR=$(readlink -f "$TESTDIR") |
b916da6b JR |
513 | |
514 | # Get long_bit value for 32/64 consumerd | |
515 | case "$long_bit_value" in | |
516 | 32) | |
517 | consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
518 | ;; | |
519 | 64) | |
520 | consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
521 | ;; | |
522 | *) | |
523 | return | |
524 | ;; | |
525 | esac | |
526 | ||
4b01971f JR |
527 | # Check for env. variable. Allow the use of LD_PRELOAD etc. |
528 | if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then | |
529bb942 | 529 | env_vars="${LTTNG_SESSIOND_ENV_VARS} " |
4b01971f | 530 | fi |
529bb942 | 531 | env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" |
4b01971f | 532 | |
529bb942 | 533 | if ! validate_kernel_version; then |
29655db7 CB |
534 | fail "Start session daemon" |
535 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
536 | fi |
537 | ||
529bb942 | 538 | : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}" |
d3d97763 | 539 | export LTTNG_SESSION_CONFIG_XSD_PATH |
29655db7 | 540 | |
529bb942 | 541 | if [ -z "$(pgrep "${SESSIOND_MATCH}")" ]; then |
8d51ddbc | 542 | # Have a load path ? |
05aa48da | 543 | if [ -n "$load_path" ]; then |
529bb942 MD |
544 | # shellcheck disable=SC2086 |
545 | env $env_vars --load "$load_path" --background "$consumerd" | |
8d51ddbc | 546 | else |
529bb942 MD |
547 | # shellcheck disable=SC2086 |
548 | env $env_vars --background "$consumerd" | |
8d51ddbc | 549 | fi |
0fc2834c | 550 | #$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 | 551 | status=$? |
529bb942 | 552 | if [ "$withtap" -eq "1" ]; then |
05aa48da MD |
553 | ok $status "Start session daemon" |
554 | fi | |
29655db7 | 555 | fi |
355f483d DG |
556 | } |
557 | ||
05aa48da MD |
558 | function start_lttng_sessiond() |
559 | { | |
560 | start_lttng_sessiond_opt 1 "$@" | |
561 | } | |
562 | ||
563 | function start_lttng_sessiond_notap() | |
d3e8f6bb | 564 | { |
05aa48da MD |
565 | start_lttng_sessiond_opt 0 "$@" |
566 | } | |
567 | ||
568 | function stop_lttng_sessiond_opt() | |
569 | { | |
570 | local withtap=$1 | |
4c80129b | 571 | local signal=$2 |
05aa48da | 572 | |
529bb942 MD |
573 | if [ -z "$signal" ]; then |
574 | signal=SIGTERM | |
575 | fi | |
576 | ||
577 | local timeout_s=$3 | |
578 | local dtimeleft_s= | |
579 | ||
580 | # Multiply time by 2 to simplify integer arithmetic | |
581 | if [ -n "$timeout_s" ]; then | |
582 | dtimeleft_s=$((timeout_s * 2)) | |
583 | fi | |
584 | ||
585 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
355f483d | 586 | # Env variable requested no session daemon |
529bb942 | 587 | return 0 |
355f483d DG |
588 | fi |
589 | ||
529bb942 | 590 | local retval=0 |
d3e8f6bb | 591 | |
529bb942 MD |
592 | local runas_pids= |
593 | runas_pids=$(pgrep "$RUNAS_MATCH") | |
594 | ||
595 | local pids= | |
596 | pids=$(pgrep "$SESSIOND_MATCH") | |
597 | ||
598 | if [ -n "$runas_pids" ]; then | |
599 | pids="$pids $runas_pids" | |
4c80129b | 600 | fi |
529bb942 MD |
601 | |
602 | if [ -z "$pids" ]; then | |
603 | if [ "$withtap" -eq "1" ]; then | |
604 | pass "No session daemon to kill" | |
605 | fi | |
606 | return 0 | |
8490897a | 607 | fi |
29655db7 | 608 | |
529bb942 MD |
609 | diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
610 | ||
611 | # shellcheck disable=SC2086 | |
612 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
613 | retval=1 | |
614 | if [ "$withtap" -eq "1" ]; then | |
05aa48da MD |
615 | fail "Kill sessions daemon" |
616 | fi | |
d3e8f6bb | 617 | else |
5fa32580 DG |
618 | out=1 |
619 | while [ -n "$out" ]; do | |
529bb942 MD |
620 | out=$(pgrep "${SESSIOND_MATCH}") |
621 | if [ -n "$dtimeleft_s" ]; then | |
622 | if [ $dtimeleft_s -lt 0 ]; then | |
623 | out= | |
624 | retval=1 | |
625 | fi | |
626 | dtimeleft_s=$((dtimeleft_s - 1)) | |
627 | fi | |
5fa32580 DG |
628 | sleep 0.5 |
629 | done | |
f7613992 MD |
630 | out=1 |
631 | while [ -n "$out" ]; do | |
529bb942 MD |
632 | out=$(pgrep "$CONSUMERD_MATCH") |
633 | if [ -n "$dtimeleft_s" ]; then | |
634 | if [ $dtimeleft_s -lt 0 ]; then | |
635 | out= | |
636 | retval=1 | |
637 | fi | |
638 | dtimeleft_s=$((dtimeleft_s - 1)) | |
639 | fi | |
f7613992 MD |
640 | sleep 0.5 |
641 | done | |
1c362dc7 | 642 | |
529bb942 MD |
643 | if [ "$withtap" -eq "1" ]; then |
644 | if [ "$retval" -eq "0" ]; then | |
645 | pass "Wait after kill session daemon" | |
646 | else | |
647 | fail "Wait after kill session daemon" | |
648 | fi | |
05aa48da | 649 | fi |
d3e8f6bb | 650 | fi |
529bb942 MD |
651 | if [ "$signal" = "SIGKILL" ]; then |
652 | if [ "$(id -u)" -eq "0" ]; then | |
653 | local modules= | |
654 | modules="$(lsmod | grep ^lttng | awk '{print $1}')" | |
655 | ||
656 | if [ -n "$modules" ]; then | |
657 | diag "Unloading all LTTng modules" | |
658 | modprobe -r "$modules" | |
659 | fi | |
660 | fi | |
661 | fi | |
662 | ||
663 | return $retval | |
d3e8f6bb DG |
664 | } |
665 | ||
05aa48da MD |
666 | function stop_lttng_sessiond() |
667 | { | |
668 | stop_lttng_sessiond_opt 1 "$@" | |
669 | } | |
670 | ||
671 | function stop_lttng_sessiond_notap() | |
672 | { | |
673 | stop_lttng_sessiond_opt 0 "$@" | |
674 | } | |
675 | ||
8490897a MD |
676 | function sigstop_lttng_sessiond_opt() |
677 | { | |
678 | local withtap=$1 | |
679 | local signal=SIGSTOP | |
8490897a | 680 | |
529bb942 | 681 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
8490897a MD |
682 | # Env variable requested no session daemon |
683 | return | |
684 | fi | |
685 | ||
529bb942 | 686 | PID_SESSIOND="$(pgrep "${SESSIOND_MATCH}") $(pgrep "$RUNAS_MATCH")" |
8490897a | 687 | |
529bb942 MD |
688 | if [ "$withtap" -eq "1" ]; then |
689 | diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')" | |
8490897a | 690 | fi |
8490897a | 691 | |
529bb942 MD |
692 | # shellcheck disable=SC2086 |
693 | if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
694 | if [ "$withtap" -eq "1" ]; then | |
8490897a MD |
695 | fail "Sending SIGSTOP to session daemon" |
696 | fi | |
697 | else | |
698 | out=1 | |
699 | while [ $out -ne 0 ]; do | |
529bb942 | 700 | pid="$(pgrep "$SESSIOND_MATCH")" |
8490897a MD |
701 | |
702 | # Wait until state becomes stopped for session | |
703 | # daemon(s). | |
704 | out=0 | |
705 | for sessiond_pid in $pid; do | |
529bb942 | 706 | state="$(ps -p "$sessiond_pid" -o state= )" |
8490897a MD |
707 | if [[ -n "$state" && "$state" != "T" ]]; then |
708 | out=1 | |
709 | fi | |
710 | done | |
711 | sleep 0.5 | |
712 | done | |
529bb942 | 713 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
714 | pass "Sending SIGSTOP to session daemon" |
715 | fi | |
716 | fi | |
717 | } | |
718 | ||
719 | function sigstop_lttng_sessiond() | |
720 | { | |
721 | sigstop_lttng_sessiond_opt 1 "$@" | |
722 | } | |
723 | ||
724 | function sigstop_lttng_sessiond_notap() | |
725 | { | |
726 | sigstop_lttng_sessiond_opt 0 "$@" | |
727 | } | |
728 | ||
4c80129b JR |
729 | function stop_lttng_consumerd_opt() |
730 | { | |
731 | local withtap=$1 | |
732 | local signal=$2 | |
4c80129b | 733 | |
529bb942 MD |
734 | if [ -z "$signal" ]; then |
735 | signal=SIGTERM | |
736 | fi | |
737 | ||
738 | local timeout_s=$3 | |
739 | local dtimeleft_s= | |
4c80129b | 740 | |
529bb942 MD |
741 | # Multiply time by 2 to simplify integer arithmetic |
742 | if [ -n "$timeout_s" ]; then | |
743 | dtimeleft_s=$((timeout_s * 2)) | |
4c80129b JR |
744 | fi |
745 | ||
529bb942 MD |
746 | local retval=0 |
747 | ||
748 | PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")" | |
749 | ||
750 | if [ -z "$PID_CONSUMERD" ]; then | |
751 | if [ "$withtap" -eq "1" ]; then | |
752 | pass "No consumer daemon to kill" | |
753 | fi | |
754 | return 0 | |
4c80129b | 755 | fi |
3355fd4d | 756 | |
529bb942 | 757 | diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')" |
4c80129b | 758 | |
529bb942 MD |
759 | # shellcheck disable=SC2086 |
760 | if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
761 | retval=1 | |
762 | if [ "$withtap" -eq "1" ]; then | |
4c80129b JR |
763 | fail "Kill consumer daemon" |
764 | fi | |
4c80129b JR |
765 | else |
766 | out=1 | |
767 | while [ $out -ne 0 ]; do | |
529bb942 | 768 | pid="$(pgrep "$CONSUMERD_MATCH")" |
4c80129b JR |
769 | |
770 | # If consumerds are still present check their status. | |
771 | # A zombie status qualifies the consumerd as *killed* | |
772 | out=0 | |
773 | for consumer_pid in $pid; do | |
529bb942 | 774 | state="$(ps -p "$consumer_pid" -o state= )" |
4c80129b JR |
775 | if [[ -n "$state" && "$state" != "Z" ]]; then |
776 | out=1 | |
777 | fi | |
778 | done | |
529bb942 MD |
779 | if [ -n "$dtimeleft_s" ]; then |
780 | if [ $dtimeleft_s -lt 0 ]; then | |
781 | out=0 | |
782 | retval=1 | |
783 | fi | |
784 | dtimeleft_s=$((dtimeleft_s - 1)) | |
785 | fi | |
4c80129b JR |
786 | sleep 0.5 |
787 | done | |
529bb942 MD |
788 | if [ "$withtap" -eq "1" ]; then |
789 | if [ "$retval" -eq "0" ]; then | |
790 | pass "Wait after kill consumer daemon" | |
791 | else | |
792 | fail "Wait after kill consumer daemon" | |
793 | fi | |
4c80129b JR |
794 | fi |
795 | fi | |
529bb942 | 796 | |
4c80129b JR |
797 | return $retval |
798 | } | |
799 | ||
800 | function stop_lttng_consumerd() | |
801 | { | |
802 | stop_lttng_consumerd_opt 1 "$@" | |
803 | } | |
804 | ||
805 | function stop_lttng_consumerd_notap() | |
806 | { | |
807 | stop_lttng_consumerd_opt 0 "$@" | |
808 | } | |
809 | ||
8490897a MD |
810 | function sigstop_lttng_consumerd_opt() |
811 | { | |
812 | local withtap=$1 | |
813 | local signal=SIGSTOP | |
8490897a | 814 | |
529bb942 | 815 | PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")" |
8490897a | 816 | |
529bb942 | 817 | diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')" |
8490897a | 818 | |
529bb942 MD |
819 | # shellcheck disable=SC2086 |
820 | kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
8490897a | 821 | retval=$? |
8490897a | 822 | |
529bb942 MD |
823 | if [ $retval -eq 1 ]; then |
824 | if [ "$withtap" -eq "1" ]; then | |
8490897a MD |
825 | fail "Sending SIGSTOP to consumer daemon" |
826 | fi | |
827 | return 1 | |
828 | else | |
829 | out=1 | |
830 | while [ $out -ne 0 ]; do | |
529bb942 | 831 | pid="$(pgrep "$CONSUMERD_MATCH")" |
8490897a MD |
832 | |
833 | # Wait until state becomes stopped for all | |
834 | # consumers. | |
835 | out=0 | |
836 | for consumer_pid in $pid; do | |
529bb942 | 837 | state="$(ps -p "$consumer_pid" -o state= )" |
8490897a MD |
838 | if [[ -n "$state" && "$state" != "T" ]]; then |
839 | out=1 | |
840 | fi | |
841 | done | |
842 | sleep 0.5 | |
843 | done | |
529bb942 | 844 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
845 | pass "Sending SIGSTOP to consumer daemon" |
846 | fi | |
847 | fi | |
848 | return $retval | |
849 | } | |
850 | ||
851 | function sigstop_lttng_consumerd() | |
852 | { | |
853 | sigstop_lttng_consumerd_opt 1 "$@" | |
854 | } | |
855 | ||
856 | function sigstop_lttng_consumerd_notap() | |
857 | { | |
858 | sigstop_lttng_consumerd_opt 0 "$@" | |
859 | } | |
860 | ||
873c2aae JRJ |
861 | function list_lttng_with_opts () |
862 | { | |
7d0ad314 | 863 | local opts=$1 |
2cf48300 | 864 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
873c2aae JRJ |
865 | ok $? "Lttng-tool list command with option $opts" |
866 | } | |
867 | ||
07b86b52 JD |
868 | function create_lttng_session_no_output () |
869 | { | |
7d0ad314 | 870 | local sess_name=$1 |
2a166864 | 871 | local opts="${@:2}" |
07b86b52 | 872 | |
2a166864 | 873 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
874 | ok $? "Create session $sess_name in no-output mode" |
875 | } | |
876 | ||
f0d43d3d JR |
877 | function create_lttng_session_uri () { |
878 | local sess_name=$1 | |
879 | local uri=$2 | |
880 | local opts="${@:3}" | |
881 | ||
882 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
883 | ok $? "Create session $sess_name with uri:$uri and opts: $opts" | |
884 | } | |
885 | ||
d3e8f6bb DG |
886 | function create_lttng_session () |
887 | { | |
434f8068 JR |
888 | local withtap=$1 |
889 | local expected_to_fail=$2 | |
890 | local sess_name=$3 | |
891 | local trace_path=$4 | |
892 | local opt=$5 | |
d3e8f6bb | 893 | |
01654d69 JR |
894 | if [ -z "$trace_path" ]; then |
895 | # Use lttng-sessiond default output. | |
896 | trace_path="" | |
897 | else | |
898 | trace_path="-o $trace_path" | |
899 | fi | |
900 | ||
901 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
873c2aae | 902 | ret=$? |
434f8068 | 903 | if [ $expected_to_fail -eq "1" ]; then |
01513c3e | 904 | test "$ret" -ne "0" |
434f8068 JR |
905 | ret=$? |
906 | if [ $withtap -eq "1" ]; then | |
907 | ok $ret "Create session $sess_name in $trace_path failed as expected" | |
908 | fi | |
873c2aae | 909 | else |
434f8068 JR |
910 | if [ $withtap -eq "1" ]; then |
911 | ok $ret "Create session $sess_name in $trace_path" | |
912 | fi | |
873c2aae | 913 | fi |
434f8068 | 914 | return $ret |
d4018451 DG |
915 | } |
916 | ||
bf6ae429 JR |
917 | function create_lttng_session_ok () |
918 | { | |
434f8068 | 919 | create_lttng_session 1 0 "$@" |
bf6ae429 JR |
920 | } |
921 | ||
922 | function create_lttng_session_fail () | |
923 | { | |
434f8068 JR |
924 | create_lttng_session 1 1 "$@" |
925 | } | |
926 | ||
927 | function create_lttng_session_notap () | |
928 | { | |
929 | create_lttng_session 0 0 "$@" | |
bf6ae429 JR |
930 | } |
931 | ||
932 | ||
827caf52 | 933 | function enable_ust_lttng_channel () |
d4018451 | 934 | { |
434f8068 JR |
935 | local withtap=$1 |
936 | local expected_to_fail=$2 | |
937 | local sess_name=$3 | |
938 | local channel_name=$4 | |
c28fcefd | 939 | local opts="${@:5}" |
d4018451 | 940 | |
c28fcefd | 941 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
312dabc3 | 942 | ret=$? |
34ab15c5 | 943 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 944 | test "$ret" -ne "0" |
434f8068 JR |
945 | ret=$? |
946 | if [ $withtap -eq "1" ]; then | |
947 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" | |
948 | fi | |
312dabc3 | 949 | else |
434f8068 JR |
950 | if [ $withtap -eq "1" ]; then |
951 | ok $ret "Enable channel $channel_name for session $sess_name" | |
952 | fi | |
312dabc3 | 953 | fi |
434f8068 | 954 | return $ret |
d4018451 DG |
955 | } |
956 | ||
827caf52 JR |
957 | function enable_ust_lttng_channel_ok () |
958 | { | |
434f8068 | 959 | enable_ust_lttng_channel 1 0 "$@" |
827caf52 JR |
960 | } |
961 | ||
962 | function enable_ust_lttng_channel_fail () | |
963 | { | |
434f8068 JR |
964 | enable_ust_lttng_channel 1 1 "$@" |
965 | } | |
966 | ||
967 | function enable_ust_lttng_channel_notap () | |
968 | { | |
969 | enable_ust_lttng_channel 0 0 "$@" | |
827caf52 JR |
970 | } |
971 | ||
29655db7 | 972 | function disable_ust_lttng_channel() |
d4018451 | 973 | { |
7d0ad314 JRJ |
974 | local sess_name=$1 |
975 | local channel_name=$2 | |
d4018451 | 976 | |
2cf48300 | 977 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 978 | ok $? "Disable channel $channel_name for session $sess_name" |
d3e8f6bb DG |
979 | } |
980 | ||
07b86b52 JD |
981 | function enable_lttng_mmap_overwrite_kernel_channel() |
982 | { | |
7d0ad314 JRJ |
983 | local sess_name=$1 |
984 | local channel_name=$2 | |
07b86b52 | 985 | |
2cf48300 | 986 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
987 | ok $? "Enable channel $channel_name for session $sess_name" |
988 | } | |
989 | ||
086e6add MD |
990 | function enable_lttng_mmap_discard_small_kernel_channel() |
991 | { | |
992 | local sess_name=$1 | |
993 | local channel_name=$2 | |
994 | ||
995 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
996 | ok $? "Enable small discard channel $channel_name for session $sess_name" | |
997 | } | |
998 | ||
999 | function enable_lttng_mmap_overwrite_small_kernel_channel() | |
1000 | { | |
1001 | local sess_name=$1 | |
1002 | local channel_name=$2 | |
1003 | ||
1004 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1005 | ok $? "Enable small discard channel $channel_name for session $sess_name" | |
1006 | } | |
1007 | ||
ebaaaf5e JD |
1008 | function enable_lttng_mmap_overwrite_ust_channel() |
1009 | { | |
7d0ad314 JRJ |
1010 | local sess_name=$1 |
1011 | local channel_name=$2 | |
ebaaaf5e | 1012 | |
2cf48300 | 1013 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
ebaaaf5e JD |
1014 | ok $? "Enable channel $channel_name for session $sess_name" |
1015 | } | |
1016 | ||
d3e8f6bb DG |
1017 | function enable_ust_lttng_event () |
1018 | { | |
434f8068 JR |
1019 | local withtap=$1 |
1020 | local expected_to_fail=$2 | |
1021 | local sess_name=$3 | |
1022 | local event_name="$4" | |
1023 | local channel_name=$5 | |
ebaaaf5e JD |
1024 | |
1025 | if [ -z $channel_name ]; then | |
1026 | # default channel if none specified | |
1027 | chan="" | |
1028 | else | |
1029 | chan="-c $channel_name" | |
1030 | fi | |
d3e8f6bb | 1031 | |
2cf48300 | 1032 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1033 | ret=$? |
c4926bb5 | 1034 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1035 | test $ret -ne "0" |
434f8068 JR |
1036 | ret=$? |
1037 | if [[ $withtap -eq "1" ]]; then | |
1038 | ok $ret "Enable ust event $event_name for session $session_name failed as expected" | |
1039 | fi | |
01513c3e | 1040 | else |
434f8068 JR |
1041 | if [[ $withtap -eq "1" ]]; then |
1042 | ok $ret "Enable ust event $event_name for session $sess_name" | |
1043 | fi | |
01513c3e | 1044 | fi |
434f8068 | 1045 | return $ret |
26b53d3b DG |
1046 | } |
1047 | ||
c4926bb5 JR |
1048 | function enable_ust_lttng_event_ok () |
1049 | { | |
434f8068 | 1050 | enable_ust_lttng_event 1 0 "$@" |
c4926bb5 JR |
1051 | } |
1052 | ||
1053 | function enable_ust_lttng_event_fail () | |
1054 | { | |
434f8068 JR |
1055 | enable_ust_lttng_event 1 1 "$@" |
1056 | } | |
1057 | ||
1058 | function enable_ust_lttng_event_notap () | |
1059 | { | |
1060 | enable_ust_lttng_event 0 0 "$@" | |
c4926bb5 JR |
1061 | } |
1062 | ||
37175ce4 DG |
1063 | function enable_jul_lttng_event() |
1064 | { | |
1065 | sess_name=$1 | |
1066 | event_name="$2" | |
1067 | channel_name=$3 | |
1068 | ||
1069 | if [ -z $channel_name ]; then | |
1070 | # default channel if none specified | |
1071 | chan="" | |
1072 | else | |
1073 | chan="-c $channel_name" | |
1074 | fi | |
1075 | ||
2cf48300 | 1076 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
37175ce4 DG |
1077 | ok $? "Enable JUL event $event_name for session $sess_name" |
1078 | } | |
1079 | ||
b2064f54 DG |
1080 | function enable_jul_lttng_event_loglevel() |
1081 | { | |
7d0ad314 JRJ |
1082 | local sess_name=$1 |
1083 | local event_name="$2" | |
1084 | local loglevel=$3 | |
1085 | local channel_name=$4 | |
b2064f54 DG |
1086 | |
1087 | if [ -z $channel_name ]; then | |
1088 | # default channel if none specified | |
1089 | chan="" | |
1090 | else | |
1091 | chan="-c $channel_name" | |
1092 | fi | |
1093 | ||
2cf48300 | 1094 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
b2064f54 DG |
1095 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
1096 | } | |
1097 | ||
504d4ace DG |
1098 | function enable_log4j_lttng_event() |
1099 | { | |
1100 | sess_name=$1 | |
1101 | event_name="$2" | |
1102 | channel_name=$3 | |
1103 | ||
1104 | if [ -z $channel_name ]; then | |
1105 | # default channel if none specified | |
1106 | chan="" | |
1107 | else | |
1108 | chan="-c $channel_name" | |
1109 | fi | |
1110 | ||
2cf48300 | 1111 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
504d4ace DG |
1112 | ok $? "Enable LOG4J event $event_name for session $sess_name" |
1113 | } | |
1114 | ||
1115 | function enable_log4j_lttng_event_loglevel() | |
1116 | { | |
1117 | local sess_name=$1 | |
1118 | local event_name="$2" | |
1119 | local loglevel=$3 | |
1120 | local channel_name=$4 | |
1121 | ||
1122 | if [ -z $channel_name ]; then | |
1123 | # default channel if none specified | |
1124 | chan="" | |
1125 | else | |
1126 | chan="-c $channel_name" | |
1127 | fi | |
1128 | ||
2cf48300 | 1129 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
504d4ace DG |
1130 | ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel" |
1131 | } | |
1132 | ||
0e115563 DG |
1133 | function enable_python_lttng_event() |
1134 | { | |
1135 | sess_name=$1 | |
1136 | event_name="$2" | |
1137 | channel_name=$3 | |
1138 | ||
1139 | if [ -z $channel_name ]; then | |
1140 | # default channel if none specified | |
1141 | chan="" | |
1142 | else | |
1143 | chan="-c $channel_name" | |
1144 | fi | |
1145 | ||
2cf48300 | 1146 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
1147 | ok $? "Enable Python event $event_name for session $sess_name" |
1148 | } | |
1149 | ||
1150 | function enable_python_lttng_event_loglevel() | |
1151 | { | |
1152 | local sess_name=$1 | |
1153 | local event_name="$2" | |
1154 | local loglevel=$3 | |
1155 | local channel_name=$4 | |
1156 | ||
1157 | if [ -z $channel_name ]; then | |
1158 | # default channel if none specified | |
1159 | chan="" | |
1160 | else | |
1161 | chan="-c $channel_name" | |
1162 | fi | |
1163 | ||
2cf48300 | 1164 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
1165 | ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel" |
1166 | } | |
1167 | ||
26b53d3b DG |
1168 | function enable_ust_lttng_event_filter() |
1169 | { | |
7d0ad314 JRJ |
1170 | local sess_name="$1" |
1171 | local event_name="$2" | |
1172 | local filter="$3" | |
26b53d3b | 1173 | |
2cf48300 | 1174 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1175 | ok $? "Enable event $event_name with filtering for session $sess_name" |
26b53d3b DG |
1176 | } |
1177 | ||
1178 | function enable_ust_lttng_event_loglevel() | |
1179 | { | |
7d0ad314 JRJ |
1180 | local sess_name="$1" |
1181 | local event_name="$2" | |
1182 | local loglevel="$3" | |
26b53d3b | 1183 | |
2cf48300 | 1184 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1185 | ok $? "Enable event $event_name with loglevel $loglevel" |
26b53d3b DG |
1186 | } |
1187 | ||
1188 | function enable_ust_lttng_event_loglevel_only() | |
1189 | { | |
7d0ad314 JRJ |
1190 | local sess_name="$1" |
1191 | local event_name="$2" | |
1192 | local loglevel="$3" | |
26b53d3b | 1193 | |
2cf48300 | 1194 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1195 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
26b53d3b DG |
1196 | } |
1197 | ||
1198 | function disable_ust_lttng_event () | |
1199 | { | |
7d0ad314 JRJ |
1200 | local sess_name="$1" |
1201 | local event_name="$2" | |
01513c3e | 1202 | local channel_name="$3" |
26b53d3b | 1203 | |
01513c3e JRJ |
1204 | if [ -z $channel_name ]; then |
1205 | # default channel if none specified | |
1206 | chan="" | |
1207 | else | |
1208 | chan="-c $channel_name" | |
1209 | fi | |
1210 | ||
2cf48300 | 1211 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1212 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
1213 | } |
1214 | ||
1d842d5a DG |
1215 | function disable_jul_lttng_event () |
1216 | { | |
1217 | local sess_name="$1" | |
1218 | local event_name="$2" | |
1219 | ||
1220 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
1221 | ok $? "Disable JUL event $event_name for session $sess_name" | |
1222 | } | |
1223 | ||
504d4ace DG |
1224 | function disable_log4j_lttng_event () |
1225 | { | |
1226 | local sess_name="$1" | |
1227 | local event_name="$2" | |
1228 | ||
1229 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1 | |
1230 | ok $? "Disable LOG4J event $event_name for session $sess_name" | |
1231 | } | |
1232 | ||
0e115563 DG |
1233 | function disable_python_lttng_event () |
1234 | { | |
1235 | local sess_name="$1" | |
1236 | local event_name="$2" | |
1237 | ||
2cf48300 | 1238 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
1239 | ok $? "Disable Python event $event_name for session $sess_name" |
1240 | } | |
1241 | ||
7fe98a98 | 1242 | function start_lttng_tracing_opt () |
d3e8f6bb | 1243 | { |
7fe98a98 JG |
1244 | local withtap=$1 |
1245 | local expected_to_fail=$2 | |
1246 | local sess_name=$3 | |
d3e8f6bb | 1247 | |
2cf48300 | 1248 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1249 | ret=$? |
e563bbdb | 1250 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1251 | test "$ret" -ne "0" |
7fe98a98 JG |
1252 | ret=$? |
1253 | if [ $withtap -eq "1" ]; then | |
1254 | ok $? "Start tracing for session $sess_name failed as expected" | |
1255 | fi | |
01513c3e | 1256 | else |
7fe98a98 JG |
1257 | if [ $withtap -eq "1" ]; then |
1258 | ok $ret "Start tracing for session $sess_name" | |
1259 | fi | |
01513c3e | 1260 | fi |
d3e8f6bb DG |
1261 | } |
1262 | ||
e563bbdb JR |
1263 | function start_lttng_tracing_ok () |
1264 | { | |
7fe98a98 | 1265 | start_lttng_tracing_opt 1 0 "$@" |
e563bbdb JR |
1266 | } |
1267 | ||
1268 | function start_lttng_tracing_fail () | |
1269 | { | |
7fe98a98 | 1270 | start_lttng_tracing_opt 1 1 "$@" |
e563bbdb JR |
1271 | } |
1272 | ||
7fe98a98 | 1273 | function start_lttng_tracing_notap () |
d3e8f6bb | 1274 | { |
7fe98a98 JG |
1275 | start_lttng_tracing_opt 0 1 "$@" |
1276 | } | |
1277 | ||
1278 | function stop_lttng_tracing_opt () | |
1279 | { | |
1280 | local withtap=$1 | |
1281 | local expected_to_fail=$2 | |
1282 | local sess_name=$3 | |
d3e8f6bb | 1283 | |
2cf48300 | 1284 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1285 | ret=$? |
96340a01 | 1286 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1287 | test "$ret" -ne "0" |
7fe98a98 JG |
1288 | ret=$? |
1289 | if [ $withtap -eq "1" ]; then | |
1290 | ok $? "Stop lttng tracing for session $sess_name failed as expected" | |
1291 | fi | |
01513c3e | 1292 | else |
7fe98a98 JG |
1293 | if [ $withtap -eq "1" ]; then |
1294 | ok $ret "Stop lttng tracing for session $sess_name" | |
1295 | fi | |
01513c3e | 1296 | fi |
d3e8f6bb DG |
1297 | } |
1298 | ||
96340a01 JR |
1299 | function stop_lttng_tracing_ok () |
1300 | { | |
7fe98a98 | 1301 | stop_lttng_tracing_opt 1 0 "$@" |
96340a01 JR |
1302 | } |
1303 | ||
1304 | function stop_lttng_tracing_fail () | |
1305 | { | |
7fe98a98 JG |
1306 | stop_lttng_tracing_opt 1 1 "$@" |
1307 | } | |
1308 | ||
1309 | function stop_lttng_tracing_notap () | |
1310 | { | |
1311 | stop_lttng_tracing_opt 0 0 "$@" | |
96340a01 JR |
1312 | } |
1313 | ||
d3e8f6bb DG |
1314 | function destroy_lttng_session () |
1315 | { | |
854382b8 JR |
1316 | local withtap=$1 |
1317 | local expected_to_fail=$2 | |
1318 | local sess_name=$3 | |
d3e8f6bb | 1319 | |
2cf48300 | 1320 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1321 | ret=$? |
96340a01 | 1322 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1323 | test "$ret" -ne "0" |
854382b8 JR |
1324 | ret=$? |
1325 | if [ $withtap -eq "1" ]; then | |
1326 | ok $ret "Destroy session $sess_name failed as expected" | |
1327 | fi | |
01513c3e | 1328 | else |
854382b8 JR |
1329 | if [ $withtap -eq "1" ]; then |
1330 | ok $ret "Destroy session $sess_name" | |
1331 | fi | |
01513c3e | 1332 | fi |
d3e8f6bb DG |
1333 | } |
1334 | ||
67b4c664 JR |
1335 | function destroy_lttng_session_ok () |
1336 | { | |
854382b8 | 1337 | destroy_lttng_session 1 0 "$@" |
67b4c664 JR |
1338 | |
1339 | } | |
1340 | ||
1341 | function destroy_lttng_session_fail () | |
1342 | { | |
854382b8 | 1343 | destroy_lttng_session 1 1 "$@" |
67b4c664 JR |
1344 | } |
1345 | ||
854382b8 JR |
1346 | function destroy_lttng_session_notap () |
1347 | { | |
1348 | destroy_lttng_session 0 0 "$@" | |
1349 | } | |
67b4c664 | 1350 | |
873c2aae JRJ |
1351 | function destroy_lttng_sessions () |
1352 | { | |
2cf48300 | 1353 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
873c2aae JRJ |
1354 | ok $? "Destroy all lttng sessions" |
1355 | } | |
1356 | ||
07b86b52 JD |
1357 | function lttng_snapshot_add_output () |
1358 | { | |
b5633831 JR |
1359 | local expected_to_fail=$1 |
1360 | local sess_name=$2 | |
1361 | local trace_path=$3 | |
9f0e230a | 1362 | local opts=$4 |
07b86b52 | 1363 | |
9f0e230a | 1364 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1365 | ret=$? |
b5633831 | 1366 | if [[ $expected_to_fail -eq 1 ]]; then |
01513c3e | 1367 | test "$ret" -ne "0" |
9f0e230a | 1368 | ok $? "Added snapshot output $trace_path failed as expected" |
01513c3e | 1369 | else |
9f0e230a | 1370 | ok $ret "Added snapshot output $trace_path" |
01513c3e | 1371 | fi |
07b86b52 JD |
1372 | } |
1373 | ||
b5633831 JR |
1374 | function lttng_snapshot_add_output_ok () |
1375 | { | |
1376 | lttng_snapshot_add_output 0 "$@" | |
1377 | } | |
1378 | ||
1379 | function lttng_snapshot_add_output_fail () | |
1380 | { | |
1381 | lttng_snapshot_add_output 1 "$@" | |
1382 | } | |
1383 | ||
26402e0c DG |
1384 | function lttng_snapshot_del_output () |
1385 | { | |
31580dc7 JR |
1386 | local expected_to_fail=$1 |
1387 | local sess_name=$2 | |
1388 | local id=$3 | |
26402e0c | 1389 | |
2cf48300 | 1390 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1391 | ret=$? |
31580dc7 | 1392 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1393 | test "$ret" -ne "0" |
34ab15c5 | 1394 | ok $? "Deleted snapshot output id $id failed as expected" |
01513c3e JRJ |
1395 | else |
1396 | ok $ret "Deleted snapshot output id $id" | |
1397 | fi | |
26402e0c DG |
1398 | } |
1399 | ||
31580dc7 JR |
1400 | function lttng_snapshot_del_output_ok () |
1401 | { | |
1402 | lttng_snapshot_del_output 0 "$@" | |
1403 | } | |
1404 | ||
1405 | function lttng_snapshot_del_output_fail () | |
1406 | { | |
1407 | lttng_snapshot_del_output 1 "$@" | |
1408 | } | |
1409 | ||
07b86b52 JD |
1410 | function lttng_snapshot_record () |
1411 | { | |
7d0ad314 | 1412 | local sess_name=$1 |
07b86b52 | 1413 | |
2a166864 | 1414 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name $trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
1415 | ok $? "Snapshot recorded" |
1416 | } | |
1417 | ||
01513c3e JRJ |
1418 | function lttng_snapshot_list () |
1419 | { | |
1420 | local sess_name=$1 | |
2cf48300 | 1421 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e JRJ |
1422 | ok $? "Snapshot list" |
1423 | } | |
1424 | ||
e02b109b DG |
1425 | function lttng_save() |
1426 | { | |
1427 | local sess_name=$1 | |
1428 | local opts=$2 | |
1429 | ||
2cf48300 | 1430 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
34ab15c5 | 1431 | ok $? "Session saved" |
e02b109b DG |
1432 | } |
1433 | ||
1434 | function lttng_load() | |
1435 | { | |
192ac418 JR |
1436 | local expected_to_fail=$1 |
1437 | local opts=$2 | |
e02b109b | 1438 | |
2cf48300 | 1439 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
192ac418 JR |
1440 | ret=$? |
1441 | if [[ $expected_to_fail -eq "1" ]]; then | |
1442 | test $ret -ne "0" | |
1443 | ok $? "Load command failed as expected with opts: $opts" | |
1444 | else | |
1445 | ok $ret "Load command with opts: $opts" | |
1446 | fi | |
1447 | } | |
1448 | ||
1449 | function lttng_load_ok() | |
1450 | { | |
1451 | lttng_load 0 "$@" | |
1452 | } | |
1453 | ||
1454 | function lttng_load_fail() | |
1455 | { | |
1456 | lttng_load 1 "$@" | |
e02b109b DG |
1457 | } |
1458 | ||
e83a8bdb JR |
1459 | function lttng_track() |
1460 | { | |
ba5e8d0a | 1461 | local expected_to_fail="$1" |
c47a705b | 1462 | shift 1 |
ba5e8d0a | 1463 | local opts="$@" |
e83a8bdb JR |
1464 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST |
1465 | ret=$? | |
1466 | if [[ $expected_to_fail -eq "1" ]]; then | |
1467 | test $ret -ne "0" | |
1468 | ok $? "Track command failed as expected with opts: $opts" | |
1469 | else | |
34ab15c5 | 1470 | ok $ret "Track command with opts: $opts" |
e83a8bdb JR |
1471 | fi |
1472 | } | |
1473 | ||
1474 | function lttng_track_ok() | |
1475 | { | |
1476 | lttng_track 0 "$@" | |
1477 | } | |
1478 | ||
1479 | function lttng_track_fail() | |
1480 | { | |
1481 | lttng_track 1 "$@" | |
1482 | } | |
1483 | ||
1484 | function lttng_untrack() | |
1485 | { | |
ba5e8d0a | 1486 | local expected_to_fail="$1" |
c47a705b | 1487 | shift 1 |
ba5e8d0a | 1488 | local opts="$@" |
e83a8bdb JR |
1489 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST |
1490 | ret=$? | |
1491 | if [[ $expected_to_fail -eq "1" ]]; then | |
1492 | test $ret -ne "0" | |
1493 | ok $? "Untrack command failed as expected with opts: $opts" | |
1494 | else | |
34ab15c5 | 1495 | ok $ret "Untrack command with opts: $opts" |
e83a8bdb JR |
1496 | fi |
1497 | } | |
1498 | ||
1499 | function lttng_untrack_ok() | |
1500 | { | |
1501 | lttng_untrack 0 "$@" | |
1502 | } | |
1503 | ||
1504 | function lttng_untrack_fail() | |
1505 | { | |
1506 | lttng_untrack 1 "$@" | |
1507 | } | |
1508 | ||
c8e51d15 FD |
1509 | function lttng_track_pid_ok() |
1510 | { | |
1511 | PID=$1 | |
1512 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1513 | ok $? "Lttng track pid on the kernel domain" | |
1514 | } | |
1515 | ||
1516 | function lttng_untrack_kernel_all_ok() | |
1517 | { | |
1518 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1519 | ok $? "Lttng untrack all pid on the kernel domain" | |
1520 | } | |
1521 | ||
ba5e8d0a MD |
1522 | function lttng_track_ust_ok() |
1523 | { | |
1524 | lttng_track_ok -u "$@" | |
1525 | } | |
1526 | ||
1527 | function lttng_track_ust_fail() | |
1528 | { | |
1529 | lttng_track_fail -u "$@" | |
1530 | } | |
1531 | ||
1532 | function lttng_track_kernel_ok() | |
1533 | { | |
1534 | lttng_track_ok -k "$@" | |
1535 | } | |
1536 | ||
1537 | function lttng_track_kernel_fail() | |
1538 | { | |
1539 | lttng_track_fail -k "$@" | |
1540 | } | |
1541 | ||
1542 | function lttng_untrack_ust_ok() | |
1543 | { | |
1544 | lttng_untrack_ok -u "$@" | |
1545 | } | |
1546 | ||
1547 | function lttng_untrack_ust_fail() | |
1548 | { | |
1549 | lttng_untrack_fail -u "$@" | |
1550 | } | |
1551 | ||
1552 | function lttng_untrack_kernel_ok() | |
1553 | { | |
1554 | lttng_untrack_ok -k "$@" | |
1555 | } | |
1556 | ||
1557 | function lttng_untrack_kernel_fail() | |
1558 | { | |
1559 | lttng_untrack_fail -k "$@" | |
1560 | } | |
1561 | ||
59deec0c JR |
1562 | function lttng_add_context_list() |
1563 | { | |
1564 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1565 | ret=$? | |
1566 | ok $ret "Context listing" | |
1567 | } | |
1568 | ||
8dcef147 JR |
1569 | function add_context_lttng() |
1570 | { | |
1571 | local expected_to_fail="$1" | |
1572 | local domain="$2" | |
1573 | local session_name="$3" | |
1574 | local channel_name="$4" | |
1575 | local type="$5" | |
1576 | ||
1577 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1578 | ret=$? | |
1579 | if [[ $expected_to_fail -eq "1" ]]; then | |
1580 | test $ret -ne "0" | |
1581 | ok $? "Add context command failed as expected for type: $type" | |
1582 | else | |
1583 | ok $ret "Add context command for type: $type" | |
1584 | fi | |
1585 | } | |
1586 | ||
1587 | function add_context_ust_ok() | |
1588 | { | |
1589 | add_context_lttng 0 -u "$@" | |
1590 | } | |
1591 | ||
1592 | function add_context_ust_fail() | |
1593 | { | |
1594 | add_context_lttng 1 -u "$@" | |
1595 | } | |
1596 | ||
1597 | function add_context_kernel_ok() | |
1598 | { | |
1599 | add_context_lttng 0 -k "$@" | |
1600 | } | |
1601 | ||
1602 | function add_context_kernel_fail() | |
1603 | { | |
1604 | add_context_lttng 1 -k "$@" | |
1605 | } | |
1606 | ||
c28fcefd JR |
1607 | function validate_directory_empty () |
1608 | { | |
1609 | local trace_path=$1 | |
1610 | ||
1611 | ls -A $local_path > /dev/null 2>&1 | |
1612 | if [ $? -eq 0 ]; then | |
1613 | pass "Directory empty" | |
1614 | else | |
1615 | fail "Directory empty" | |
1616 | fi | |
1617 | } | |
1618 | ||
1619 | function wait_live_trace_ready () | |
1620 | { | |
1621 | local url=$1 | |
1622 | local zero_client_match=0 | |
1623 | ||
1624 | diag "Waiting for live trace at url: $url" | |
1625 | while [ $zero_client_match -eq 0 ]; do | |
1626 | zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l) | |
1627 | sleep 0.5 | |
1628 | done | |
1629 | pass "Waiting for live trace at url: $url" | |
1630 | } | |
1631 | ||
1632 | function wait_live_viewer_connect () | |
1633 | { | |
1634 | local url=$1 | |
1635 | local one_client_match=0 | |
1636 | ||
1637 | diag "Waiting for live viewers on url: $url" | |
1638 | while [ $one_client_match -eq 0 ]; do | |
1639 | one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l) | |
1640 | sleep 0.5 | |
1641 | done | |
1642 | pass "Waiting for live viewers on url: $url" | |
1643 | } | |
1644 | ||
c54b437e FD |
1645 | function validate_metadata_event () |
1646 | { | |
1647 | local event_name=$1 | |
1648 | local nr_event_id=$2 | |
1649 | local trace_path=$3 | |
1650 | ||
1651 | local metadata_file=$(find $trace_path | grep metadata) | |
1652 | local metadata_path=$(dirname $metadata_file) | |
1653 | ||
1654 | which $BABELTRACE_BIN >/dev/null | |
1655 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1656 | ||
1657 | local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l) | |
1658 | ||
1659 | if [ "$count" -ne "$nr_event_id" ]; then | |
1660 | fail "Metadata match with the metadata of $count event(s) named $event_name" | |
1661 | diag "$count matching event id found in metadata" | |
1662 | else | |
1663 | pass "Metadata match with the metadata of $count event(s) named $event_name" | |
1664 | fi | |
1665 | ||
1666 | } | |
1667 | ||
d3e8f6bb DG |
1668 | function trace_matches () |
1669 | { | |
7d0ad314 JRJ |
1670 | local event_name=$1 |
1671 | local nr_iter=$2 | |
1672 | local trace_path=$3 | |
d3e8f6bb | 1673 | |
317eef93 | 1674 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 1675 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb | 1676 | |
7d0ad314 | 1677 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
29655db7 | 1678 | |
d3e8f6bb | 1679 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 | 1680 | fail "Trace match" |
af91abc9 | 1681 | diag "$count matching events found in trace" |
d3e8f6bb | 1682 | else |
29655db7 | 1683 | pass "Trace match" |
d3e8f6bb DG |
1684 | fi |
1685 | } | |
f4e40ab6 | 1686 | |
d53addeb DG |
1687 | function trace_match_only() |
1688 | { | |
1689 | local event_name=$1 | |
1690 | local nr_iter=$2 | |
1691 | local trace_path=$3 | |
1692 | ||
1693 | which $BABELTRACE_BIN >/dev/null | |
1694 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1695 | ||
1696 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
1697 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
1698 | ||
08f96a38 JG |
1699 | if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then |
1700 | pass "Trace match with $total event $event_name" | |
1701 | else | |
1702 | fail "Trace match" | |
1703 | diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" | |
1704 | fi | |
d53addeb DG |
1705 | } |
1706 | ||
f4e40ab6 DG |
1707 | function validate_trace |
1708 | { | |
7d0ad314 JRJ |
1709 | local event_name=$1 |
1710 | local trace_path=$2 | |
f4e40ab6 DG |
1711 | |
1712 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
1713 | if [ $? -ne 0 ]; then |
1714 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
1715 | fi |
1716 | ||
07b86b52 JD |
1717 | OLDIFS=$IFS |
1718 | IFS="," | |
1719 | for i in $event_name; do | |
1720 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1721 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 1722 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
1723 | else |
1724 | fail "Validate trace for event $i" | |
1725 | diag "Found $traced occurences of $i" | |
1726 | fi | |
1727 | done | |
1728 | ret=$? | |
1729 | IFS=$OLDIFS | |
1730 | return $ret | |
f4e40ab6 | 1731 | } |
8cfcd41c | 1732 | |
54cd6107 JD |
1733 | function validate_trace_count |
1734 | { | |
1735 | local event_name=$1 | |
1736 | local trace_path=$2 | |
1737 | local expected_count=$3 | |
1738 | ||
1739 | which $BABELTRACE_BIN >/dev/null | |
1740 | if [ $? -ne 0 ]; then | |
1741 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1742 | fi | |
1743 | ||
1744 | cnt=0 | |
1745 | OLDIFS=$IFS | |
1746 | IFS="," | |
1747 | for i in $event_name; do | |
1748 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1749 | if [ "$traced" -ne 0 ]; then | |
1750 | pass "Validate trace for event $i, $traced events" | |
1751 | else | |
1752 | fail "Validate trace for event $i" | |
1753 | diag "Found $traced occurences of $i" | |
1754 | fi | |
1755 | cnt=$(($cnt + $traced)) | |
1756 | done | |
1757 | IFS=$OLDIFS | |
1758 | test $cnt -eq $expected_count | |
1759 | ok $? "Read a total of $cnt events, expected $expected_count" | |
1760 | } | |
1761 | ||
c28fcefd JR |
1762 | function validate_trace_count_range_incl_min_excl_max |
1763 | { | |
1764 | local event_name=$1 | |
1765 | local trace_path=$2 | |
1766 | local expected_min=$3 | |
1767 | local expected_max=$4 | |
1768 | ||
1769 | which $BABELTRACE_BIN >/dev/null | |
1770 | if [ $? -ne 0 ]; then | |
1771 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1772 | fi | |
1773 | ||
1774 | cnt=0 | |
1775 | OLDIFS=$IFS | |
1776 | IFS="," | |
1777 | for i in $event_name; do | |
1778 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1779 | if [ "$traced" -ge $expected_min ]; then | |
1780 | pass "Validate trace for event $i, $traced events" | |
1781 | else | |
1782 | fail "Validate trace for event $i" | |
1783 | diag "Found $traced occurences of $i" | |
1784 | fi | |
1785 | cnt=$(($cnt + $traced)) | |
1786 | done | |
1787 | IFS=$OLDIFS | |
1788 | test $cnt -lt $expected_max | |
1789 | ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max[" | |
1790 | } | |
1791 | ||
086e6add MD |
1792 | function trace_first_line |
1793 | { | |
1794 | local trace_path=$1 | |
1795 | ||
1796 | which $BABELTRACE_BIN >/dev/null | |
1797 | if [ $? -ne 0 ]; then | |
1798 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1799 | fi | |
1800 | ||
1801 | $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1 | |
1802 | } | |
1803 | ||
8cfcd41c MD |
1804 | function validate_trace_exp() |
1805 | { | |
1806 | local event_exp=$1 | |
1807 | local trace_path=$2 | |
1808 | ||
1809 | which $BABELTRACE_BIN >/dev/null | |
1810 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation" | |
1811 | ||
49538c32 | 1812 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l) |
8cfcd41c MD |
1813 | if [ "$traced" -ne 0 ]; then |
1814 | pass "Validate trace for expression '${event_exp}', $traced events" | |
1815 | else | |
1816 | fail "Validate trace for expression '${event_exp}'" | |
1817 | diag "Found $traced occurences of '${event_exp}'" | |
1818 | fi | |
1819 | ret=$? | |
1820 | return $ret | |
1821 | } | |
1822 | ||
1823 | function validate_trace_only_exp() | |
1824 | { | |
1825 | local event_exp=$1 | |
1826 | local trace_path=$2 | |
1827 | ||
1828 | which $BABELTRACE_BIN >/dev/null | |
1829 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1830 | ||
49538c32 | 1831 | local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l) |
8cfcd41c MD |
1832 | local total=$($BABELTRACE_BIN $trace_path | wc -l) |
1833 | ||
1834 | if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then | |
ab95d85d | 1835 | pass "Trace match with $total for expression '${event_exp}'" |
8cfcd41c MD |
1836 | else |
1837 | fail "Trace match" | |
1838 | diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" | |
1839 | fi | |
1840 | ret=$? | |
1841 | return $ret | |
1842 | } | |
1843 | ||
1844 | function validate_trace_empty() | |
1845 | { | |
1846 | local trace_path=$1 | |
1847 | ||
1848 | which $BABELTRACE_BIN >/dev/null | |
1849 | if [ $? -ne 0 ]; then | |
1850 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1851 | fi | |
1852 | ||
2462eee7 JD |
1853 | events=$($BABELTRACE_BIN $trace_path 2>/dev/null) |
1854 | ret=$? | |
1855 | if [ $ret -ne 0 ]; then | |
1856 | fail "Failed to parse trace" | |
1857 | return $ret | |
1858 | fi | |
1859 | ||
1860 | traced=$(echo -n "$events" | wc -l) | |
8cfcd41c MD |
1861 | if [ "$traced" -eq 0 ]; then |
1862 | pass "Validate empty trace" | |
1863 | else | |
1864 | fail "Validate empty trace" | |
1865 | diag "Found $traced events in trace" | |
1866 | fi | |
1867 | ret=$? | |
1868 | return $ret | |
1869 | } | |
801236b0 | 1870 | |
ba5e8d0a MD |
1871 | function validate_folder_is_empty() |
1872 | { | |
1873 | local folder=$1 | |
1874 | ||
1875 | test -z "$(ls -A "$folder")" | |
1876 | ok $? "Folder ${folder} is empty" | |
1877 | } | |
1878 | ||
1879 | function validate_trace_session_ust_empty() | |
1880 | { | |
1881 | validate_folder_is_empty "$1"/ust | |
1882 | } | |
1883 | ||
1884 | function validate_trace_session_kernel_empty() | |
1885 | { | |
1886 | validate_trace_empty "$1"/kernel | |
1887 | } | |
1888 | ||
eded6438 | 1889 | function regenerate_metadata () |
801236b0 JD |
1890 | { |
1891 | local expected_to_fail=$1 | |
1892 | local sess_name=$2 | |
1893 | ||
eded6438 | 1894 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
801236b0 JD |
1895 | ret=$? |
1896 | if [[ $expected_to_fail -eq "1" ]]; then | |
1897 | test "$ret" -ne "0" | |
eded6438 | 1898 | ok $? "Expected fail on regenerate metadata $sess_name" |
801236b0 JD |
1899 | else |
1900 | ok $ret "Metadata regenerate $sess_name" | |
1901 | fi | |
1902 | } | |
1903 | ||
eded6438 | 1904 | function regenerate_metadata_ok () |
801236b0 | 1905 | { |
eded6438 | 1906 | regenerate_metadata 0 "$@" |
801236b0 JD |
1907 | } |
1908 | ||
eded6438 | 1909 | function regenerate_metadata_fail () |
801236b0 | 1910 | { |
eded6438 | 1911 | regenerate_metadata 1 "$@" |
801236b0 | 1912 | } |
512eb148 | 1913 | |
54cd6107 JD |
1914 | function regenerate_statedump () |
1915 | { | |
1916 | local expected_to_fail=$1 | |
1917 | local sess_name=$2 | |
1918 | ||
1919 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1920 | ret=$? | |
1921 | if [[ $expected_to_fail -eq "1" ]]; then | |
1922 | test "$ret" -ne "0" | |
1923 | ok $? "Expected fail on regenerate statedump $sess_name" | |
1924 | else | |
5ebb1a9f | 1925 | ok $ret "Statedump regenerate $sess_name" |
54cd6107 JD |
1926 | fi |
1927 | } | |
1928 | ||
1929 | function regenerate_statedump_ok () | |
1930 | { | |
1931 | regenerate_statedump 0 "$@" | |
1932 | } | |
1933 | ||
1934 | function regenerate_statedump_fail () | |
1935 | { | |
1936 | regenerate_statedump 1 "$@" | |
1937 | } | |
1938 | ||
e7716c6a JD |
1939 | function rotate_session () |
1940 | { | |
1941 | local expected_to_fail=$1 | |
1942 | local sess_name=$2 | |
1943 | ||
1944 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1945 | ret=$? | |
1946 | if [[ $expected_to_fail -eq "1" ]]; then | |
1947 | test "$ret" -ne "0" | |
1948 | ok $? "Expected fail on rotate session $sess_name" | |
1949 | else | |
1950 | ok $ret "Rotate session $sess_name" | |
1951 | fi | |
1952 | } | |
1953 | ||
1954 | function rotate_session_ok () | |
1955 | { | |
1956 | rotate_session 0 "$@" | |
1957 | } | |
1958 | ||
1959 | function rotate_session_fail () | |
1960 | { | |
1961 | rotate_session 1 "$@" | |
1962 | } | |
1963 | ||
512eb148 JD |
1964 | function destructive_tests_enabled () |
1965 | { | |
1966 | if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then | |
1967 | return 0 | |
1968 | else | |
1969 | return 1 | |
1970 | fi | |
1971 | } | |
e7716c6a JD |
1972 | |
1973 | function lttng_enable_rotation_timer () | |
1974 | { | |
1975 | local expected_to_fail=$1 | |
1976 | local sess_name=$2 | |
1977 | local period=$3 | |
1978 | ||
1979 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1980 | ret=$? | |
1981 | if [[ $expected_to_fail -eq "1" ]]; then | |
1982 | test "$ret" -ne "0" | |
9498e289 | 1983 | ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name" |
e7716c6a | 1984 | else |
795f9063 | 1985 | ok $ret "Set periodic rotation ($period) of session $sess_name" |
e7716c6a JD |
1986 | fi |
1987 | } | |
1988 | ||
1989 | function lttng_enable_rotation_timer_ok () | |
1990 | { | |
1991 | lttng_enable_rotation_timer 0 $@ | |
1992 | } | |
1993 | ||
1994 | function lttng_enable_rotation_timer_fail () | |
1995 | { | |
1996 | lttng_enable_rotation_timer 1 $@ | |
1997 | } | |
1998 | ||
1999 | function lttng_enable_rotation_size () | |
2000 | { | |
2001 | local expected_to_fail=$1 | |
2002 | local sess_name=$2 | |
2003 | local size=$3 | |
2004 | ||
2005 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
2006 | ret=$? | |
2007 | if [[ $expected_to_fail -eq "1" ]]; then | |
2008 | test "$ret" -ne "0" | |
2009 | ok $? "Expected fail on rotate session $sess_name" | |
2010 | else | |
2011 | ok $ret "Rotate session $sess_name" | |
2012 | fi | |
2013 | } | |
2014 | ||
2015 | function lttng_enable_rotation_size_ok () | |
2016 | { | |
2017 | lttng_enable_rotation_size 0 $@ | |
2018 | } | |
2019 | ||
2020 | function lttng_enable_rotation_size_fail () | |
2021 | { | |
2022 | lttng_enable_rotation_size 1 $@ | |
2023 | } | |
c28fcefd JR |
2024 | |
2025 | function lttng_clear_session () | |
2026 | { | |
2027 | local expected_to_fail=$1 | |
2028 | local sess_name=$2 | |
2029 | ||
2030 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
2031 | ret=$? | |
2032 | if [[ $expected_to_fail -eq "1" ]]; then | |
2033 | test "$ret" -ne "0" | |
2034 | ok $? "Expected fail on clear session $sess_name" | |
2035 | else | |
2036 | ok $ret "Clear session $sess_name" | |
2037 | fi | |
2038 | } | |
2039 | ||
2040 | function lttng_clear_session_ok () | |
2041 | { | |
2042 | lttng_clear_session 0 $@ | |
2043 | } | |
2044 | ||
2045 | function lttng_clear_session_fail () | |
2046 | { | |
2047 | lttng_clear_session 1 $@ | |
2048 | } | |
5ee26199 JR |
2049 | |
2050 | function lttng_clear_all () | |
2051 | { | |
2052 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
2053 | ok $? "Clear all lttng sessions" | |
2054 | } |