| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2020 EfficiOS, inc |
| 4 | # |
| 5 | # This library is free software; you can redistribute it and/or modify it under |
| 6 | # the terms of the GNU Lesser General Public License as published by the Free |
| 7 | # Software Foundation; version 2.1 of the License. |
| 8 | # |
| 9 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 12 | # details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU Lesser General Public License |
| 15 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | |
| 18 | # Test the `lttng add-trigger` command line interface. |
| 19 | |
| 20 | CURDIR="$(dirname "$0")" |
| 21 | TESTDIR="$CURDIR/../../.." |
| 22 | |
| 23 | # shellcheck source=../../../utils/utils.sh |
| 24 | source "$TESTDIR/utils/utils.sh" |
| 25 | |
| 26 | plan_tests 286 |
| 27 | |
| 28 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" |
| 29 | |
| 30 | # shellcheck disable=SC2119 |
| 31 | start_lttng_sessiond_notap |
| 32 | |
| 33 | tmp_stdout=$(mktemp --tmpdir -t test_parse_cli_trigger_stdout.XXXXXX) |
| 34 | tmp_stderr=$(mktemp --tmpdir -t test_parse_cli_trigger_stderr.XXXXXX) |
| 35 | uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary" |
| 36 | |
| 37 | if [ "$(id -u)" == "0" ]; then |
| 38 | ist_root=1 |
| 39 | else |
| 40 | ist_root=0 |
| 41 | fi |
| 42 | |
| 43 | function test_success () |
| 44 | { |
| 45 | local test_name="$1" |
| 46 | local trigger_name="$2" |
| 47 | shift 2 |
| 48 | |
| 49 | diag "${FULL_LTTNG_BIN} add-trigger $*" |
| 50 | set -x |
| 51 | "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" |
| 52 | ok $? "${test_name}: exit code is 0" |
| 53 | set +x |
| 54 | |
| 55 | diff -u "${tmp_stdout}" <(echo "Added trigger \`$trigger_name\`.") |
| 56 | ok $? "${test_name}: expected stdout" |
| 57 | |
| 58 | diff -u "${tmp_stderr}" /dev/null |
| 59 | ok $? "${test_name}: expected stderr" |
| 60 | } |
| 61 | |
| 62 | function test_failure () |
| 63 | { |
| 64 | local test_name="$1" |
| 65 | local error_msg="$2" |
| 66 | |
| 67 | shift 2 |
| 68 | |
| 69 | diag "${FULL_LTTNG_BIN} add-trigger $*" |
| 70 | "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" |
| 71 | isnt $? 0 "${test_name}: exit code is not 0" |
| 72 | |
| 73 | diff -u "${tmp_stdout}" /dev/null |
| 74 | ok $? "${test_name}: expected stdout" |
| 75 | |
| 76 | diff -u "${tmp_stderr}" <(echo "${error_msg}") |
| 77 | ok $? "${test_name}: expected stderr" |
| 78 | } |
| 79 | |
| 80 | function test_mi () |
| 81 | { |
| 82 | local tmp_stdout_raw |
| 83 | local tmp_expected_stdout |
| 84 | |
| 85 | # Concretely the code used to serialize a trigger object is the same as |
| 86 | # the one used by the list command. Here we simply validate that a |
| 87 | # simple trigger is correctly generated. |
| 88 | |
| 89 | tmp_stdout_raw=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") |
| 90 | tmp_expected_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX") |
| 91 | |
| 92 | diag "${FULL_LTTNG_BIN} --mi=xml add-trigger" |
| 93 | |
| 94 | cat > "${tmp_expected_stdout}" <<- EOF |
| 95 | <?xml version="1.0" encoding="UTF-8"?> |
| 96 | <command xmlns="https://lttng.org/xml/ns/lttng-mi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://lttng.org/xml/ns/lttng-mi https://lttng.org/xml/schemas/lttng-mi/${MI_XSD_MAJOR_VERSION}/lttng-mi-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd" schemaVersion="${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}"> |
| 97 | <name>add-trigger</name> |
| 98 | <output> |
| 99 | <trigger> |
| 100 | <name>mi_hohoho</name> |
| 101 | <owner_uid>${UID}</owner_uid> |
| 102 | <condition> |
| 103 | <condition_event_rule_matches> |
| 104 | <event_rule> |
| 105 | <event_rule_user_tracepoint> |
| 106 | <name_pattern>some-event-id</name_pattern> |
| 107 | </event_rule_user_tracepoint> |
| 108 | </event_rule> |
| 109 | <capture_descriptors/> |
| 110 | </condition_event_rule_matches> |
| 111 | </condition> |
| 112 | <action> |
| 113 | <action_list> |
| 114 | <action> |
| 115 | <action_notify> |
| 116 | <rate_policy> |
| 117 | <rate_policy_every_n> |
| 118 | <interval>1</interval> |
| 119 | </rate_policy_every_n> |
| 120 | </rate_policy> |
| 121 | </action_notify> |
| 122 | </action> |
| 123 | </action_list> |
| 124 | </action> |
| 125 | </trigger> |
| 126 | </output> |
| 127 | <success>true</success> |
| 128 | </command> |
| 129 | EOF |
| 130 | |
| 131 | "${FULL_LTTNG_BIN}" --mi xml add-trigger --name mi_hohoho \ |
| 132 | --condition event-rule-matches --name=some-event-id --type=user \ |
| 133 | --action notify > "${tmp_stdout_raw}" 2> "${tmp_stderr}" |
| 134 | |
| 135 | ok $? "add-trigger mi: exit code is 0" |
| 136 | |
| 137 | # Pretty-fy xml before further test. |
| 138 | $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}" |
| 139 | |
| 140 | $MI_VALIDATE "${tmp_stdout}" |
| 141 | ok $? "add-trigger mi is valid" |
| 142 | |
| 143 | diff -u "${tmp_expected_stdout}" "${tmp_stdout}" |
| 144 | ok $? "mi: expected stdout" |
| 145 | |
| 146 | diff -u "${tmp_stderr}" /dev/null |
| 147 | ok $? "mi: expected stderr" |
| 148 | |
| 149 | rm -f "${tmp_stdout_raw}" |
| 150 | } |
| 151 | |
| 152 | # top-level options |
| 153 | test_success "explicit name" "hohoho" \ |
| 154 | --name hohoho \ |
| 155 | --condition event-rule-matches --type=user \ |
| 156 | --action notify |
| 157 | |
| 158 | # `--condition event-rule-matches` successes |
| 159 | test_success "--condition event-rule-matches some-event --type=user" \ |
| 160 | "some-event" \ |
| 161 | --name=some-event --condition event-rule-matches --type=user \ |
| 162 | --action notify |
| 163 | |
| 164 | test_success "--condition event-rule-matches --type=user" "trigger0" \ |
| 165 | --condition event-rule-matches --type=user \ |
| 166 | --action notify |
| 167 | |
| 168 | test_success "notify action policies" "test-rate-policy-1" \ |
| 169 | --name=test-rate-policy-1 \ |
| 170 | --condition event-rule-matches --type=user \ |
| 171 | --action notify \ |
| 172 | --rate-policy=every:55 \ |
| 173 | --action notify \ |
| 174 | --rate-policy=once-after:55 |
| 175 | |
| 176 | test_success "start session action policies" "test-rate-policy-2" \ |
| 177 | --name=test-rate-policy-2 \ |
| 178 | --condition event-rule-matches --type=user \ |
| 179 | --action start-session my_session \ |
| 180 | --rate-policy=every:55 \ |
| 181 | --action start-session my_session \ |
| 182 | --rate-policy=once-after:55 |
| 183 | |
| 184 | test_success "stop session action policies" "test-rate-policy-3" \ |
| 185 | --name=test-rate-policy-3 \ |
| 186 | --condition event-rule-matches --type=user \ |
| 187 | --action stop-session my_session \ |
| 188 | --rate-policy=every:55 \ |
| 189 | --action stop-session my_session \ |
| 190 | --rate-policy=once-after:55 |
| 191 | |
| 192 | test_success "snapshot session action policies" "test-rate-policy-4" \ |
| 193 | --name=test-rate-policy-4 \ |
| 194 | --condition event-rule-matches --type=user \ |
| 195 | --action snapshot-session my_session \ |
| 196 | --rate-policy=every:55 \ |
| 197 | --action snapshot-session my_session \ |
| 198 | --rate-policy=once-after:55 |
| 199 | |
| 200 | test_success "rotate session action policies" "test-rate-policy-5" \ |
| 201 | --name=test-rate-policy-5 \ |
| 202 | --condition event-rule-matches --type=user \ |
| 203 | --action rotate-session my_session \ |
| 204 | --rate-policy=every:55 \ |
| 205 | --action rotate-session my_session \ |
| 206 | --rate-policy=once-after:55 |
| 207 | |
| 208 | test_success "--log-level single level" "trigger1" \ |
| 209 | --condition event-rule-matches --type=user --log-level=INFO \ |
| 210 | --action notify |
| 211 | |
| 212 | test_success "--log-level range open max" "trigger2" \ |
| 213 | --condition event-rule-matches --type=user --log-level=INFO.. \ |
| 214 | --action notify |
| 215 | |
| 216 | test_success "--log-level range any" "trigger3" \ |
| 217 | --condition event-rule-matches --type=user --log-level=.. \ |
| 218 | --action notify |
| 219 | |
| 220 | test_success "--exclude-name one" "trigger4" \ |
| 221 | --condition event-rule-matches --type=user --name='bernard*' --exclude-name=bernard-lermite \ |
| 222 | --action notify |
| 223 | |
| 224 | test_success "--exclude-name two" "trigger5" \ |
| 225 | --condition event-rule-matches --type=user --name='jean-*' --exclude-name jean-chretien -x jean-charest \ |
| 226 | --action notify |
| 227 | |
| 228 | skip $ist_root "non-root user: skipping kprobe tests" 18 || { |
| 229 | i=0 |
| 230 | |
| 231 | for type in kprobe kernel:kprobe; do |
| 232 | test_success "--condition event-rule-matches probe by symbol" "kprobe-trigger-$i" \ |
| 233 | --name="kprobe-trigger-$i" \ |
| 234 | --condition event-rule-matches --type=$type --location=lttng_channel_enable --event-name=my_channel_enable \ |
| 235 | --action notify |
| 236 | |
| 237 | channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') |
| 238 | channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') |
| 239 | |
| 240 | # We need to find a valid offset. |
| 241 | base_symbol="" |
| 242 | offset=0 |
| 243 | if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then |
| 244 | base_symbol="lttng_channel_enable" |
| 245 | offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr )) |
| 246 | else |
| 247 | base_symbol="lttng_channel_disable" |
| 248 | offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr )) |
| 249 | fi |
| 250 | |
| 251 | offset_hex="0x$(printf '%x' $offset)" |
| 252 | |
| 253 | |
| 254 | test_success "--condition event-rule-matches probe by symbol with offset" "kprobe-trigger-$((i+1))" \ |
| 255 | --name="kprobe-trigger-$((i+1))" \ |
| 256 | --condition event-rule-matches --type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \ |
| 257 | --action notify |
| 258 | |
| 259 | test_success "--condition event-rule-matches probe by address" "kprobe-trigger-$((i+2))" \ |
| 260 | --name="kprobe-trigger-$((i+2))" \ |
| 261 | --condition event-rule-matches --type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \ |
| 262 | --action notify |
| 263 | i=$((i+3)) |
| 264 | done |
| 265 | } |
| 266 | |
| 267 | skip $ist_root "non-root user: skipping uprobe tests" 6 || { |
| 268 | test_success "--condition event-rule-matches uprobe" "uprobe-trigger-0" \ |
| 269 | --name="uprobe-trigger-0" \ |
| 270 | --condition event-rule-matches --type=kernel:uprobe --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \ |
| 271 | --action notify |
| 272 | |
| 273 | test_success "--condition event-rule-matches uprobe with elf prefix" "uprobe-trigger-1" \ |
| 274 | --name="uprobe-trigger-1" \ |
| 275 | --condition event-rule-matches --type=kernel:uprobe --location=elf:${uprobe_elf_binary}:test_function --event-name=ma-probe-2 \ |
| 276 | --action notify |
| 277 | } |
| 278 | |
| 279 | skip $ist_root "non-root user: skipping syscall tests" 30 || { |
| 280 | test_success "--condition event-rule-matches one syscall" "syscall-trigger-0" \ |
| 281 | --name="syscall-trigger-0" \ |
| 282 | --condition event-rule-matches --type=syscall --name=open \ |
| 283 | --action notify |
| 284 | |
| 285 | test_success "--condition event-rule-matches all syscalls" "syscall-trigger-1" \ |
| 286 | --name="syscall-trigger-1" \ |
| 287 | --condition event-rule-matches --type=syscall \ |
| 288 | --action notify |
| 289 | |
| 290 | test_success "--condition event-rule-matches one syscall with filter" "syscall-trigger-2" \ |
| 291 | --name="syscall-trigger-2" \ |
| 292 | --condition event-rule-matches --type=syscall --filter 'a > 2' --name=open \ |
| 293 | --action notify |
| 294 | test_success "--condition event-rule-matches one syscall:entry" "syscall-trigger-3" \ |
| 295 | --name="syscall-trigger-3" \ |
| 296 | --condition event-rule-matches --type=syscall:entry --name=open \ |
| 297 | --action notify |
| 298 | test_success "--condition event-rule-matches one syscall:exit" "syscall-trigger-4" \ |
| 299 | --name="syscall-trigger-4" \ |
| 300 | --condition event-rule-matches --type=syscall:exit --name=open \ |
| 301 | --action notify |
| 302 | test_success "--condition event-rule-matches one syscall:entry-exit" "syscall-trigger-5" \ |
| 303 | --name="syscall-trigger-5" \ |
| 304 | --condition event-rule-matches --type=syscall:entry+exit --name=open \ |
| 305 | --action notify |
| 306 | |
| 307 | # Same thing but with "kernel:syscall" type instead: |
| 308 | test_success "--condition event-rule-matches one syscall" "syscall-trigger-6" \ |
| 309 | --name="syscall-trigger-6" \ |
| 310 | --condition event-rule-matches --type=kernel:syscall --name=open \ |
| 311 | --action notify |
| 312 | |
| 313 | test_success "--condition event-rule-matches one kernel:syscall:entry" "syscall-trigger-7" \ |
| 314 | --name="syscall-trigger-7" \ |
| 315 | --condition event-rule-matches --type=kernel:syscall:entry --name=open \ |
| 316 | --action notify |
| 317 | test_success "--condition event-rule-matches one kernel:syscall:exit" "syscall-trigger-8" \ |
| 318 | --name="syscall-trigger-8" \ |
| 319 | --condition event-rule-matches --type=kernel:syscall:exit --name=open \ |
| 320 | --action notify |
| 321 | test_success "--condition event-rule-matches one kernel:syscall:entry-exit" "syscall-trigger-9" \ |
| 322 | --name="syscall-trigger-9" \ |
| 323 | --condition event-rule-matches --type=kernel:syscall:entry+exit --name=open \ |
| 324 | --action notify |
| 325 | |
| 326 | } |
| 327 | |
| 328 | # `--action notify` successes |
| 329 | test_success "--action notify" "notify-1" \ |
| 330 | --name=notify-1 \ |
| 331 | --condition event-rule-matches --type=user \ |
| 332 | --action notify |
| 333 | |
| 334 | test_success "--action notify --capture foo" "notify-2" \ |
| 335 | --name=notify-2 \ |
| 336 | --condition event-rule-matches --type=user \ |
| 337 | --capture foo --action notify |
| 338 | |
| 339 | test_success "--action notify --capture foo[2]" "notify-3" \ |
| 340 | --name=notify-3 \ |
| 341 | --condition event-rule-matches --type=user \ |
| 342 | --capture 'foo[2]' --action notify |
| 343 | |
| 344 | test_success '--action notify --capture $ctx.foo' "notify-4" \ |
| 345 | --name=notify-4 \ |
| 346 | --condition event-rule-matches --type=user \ |
| 347 | --capture '$ctx.foo' --action notify |
| 348 | |
| 349 | test_success '--action notify --capture $ctx.foo[2]' "notify-5" \ |
| 350 | --name=notify-5 \ |
| 351 | --condition event-rule-matches --type=user \ |
| 352 | --capture '$ctx.foo[2]' --action notify |
| 353 | |
| 354 | test_success '--action notify --capture $app.prov:type' "notify-6" \ |
| 355 | --name=notify-6 \ |
| 356 | --condition event-rule-matches --type=user \ |
| 357 | --capture '$app.prov:type' --action notify |
| 358 | |
| 359 | test_success '--action notify --capture $app.prov:type[2]' "notify-7" \ |
| 360 | --name=notify-7 \ |
| 361 | --condition event-rule-matches --type=user \ |
| 362 | --capture '$app.prov:type[2]' --action notify |
| 363 | |
| 364 | test_success '--action notify multiple captures' "notify-8" \ |
| 365 | --name=notify-8 \ |
| 366 | --condition event-rule-matches --type=user \ |
| 367 | --capture foo --capture '$app.hello:world' --action notify |
| 368 | |
| 369 | # `--action start-session` successes |
| 370 | test_success "--action start-session" "notify-9" \ |
| 371 | --name=notify-9 \ |
| 372 | --condition event-rule-matches --type=user \ |
| 373 | --action start-session ze-session |
| 374 | |
| 375 | # `--action stop-session` successes |
| 376 | test_success "--action stop-session foo" "notify-10"\ |
| 377 | --name=notify-10 \ |
| 378 | --condition event-rule-matches --type=user \ |
| 379 | --action stop-session ze-session |
| 380 | |
| 381 | # `--action rotate-session` successes |
| 382 | test_success "--action rotate-session foo" "notify-11"\ |
| 383 | --name=notify-11 \ |
| 384 | --condition event-rule-matches --type=user \ |
| 385 | --action rotate-session ze-session |
| 386 | |
| 387 | # `--action snapshot-session` successes |
| 388 | test_success "--action snapshot-session foo" "notify-12"\ |
| 389 | --name=notify-12 \ |
| 390 | --condition event-rule-matches --type=user \ |
| 391 | --action snapshot-session ze-session |
| 392 | |
| 393 | test_success "--action snapshot-session with file URI" "notify-13"\ |
| 394 | --name=notify-13 \ |
| 395 | --condition event-rule-matches --type=user \ |
| 396 | --action snapshot-session ze-session --path /hello |
| 397 | |
| 398 | test_success "--action snapshot-session with net URI" "notify-14"\ |
| 399 | --name=notify-14 \ |
| 400 | --condition event-rule-matches --type=user \ |
| 401 | --action snapshot-session ze-session --url net://1.2.3.4 |
| 402 | |
| 403 | test_success "--action snapshot-session with ctrl/data URIs" "notify-15"\ |
| 404 | --name=notify-15 \ |
| 405 | --condition event-rule-matches --type=user \ |
| 406 | --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1234 --data-url=tcp://1.2.3.4:1235 |
| 407 | |
| 408 | # top-level failures |
| 409 | test_failure "no args" "Error: Missing --condition." |
| 410 | |
| 411 | test_failure "unknown option" \ |
| 412 | "Error: While parsing argument #2 (\`--hello\`): Unknown option \`--hello\`" \ |
| 413 | --hello |
| 414 | |
| 415 | test_failure "missing --action" \ |
| 416 | "Error: Need at least one --action." \ |
| 417 | --condition event-rule-matches --type=user |
| 418 | |
| 419 | test_failure "two --condition" \ |
| 420 | "Error: A --condition was already given." \ |
| 421 | --condition event-rule-matches --name=aaa --type=user \ |
| 422 | --condition event-rule-matches --name=bbb --type=user \ |
| 423 | --action notify |
| 424 | |
| 425 | test_failure "missing argument to --name" \ |
| 426 | "Error: While parsing argument #2 (\`--name\`): Missing required argument for option \`--name\`" \ |
| 427 | --name |
| 428 | |
| 429 | for cmd in rate-policy=once-after rate-policy=every; do |
| 430 | test_failure "missing argument to --${cmd}" \ |
| 431 | "Error: Rate policy format is invalid." \ |
| 432 | --condition event-rule-matches --type=user --action notify \ |
| 433 | --${cmd} |
| 434 | |
| 435 | test_failure "invalid argument to --${cmd}: non-digit character" \ |
| 436 | "Error: Failed to parse rate policy value \`123bob\` as an integer." \ |
| 437 | --condition event-rule-matches --type=user --action notify \ |
| 438 | --${cmd}:123bob |
| 439 | |
| 440 | test_failure "invalid argument to --${cmd}: empty string" \ |
| 441 | "Error: Failed to parse rate policy value \`\` as an integer." \ |
| 442 | --condition event-rule-matches --type=user --action notify \ |
| 443 | --${cmd}":" |
| 444 | done |
| 445 | |
| 446 | test_failure "invalid argument to --rate-policy: unknown policy type" \ |
| 447 | "Error: Rate policy type \`bob\` unknown." \ |
| 448 | --condition event-rule-matches --type=user --action notify \ |
| 449 | --rate-policy=bob:123 |
| 450 | |
| 451 | # `--condition` failures |
| 452 | test_failure "missing args after --condition" \ |
| 453 | "Error: While parsing argument #2 (\`--condition\`): Missing required argument for option \`--condition\`" \ |
| 454 | --condition |
| 455 | test_failure "unknown --condition" \ |
| 456 | "Error: Unknown condition name 'zoofest'" \ |
| 457 | --condition zoofest |
| 458 | |
| 459 | # `--condition event-rule-matches` failures |
| 460 | test_failure "missing args after --condition event-rule-matches" \ |
| 461 | "Error: Need at least one --action." \ |
| 462 | --condition event-rule-matches --type=user |
| 463 | |
| 464 | test_failure "extra args after --condition event-rule-matches" \ |
| 465 | "Error: Unexpected argument 'bozo'" \ |
| 466 | --condition event-rule-matches --type=user bozo |
| 467 | |
| 468 | test_failure "--log-level unknown level" \ |
| 469 | "Error: Failed to parse log level string \`FOO\`." \ |
| 470 | --condition event-rule-matches --type=user --log-level=FOO |
| 471 | |
| 472 | for type in kprobe kernel:kprobe; do |
| 473 | test_failure "--condition event-rule-matches: --name with --type=$type" \ |
| 474 | "Error: Can't use --name with kernel kprobe event rules." \ |
| 475 | --condition event-rule-matches --type=$type --location=do_sys_open --name='hello' |
| 476 | done |
| 477 | |
| 478 | test_failure "--condition event-rule-matches: --location with user tracepoint event rule" \ |
| 479 | "Error: Can't use --location with user tracepoint event rules." \ |
| 480 | --condition event-rule-matches --type=user --location='hello' |
| 481 | |
| 482 | test_failure "--condition event-rule-matches: --event-name with user tracepoint event rule" \ |
| 483 | "Error: Can't use --event-name with user tracepoint event rules." \ |
| 484 | --condition event-rule-matches --type=user --event-name='hello' |
| 485 | |
| 486 | test_failure "--condition event-rule-matches: extra argument with --type=kernel:uprobe" \ |
| 487 | "Error: Unexpected argument 'hello'" \ |
| 488 | --condition event-rule-matches --type=$type --location=${uprobe_elf_binary}:test_failure hello |
| 489 | |
| 490 | test_failure "--condition event-rule-matches: extra argument with --type=syscall" \ |
| 491 | "Error: Unexpected argument 'open'" \ |
| 492 | --condition event-rule-matches --type=syscall open |
| 493 | |
| 494 | test_failure "--condition event-rule-matches: --type=syscall:nope" \ |
| 495 | "Error: Failed to parse syscall type 'syscall:nope'." \ |
| 496 | --condition event-rule-matches --type=syscall:nope \ |
| 497 | --name=open |
| 498 | |
| 499 | test_failure "--exclude-name with non-glob name" \ |
| 500 | "Error: Event jean: Exclusions can only be used with a globbing pattern" \ |
| 501 | --condition event-rule-matches --type=user --name='jean' --exclude-name jean-chretien \ |
| 502 | --action notify |
| 503 | |
| 504 | test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \ |
| 505 | 'Error: While parsing argument #7 (`--capture`): Missing required argument for option `--capture`' \ |
| 506 | --action notify \ |
| 507 | --condition event-rule-matches --type=user --capture |
| 508 | |
| 509 | test_failure "--condition event-rule-matches --capture: missing argument (before another option)" \ |
| 510 | 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \ |
| 511 | --condition event-rule-matches --type=user --capture \ |
| 512 | --action notify \ |
| 513 | |
| 514 | test_failure "--condition event-rule-matches --capture: binary operator" \ |
| 515 | 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \ |
| 516 | --condition event-rule-matches --type=user \ |
| 517 | --capture 'foo == 2' --action notify |
| 518 | |
| 519 | test_failure "--condition event-rule-matches --capture: unary operator" \ |
| 520 | 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \ |
| 521 | --condition event-rule-matches --type=user \ |
| 522 | --capture '!foo' --action notify |
| 523 | |
| 524 | test_failure "--condition event-rule-matches --capture: logical operator" \ |
| 525 | 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \ |
| 526 | --condition event-rule-matches --type=user \ |
| 527 | --capture 'foo || bar' --action notify |
| 528 | |
| 529 | test_failure "--condition event-rule-matches --capture: accessing a sub-field" \ |
| 530 | 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \ |
| 531 | --condition event-rule-matches --type=user \ |
| 532 | --capture 'foo.bar' --action notify |
| 533 | |
| 534 | test_failure "--condition event-rule-matches --capture: accessing the sub-field of an array element" \ |
| 535 | 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \ |
| 536 | --condition event-rule-matches --type=user \ |
| 537 | --capture 'foo[3].bar' --action notify |
| 538 | |
| 539 | test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \ |
| 540 | 'Error: Invalid app-specific context field name: missing colon in `foo`.' \ |
| 541 | --condition event-rule-matches --type=user \ |
| 542 | --capture '$app.foo' --action notify |
| 543 | |
| 544 | test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \ |
| 545 | 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \ |
| 546 | --condition event-rule-matches --type=user \ |
| 547 | --capture '$app.foo:' --action notify |
| 548 | |
| 549 | # `--action` failures |
| 550 | test_failure "missing args after --action" \ |
| 551 | "Error: While parsing argument #5 (\`--action\`): Missing required argument for option \`--action\`" \ |
| 552 | --condition event-rule-matches --type=user \ |
| 553 | --action |
| 554 | |
| 555 | # `--action notify` failures |
| 556 | test_failure "extra arg after --action notify" \ |
| 557 | "Error: Unexpected argument \`bob\`." \ |
| 558 | --condition event-rule-matches --type=user \ |
| 559 | --action notify bob |
| 560 | |
| 561 | # `--action start-session` failures |
| 562 | test_failure "missing arg after --action start-session" \ |
| 563 | "Error: Missing session name." \ |
| 564 | --condition event-rule-matches --type=user \ |
| 565 | --action start-session |
| 566 | test_failure "extra arg after --action start-session" \ |
| 567 | "Error: Unexpected argument \`bob\`." \ |
| 568 | --condition event-rule-matches --type=user \ |
| 569 | --action start-session ze-session bob |
| 570 | |
| 571 | # `--action stop-session` failures |
| 572 | test_failure "missing arg after --action stop-session" \ |
| 573 | "Error: Missing session name." \ |
| 574 | --condition event-rule-matches --type=user \ |
| 575 | --action stop-session |
| 576 | test_failure "extra arg after --action stop-session" \ |
| 577 | "Error: Unexpected argument \`bob\`." \ |
| 578 | --condition event-rule-matches --type=user \ |
| 579 | --action stop-session ze-session bob |
| 580 | |
| 581 | # `--action rotate-session` failures |
| 582 | test_failure "missing arg after --action rotate-session" \ |
| 583 | "Error: Missing session name." \ |
| 584 | --condition event-rule-matches --type=user \ |
| 585 | --action rotate-session |
| 586 | test_failure "extra arg after --action rotate-session" \ |
| 587 | "Error: Unexpected argument \`bob\`." \ |
| 588 | --condition event-rule-matches --type=user \ |
| 589 | --action rotate-session ze-session bob |
| 590 | |
| 591 | # `--action snapshot-session` failures |
| 592 | test_failure "missing arg after --action snapshot-session" \ |
| 593 | "Error: Missing session name." \ |
| 594 | --condition event-rule-matches --type=user \ |
| 595 | --action snapshot-session |
| 596 | test_failure "extra arg after --action snapshot-session" \ |
| 597 | "Error: Unexpected argument \`bob\`." \ |
| 598 | --condition event-rule-matches --type=user \ |
| 599 | --action snapshot-session ze-session bob |
| 600 | test_failure "snapshot-session action, --max-size without destination" \ |
| 601 | "Error: Can't provide a snapshot output max size without a snapshot output destination." \ |
| 602 | --condition event-rule-matches --type=user \ |
| 603 | --action snapshot-session ze-session --max-size 10M |
| 604 | test_failure "snapshot-session action, --name without destination" \ |
| 605 | "Error: Can't provide a snapshot output name without a snapshot output destination." \ |
| 606 | --condition event-rule-matches --type=user \ |
| 607 | --action snapshot-session ze-session --name hallo |
| 608 | test_failure "snapshot-session action, --name with-local-path-instead-of-url" \ |
| 609 | "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \ |
| 610 | --condition event-rule-matches --type=user \ |
| 611 | --action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path |
| 612 | test_failure "snapshot-session action, --name with-net-url-instead-of-path" \ |
| 613 | "Error: Failed to parse 'net://8.8.8.8/' as a local path." \ |
| 614 | --condition event-rule-matches --type=user \ |
| 615 | --action snapshot-session ze-session --name hallo --path net://8.8.8.8/ |
| 616 | |
| 617 | test_mi |
| 618 | |
| 619 | # Cleanup |
| 620 | stop_lttng_sessiond_notap |
| 621 | rm -f "${tmp_stdout}" |
| 622 | rm -f "${tmp_stderr}" |