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