| 1 | # Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 2 | # |
| 3 | # SPDX-License-Identifier: LGPL-2.1-only |
| 4 | # |
| 5 | |
| 6 | SESSIOND_BIN="lttng-sessiond" |
| 7 | SESSIOND_MATCH=".*lttng-sess.*" |
| 8 | RUNAS_BIN="lttng-runas" |
| 9 | RUNAS_MATCH=".*lttng-runas.*" |
| 10 | CONSUMERD_BIN="lttng-consumerd" |
| 11 | CONSUMERD_MATCH=".*lttng-consumerd.*" |
| 12 | RELAYD_BIN="lttng-relayd" |
| 13 | RELAYD_MATCH=".*lttng-relayd.*" |
| 14 | LTTNG_BIN="lttng" |
| 15 | BABELTRACE_BIN="babeltrace" |
| 16 | OUTPUT_DEST=/dev/null |
| 17 | ERROR_OUTPUT_DEST=/dev/null |
| 18 | MI_XSD_PATH=$TESTDIR/../src/common/mi-lttng-4.0.xsd |
| 19 | XML_PRETTY_BIN="$TESTDIR/utils/xml-utils/pretty_xml" |
| 20 | XML_VALIDATE_BIN="$TESTDIR/utils/xml-utils/validate_xml" |
| 21 | |
| 22 | # To match 20201127-175802 |
| 23 | date_time_pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]" |
| 24 | # The size of a long on this system |
| 25 | system_long_bit_size=$(getconf LONG_BIT) |
| 26 | |
| 27 | # Minimal kernel version supported for session daemon tests |
| 28 | KERNEL_MAJOR_VERSION=2 |
| 29 | KERNEL_MINOR_VERSION=6 |
| 30 | KERNEL_PATCHLEVEL_VERSION=27 |
| 31 | |
| 32 | # We set the default UST register timeout and network and app socket timeout to |
| 33 | # "wait forever", so that basic tests don't have to worry about hitting |
| 34 | # timeouts on busy systems. Specialized tests should test those corner-cases. |
| 35 | export LTTNG_UST_REGISTER_TIMEOUT=-1 |
| 36 | export LTTNG_NETWORK_SOCKET_TIMEOUT=-1 |
| 37 | export LTTNG_APP_SOCKET_TIMEOUT=-1 |
| 38 | |
| 39 | # We set the default lttng-sessiond path to /bin/true to prevent the spawning |
| 40 | # of a daemonized sessiond. This is necessary since 'lttng create' will spawn |
| 41 | # its own sessiond if none is running. It also ensures that 'lttng create' |
| 42 | # fails when no sessiond is running. |
| 43 | export LTTNG_SESSIOND_PATH="/bin/true" |
| 44 | |
| 45 | source $TESTDIR/utils/tap/tap.sh |
| 46 | |
| 47 | if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then |
| 48 | LTTNG_TEST_TEARDOWN_TIMEOUT=60 |
| 49 | fi |
| 50 | |
| 51 | # Enable job monitor mode. |
| 52 | # Here we are mostly interested in the following from the monitor mode: |
| 53 | # All processes run in a separate process group. |
| 54 | # This allows us to ensure that all subprocesses from all background tasks are |
| 55 | # cleaned up correctly using signal to process group id. |
| 56 | set -m |
| 57 | |
| 58 | kill_background_jobs () |
| 59 | { |
| 60 | local pids |
| 61 | pids=$(jobs -p) |
| 62 | |
| 63 | if [ -z "$pids" ]; then |
| 64 | # Empty |
| 65 | return 0 |
| 66 | fi |
| 67 | |
| 68 | while read -r pid; |
| 69 | do |
| 70 | # Use negative number to send the signal to the process group. |
| 71 | # This ensure that any subprocesses receive the signal. |
| 72 | # /dev/null is used since there is an acceptable race between |
| 73 | # the moments the pids are listed and the moment we send a |
| 74 | # signal. |
| 75 | kill -SIGTERM -- "-$pid" 2>/dev/null |
| 76 | done <<< "$pids" |
| 77 | } |
| 78 | |
| 79 | function cleanup () |
| 80 | { |
| 81 | # Try to kill daemons gracefully |
| 82 | stop_lttng_relayd_cleanup SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT |
| 83 | stop_lttng_sessiond_cleanup SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT |
| 84 | |
| 85 | # If daemons are still present, forcibly kill them |
| 86 | stop_lttng_relayd_cleanup SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT |
| 87 | stop_lttng_sessiond_cleanup SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT |
| 88 | stop_lttng_consumerd_cleanup SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT |
| 89 | |
| 90 | kill_background_jobs |
| 91 | } |
| 92 | |
| 93 | function full_cleanup () |
| 94 | { |
| 95 | cleanup |
| 96 | exit 1 |
| 97 | } |
| 98 | |
| 99 | function LTTNG_BAIL_OUT () |
| 100 | { |
| 101 | cleanup |
| 102 | BAIL_OUT "$@" |
| 103 | } |
| 104 | |
| 105 | function null_pipes () |
| 106 | { |
| 107 | exec 0>/dev/null |
| 108 | exec 1>/dev/null |
| 109 | exec 2>/dev/null |
| 110 | } |
| 111 | |
| 112 | trap full_cleanup SIGINT SIGTERM |
| 113 | |
| 114 | # perl prove closes its child pipes before giving it a chance to run its |
| 115 | # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught |
| 116 | # to allow those trap handlers to proceed. |
| 117 | |
| 118 | trap null_pipes SIGPIPE |
| 119 | |
| 120 | # Check pgrep from env, default to pgrep if none |
| 121 | if [ -z "$PGREP" ]; then |
| 122 | PGREP=pgrep |
| 123 | fi |
| 124 | |
| 125 | # Due to the renaming of threads we need to use the full command (pgrep -f) to |
| 126 | # identify the pids for multiple lttng related processes. The problem with "pgrep |
| 127 | # -f" is that it ends up also looking at the arguments. We use a two stage |
| 128 | # lookup. The first one is using "pgrep -f" yielding potential candidate. |
| 129 | # The second on perform grep on the basename of the first field of the |
| 130 | # /proc/pid/cmdline of the previously identified pids. The first field |
| 131 | # correspond to the actual command. |
| 132 | function lttng_pgrep () |
| 133 | { |
| 134 | local pattern=$1 |
| 135 | local possible_pids |
| 136 | local full_command_no_argument |
| 137 | local command_basename |
| 138 | |
| 139 | possible_pids=$($PGREP -f "$pattern") |
| 140 | if [ -z "$possible_pids" ]; then |
| 141 | return 0 |
| 142 | fi |
| 143 | |
| 144 | while IFS= read -r pid ; do |
| 145 | # /proc/pid/cmdline is null separated. |
| 146 | if full_command_no_argument=$(cut -d '' -f 1 2>/dev/null < /proc/"$pid"/cmdline); then |
| 147 | command_basename=$(basename "$full_command_no_argument") |
| 148 | if grep -q "$pattern" <<< "$command_basename"; then |
| 149 | echo "$pid" |
| 150 | fi |
| 151 | fi |
| 152 | done <<< "$possible_pids" |
| 153 | return 0 |
| 154 | } |
| 155 | |
| 156 | function print_ok () |
| 157 | { |
| 158 | # Check if we are a terminal |
| 159 | if [ -t 1 ]; then |
| 160 | echo -e "\e[1;32mOK\e[0m" |
| 161 | else |
| 162 | echo -e "OK" |
| 163 | fi |
| 164 | } |
| 165 | |
| 166 | function print_fail () |
| 167 | { |
| 168 | # Check if we are a terminal |
| 169 | if [ -t 1 ]; then |
| 170 | echo -e "\e[1;31mFAIL\e[0m" |
| 171 | else |
| 172 | echo -e "FAIL" |
| 173 | fi |
| 174 | } |
| 175 | |
| 176 | function print_test_banner () |
| 177 | { |
| 178 | local desc="$1" |
| 179 | diag "$desc" |
| 180 | } |
| 181 | |
| 182 | function validate_kernel_version () |
| 183 | { |
| 184 | local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) |
| 185 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then |
| 186 | return 0 |
| 187 | fi |
| 188 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then |
| 189 | return 0 |
| 190 | fi |
| 191 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then |
| 192 | return 0 |
| 193 | fi |
| 194 | return 1 |
| 195 | } |
| 196 | |
| 197 | # Generate a random string |
| 198 | # $1 = number of characters; defaults to 16 |
| 199 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes |
| 200 | function randstring() |
| 201 | { |
| 202 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" |
| 203 | cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null |
| 204 | echo |
| 205 | } |
| 206 | |
| 207 | # Return the number of _configured_ CPUs. |
| 208 | function conf_proc_count() |
| 209 | { |
| 210 | getconf _NPROCESSORS_CONF |
| 211 | if [ $? -ne 0 ]; then |
| 212 | diag "Failed to get the number of configured CPUs" |
| 213 | fi |
| 214 | echo |
| 215 | } |
| 216 | |
| 217 | # Check if base lttng-modules are present. |
| 218 | # Bail out on failure |
| 219 | function validate_lttng_modules_present () |
| 220 | { |
| 221 | # Check for loadable modules. |
| 222 | modprobe -n lttng-tracer 2>/dev/null |
| 223 | if [ $? -eq 0 ]; then |
| 224 | return 0 |
| 225 | fi |
| 226 | |
| 227 | # Check for builtin modules. |
| 228 | ls /proc/lttng > /dev/null 2>&1 |
| 229 | if [ $? -eq 0 ]; then |
| 230 | return 0 |
| 231 | fi |
| 232 | |
| 233 | LTTNG_BAIL_OUT "LTTng modules not detected." |
| 234 | } |
| 235 | |
| 236 | function enable_kernel_lttng_event |
| 237 | { |
| 238 | local withtap="$1" |
| 239 | local expected_to_fail="$2" |
| 240 | local sess_name="$3" |
| 241 | local event_name="$4" |
| 242 | local channel_name="$5" |
| 243 | |
| 244 | if [ -z "$event_name" ]; then |
| 245 | # Enable all event if no event name specified |
| 246 | event_name="-a" |
| 247 | fi |
| 248 | |
| 249 | if [ -z "$channel_name" ]; then |
| 250 | # default channel if none specified |
| 251 | chan="" |
| 252 | else |
| 253 | chan="-c $channel_name" |
| 254 | fi |
| 255 | |
| 256 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 257 | ret=$? |
| 258 | if [[ $expected_to_fail -eq "1" ]]; then |
| 259 | test $ret -ne "0" |
| 260 | ret=$? |
| 261 | if [ $withtap -eq "1" ]; then |
| 262 | ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected" |
| 263 | fi |
| 264 | else |
| 265 | if [ $withtap -eq "1" ]; then |
| 266 | ok $ret "Enable kernel event $event_name for session $sess_name" |
| 267 | fi |
| 268 | fi |
| 269 | } |
| 270 | |
| 271 | function enable_kernel_lttng_event_ok () |
| 272 | { |
| 273 | enable_kernel_lttng_event 1 0 "$@" |
| 274 | } |
| 275 | |
| 276 | function enable_kernel_lttng_event_fail () |
| 277 | { |
| 278 | enable_kernel_lttng_event 1 1 "$@" |
| 279 | } |
| 280 | |
| 281 | function enable_kernel_lttng_event_notap () |
| 282 | { |
| 283 | enable_kernel_lttng_event 0 0 "$@" |
| 284 | } |
| 285 | |
| 286 | # Old interface |
| 287 | function lttng_enable_kernel_event |
| 288 | { |
| 289 | enable_kernel_lttng_event_ok "$@" |
| 290 | } |
| 291 | |
| 292 | function lttng_enable_kernel_syscall() |
| 293 | { |
| 294 | local expected_to_fail=$1 |
| 295 | local sess_name=$2 |
| 296 | local syscall_name=$3 |
| 297 | local channel_name=$4 |
| 298 | |
| 299 | if [ -z $syscall_name ]; then |
| 300 | # Enable all event if no syscall name specified |
| 301 | syscall_name="-a" |
| 302 | fi |
| 303 | |
| 304 | if [ -z $channel_name ]; then |
| 305 | # default channel if none specified |
| 306 | chan="" |
| 307 | else |
| 308 | chan="-c $channel_name" |
| 309 | fi |
| 310 | |
| 311 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 312 | ret=$? |
| 313 | if [[ $expected_to_fail -eq "1" ]]; then |
| 314 | test $ret -ne "0" |
| 315 | ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" |
| 316 | else |
| 317 | ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name" |
| 318 | fi |
| 319 | } |
| 320 | |
| 321 | function lttng_enable_kernel_syscall_ok() |
| 322 | { |
| 323 | lttng_enable_kernel_syscall 0 "$@" |
| 324 | } |
| 325 | |
| 326 | function lttng_enable_kernel_syscall_fail() |
| 327 | { |
| 328 | lttng_enable_kernel_syscall 1 "$@" |
| 329 | } |
| 330 | |
| 331 | function lttng_disable_kernel_syscall() |
| 332 | { |
| 333 | local expected_to_fail=$1 |
| 334 | local sess_name=$2 |
| 335 | local syscall_name=$3 |
| 336 | local channel_name=$4 |
| 337 | |
| 338 | if [ -z $syscall_name ]; then |
| 339 | # Enable all event if no syscall name specified |
| 340 | syscall_name="-a" |
| 341 | fi |
| 342 | |
| 343 | if [ -z $channel_name ]; then |
| 344 | # default channel if none specified |
| 345 | chan="" |
| 346 | else |
| 347 | chan="-c $channel_name" |
| 348 | fi |
| 349 | |
| 350 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 351 | |
| 352 | ret=$? |
| 353 | if [[ $expected_to_fail -eq "1" ]]; then |
| 354 | test $ret -ne "0" |
| 355 | ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected" |
| 356 | else |
| 357 | ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name" |
| 358 | fi |
| 359 | } |
| 360 | |
| 361 | function lttng_disable_kernel_syscall_ok() |
| 362 | { |
| 363 | lttng_disable_kernel_syscall 0 "$@" |
| 364 | } |
| 365 | |
| 366 | function lttng_disable_kernel_syscall_fail() |
| 367 | { |
| 368 | lttng_disable_kernel_syscall 1 "$@" |
| 369 | } |
| 370 | |
| 371 | function lttng_enable_kernel_function_event () |
| 372 | { |
| 373 | local expected_to_fail="$1" |
| 374 | local sess_name="$2" |
| 375 | local target="$3" |
| 376 | local event_name="$4" |
| 377 | |
| 378 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" |
| 379 | ret=$? |
| 380 | if [[ $expected_to_fail -eq "1" ]]; then |
| 381 | test $ret -ne "0" |
| 382 | ok $? "Enable kernel function event for session $sess_name failed as expected" |
| 383 | else |
| 384 | ok $ret "Enable kernel function event for session $sess_name" |
| 385 | fi |
| 386 | } |
| 387 | |
| 388 | function lttng_enable_kernel_function_event_ok () |
| 389 | { |
| 390 | lttng_enable_kernel_function_event 0 "$@" |
| 391 | } |
| 392 | |
| 393 | function lttng_enable_kernel_userspace_probe_event () |
| 394 | { |
| 395 | local expected_to_fail="$1" |
| 396 | local sess_name="$2" |
| 397 | local target="$3" |
| 398 | local event_name="$4" |
| 399 | |
| 400 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" |
| 401 | ret=$? |
| 402 | if [[ $expected_to_fail -eq "1" ]]; then |
| 403 | test $ret -ne "0" |
| 404 | ok $? "Enable kernel userspace probe event for session $sess_name failed as expected" |
| 405 | else |
| 406 | ok $ret "Enable kernel userspace probe event for session $sess_name" |
| 407 | fi |
| 408 | } |
| 409 | |
| 410 | function lttng_enable_kernel_userspace_probe_event_fail () |
| 411 | { |
| 412 | lttng_enable_kernel_userspace_probe_event 1 "$@" |
| 413 | } |
| 414 | |
| 415 | function lttng_enable_kernel_userspace_probe_event_ok () |
| 416 | { |
| 417 | lttng_enable_kernel_userspace_probe_event 0 "$@" |
| 418 | } |
| 419 | |
| 420 | function disable_kernel_lttng_userspace_probe_event_ok () |
| 421 | { |
| 422 | local sess_name="$1" |
| 423 | local event_name="$2" |
| 424 | |
| 425 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" |
| 426 | ok $? "Disable kernel event $target for session $sess_name" |
| 427 | } |
| 428 | function lttng_enable_kernel_channel() |
| 429 | { |
| 430 | local withtap=$1 |
| 431 | local expected_to_fail=$2 |
| 432 | local sess_name=$3 |
| 433 | local channel_name=$4 |
| 434 | local opts="${@:5}" |
| 435 | |
| 436 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 437 | ret=$? |
| 438 | if [[ $expected_to_fail -eq "1" ]]; then |
| 439 | test "$ret" -ne "0" |
| 440 | ret=$? |
| 441 | if [ $withtap -eq "1" ]; then |
| 442 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" |
| 443 | fi |
| 444 | else |
| 445 | if [ $withtap -eq "1" ]; then |
| 446 | ok $ret "Enable channel $channel_name for session $sess_name" |
| 447 | fi |
| 448 | fi |
| 449 | } |
| 450 | |
| 451 | function lttng_enable_kernel_channel_ok() |
| 452 | { |
| 453 | lttng_enable_kernel_channel 1 0 "$@" |
| 454 | } |
| 455 | |
| 456 | function lttng_enable_kernel_channel_fail() |
| 457 | { |
| 458 | lttng_enable_kernel_channel 1 1 "$@" |
| 459 | } |
| 460 | |
| 461 | function lttng_enable_kernel_channel_notap() |
| 462 | { |
| 463 | lttng_enable_kernel_channel 0 0 "$@" |
| 464 | } |
| 465 | |
| 466 | function enable_kernel_lttng_channel_ok() |
| 467 | { |
| 468 | lttng_enable_kernel_channel 1 0 "$@" |
| 469 | } |
| 470 | |
| 471 | function lttng_disable_kernel_channel() |
| 472 | { |
| 473 | local expected_to_fail=$1 |
| 474 | local sess_name=$2 |
| 475 | local channel_name=$3 |
| 476 | |
| 477 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 478 | ret=$? |
| 479 | if [[ $expected_to_fail -eq "1" ]]; then |
| 480 | test "$ret" -ne "0" |
| 481 | ok $? "Disable channel $channel_name for session $sess_name failed as expected" |
| 482 | else |
| 483 | ok $ret "Disable channel $channel_name for session $sess_name" |
| 484 | fi |
| 485 | } |
| 486 | |
| 487 | function lttng_disable_kernel_channel_ok() |
| 488 | { |
| 489 | lttng_disable_kernel_channel 0 "$@" |
| 490 | } |
| 491 | |
| 492 | function lttng_disable_kernel_channel_fail() |
| 493 | { |
| 494 | lttng_disable_kernel_channel 1 "$@" |
| 495 | } |
| 496 | |
| 497 | function start_lttng_relayd_opt() |
| 498 | { |
| 499 | local withtap=$1 |
| 500 | local process_mode=$2 |
| 501 | local opt=$3 |
| 502 | |
| 503 | DIR=$(readlink -f "$TESTDIR") |
| 504 | |
| 505 | if [ -z $(lttng_pgrep "$RELAYD_MATCH") ]; then |
| 506 | # shellcheck disable=SC2086 |
| 507 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 508 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
| 509 | if [ $? -eq 1 ]; then |
| 510 | if [ $withtap -eq "1" ]; then |
| 511 | fail "Start lttng-relayd (process mode: $process_mode opt: $opt)" |
| 512 | fi |
| 513 | return 1 |
| 514 | else |
| 515 | if [ $withtap -eq "1" ]; then |
| 516 | pass "Start lttng-relayd (process mode: $process_mode opt: $opt)" |
| 517 | fi |
| 518 | fi |
| 519 | else |
| 520 | pass "Start lttng-relayd (opt: $opt)" |
| 521 | fi |
| 522 | } |
| 523 | |
| 524 | function start_lttng_relayd() |
| 525 | { |
| 526 | start_lttng_relayd_opt 1 "-b" "$@" |
| 527 | } |
| 528 | |
| 529 | function start_lttng_relayd_notap() |
| 530 | { |
| 531 | start_lttng_relayd_opt 0 "-b" "$@" |
| 532 | } |
| 533 | |
| 534 | function stop_lttng_relayd_opt() |
| 535 | { |
| 536 | local withtap=$1 |
| 537 | local is_cleanup=$2 |
| 538 | local signal=$3 |
| 539 | local timeout_s=$4 |
| 540 | local dtimeleft_s= |
| 541 | local retval=0 |
| 542 | local pids |
| 543 | |
| 544 | if [ -z "$signal" ]; then |
| 545 | signal="SIGTERM" |
| 546 | fi |
| 547 | |
| 548 | |
| 549 | # Multiply time by 2 to simplify integer arithmetic |
| 550 | if [ -n "$timeout_s" ]; then |
| 551 | dtimeleft_s=$((timeout_s * 2)) |
| 552 | fi |
| 553 | |
| 554 | |
| 555 | pids=$(lttng_pgrep "$RELAYD_MATCH") |
| 556 | if [ -z "$pids" ]; then |
| 557 | if [ "$is_cleanup" -eq 1 ]; then |
| 558 | : |
| 559 | elif [ "$withtap" -eq "1" ]; then |
| 560 | fail "No relay daemon to kill" |
| 561 | else |
| 562 | LTTNG_BAIL_OUT "No relay daemon to kill" |
| 563 | fi |
| 564 | return 0 |
| 565 | fi |
| 566 | |
| 567 | diag "Killing (signal $signal) lttng-relayd (pid: $pids)" |
| 568 | |
| 569 | # shellcheck disable=SC2086 |
| 570 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then |
| 571 | retval=1 |
| 572 | if [ "$withtap" -eq "1" ]; then |
| 573 | fail "Kill relay daemon" |
| 574 | fi |
| 575 | else |
| 576 | out=1 |
| 577 | while [ -n "$out" ]; do |
| 578 | out=$(lttng_pgrep "$RELAYD_MATCH") |
| 579 | if [ -n "$dtimeleft_s" ]; then |
| 580 | if [ $dtimeleft_s -lt 0 ]; then |
| 581 | out= |
| 582 | retval=1 |
| 583 | fi |
| 584 | dtimeleft_s=$((dtimeleft_s - 1)) |
| 585 | fi |
| 586 | sleep 0.5 |
| 587 | done |
| 588 | if [ "$withtap" -eq "1" ]; then |
| 589 | if [ "$retval" -eq "0" ]; then |
| 590 | pass "Wait after kill relay daemon" |
| 591 | else |
| 592 | fail "Wait after kill relay daemon" |
| 593 | fi |
| 594 | fi |
| 595 | fi |
| 596 | return $retval |
| 597 | } |
| 598 | |
| 599 | function stop_lttng_relayd() |
| 600 | { |
| 601 | stop_lttng_relayd_opt 1 0 "$@" |
| 602 | } |
| 603 | |
| 604 | function stop_lttng_relayd_notap() |
| 605 | { |
| 606 | stop_lttng_relayd_opt 0 0 "$@" |
| 607 | } |
| 608 | |
| 609 | function stop_lttng_relayd_cleanup() |
| 610 | { |
| 611 | stop_lttng_relayd_opt 0 1 "$@" |
| 612 | } |
| 613 | |
| 614 | #First arg: show tap output |
| 615 | #Second argument: load path for automatic loading |
| 616 | function start_lttng_sessiond_opt() |
| 617 | { |
| 618 | local withtap=$1 |
| 619 | local load_path=$2 |
| 620 | |
| 621 | # The rest of the arguments will be passed directly to lttng-sessiond. |
| 622 | shift 2 |
| 623 | |
| 624 | local env_vars="" |
| 625 | local consumerd="" |
| 626 | |
| 627 | local long_bit_value= |
| 628 | long_bit_value=$(getconf LONG_BIT) |
| 629 | |
| 630 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
| 631 | # Env variable requested no session daemon |
| 632 | return |
| 633 | fi |
| 634 | |
| 635 | DIR=$(readlink -f "$TESTDIR") |
| 636 | |
| 637 | # Get long_bit value for 32/64 consumerd |
| 638 | case "$long_bit_value" in |
| 639 | 32) |
| 640 | consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
| 641 | ;; |
| 642 | 64) |
| 643 | consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
| 644 | ;; |
| 645 | *) |
| 646 | return |
| 647 | ;; |
| 648 | esac |
| 649 | |
| 650 | # Check for env. variable. Allow the use of LD_PRELOAD etc. |
| 651 | if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then |
| 652 | env_vars="${LTTNG_SESSIOND_ENV_VARS} " |
| 653 | fi |
| 654 | env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" |
| 655 | |
| 656 | if ! validate_kernel_version; then |
| 657 | fail "Start session daemon" |
| 658 | LTTNG_BAIL_OUT "*** Kernel too old for session daemon tests ***" |
| 659 | fi |
| 660 | |
| 661 | : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}" |
| 662 | export LTTNG_SESSION_CONFIG_XSD_PATH |
| 663 | |
| 664 | if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then |
| 665 | # Have a load path ? |
| 666 | if [ -n "$load_path" ]; then |
| 667 | # shellcheck disable=SC2086 |
| 668 | env $env_vars --load "$load_path" --background "$consumerd" "$@" |
| 669 | else |
| 670 | # shellcheck disable=SC2086 |
| 671 | env $env_vars --background "$consumerd" "$@" |
| 672 | fi |
| 673 | #$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 |
| 674 | status=$? |
| 675 | if [ "$withtap" -eq "1" ]; then |
| 676 | ok $status "Start session daemon" |
| 677 | fi |
| 678 | fi |
| 679 | } |
| 680 | |
| 681 | function start_lttng_sessiond() |
| 682 | { |
| 683 | start_lttng_sessiond_opt 1 "$@" |
| 684 | } |
| 685 | |
| 686 | function start_lttng_sessiond_notap() |
| 687 | { |
| 688 | start_lttng_sessiond_opt 0 "$@" |
| 689 | } |
| 690 | |
| 691 | function stop_lttng_sessiond_opt() |
| 692 | { |
| 693 | local withtap=$1 |
| 694 | local is_cleanup=$2 |
| 695 | local signal=$3 |
| 696 | local timeout_s=$4 |
| 697 | local dtimeleft_s= |
| 698 | local retval=0 |
| 699 | local runas_pids |
| 700 | local pids |
| 701 | |
| 702 | if [ -z "$signal" ]; then |
| 703 | signal=SIGTERM |
| 704 | fi |
| 705 | |
| 706 | # Multiply time by 2 to simplify integer arithmetic |
| 707 | if [ -n "$timeout_s" ]; then |
| 708 | dtimeleft_s=$((timeout_s * 2)) |
| 709 | fi |
| 710 | |
| 711 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
| 712 | # Env variable requested no session daemon |
| 713 | return 0 |
| 714 | fi |
| 715 | |
| 716 | runas_pids=$(lttng_pgrep "$RUNAS_MATCH") |
| 717 | pids=$(lttng_pgrep "$SESSIOND_MATCH") |
| 718 | |
| 719 | if [ -n "$runas_pids" ]; then |
| 720 | pids="$pids $runas_pids" |
| 721 | fi |
| 722 | |
| 723 | if [ -z "$pids" ]; then |
| 724 | if [ "$is_cleanup" -eq 1 ]; then |
| 725 | : |
| 726 | elif [ "$withtap" -eq "1" ]; then |
| 727 | fail "No session daemon to kill" |
| 728 | else |
| 729 | LTTNG_BAIL_OUT "No session daemon to kill" |
| 730 | fi |
| 731 | return 0 |
| 732 | fi |
| 733 | |
| 734 | diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
| 735 | |
| 736 | # shellcheck disable=SC2086 |
| 737 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then |
| 738 | retval=1 |
| 739 | if [ "$withtap" -eq "1" ]; then |
| 740 | fail "Kill sessions daemon" |
| 741 | fi |
| 742 | else |
| 743 | out=1 |
| 744 | while [ -n "$out" ]; do |
| 745 | out=$(lttng_pgrep "${SESSIOND_MATCH}") |
| 746 | if [ -n "$dtimeleft_s" ]; then |
| 747 | if [ $dtimeleft_s -lt 0 ]; then |
| 748 | out= |
| 749 | retval=1 |
| 750 | fi |
| 751 | dtimeleft_s=$((dtimeleft_s - 1)) |
| 752 | fi |
| 753 | sleep 0.5 |
| 754 | done |
| 755 | out=1 |
| 756 | while [ -n "$out" ]; do |
| 757 | out=$(lttng_pgrep "$CONSUMERD_MATCH") |
| 758 | if [ -n "$dtimeleft_s" ]; then |
| 759 | if [ $dtimeleft_s -lt 0 ]; then |
| 760 | out= |
| 761 | retval=1 |
| 762 | fi |
| 763 | dtimeleft_s=$((dtimeleft_s - 1)) |
| 764 | fi |
| 765 | sleep 0.5 |
| 766 | done |
| 767 | |
| 768 | if [ "$withtap" -eq "1" ]; then |
| 769 | if [ "$retval" -eq "0" ]; then |
| 770 | pass "Wait after kill session daemon" |
| 771 | else |
| 772 | fail "Wait after kill session daemon" |
| 773 | fi |
| 774 | fi |
| 775 | fi |
| 776 | if [ "$signal" = "SIGKILL" ]; then |
| 777 | if [ "$(id -u)" -eq "0" ]; then |
| 778 | local modules= |
| 779 | modules="$(lsmod | grep ^lttng | awk '{print $1}')" |
| 780 | |
| 781 | if [ -n "$modules" ]; then |
| 782 | diag "Unloading all LTTng modules" |
| 783 | modprobe --remove "$modules" |
| 784 | fi |
| 785 | fi |
| 786 | fi |
| 787 | |
| 788 | return $retval |
| 789 | } |
| 790 | |
| 791 | function stop_lttng_sessiond() |
| 792 | { |
| 793 | stop_lttng_sessiond_opt 1 0 "$@" |
| 794 | } |
| 795 | |
| 796 | function stop_lttng_sessiond_notap() |
| 797 | { |
| 798 | stop_lttng_sessiond_opt 0 0 "$@" |
| 799 | } |
| 800 | |
| 801 | function stop_lttng_sessiond_cleanup() |
| 802 | { |
| 803 | stop_lttng_sessiond_opt 0 1 "$@" |
| 804 | } |
| 805 | |
| 806 | function sigstop_lttng_sessiond_opt() |
| 807 | { |
| 808 | local withtap=$1 |
| 809 | local signal=SIGSTOP |
| 810 | local pids |
| 811 | |
| 812 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
| 813 | # Env variable requested no session daemon |
| 814 | return |
| 815 | fi |
| 816 | |
| 817 | pids="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")" |
| 818 | |
| 819 | if [ "$withtap" -eq "1" ]; then |
| 820 | diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
| 821 | fi |
| 822 | |
| 823 | # shellcheck disable=SC2086 |
| 824 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then |
| 825 | if [ "$withtap" -eq "1" ]; then |
| 826 | fail "Sending SIGSTOP to session daemon" |
| 827 | fi |
| 828 | else |
| 829 | out=1 |
| 830 | while [ $out -ne 0 ]; do |
| 831 | pids="$(lttng_pgrep "$SESSIOND_MATCH")" |
| 832 | |
| 833 | # Wait until state becomes stopped for session |
| 834 | # daemon(s). |
| 835 | out=0 |
| 836 | for sessiond_pid in $pids; do |
| 837 | state="$(ps -p "$sessiond_pid" -o state= )" |
| 838 | if [[ -n "$state" && "$state" != "T" ]]; then |
| 839 | out=1 |
| 840 | fi |
| 841 | done |
| 842 | sleep 0.5 |
| 843 | done |
| 844 | if [ "$withtap" -eq "1" ]; then |
| 845 | pass "Sending SIGSTOP to session daemon" |
| 846 | fi |
| 847 | fi |
| 848 | } |
| 849 | |
| 850 | function sigstop_lttng_sessiond() |
| 851 | { |
| 852 | sigstop_lttng_sessiond_opt 1 "$@" |
| 853 | } |
| 854 | |
| 855 | function sigstop_lttng_sessiond_notap() |
| 856 | { |
| 857 | sigstop_lttng_sessiond_opt 0 "$@" |
| 858 | } |
| 859 | |
| 860 | function stop_lttng_consumerd_opt() |
| 861 | { |
| 862 | local withtap=$1 |
| 863 | local is_cleanup=$2 |
| 864 | local signal=$3 |
| 865 | local timeout_s=$4 |
| 866 | local dtimeleft_s= |
| 867 | local retval=0 |
| 868 | local pids |
| 869 | |
| 870 | if [ -z "$signal" ]; then |
| 871 | signal=SIGTERM |
| 872 | fi |
| 873 | |
| 874 | # Multiply time by 2 to simplify integer arithmetic |
| 875 | if [ -n "$timeout_s" ]; then |
| 876 | dtimeleft_s=$((timeout_s * 2)) |
| 877 | fi |
| 878 | |
| 879 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
| 880 | |
| 881 | if [ -z "$pids" ]; then |
| 882 | if [ "$is_cleanup" -eq 1 ]; then |
| 883 | : |
| 884 | elif [ "$withtap" -eq "1" ]; then |
| 885 | fail "No consumerd daemon to kill" |
| 886 | else |
| 887 | LTTNG_BAIL_OUT "No consumerd daemon to kill" |
| 888 | fi |
| 889 | return 0 |
| 890 | fi |
| 891 | |
| 892 | diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
| 893 | |
| 894 | # shellcheck disable=SC2086 |
| 895 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then |
| 896 | retval=1 |
| 897 | if [ "$withtap" -eq "1" ]; then |
| 898 | fail "Kill consumer daemon" |
| 899 | fi |
| 900 | else |
| 901 | out=1 |
| 902 | while [ $out -ne 0 ]; do |
| 903 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
| 904 | |
| 905 | # If consumerds are still present check their status. |
| 906 | # A zombie status qualifies the consumerd as *killed* |
| 907 | out=0 |
| 908 | for consumer_pid in $pids; do |
| 909 | state="$(ps -p "$consumer_pid" -o state= )" |
| 910 | if [[ -n "$state" && "$state" != "Z" ]]; then |
| 911 | out=1 |
| 912 | fi |
| 913 | done |
| 914 | if [ -n "$dtimeleft_s" ]; then |
| 915 | if [ $dtimeleft_s -lt 0 ]; then |
| 916 | out=0 |
| 917 | retval=1 |
| 918 | fi |
| 919 | dtimeleft_s=$((dtimeleft_s - 1)) |
| 920 | fi |
| 921 | sleep 0.5 |
| 922 | done |
| 923 | if [ "$withtap" -eq "1" ]; then |
| 924 | if [ "$retval" -eq "0" ]; then |
| 925 | pass "Wait after kill consumer daemon" |
| 926 | else |
| 927 | fail "Wait after kill consumer daemon" |
| 928 | fi |
| 929 | fi |
| 930 | fi |
| 931 | |
| 932 | return $retval |
| 933 | } |
| 934 | |
| 935 | function stop_lttng_consumerd() |
| 936 | { |
| 937 | stop_lttng_consumerd_opt 1 0 "$@" |
| 938 | } |
| 939 | |
| 940 | function stop_lttng_consumerd_notap() |
| 941 | { |
| 942 | stop_lttng_consumerd_opt 0 0 "$@" |
| 943 | } |
| 944 | |
| 945 | function stop_lttng_consumerd_cleanup() |
| 946 | { |
| 947 | stop_lttng_consumerd_opt 0 1 "$@" |
| 948 | } |
| 949 | |
| 950 | function sigstop_lttng_consumerd_opt() |
| 951 | { |
| 952 | local withtap=$1 |
| 953 | local signal=SIGSTOP |
| 954 | local pids |
| 955 | |
| 956 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
| 957 | |
| 958 | diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
| 959 | |
| 960 | # shellcheck disable=SC2086 |
| 961 | kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 962 | retval=$? |
| 963 | |
| 964 | if [ $retval -eq 1 ]; then |
| 965 | if [ "$withtap" -eq "1" ]; then |
| 966 | fail "Sending SIGSTOP to consumer daemon" |
| 967 | fi |
| 968 | return 1 |
| 969 | else |
| 970 | out=1 |
| 971 | while [ $out -ne 0 ]; do |
| 972 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
| 973 | |
| 974 | # Wait until state becomes stopped for all |
| 975 | # consumers. |
| 976 | out=0 |
| 977 | for consumer_pid in $pids; do |
| 978 | state="$(ps -p "$consumer_pid" -o state= )" |
| 979 | if [[ -n "$state" && "$state" != "T" ]]; then |
| 980 | out=1 |
| 981 | fi |
| 982 | done |
| 983 | sleep 0.5 |
| 984 | done |
| 985 | if [ "$withtap" -eq "1" ]; then |
| 986 | pass "Sending SIGSTOP to consumer daemon" |
| 987 | fi |
| 988 | fi |
| 989 | return $retval |
| 990 | } |
| 991 | |
| 992 | function sigstop_lttng_consumerd() |
| 993 | { |
| 994 | sigstop_lttng_consumerd_opt 1 "$@" |
| 995 | } |
| 996 | |
| 997 | function sigstop_lttng_consumerd_notap() |
| 998 | { |
| 999 | sigstop_lttng_consumerd_opt 0 "$@" |
| 1000 | } |
| 1001 | |
| 1002 | function list_lttng_with_opts () |
| 1003 | { |
| 1004 | local opts=$1 |
| 1005 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1006 | ok $? "Lttng-tool list command with option $opts" |
| 1007 | } |
| 1008 | |
| 1009 | function create_lttng_session_no_output () |
| 1010 | { |
| 1011 | local sess_name=$1 |
| 1012 | local opts="${@:2}" |
| 1013 | |
| 1014 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1015 | ok $? "Create session $sess_name in no-output mode" |
| 1016 | } |
| 1017 | |
| 1018 | function create_lttng_session_uri () { |
| 1019 | local sess_name=$1 |
| 1020 | local uri=$2 |
| 1021 | local opts="${@:3}" |
| 1022 | |
| 1023 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1024 | ok $? "Create session $sess_name with uri:$uri and opts: $opts" |
| 1025 | } |
| 1026 | |
| 1027 | function create_lttng_session () |
| 1028 | { |
| 1029 | local withtap=$1 |
| 1030 | local expected_to_fail=$2 |
| 1031 | local sess_name=$3 |
| 1032 | local trace_path=$4 |
| 1033 | local opt=$5 |
| 1034 | |
| 1035 | if [ -z "$trace_path" ]; then |
| 1036 | # Use lttng-sessiond default output. |
| 1037 | trace_path="" |
| 1038 | else |
| 1039 | trace_path="-o $trace_path" |
| 1040 | fi |
| 1041 | |
| 1042 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create "$sess_name" $trace_path $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1043 | ret=$? |
| 1044 | if [ $expected_to_fail -eq "1" ]; then |
| 1045 | test "$ret" -ne "0" |
| 1046 | ret=$? |
| 1047 | if [ $withtap -eq "1" ]; then |
| 1048 | ok $ret "Create session $sess_name in $trace_path failed as expected" |
| 1049 | fi |
| 1050 | else |
| 1051 | if [ $withtap -eq "1" ]; then |
| 1052 | ok $ret "Create session $sess_name in $trace_path" |
| 1053 | fi |
| 1054 | fi |
| 1055 | return $ret |
| 1056 | } |
| 1057 | |
| 1058 | function create_lttng_session_ok () |
| 1059 | { |
| 1060 | create_lttng_session 1 0 "$@" |
| 1061 | } |
| 1062 | |
| 1063 | function create_lttng_session_fail () |
| 1064 | { |
| 1065 | create_lttng_session 1 1 "$@" |
| 1066 | } |
| 1067 | |
| 1068 | function create_lttng_session_notap () |
| 1069 | { |
| 1070 | create_lttng_session 0 0 "$@" |
| 1071 | } |
| 1072 | |
| 1073 | |
| 1074 | function enable_ust_lttng_channel () |
| 1075 | { |
| 1076 | local withtap=$1 |
| 1077 | local expected_to_fail=$2 |
| 1078 | local sess_name=$3 |
| 1079 | local channel_name=$4 |
| 1080 | local opts="${@:5}" |
| 1081 | |
| 1082 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1083 | ret=$? |
| 1084 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1085 | test "$ret" -ne "0" |
| 1086 | ret=$? |
| 1087 | if [ $withtap -eq "1" ]; then |
| 1088 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" |
| 1089 | fi |
| 1090 | else |
| 1091 | if [ $withtap -eq "1" ]; then |
| 1092 | ok $ret "Enable channel $channel_name for session $sess_name" |
| 1093 | fi |
| 1094 | fi |
| 1095 | return $ret |
| 1096 | } |
| 1097 | |
| 1098 | function enable_ust_lttng_channel_ok () |
| 1099 | { |
| 1100 | enable_ust_lttng_channel 1 0 "$@" |
| 1101 | } |
| 1102 | |
| 1103 | function enable_ust_lttng_channel_fail () |
| 1104 | { |
| 1105 | enable_ust_lttng_channel 1 1 "$@" |
| 1106 | } |
| 1107 | |
| 1108 | function enable_ust_lttng_channel_notap () |
| 1109 | { |
| 1110 | enable_ust_lttng_channel 0 0 "$@" |
| 1111 | } |
| 1112 | |
| 1113 | function disable_ust_lttng_channel() |
| 1114 | { |
| 1115 | local sess_name=$1 |
| 1116 | local channel_name=$2 |
| 1117 | |
| 1118 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1119 | ok $? "Disable channel $channel_name for session $sess_name" |
| 1120 | } |
| 1121 | |
| 1122 | function enable_lttng_mmap_overwrite_kernel_channel() |
| 1123 | { |
| 1124 | local sess_name=$1 |
| 1125 | local channel_name=$2 |
| 1126 | |
| 1127 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1128 | ok $? "Enable channel $channel_name for session $sess_name" |
| 1129 | } |
| 1130 | |
| 1131 | function enable_lttng_mmap_discard_small_kernel_channel() |
| 1132 | { |
| 1133 | local sess_name=$1 |
| 1134 | local channel_name=$2 |
| 1135 | |
| 1136 | $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 |
| 1137 | ok $? "Enable small discard channel $channel_name for session $sess_name" |
| 1138 | } |
| 1139 | |
| 1140 | function enable_lttng_mmap_overwrite_small_kernel_channel() |
| 1141 | { |
| 1142 | local sess_name=$1 |
| 1143 | local channel_name=$2 |
| 1144 | |
| 1145 | $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 |
| 1146 | ok $? "Enable small discard channel $channel_name for session $sess_name" |
| 1147 | } |
| 1148 | |
| 1149 | function enable_lttng_mmap_overwrite_ust_channel() |
| 1150 | { |
| 1151 | local sess_name=$1 |
| 1152 | local channel_name=$2 |
| 1153 | |
| 1154 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1155 | ok $? "Enable channel $channel_name for session $sess_name" |
| 1156 | } |
| 1157 | |
| 1158 | function enable_ust_lttng_event () |
| 1159 | { |
| 1160 | local withtap=$1 |
| 1161 | local expected_to_fail=$2 |
| 1162 | local sess_name=$3 |
| 1163 | local event_name="$4" |
| 1164 | local channel_name=$5 |
| 1165 | |
| 1166 | if [ -z $channel_name ]; then |
| 1167 | # default channel if none specified |
| 1168 | chan="" |
| 1169 | else |
| 1170 | chan="-c $channel_name" |
| 1171 | fi |
| 1172 | |
| 1173 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1174 | ret=$? |
| 1175 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1176 | test $ret -ne "0" |
| 1177 | ret=$? |
| 1178 | if [[ $withtap -eq "1" ]]; then |
| 1179 | ok $ret "Enable ust event $event_name for session $session_name failed as expected" |
| 1180 | fi |
| 1181 | else |
| 1182 | if [[ $withtap -eq "1" ]]; then |
| 1183 | ok $ret "Enable ust event $event_name for session $sess_name" |
| 1184 | fi |
| 1185 | fi |
| 1186 | return $ret |
| 1187 | } |
| 1188 | |
| 1189 | function enable_ust_lttng_event_ok () |
| 1190 | { |
| 1191 | enable_ust_lttng_event 1 0 "$@" |
| 1192 | } |
| 1193 | |
| 1194 | function enable_ust_lttng_event_fail () |
| 1195 | { |
| 1196 | enable_ust_lttng_event 1 1 "$@" |
| 1197 | } |
| 1198 | |
| 1199 | function enable_ust_lttng_event_notap () |
| 1200 | { |
| 1201 | enable_ust_lttng_event 0 0 "$@" |
| 1202 | } |
| 1203 | |
| 1204 | function enable_jul_lttng_event() |
| 1205 | { |
| 1206 | sess_name=$1 |
| 1207 | event_name="$2" |
| 1208 | channel_name=$3 |
| 1209 | |
| 1210 | if [ -z $channel_name ]; then |
| 1211 | # default channel if none specified |
| 1212 | chan="" |
| 1213 | else |
| 1214 | chan="-c $channel_name" |
| 1215 | fi |
| 1216 | |
| 1217 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1218 | ok $? "Enable JUL event $event_name for session $sess_name" |
| 1219 | } |
| 1220 | |
| 1221 | function enable_jul_lttng_event_loglevel() |
| 1222 | { |
| 1223 | local sess_name=$1 |
| 1224 | local event_name="$2" |
| 1225 | local loglevel=$3 |
| 1226 | local channel_name=$4 |
| 1227 | |
| 1228 | if [ -z $channel_name ]; then |
| 1229 | # default channel if none specified |
| 1230 | chan="" |
| 1231 | else |
| 1232 | chan="-c $channel_name" |
| 1233 | fi |
| 1234 | |
| 1235 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1236 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
| 1237 | } |
| 1238 | |
| 1239 | function enable_log4j_lttng_event() |
| 1240 | { |
| 1241 | sess_name=$1 |
| 1242 | event_name="$2" |
| 1243 | channel_name=$3 |
| 1244 | |
| 1245 | if [ -z $channel_name ]; then |
| 1246 | # default channel if none specified |
| 1247 | chan="" |
| 1248 | else |
| 1249 | chan="-c $channel_name" |
| 1250 | fi |
| 1251 | |
| 1252 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1253 | ok $? "Enable LOG4J event $event_name for session $sess_name" |
| 1254 | } |
| 1255 | |
| 1256 | function enable_log4j_lttng_event_loglevel() |
| 1257 | { |
| 1258 | local sess_name=$1 |
| 1259 | local event_name="$2" |
| 1260 | local loglevel=$3 |
| 1261 | local channel_name=$4 |
| 1262 | |
| 1263 | if [ -z $channel_name ]; then |
| 1264 | # default channel if none specified |
| 1265 | chan="" |
| 1266 | else |
| 1267 | chan="-c $channel_name" |
| 1268 | fi |
| 1269 | |
| 1270 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1271 | ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel" |
| 1272 | } |
| 1273 | |
| 1274 | function enable_python_lttng_event() |
| 1275 | { |
| 1276 | sess_name=$1 |
| 1277 | event_name="$2" |
| 1278 | channel_name=$3 |
| 1279 | |
| 1280 | if [ -z $channel_name ]; then |
| 1281 | # default channel if none specified |
| 1282 | chan="" |
| 1283 | else |
| 1284 | chan="-c $channel_name" |
| 1285 | fi |
| 1286 | |
| 1287 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1288 | ok $? "Enable Python event $event_name for session $sess_name" |
| 1289 | } |
| 1290 | |
| 1291 | function enable_python_lttng_event_loglevel() |
| 1292 | { |
| 1293 | local sess_name=$1 |
| 1294 | local event_name="$2" |
| 1295 | local loglevel=$3 |
| 1296 | local channel_name=$4 |
| 1297 | |
| 1298 | if [ -z $channel_name ]; then |
| 1299 | # default channel if none specified |
| 1300 | chan="" |
| 1301 | else |
| 1302 | chan="-c $channel_name" |
| 1303 | fi |
| 1304 | |
| 1305 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1306 | ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel" |
| 1307 | } |
| 1308 | |
| 1309 | function enable_ust_lttng_event_filter() |
| 1310 | { |
| 1311 | local sess_name="$1" |
| 1312 | local event_name="$2" |
| 1313 | local filter="$3" |
| 1314 | local channel_name=$4 |
| 1315 | |
| 1316 | if [ -z $channel_name ]; then |
| 1317 | # default channel if none specified |
| 1318 | chan="" |
| 1319 | else |
| 1320 | chan="-c $channel_name" |
| 1321 | fi |
| 1322 | |
| 1323 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $chan "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1324 | ok $? "Enable event $event_name with filtering for session $sess_name" |
| 1325 | } |
| 1326 | |
| 1327 | function enable_ust_lttng_event_loglevel() |
| 1328 | { |
| 1329 | local sess_name="$1" |
| 1330 | local event_name="$2" |
| 1331 | local loglevel="$3" |
| 1332 | |
| 1333 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1334 | ok $? "Enable event $event_name with loglevel $loglevel" |
| 1335 | } |
| 1336 | |
| 1337 | function enable_ust_lttng_event_loglevel_only() |
| 1338 | { |
| 1339 | local sess_name="$1" |
| 1340 | local event_name="$2" |
| 1341 | local loglevel="$3" |
| 1342 | |
| 1343 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1344 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
| 1345 | } |
| 1346 | |
| 1347 | function disable_ust_lttng_event () |
| 1348 | { |
| 1349 | local sess_name="$1" |
| 1350 | local event_name="$2" |
| 1351 | local channel_name="$3" |
| 1352 | |
| 1353 | if [ -z $channel_name ]; then |
| 1354 | # default channel if none specified |
| 1355 | chan="" |
| 1356 | else |
| 1357 | chan="-c $channel_name" |
| 1358 | fi |
| 1359 | |
| 1360 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1361 | ok $? "Disable event $event_name for session $sess_name" |
| 1362 | } |
| 1363 | |
| 1364 | function disable_jul_lttng_event () |
| 1365 | { |
| 1366 | local sess_name="$1" |
| 1367 | local event_name="$2" |
| 1368 | |
| 1369 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 |
| 1370 | ok $? "Disable JUL event $event_name for session $sess_name" |
| 1371 | } |
| 1372 | |
| 1373 | function disable_log4j_lttng_event () |
| 1374 | { |
| 1375 | local sess_name="$1" |
| 1376 | local event_name="$2" |
| 1377 | |
| 1378 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1 |
| 1379 | ok $? "Disable LOG4J event $event_name for session $sess_name" |
| 1380 | } |
| 1381 | |
| 1382 | function disable_python_lttng_event () |
| 1383 | { |
| 1384 | local sess_name="$1" |
| 1385 | local event_name="$2" |
| 1386 | |
| 1387 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1388 | ok $? "Disable Python event $event_name for session $sess_name" |
| 1389 | } |
| 1390 | |
| 1391 | function start_lttng_tracing_opt () |
| 1392 | { |
| 1393 | local withtap=$1 |
| 1394 | local expected_to_fail=$2 |
| 1395 | local sess_name=$3 |
| 1396 | |
| 1397 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1398 | ret=$? |
| 1399 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1400 | test "$ret" -ne "0" |
| 1401 | ret=$? |
| 1402 | if [ $withtap -eq "1" ]; then |
| 1403 | ok $? "Start tracing for session $sess_name failed as expected" |
| 1404 | fi |
| 1405 | else |
| 1406 | if [ $withtap -eq "1" ]; then |
| 1407 | ok $ret "Start tracing for session $sess_name" |
| 1408 | fi |
| 1409 | fi |
| 1410 | } |
| 1411 | |
| 1412 | function start_lttng_tracing_ok () |
| 1413 | { |
| 1414 | start_lttng_tracing_opt 1 0 "$@" |
| 1415 | } |
| 1416 | |
| 1417 | function start_lttng_tracing_fail () |
| 1418 | { |
| 1419 | start_lttng_tracing_opt 1 1 "$@" |
| 1420 | } |
| 1421 | |
| 1422 | function start_lttng_tracing_notap () |
| 1423 | { |
| 1424 | start_lttng_tracing_opt 0 1 "$@" |
| 1425 | } |
| 1426 | |
| 1427 | function stop_lttng_tracing_opt () |
| 1428 | { |
| 1429 | local withtap=$1 |
| 1430 | local expected_to_fail=$2 |
| 1431 | local sess_name=$3 |
| 1432 | |
| 1433 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1434 | ret=$? |
| 1435 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1436 | test "$ret" -ne "0" |
| 1437 | ret=$? |
| 1438 | if [ $withtap -eq "1" ]; then |
| 1439 | ok $? "Stop lttng tracing for session $sess_name failed as expected" |
| 1440 | fi |
| 1441 | else |
| 1442 | if [ $withtap -eq "1" ]; then |
| 1443 | ok $ret "Stop lttng tracing for session $sess_name" |
| 1444 | fi |
| 1445 | fi |
| 1446 | } |
| 1447 | |
| 1448 | function stop_lttng_tracing_ok () |
| 1449 | { |
| 1450 | stop_lttng_tracing_opt 1 0 "$@" |
| 1451 | } |
| 1452 | |
| 1453 | function stop_lttng_tracing_fail () |
| 1454 | { |
| 1455 | stop_lttng_tracing_opt 1 1 "$@" |
| 1456 | } |
| 1457 | |
| 1458 | function stop_lttng_tracing_notap () |
| 1459 | { |
| 1460 | stop_lttng_tracing_opt 0 0 "$@" |
| 1461 | } |
| 1462 | |
| 1463 | function destroy_lttng_session () |
| 1464 | { |
| 1465 | local withtap=$1 |
| 1466 | local expected_to_fail=$2 |
| 1467 | local sess_name=$3 |
| 1468 | |
| 1469 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1470 | ret=$? |
| 1471 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1472 | test "$ret" -ne "0" |
| 1473 | ret=$? |
| 1474 | if [ $withtap -eq "1" ]; then |
| 1475 | ok $ret "Destroy session $sess_name failed as expected" |
| 1476 | fi |
| 1477 | else |
| 1478 | if [ $withtap -eq "1" ]; then |
| 1479 | ok $ret "Destroy session $sess_name" |
| 1480 | fi |
| 1481 | fi |
| 1482 | } |
| 1483 | |
| 1484 | function destroy_lttng_session_ok () |
| 1485 | { |
| 1486 | destroy_lttng_session 1 0 "$@" |
| 1487 | |
| 1488 | } |
| 1489 | |
| 1490 | function destroy_lttng_session_fail () |
| 1491 | { |
| 1492 | destroy_lttng_session 1 1 "$@" |
| 1493 | } |
| 1494 | |
| 1495 | function destroy_lttng_session_notap () |
| 1496 | { |
| 1497 | destroy_lttng_session 0 0 "$@" |
| 1498 | } |
| 1499 | |
| 1500 | function destroy_lttng_sessions () |
| 1501 | { |
| 1502 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1503 | ok $? "Destroy all lttng sessions" |
| 1504 | } |
| 1505 | |
| 1506 | function lttng_snapshot_add_output () |
| 1507 | { |
| 1508 | local expected_to_fail=$1 |
| 1509 | local sess_name=$2 |
| 1510 | local trace_path=$3 |
| 1511 | local opts=$4 |
| 1512 | |
| 1513 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $trace_path $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1514 | ret=$? |
| 1515 | if [[ $expected_to_fail -eq 1 ]]; then |
| 1516 | test "$ret" -ne "0" |
| 1517 | ok $? "Added snapshot output $trace_path failed as expected" |
| 1518 | else |
| 1519 | ok $ret "Added snapshot output $trace_path" |
| 1520 | fi |
| 1521 | } |
| 1522 | |
| 1523 | function lttng_snapshot_add_output_ok () |
| 1524 | { |
| 1525 | lttng_snapshot_add_output 0 "$@" |
| 1526 | } |
| 1527 | |
| 1528 | function lttng_snapshot_add_output_fail () |
| 1529 | { |
| 1530 | lttng_snapshot_add_output 1 "$@" |
| 1531 | } |
| 1532 | |
| 1533 | function lttng_snapshot_del_output () |
| 1534 | { |
| 1535 | local expected_to_fail=$1 |
| 1536 | local sess_name=$2 |
| 1537 | local id=$3 |
| 1538 | |
| 1539 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1540 | ret=$? |
| 1541 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1542 | test "$ret" -ne "0" |
| 1543 | ok $? "Deleted snapshot output id $id failed as expected" |
| 1544 | else |
| 1545 | ok $ret "Deleted snapshot output id $id" |
| 1546 | fi |
| 1547 | } |
| 1548 | |
| 1549 | function lttng_snapshot_del_output_ok () |
| 1550 | { |
| 1551 | lttng_snapshot_del_output 0 "$@" |
| 1552 | } |
| 1553 | |
| 1554 | function lttng_snapshot_del_output_fail () |
| 1555 | { |
| 1556 | lttng_snapshot_del_output 1 "$@" |
| 1557 | } |
| 1558 | |
| 1559 | function lttng_snapshot_record () |
| 1560 | { |
| 1561 | local sess_name=$1 |
| 1562 | local trace_path=$2 |
| 1563 | |
| 1564 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s "$sess_name" "$trace_path" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1565 | ok $? "Snapshot recorded" |
| 1566 | } |
| 1567 | |
| 1568 | function lttng_snapshot_list () |
| 1569 | { |
| 1570 | local sess_name=$1 |
| 1571 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1572 | ok $? "Snapshot list" |
| 1573 | } |
| 1574 | |
| 1575 | function lttng_save() |
| 1576 | { |
| 1577 | local sess_name=$1 |
| 1578 | local opts=$2 |
| 1579 | |
| 1580 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1581 | ok $? "Session saved" |
| 1582 | } |
| 1583 | |
| 1584 | function lttng_load() |
| 1585 | { |
| 1586 | local expected_to_fail=$1 |
| 1587 | local opts=$2 |
| 1588 | |
| 1589 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1590 | ret=$? |
| 1591 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1592 | test $ret -ne "0" |
| 1593 | ok $? "Load command failed as expected with opts: $opts" |
| 1594 | else |
| 1595 | ok $ret "Load command with opts: $opts" |
| 1596 | fi |
| 1597 | } |
| 1598 | |
| 1599 | function lttng_load_ok() |
| 1600 | { |
| 1601 | lttng_load 0 "$@" |
| 1602 | } |
| 1603 | |
| 1604 | function lttng_load_fail() |
| 1605 | { |
| 1606 | lttng_load 1 "$@" |
| 1607 | } |
| 1608 | |
| 1609 | function lttng_track() |
| 1610 | { |
| 1611 | local expected_to_fail="$1" |
| 1612 | shift 1 |
| 1613 | local opts="$@" |
| 1614 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST |
| 1615 | ret=$? |
| 1616 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1617 | test $ret -ne "0" |
| 1618 | ok $? "Track command failed as expected with opts: $opts" |
| 1619 | else |
| 1620 | ok $ret "Track command with opts: $opts" |
| 1621 | fi |
| 1622 | } |
| 1623 | |
| 1624 | function lttng_track_ok() |
| 1625 | { |
| 1626 | lttng_track 0 "$@" |
| 1627 | } |
| 1628 | |
| 1629 | function lttng_track_fail() |
| 1630 | { |
| 1631 | lttng_track 1 "$@" |
| 1632 | } |
| 1633 | |
| 1634 | function lttng_untrack() |
| 1635 | { |
| 1636 | local expected_to_fail="$1" |
| 1637 | shift 1 |
| 1638 | local opts="$@" |
| 1639 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST |
| 1640 | ret=$? |
| 1641 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1642 | test $ret -ne "0" |
| 1643 | ok $? "Untrack command failed as expected with opts: $opts" |
| 1644 | else |
| 1645 | ok $ret "Untrack command with opts: $opts" |
| 1646 | fi |
| 1647 | } |
| 1648 | |
| 1649 | function lttng_untrack_ok() |
| 1650 | { |
| 1651 | lttng_untrack 0 "$@" |
| 1652 | } |
| 1653 | |
| 1654 | function lttng_untrack_fail() |
| 1655 | { |
| 1656 | lttng_untrack 1 "$@" |
| 1657 | } |
| 1658 | |
| 1659 | function lttng_track_pid_ok() |
| 1660 | { |
| 1661 | PID=$1 |
| 1662 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1663 | ok $? "Lttng track pid on the kernel domain" |
| 1664 | } |
| 1665 | |
| 1666 | function lttng_untrack_kernel_all_ok() |
| 1667 | { |
| 1668 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1669 | ok $? "Lttng untrack all pid on the kernel domain" |
| 1670 | } |
| 1671 | |
| 1672 | function lttng_track_ust_ok() |
| 1673 | { |
| 1674 | lttng_track_ok -u "$@" |
| 1675 | } |
| 1676 | |
| 1677 | function lttng_track_ust_fail() |
| 1678 | { |
| 1679 | lttng_track_fail -u "$@" |
| 1680 | } |
| 1681 | |
| 1682 | function lttng_track_kernel_ok() |
| 1683 | { |
| 1684 | lttng_track_ok -k "$@" |
| 1685 | } |
| 1686 | |
| 1687 | function lttng_track_kernel_fail() |
| 1688 | { |
| 1689 | lttng_track_fail -k "$@" |
| 1690 | } |
| 1691 | |
| 1692 | function lttng_untrack_ust_ok() |
| 1693 | { |
| 1694 | lttng_untrack_ok -u "$@" |
| 1695 | } |
| 1696 | |
| 1697 | function lttng_untrack_ust_fail() |
| 1698 | { |
| 1699 | lttng_untrack_fail -u "$@" |
| 1700 | } |
| 1701 | |
| 1702 | function lttng_untrack_kernel_ok() |
| 1703 | { |
| 1704 | lttng_untrack_ok -k "$@" |
| 1705 | } |
| 1706 | |
| 1707 | function lttng_untrack_kernel_fail() |
| 1708 | { |
| 1709 | lttng_untrack_fail -k "$@" |
| 1710 | } |
| 1711 | |
| 1712 | function lttng_add_context_list() |
| 1713 | { |
| 1714 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1715 | ret=$? |
| 1716 | ok $ret "Context listing" |
| 1717 | } |
| 1718 | |
| 1719 | function add_context_lttng() |
| 1720 | { |
| 1721 | local expected_to_fail="$1" |
| 1722 | local domain="$2" |
| 1723 | local session_name="$3" |
| 1724 | local channel_name="$4" |
| 1725 | local type="$5" |
| 1726 | |
| 1727 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 1728 | ret=$? |
| 1729 | if [[ $expected_to_fail -eq "1" ]]; then |
| 1730 | test $ret -ne "0" |
| 1731 | ok $? "Add context command failed as expected for type: $type" |
| 1732 | else |
| 1733 | ok $ret "Add context command for type: $type" |
| 1734 | fi |
| 1735 | } |
| 1736 | |
| 1737 | function add_context_ust_ok() |
| 1738 | { |
| 1739 | add_context_lttng 0 -u "$@" |
| 1740 | } |
| 1741 | |
| 1742 | function add_context_ust_fail() |
| 1743 | { |
| 1744 | add_context_lttng 1 -u "$@" |
| 1745 | } |
| 1746 | |
| 1747 | function add_context_kernel_ok() |
| 1748 | { |
| 1749 | add_context_lttng 0 -k "$@" |
| 1750 | } |
| 1751 | |
| 1752 | function add_context_kernel_fail() |
| 1753 | { |
| 1754 | add_context_lttng 1 -k "$@" |
| 1755 | } |
| 1756 | |
| 1757 | function wait_live_trace_ready () |
| 1758 | { |
| 1759 | local url=$1 |
| 1760 | local zero_client_match=0 |
| 1761 | |
| 1762 | diag "Waiting for live trace at url: $url" |
| 1763 | while [ $zero_client_match -eq 0 ]; do |
| 1764 | zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l) |
| 1765 | sleep 0.5 |
| 1766 | done |
| 1767 | pass "Waiting for live trace at url: $url" |
| 1768 | } |
| 1769 | |
| 1770 | function wait_live_viewer_connect () |
| 1771 | { |
| 1772 | local url=$1 |
| 1773 | local one_client_match=0 |
| 1774 | |
| 1775 | diag "Waiting for live viewers on url: $url" |
| 1776 | while [ $one_client_match -eq 0 ]; do |
| 1777 | one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l) |
| 1778 | sleep 0.5 |
| 1779 | done |
| 1780 | pass "Waiting for live viewers on url: $url" |
| 1781 | } |
| 1782 | |
| 1783 | function validate_metadata_event () |
| 1784 | { |
| 1785 | local event_name=$1 |
| 1786 | local nr_event_id=$2 |
| 1787 | local trace_path=$3 |
| 1788 | |
| 1789 | local metadata_file=$(find $trace_path -name "metadata") |
| 1790 | local metadata_path=$(dirname $metadata_file) |
| 1791 | |
| 1792 | which $BABELTRACE_BIN >/dev/null |
| 1793 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
| 1794 | |
| 1795 | local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l) |
| 1796 | |
| 1797 | if [ "$count" -ne "$nr_event_id" ]; then |
| 1798 | fail "Metadata match with the metadata of $count event(s) named $event_name" |
| 1799 | diag "$count matching event id found in metadata" |
| 1800 | else |
| 1801 | pass "Metadata match with the metadata of $count event(s) named $event_name" |
| 1802 | fi |
| 1803 | |
| 1804 | } |
| 1805 | |
| 1806 | function trace_matches () |
| 1807 | { |
| 1808 | local event_name=$1 |
| 1809 | local nr_iter=$2 |
| 1810 | local trace_path=$3 |
| 1811 | |
| 1812 | which $BABELTRACE_BIN >/dev/null |
| 1813 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
| 1814 | |
| 1815 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
| 1816 | |
| 1817 | if [ "$count" -ne "$nr_iter" ]; then |
| 1818 | fail "Trace match" |
| 1819 | diag "$count matching events found in trace" |
| 1820 | else |
| 1821 | pass "Trace match" |
| 1822 | fi |
| 1823 | } |
| 1824 | |
| 1825 | function trace_match_only() |
| 1826 | { |
| 1827 | local event_name=$1 |
| 1828 | local nr_iter=$2 |
| 1829 | local trace_path=$3 |
| 1830 | |
| 1831 | which $BABELTRACE_BIN >/dev/null |
| 1832 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
| 1833 | |
| 1834 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
| 1835 | local total=$($BABELTRACE_BIN $trace_path | wc -l) |
| 1836 | |
| 1837 | if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then |
| 1838 | pass "Trace match with $total event $event_name" |
| 1839 | else |
| 1840 | fail "Trace match" |
| 1841 | diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" |
| 1842 | fi |
| 1843 | } |
| 1844 | |
| 1845 | function validate_trace |
| 1846 | { |
| 1847 | local event_name=$1 |
| 1848 | local trace_path=$2 |
| 1849 | |
| 1850 | which $BABELTRACE_BIN >/dev/null |
| 1851 | if [ $? -ne 0 ]; then |
| 1852 | skip 0 "Babeltrace binary not found. Skipping trace validation" |
| 1853 | fi |
| 1854 | |
| 1855 | OLDIFS=$IFS |
| 1856 | IFS="," |
| 1857 | for i in $event_name; do |
| 1858 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) |
| 1859 | if [ "$traced" -ne 0 ]; then |
| 1860 | pass "Validate trace for event $i, $traced events" |
| 1861 | else |
| 1862 | fail "Validate trace for event $i" |
| 1863 | diag "Found $traced occurences of $i" |
| 1864 | fi |
| 1865 | done |
| 1866 | ret=$? |
| 1867 | IFS=$OLDIFS |
| 1868 | return $ret |
| 1869 | } |
| 1870 | |
| 1871 | function validate_trace_count |
| 1872 | { |
| 1873 | local event_name=$1 |
| 1874 | local trace_path=$2 |
| 1875 | local expected_count=$3 |
| 1876 | |
| 1877 | which $BABELTRACE_BIN >/dev/null |
| 1878 | if [ $? -ne 0 ]; then |
| 1879 | skip 0 "Babeltrace binary not found. Skipping trace validation" |
| 1880 | fi |
| 1881 | |
| 1882 | cnt=0 |
| 1883 | OLDIFS=$IFS |
| 1884 | IFS="," |
| 1885 | for i in $event_name; do |
| 1886 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) |
| 1887 | if [ "$traced" -ne 0 ]; then |
| 1888 | pass "Validate trace for event $i, $traced events" |
| 1889 | else |
| 1890 | fail "Validate trace for event $i" |
| 1891 | diag "Found $traced occurences of $i" |
| 1892 | fi |
| 1893 | cnt=$(($cnt + $traced)) |
| 1894 | done |
| 1895 | IFS=$OLDIFS |
| 1896 | test $cnt -eq $expected_count |
| 1897 | ok $? "Read a total of $cnt events, expected $expected_count" |
| 1898 | } |
| 1899 | |
| 1900 | function validate_trace_count_range_incl_min_excl_max |
| 1901 | { |
| 1902 | local event_name=$1 |
| 1903 | local trace_path=$2 |
| 1904 | local expected_min=$3 |
| 1905 | local expected_max=$4 |
| 1906 | |
| 1907 | which $BABELTRACE_BIN >/dev/null |
| 1908 | if [ $? -ne 0 ]; then |
| 1909 | skip 0 "Babeltrace binary not found. Skipping trace validation" |
| 1910 | fi |
| 1911 | |
| 1912 | cnt=0 |
| 1913 | OLDIFS=$IFS |
| 1914 | IFS="," |
| 1915 | for i in $event_name; do |
| 1916 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) |
| 1917 | if [ "$traced" -ge $expected_min ]; then |
| 1918 | pass "Validate trace for event $i, $traced events" |
| 1919 | else |
| 1920 | fail "Validate trace for event $i" |
| 1921 | diag "Found $traced occurences of $i" |
| 1922 | fi |
| 1923 | cnt=$(($cnt + $traced)) |
| 1924 | done |
| 1925 | IFS=$OLDIFS |
| 1926 | test $cnt -lt $expected_max |
| 1927 | ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max[" |
| 1928 | } |
| 1929 | |
| 1930 | function trace_first_line |
| 1931 | { |
| 1932 | local trace_path=$1 |
| 1933 | |
| 1934 | which $BABELTRACE_BIN >/dev/null |
| 1935 | if [ $? -ne 0 ]; then |
| 1936 | skip 0 "Babeltrace binary not found. Skipping trace validation" |
| 1937 | fi |
| 1938 | |
| 1939 | $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1 |
| 1940 | } |
| 1941 | |
| 1942 | function validate_trace_exp() |
| 1943 | { |
| 1944 | local event_exp=$1 |
| 1945 | local trace_path=$2 |
| 1946 | |
| 1947 | which $BABELTRACE_BIN >/dev/null |
| 1948 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation" |
| 1949 | |
| 1950 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l) |
| 1951 | if [ "$traced" -ne 0 ]; then |
| 1952 | pass "Validate trace for expression '${event_exp}', $traced events" |
| 1953 | else |
| 1954 | fail "Validate trace for expression '${event_exp}'" |
| 1955 | diag "Found $traced occurences of '${event_exp}'" |
| 1956 | fi |
| 1957 | ret=$? |
| 1958 | return $ret |
| 1959 | } |
| 1960 | |
| 1961 | function validate_trace_only_exp() |
| 1962 | { |
| 1963 | local event_exp=$1 |
| 1964 | local trace_path=$2 |
| 1965 | |
| 1966 | which $BABELTRACE_BIN >/dev/null |
| 1967 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
| 1968 | |
| 1969 | local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l) |
| 1970 | local total=$($BABELTRACE_BIN $trace_path | wc -l) |
| 1971 | |
| 1972 | if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then |
| 1973 | pass "Trace match with $total for expression '${event_exp}'" |
| 1974 | else |
| 1975 | fail "Trace match" |
| 1976 | diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" |
| 1977 | fi |
| 1978 | ret=$? |
| 1979 | return $ret |
| 1980 | } |
| 1981 | |
| 1982 | function validate_trace_empty() |
| 1983 | { |
| 1984 | local trace_path=$1 |
| 1985 | |
| 1986 | which $BABELTRACE_BIN >/dev/null |
| 1987 | if [ $? -ne 0 ]; then |
| 1988 | skip 0 "Babeltrace binary not found. Skipping trace validation" |
| 1989 | fi |
| 1990 | |
| 1991 | events=$($BABELTRACE_BIN $trace_path 2>/dev/null) |
| 1992 | ret=$? |
| 1993 | if [ $ret -ne 0 ]; then |
| 1994 | fail "Failed to parse trace" |
| 1995 | return $ret |
| 1996 | fi |
| 1997 | |
| 1998 | traced=$(echo -n "$events" | wc -l) |
| 1999 | if [ "$traced" -eq 0 ]; then |
| 2000 | pass "Validate empty trace" |
| 2001 | else |
| 2002 | fail "Validate empty trace" |
| 2003 | diag "Found $traced events in trace" |
| 2004 | fi |
| 2005 | ret=$? |
| 2006 | return $ret |
| 2007 | } |
| 2008 | |
| 2009 | function validate_directory_empty () |
| 2010 | { |
| 2011 | local trace_path="$1" |
| 2012 | |
| 2013 | # Do not double quote `$trace_path` below as we want wildcards to be |
| 2014 | # expanded. |
| 2015 | files="$(ls -A $trace_path)" |
| 2016 | ret=$? |
| 2017 | if [ $ret -ne 0 ]; then |
| 2018 | fail "Failed to list content of directory \"$trace_path\"" |
| 2019 | return $ret |
| 2020 | fi |
| 2021 | |
| 2022 | nb_files="$(echo -n "$files" | wc -l)" |
| 2023 | ok $nb_files "Directory \"$trace_path\" is empty" |
| 2024 | } |
| 2025 | |
| 2026 | function validate_trace_session_ust_empty() |
| 2027 | { |
| 2028 | validate_directory_empty "$1"/ust |
| 2029 | } |
| 2030 | |
| 2031 | function validate_trace_session_kernel_empty() |
| 2032 | { |
| 2033 | validate_trace_empty "$1"/kernel |
| 2034 | } |
| 2035 | |
| 2036 | function regenerate_metadata () |
| 2037 | { |
| 2038 | local expected_to_fail=$1 |
| 2039 | local sess_name=$2 |
| 2040 | |
| 2041 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2042 | ret=$? |
| 2043 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2044 | test "$ret" -ne "0" |
| 2045 | ok $? "Expected fail on regenerate metadata $sess_name" |
| 2046 | else |
| 2047 | ok $ret "Metadata regenerate $sess_name" |
| 2048 | fi |
| 2049 | } |
| 2050 | |
| 2051 | function regenerate_metadata_ok () |
| 2052 | { |
| 2053 | regenerate_metadata 0 "$@" |
| 2054 | } |
| 2055 | |
| 2056 | function regenerate_metadata_fail () |
| 2057 | { |
| 2058 | regenerate_metadata 1 "$@" |
| 2059 | } |
| 2060 | |
| 2061 | function regenerate_statedump () |
| 2062 | { |
| 2063 | local expected_to_fail=$1 |
| 2064 | local sess_name=$2 |
| 2065 | |
| 2066 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2067 | ret=$? |
| 2068 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2069 | test "$ret" -ne "0" |
| 2070 | ok $? "Expected fail on regenerate statedump $sess_name" |
| 2071 | else |
| 2072 | ok $ret "Statedump regenerate $sess_name" |
| 2073 | fi |
| 2074 | } |
| 2075 | |
| 2076 | function regenerate_statedump_ok () |
| 2077 | { |
| 2078 | regenerate_statedump 0 "$@" |
| 2079 | } |
| 2080 | |
| 2081 | function regenerate_statedump_fail () |
| 2082 | { |
| 2083 | regenerate_statedump 1 "$@" |
| 2084 | } |
| 2085 | |
| 2086 | function rotate_session () |
| 2087 | { |
| 2088 | local expected_to_fail=$1 |
| 2089 | local sess_name=$2 |
| 2090 | |
| 2091 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2092 | ret=$? |
| 2093 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2094 | test "$ret" -ne "0" |
| 2095 | ok $? "Expected fail on rotate session $sess_name" |
| 2096 | else |
| 2097 | ok $ret "Rotate session $sess_name" |
| 2098 | fi |
| 2099 | } |
| 2100 | |
| 2101 | function rotate_session_ok () |
| 2102 | { |
| 2103 | rotate_session 0 "$@" |
| 2104 | } |
| 2105 | |
| 2106 | function rotate_session_fail () |
| 2107 | { |
| 2108 | rotate_session 1 "$@" |
| 2109 | } |
| 2110 | |
| 2111 | function destructive_tests_enabled () |
| 2112 | { |
| 2113 | if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then |
| 2114 | return 0 |
| 2115 | else |
| 2116 | return 1 |
| 2117 | fi |
| 2118 | } |
| 2119 | |
| 2120 | function lttng_enable_rotation_timer () |
| 2121 | { |
| 2122 | local expected_to_fail=$1 |
| 2123 | local sess_name=$2 |
| 2124 | local period=$3 |
| 2125 | |
| 2126 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2127 | ret=$? |
| 2128 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2129 | test "$ret" -ne "0" |
| 2130 | ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name" |
| 2131 | else |
| 2132 | ok $ret "Set periodic rotation ($period) of session $sess_name" |
| 2133 | fi |
| 2134 | } |
| 2135 | |
| 2136 | function lttng_enable_rotation_timer_ok () |
| 2137 | { |
| 2138 | lttng_enable_rotation_timer 0 $@ |
| 2139 | } |
| 2140 | |
| 2141 | function lttng_enable_rotation_timer_fail () |
| 2142 | { |
| 2143 | lttng_enable_rotation_timer 1 $@ |
| 2144 | } |
| 2145 | |
| 2146 | function lttng_enable_rotation_size () |
| 2147 | { |
| 2148 | local expected_to_fail=$1 |
| 2149 | local sess_name=$2 |
| 2150 | local size=$3 |
| 2151 | |
| 2152 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2153 | ret=$? |
| 2154 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2155 | test "$ret" -ne "0" |
| 2156 | ok $? "Expected fail on rotate session $sess_name" |
| 2157 | else |
| 2158 | ok $ret "Rotate session $sess_name" |
| 2159 | fi |
| 2160 | } |
| 2161 | |
| 2162 | function lttng_enable_rotation_size_ok () |
| 2163 | { |
| 2164 | lttng_enable_rotation_size 0 $@ |
| 2165 | } |
| 2166 | |
| 2167 | function lttng_enable_rotation_size_fail () |
| 2168 | { |
| 2169 | lttng_enable_rotation_size 1 $@ |
| 2170 | } |
| 2171 | |
| 2172 | function lttng_clear_session () |
| 2173 | { |
| 2174 | local expected_to_fail=$1 |
| 2175 | local sess_name=$2 |
| 2176 | |
| 2177 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2178 | ret=$? |
| 2179 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2180 | test "$ret" -ne "0" |
| 2181 | ok $? "Expected fail on clear session $sess_name" |
| 2182 | else |
| 2183 | ok $ret "Clear session $sess_name" |
| 2184 | fi |
| 2185 | } |
| 2186 | |
| 2187 | function lttng_clear_session_ok () |
| 2188 | { |
| 2189 | lttng_clear_session 0 $@ |
| 2190 | } |
| 2191 | |
| 2192 | function lttng_clear_session_fail () |
| 2193 | { |
| 2194 | lttng_clear_session 1 $@ |
| 2195 | } |
| 2196 | |
| 2197 | function lttng_clear_all () |
| 2198 | { |
| 2199 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN clear --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
| 2200 | ok $? "Clear all lttng sessions" |
| 2201 | } |
| 2202 | |
| 2203 | function lttng_add_trigger() |
| 2204 | { |
| 2205 | local expected_to_fail="$1" |
| 2206 | local trigger_name="$2" |
| 2207 | shift 2 |
| 2208 | local args=("$@") |
| 2209 | |
| 2210 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}" |
| 2211 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name "$trigger_name" "${args[@]}" 1> /dev/null 2> /dev/null |
| 2212 | ret=$? |
| 2213 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2214 | test "$ret" -ne "0" |
| 2215 | ok $? "Add trigger $trigger_name failed as expected" |
| 2216 | else |
| 2217 | ok $ret "Add trigger $trigger_name" |
| 2218 | fi |
| 2219 | } |
| 2220 | |
| 2221 | function lttng_remove_trigger() |
| 2222 | { |
| 2223 | local expected_to_fail="$1" |
| 2224 | local trigger_name="$2" |
| 2225 | shift 2 |
| 2226 | |
| 2227 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*" |
| 2228 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger "$trigger_name" "$@" 1> /dev/null 2> /dev/null |
| 2229 | ret=$? |
| 2230 | if [[ $expected_to_fail -eq "1" ]]; then |
| 2231 | test "$ret" -ne "0" |
| 2232 | ok $? "Remove trigger $trigger_name failed as expected" |
| 2233 | else |
| 2234 | ok $ret "Remove trigger $trigger_name" |
| 2235 | fi |
| 2236 | } |
| 2237 | |
| 2238 | function lttng_add_trigger_ok() |
| 2239 | { |
| 2240 | lttng_add_trigger 0 "$@" |
| 2241 | } |
| 2242 | |
| 2243 | function lttng_add_trigger_fail() |
| 2244 | { |
| 2245 | lttng_add_trigger 1 "$@" |
| 2246 | } |
| 2247 | |
| 2248 | function lttng_remove_trigger_ok() |
| 2249 | { |
| 2250 | lttng_remove_trigger 0 "$@" |
| 2251 | } |
| 2252 | |
| 2253 | function list_triggers_matches_ok () |
| 2254 | { |
| 2255 | local tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") |
| 2256 | local tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX") |
| 2257 | |
| 2258 | local test_name="$1" |
| 2259 | local expected_stdout_file="$2" |
| 2260 | |
| 2261 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers" |
| 2262 | |
| 2263 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}" |
| 2264 | ok $? "${test_name}: exit code is 0" |
| 2265 | |
| 2266 | diff -u "${expected_stdout_file}" "${tmp_stdout}" |
| 2267 | ok $? "${test_name}: expected stdout" |
| 2268 | |
| 2269 | diff -u /dev/null "${tmp_stderr}" |
| 2270 | ok $? "${test_name}: expected stderr" |
| 2271 | |
| 2272 | rm -f "${tmp_stdout}" |
| 2273 | rm -f "${tmp_stderr}" |
| 2274 | } |
| 2275 | |
| 2276 | function list_triggers_matches_mi_ok () |
| 2277 | { |
| 2278 | local tmp_stdout |
| 2279 | local tmp_stdout_raw |
| 2280 | local tmp_stderr |
| 2281 | |
| 2282 | local test_name="$1" |
| 2283 | local expected_stdout_file="$2" |
| 2284 | |
| 2285 | tmp_stdout_raw=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") |
| 2286 | tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") |
| 2287 | tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX") |
| 2288 | |
| 2289 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers" |
| 2290 | |
| 2291 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers > "${tmp_stdout_raw}" 2> "${tmp_stderr}" |
| 2292 | ok $? "${test_name}: exit code is 0" |
| 2293 | |
| 2294 | # Pretty-fy xml before further test. |
| 2295 | $XML_PRETTY_BIN < "${tmp_stdout_raw}" > "${tmp_stdout}" |
| 2296 | |
| 2297 | $XML_VALIDATE_BIN "${MI_XSD_PATH}" "${tmp_stdout}" |
| 2298 | ok $? "list-trigger mi is valid" |
| 2299 | |
| 2300 | diff -u "${expected_stdout_file}" "${tmp_stdout}" |
| 2301 | ok $? "${test_name}: expected stdout" |
| 2302 | |
| 2303 | diff -u /dev/null "${tmp_stderr}" |
| 2304 | ok $? "${test_name}: expected stderr" |
| 2305 | |
| 2306 | rm -f "${tmp_stdout}" |
| 2307 | rm -f "${tmp_stdout_raw}" |
| 2308 | rm -f "${tmp_stderr}" |
| 2309 | } |
| 2310 | |
| 2311 | function validate_path_pattern () |
| 2312 | { |
| 2313 | local message=$1 |
| 2314 | local pattern=$2 |
| 2315 | # Base path is only used in error case and is used to list the content |
| 2316 | # of the base path. |
| 2317 | local base_path=$3 |
| 2318 | |
| 2319 | |
| 2320 | [ -f $pattern ] |
| 2321 | ret=$? |
| 2322 | ok $ret "$message" |
| 2323 | |
| 2324 | if [ "$ret" -ne "0" ]; then |
| 2325 | diag "Path pattern expected: $pattern" |
| 2326 | # List the tracepath for more info. We use find as a recursive |
| 2327 | # directory lister. |
| 2328 | diag "The base path content:" |
| 2329 | find "$base_path" -print |
| 2330 | fi |
| 2331 | } |
| 2332 | |
| 2333 | function validate_trace_path_ust_uid () |
| 2334 | { |
| 2335 | local trace_path=$1 |
| 2336 | local session_name=$2 |
| 2337 | local uid=$UID |
| 2338 | local pattern="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata" |
| 2339 | |
| 2340 | validate_path_pattern "UST per-uid trace path is valid" "$pattern" "$trace_path" |
| 2341 | } |
| 2342 | |
| 2343 | function validate_trace_path_ust_uid_network () |
| 2344 | { |
| 2345 | local trace_path=$1 |
| 2346 | local session_name=$2 |
| 2347 | local base_path=$3 |
| 2348 | local uid=$UID |
| 2349 | local hostname=$HOSTNAME |
| 2350 | local pattern |
| 2351 | local ret |
| 2352 | |
| 2353 | # If the session was given a network base path (e.g |
| 2354 | # 127.0.0.1/my/custom/path on creation, there is no session name |
| 2355 | # component to the path on the relayd side. Caller can simply not pass a |
| 2356 | # session name for this scenario. |
| 2357 | if [ -n "$session_name" ]; then |
| 2358 | session_name="$session_name-$date_time_pattern" |
| 2359 | if [ -n "$base_path" ]; then |
| 2360 | fail "Session name and base path are mutually exclusive" |
| 2361 | return |
| 2362 | fi |
| 2363 | fi |
| 2364 | |
| 2365 | pattern="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata" |
| 2366 | |
| 2367 | validate_path_pattern "UST per-uid network trace path is valid" "$pattern" "$trace_path" |
| 2368 | } |
| 2369 | |
| 2370 | function validate_trace_path_ust_uid_snapshot_network () |
| 2371 | { |
| 2372 | local trace_path=$1 |
| 2373 | local session_name=$2 |
| 2374 | local snapshot_name=$3 |
| 2375 | local snapshot_number=$4 |
| 2376 | local base_path=$5 |
| 2377 | local hostname=$HOSTNAME |
| 2378 | local uid=$UID |
| 2379 | local pattern |
| 2380 | local ret |
| 2381 | |
| 2382 | # If the session/output was given a network base path (e.g |
| 2383 | # 127.0.0.1/my/custom/path on creation, there is no session name |
| 2384 | # component to the path on the relayd side. Caller can simply not pass a |
| 2385 | # session name for this scenario. |
| 2386 | if [ -n "$session_name" ]; then |
| 2387 | session_name="$session_name-$date_time_pattern" |
| 2388 | if [ -n "$base_path" ]; then |
| 2389 | fail "Session name and base path are mutually exclusive" |
| 2390 | return |
| 2391 | fi |
| 2392 | fi |
| 2393 | |
| 2394 | pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata" |
| 2395 | |
| 2396 | validate_path_pattern "UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path" |
| 2397 | } |
| 2398 | |
| 2399 | function validate_trace_path_ust_uid_snapshot () |
| 2400 | { |
| 2401 | local trace_path=$1 |
| 2402 | local session_name=$2 |
| 2403 | local snapshot_name=$3 |
| 2404 | local snapshot_number=$4 |
| 2405 | local base_path=$5 |
| 2406 | local uid=$UID |
| 2407 | local pattern |
| 2408 | local ret |
| 2409 | |
| 2410 | # If the session/output was given a network base path (e.g |
| 2411 | # 127.0.0.1/my/custom/path) on creation, there is no session name |
| 2412 | # component to the path on the relayd side. Caller can simply not pass a |
| 2413 | # session name for this scenario. |
| 2414 | if [ -n "$session_name" ]; then |
| 2415 | session_name="$session_name-$date_time_pattern" |
| 2416 | if [ -n "$base_path" ]; then |
| 2417 | fail "Session name and base path are mutually exclusive" |
| 2418 | return |
| 2419 | fi |
| 2420 | fi |
| 2421 | |
| 2422 | pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata" |
| 2423 | |
| 2424 | validate_path_pattern "UST per-uid snapshot trace path is valid" "$pattern" "$trace_path" |
| 2425 | } |
| 2426 | |
| 2427 | function validate_trace_path_ust_pid () |
| 2428 | { |
| 2429 | local trace_path=$1 |
| 2430 | local session_name=$2 |
| 2431 | local app_string=$3 |
| 2432 | local pid=$4 |
| 2433 | local pattern |
| 2434 | local ret |
| 2435 | |
| 2436 | # If the session was given a trace path on creation, there is no session |
| 2437 | # name component to the path. Caller can simply not pass a session name |
| 2438 | # for this scenario. |
| 2439 | if [ -n "$session_name" ]; then |
| 2440 | session_name="$session_name-$date_time_pattern" |
| 2441 | fi |
| 2442 | |
| 2443 | pattern="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata" |
| 2444 | |
| 2445 | validate_path_pattern "UST per-pid trace path is valid" "$pattern" "$trace_path" |
| 2446 | } |
| 2447 | |
| 2448 | function validate_trace_path_kernel () |
| 2449 | { |
| 2450 | local trace_path=$1 |
| 2451 | local session_name=$2 |
| 2452 | local pattern |
| 2453 | |
| 2454 | # If the session was given a trace path on creation, there is no session |
| 2455 | # name component to the path. Caller can simply not pass a session name |
| 2456 | # for this scenario. |
| 2457 | if [ -n "$session_name" ]; then |
| 2458 | session_name="$session_name-$date_time_pattern" |
| 2459 | fi |
| 2460 | |
| 2461 | pattern="$trace_path/$session_name/kernel/metadata" |
| 2462 | |
| 2463 | validate_path_pattern "Kernel trace path is valid" "$pattern" "$trace_path" |
| 2464 | } |
| 2465 | |
| 2466 | function validate_trace_path_kernel_network () |
| 2467 | { |
| 2468 | local trace_path=$1 |
| 2469 | local session_name=$2 |
| 2470 | local hostname=$HOSTNAME |
| 2471 | local pattern="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata" |
| 2472 | |
| 2473 | validate_path_pattern "Kernel network trace path is valid" "$pattern" "$trace_path" |
| 2474 | } |
| 2475 | |
| 2476 | function validate_trace_path_kernel_snapshot () |
| 2477 | { |
| 2478 | local trace_path=$1 |
| 2479 | local session_name=$2 |
| 2480 | local snapshot_name=$3 |
| 2481 | local snapshot_number=$4 |
| 2482 | local base_path=$5 |
| 2483 | local pattern |
| 2484 | local ret |
| 2485 | |
| 2486 | # If the session/output was given a network base path (e.g |
| 2487 | # 127.0.0.1/my/custom/path on creation, there is no session name |
| 2488 | # component to the path on the relayd side. Caller can simply not pass a |
| 2489 | # session name for this scenario. |
| 2490 | if [ -n "$session_name" ]; then |
| 2491 | session_name="$session_name-$date_time_pattern" |
| 2492 | if [ -n "$base_path" ]; then |
| 2493 | fail "Session name and base path are mutually exclusive" |
| 2494 | return |
| 2495 | fi |
| 2496 | fi |
| 2497 | |
| 2498 | pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata" |
| 2499 | |
| 2500 | validate_path_pattern "Kernel snapshot trace path is valid" "$pattern" "$trace_path" |
| 2501 | } |
| 2502 | |
| 2503 | function validate_trace_path_kernel_snapshot_network () |
| 2504 | { |
| 2505 | local trace_path=$1 |
| 2506 | local session_name=$2 |
| 2507 | local snapshot_name=$3 |
| 2508 | local snapshot_number=$4 |
| 2509 | local base_path=$5 |
| 2510 | local hostname=$HOSTNAME |
| 2511 | local pattern |
| 2512 | local ret |
| 2513 | |
| 2514 | # If the session/output was given a network base path (e.g |
| 2515 | # 127.0.0.1/my/custom/path on creation, there is no session name |
| 2516 | # component to the path on the relayd side. Caller can simply not pass a |
| 2517 | # session name for this scenario. |
| 2518 | if [ -n "$session_name" ]; then |
| 2519 | session_name="$session_name-$date_time_pattern" |
| 2520 | if [ -n "$base_path" ]; then |
| 2521 | fail "Session name and base path are mutually exclusive" |
| 2522 | return |
| 2523 | fi |
| 2524 | fi |
| 2525 | |
| 2526 | pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata" |
| 2527 | |
| 2528 | validate_path_pattern "Kernel network snapshot trace path is valid" "$pattern" "$trace_path" |
| 2529 | } |