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