| 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 list-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 | NUM_TESTS=106 |
| 27 | |
| 28 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" |
| 29 | |
| 30 | tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX) |
| 31 | tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX) |
| 32 | tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX) |
| 33 | uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary") |
| 34 | uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary") |
| 35 | register_some_triggers_bin=$(realpath "${CURDIR}/utils/register-some-triggers") |
| 36 | |
| 37 | uid=$(id --user) |
| 38 | gid=$(id --group) |
| 39 | |
| 40 | if [ "$uid" == "0" ]; then |
| 41 | ist_root=1 |
| 42 | ls "$uprobe_sdt_binary" >/dev/null 2>&1 |
| 43 | if test $? == 0; then |
| 44 | hast_sdt_binary=1 |
| 45 | else |
| 46 | hast_sdt_binary=0 |
| 47 | fi |
| 48 | else |
| 49 | ist_root=0 |
| 50 | hast_sdt_binary=0 |
| 51 | fi |
| 52 | |
| 53 | |
| 54 | function list_triggers_matches_ok () |
| 55 | { |
| 56 | local test_name="$1" |
| 57 | local expected_stdout_file="$2" |
| 58 | |
| 59 | "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}" |
| 60 | ok $? "${test_name}: exit code is 0" |
| 61 | |
| 62 | diff -u "${expected_stdout_file}" "${tmp_stdout}" |
| 63 | ok $? "${test_name}: expected stdout" |
| 64 | |
| 65 | diff -u /dev/null "${tmp_stderr}" |
| 66 | ok $? "${test_name}: expected stderr" |
| 67 | } |
| 68 | |
| 69 | test_top_level_options () |
| 70 | { |
| 71 | diag "Listing top level options" |
| 72 | |
| 73 | lttng_add_trigger_ok "hello" --condition event-rule-matches --domain=user --name=test-name --action notify |
| 74 | |
| 75 | cat > "${tmp_expected_stdout}" <<- EOF |
| 76 | - name: hello |
| 77 | owner uid: ${uid} |
| 78 | condition: event rule matches |
| 79 | rule: test-name (type: tracepoint, domain: ust) |
| 80 | actions: |
| 81 | notify |
| 82 | errors: none |
| 83 | errors: none |
| 84 | EOF |
| 85 | |
| 86 | list_triggers_matches_ok "top level options" "${tmp_expected_stdout}" |
| 87 | |
| 88 | lttng_remove_trigger_ok "hello" |
| 89 | } |
| 90 | |
| 91 | test_event_rule_matches_tracepoint () |
| 92 | { |
| 93 | diag "Listing event-rule-matches tracepoint" |
| 94 | |
| 95 | lttng_add_trigger_ok "C" --condition event-rule-matches --domain=user --action notify |
| 96 | lttng_add_trigger_ok "A" --condition event-rule-matches --name=aaa --domain=user --filter 'p == 2' --action notify |
| 97 | lttng_add_trigger_ok "D" --condition event-rule-matches --name='hello*' --domain=user -x hello2 --exclude-name hello3 -x hello4 --action notify |
| 98 | lttng_add_trigger_ok "B" --condition event-rule-matches --domain=user --name=gerboise --log-level INFO.. --action notify |
| 99 | lttng_add_trigger_ok "E" --condition event-rule-matches --domain=user --name=lemming --log-level WARNING --action notify |
| 100 | lttng_add_trigger_ok "J" --condition event-rule-matches --domain=user --name=lemming --log-level .. --action notify |
| 101 | lttng_add_trigger_ok "F" --condition event-rule-matches --domain=user --name=capture-payload-field --capture a --action notify |
| 102 | lttng_add_trigger_ok "G" --condition event-rule-matches --domain=user --name=capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify |
| 103 | lttng_add_trigger_ok "H" --condition event-rule-matches --domain=user --name=capture-chan-ctx --capture '$ctx.vpid' --action notify |
| 104 | lttng_add_trigger_ok "I" --condition event-rule-matches --domain=user --name=capture-app-ctx --capture '$app.iga:active_clients' --action notify |
| 105 | |
| 106 | cat > "${tmp_expected_stdout}" <<- EOF |
| 107 | - name: A |
| 108 | owner uid: ${uid} |
| 109 | condition: event rule matches |
| 110 | rule: aaa (type: tracepoint, domain: ust, filter: p == 2) |
| 111 | actions: |
| 112 | notify |
| 113 | errors: none |
| 114 | errors: none |
| 115 | - name: B |
| 116 | owner uid: ${uid} |
| 117 | condition: event rule matches |
| 118 | rule: gerboise (type: tracepoint, domain: ust, log level at least INFO) |
| 119 | actions: |
| 120 | notify |
| 121 | errors: none |
| 122 | errors: none |
| 123 | - name: C |
| 124 | owner uid: ${uid} |
| 125 | condition: event rule matches |
| 126 | rule: * (type: tracepoint, domain: ust) |
| 127 | actions: |
| 128 | notify |
| 129 | errors: none |
| 130 | errors: none |
| 131 | - name: D |
| 132 | owner uid: ${uid} |
| 133 | condition: event rule matches |
| 134 | rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4) |
| 135 | actions: |
| 136 | notify |
| 137 | errors: none |
| 138 | errors: none |
| 139 | - name: E |
| 140 | owner uid: ${uid} |
| 141 | condition: event rule matches |
| 142 | rule: lemming (type: tracepoint, domain: ust, log level is WARNING) |
| 143 | actions: |
| 144 | notify |
| 145 | errors: none |
| 146 | errors: none |
| 147 | - name: F |
| 148 | owner uid: ${uid} |
| 149 | condition: event rule matches |
| 150 | rule: capture-payload-field (type: tracepoint, domain: ust) |
| 151 | captures: |
| 152 | - a |
| 153 | actions: |
| 154 | notify |
| 155 | errors: none |
| 156 | errors: none |
| 157 | - name: G |
| 158 | owner uid: ${uid} |
| 159 | condition: event rule matches |
| 160 | rule: capture-array (type: tracepoint, domain: ust) |
| 161 | captures: |
| 162 | - a[2] |
| 163 | - \$ctx.tourlou[18] |
| 164 | actions: |
| 165 | notify |
| 166 | errors: none |
| 167 | errors: none |
| 168 | - name: H |
| 169 | owner uid: ${uid} |
| 170 | condition: event rule matches |
| 171 | rule: capture-chan-ctx (type: tracepoint, domain: ust) |
| 172 | captures: |
| 173 | - \$ctx.vpid |
| 174 | actions: |
| 175 | notify |
| 176 | errors: none |
| 177 | errors: none |
| 178 | - name: I |
| 179 | owner uid: ${uid} |
| 180 | condition: event rule matches |
| 181 | rule: capture-app-ctx (type: tracepoint, domain: ust) |
| 182 | captures: |
| 183 | - \$app.iga:active_clients |
| 184 | actions: |
| 185 | notify |
| 186 | errors: none |
| 187 | errors: none |
| 188 | - name: J |
| 189 | owner uid: ${uid} |
| 190 | condition: event rule matches |
| 191 | rule: lemming (type: tracepoint, domain: ust) |
| 192 | actions: |
| 193 | notify |
| 194 | errors: none |
| 195 | errors: none |
| 196 | EOF |
| 197 | |
| 198 | list_triggers_matches_ok "event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}" |
| 199 | |
| 200 | lttng_remove_trigger_ok "A" |
| 201 | lttng_remove_trigger_ok "B" |
| 202 | lttng_remove_trigger_ok "C" |
| 203 | lttng_remove_trigger_ok "D" |
| 204 | lttng_remove_trigger_ok "E" |
| 205 | lttng_remove_trigger_ok "F" |
| 206 | lttng_remove_trigger_ok "G" |
| 207 | lttng_remove_trigger_ok "H" |
| 208 | lttng_remove_trigger_ok "I" |
| 209 | lttng_remove_trigger_ok "J" |
| 210 | } |
| 211 | |
| 212 | test_event_rule_matches_probe () |
| 213 | { |
| 214 | local channel_enable_addr |
| 215 | local channel_disable_addr |
| 216 | |
| 217 | diag "Listing event-rule-matches kernel probe" |
| 218 | |
| 219 | channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') |
| 220 | channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') |
| 221 | |
| 222 | # We need to find a valid offset. |
| 223 | base_symbol="" |
| 224 | offset=0 |
| 225 | if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then |
| 226 | base_symbol="lttng_channel_enable" |
| 227 | offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr )) |
| 228 | else |
| 229 | base_symbol="lttng_channel_disable" |
| 230 | offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr )) |
| 231 | fi |
| 232 | |
| 233 | offset_hex="0x$(printf '%x' $offset)" |
| 234 | |
| 235 | lttng_add_trigger_ok "T0" --condition event-rule-matches --domain=kernel --type=kprobe --location=lttng_channel_enable --event-name=my_channel_enable --action notify |
| 236 | lttng_add_trigger_ok "T1" --condition event-rule-matches --domain=kernel --type=kprobe --location="${base_symbol}+${offset_hex}" --event-name=my_channel_enable --action notify |
| 237 | lttng_add_trigger_ok "T2" --condition event-rule-matches --domain=kernel --type=kprobe --location="0x${channel_enable_addr}" --event-name=my_channel_enable --action notify |
| 238 | |
| 239 | cat > "${tmp_expected_stdout}" <<- EOF |
| 240 | - name: T0 |
| 241 | owner uid: ${uid} |
| 242 | condition: event rule matches |
| 243 | rule: my_channel_enable (type: probe, location: lttng_channel_enable) |
| 244 | actions: |
| 245 | notify |
| 246 | errors: none |
| 247 | errors: none |
| 248 | - name: T1 |
| 249 | owner uid: ${uid} |
| 250 | condition: event rule matches |
| 251 | rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex}) |
| 252 | actions: |
| 253 | notify |
| 254 | errors: none |
| 255 | errors: none |
| 256 | - name: T2 |
| 257 | owner uid: ${uid} |
| 258 | condition: event rule matches |
| 259 | rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr}) |
| 260 | actions: |
| 261 | notify |
| 262 | errors: none |
| 263 | errors: none |
| 264 | EOF |
| 265 | |
| 266 | list_triggers_matches_ok "event-rule-matches, probe event rule" "${tmp_expected_stdout}" |
| 267 | |
| 268 | lttng_remove_trigger_ok "T0" |
| 269 | lttng_remove_trigger_ok "T1" |
| 270 | lttng_remove_trigger_ok "T2" |
| 271 | } |
| 272 | |
| 273 | test_event_rule_matches_userspace_probe_elf () |
| 274 | { |
| 275 | local elf_function_name="test_function" |
| 276 | |
| 277 | diag "Listing event-rule-matches userspace-probe elf" |
| 278 | |
| 279 | lttng_add_trigger_ok "T0" --condition event-rule-matches --domain=kernel --type=uprobe --location=${uprobe_elf_binary}:test_function --event-name=ma-probe-elf --action notify |
| 280 | |
| 281 | cat > "${tmp_expected_stdout}" <<- EOF |
| 282 | - name: T0 |
| 283 | owner uid: ${uid} |
| 284 | condition: event rule matches |
| 285 | rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name}) |
| 286 | actions: |
| 287 | notify |
| 288 | errors: none |
| 289 | errors: none |
| 290 | EOF |
| 291 | |
| 292 | list_triggers_matches_ok "event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}" |
| 293 | |
| 294 | lttng_remove_trigger_ok "T0" |
| 295 | } |
| 296 | |
| 297 | test_event_rule_matches_userspace_probe_sdt () |
| 298 | { |
| 299 | local sdt_provider_name="foobar" |
| 300 | local sdt_probe_name="tp1" |
| 301 | |
| 302 | diag "Listing event-rule-matches userspace-probe sdt" |
| 303 | |
| 304 | lttng_add_trigger_ok "T0" --condition event-rule-matches --domain=kernel --type=uprobe --location=sdt:${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name} --event-name=ma-probe-sdt --action notify |
| 305 | |
| 306 | cat > "${tmp_expected_stdout}" <<- EOF |
| 307 | - name: T0 |
| 308 | owner uid: 0 |
| 309 | condition: event rule matches |
| 310 | rule: ma-probe-sdt (type: userspace probe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name}) |
| 311 | actions: |
| 312 | notify |
| 313 | errors: none |
| 314 | errors: none |
| 315 | EOF |
| 316 | |
| 317 | list_triggers_matches_ok "event-rule-matches, userspace-probe event rule SDT" "${tmp_expected_stdout}" |
| 318 | |
| 319 | lttng_remove_trigger_ok "T0" |
| 320 | } |
| 321 | |
| 322 | test_event_rule_matches_syscall () |
| 323 | { |
| 324 | diag "Listing event-rule-matches syscall" |
| 325 | |
| 326 | lttng_add_trigger_ok "T0" --condition event-rule-matches --domain=kernel --type=syscall --name=open --action notify |
| 327 | lttng_add_trigger_ok "T1" --condition event-rule-matches --domain=kernel --type=syscall:entry --name=open --action notify |
| 328 | lttng_add_trigger_ok "T2" --condition event-rule-matches --domain=kernel --type=syscall:exit --name=open --action notify |
| 329 | lttng_add_trigger_ok "T3" --condition event-rule-matches --domain=kernel --type=syscall:entry+exit --name=open --action notify |
| 330 | lttng_add_trigger_ok "T4" --condition event-rule-matches --domain=kernel --type=syscall --name=ptrace --filter 'a > 2' --action notify |
| 331 | |
| 332 | cat > "${tmp_expected_stdout}" <<- EOF |
| 333 | - name: T0 |
| 334 | owner uid: ${uid} |
| 335 | condition: event rule matches |
| 336 | rule: open (type: syscall:entry+exit) |
| 337 | actions: |
| 338 | notify |
| 339 | errors: none |
| 340 | errors: none |
| 341 | - name: T1 |
| 342 | owner uid: ${uid} |
| 343 | condition: event rule matches |
| 344 | rule: open (type: syscall:entry) |
| 345 | actions: |
| 346 | notify |
| 347 | errors: none |
| 348 | errors: none |
| 349 | - name: T2 |
| 350 | owner uid: ${uid} |
| 351 | condition: event rule matches |
| 352 | rule: open (type: syscall:exit) |
| 353 | actions: |
| 354 | notify |
| 355 | errors: none |
| 356 | errors: none |
| 357 | - name: T3 |
| 358 | owner uid: ${uid} |
| 359 | condition: event rule matches |
| 360 | rule: open (type: syscall:entry+exit) |
| 361 | actions: |
| 362 | notify |
| 363 | errors: none |
| 364 | errors: none |
| 365 | - name: T4 |
| 366 | owner uid: ${uid} |
| 367 | condition: event rule matches |
| 368 | rule: ptrace (type: syscall:entry+exit, filter: a > 2) |
| 369 | actions: |
| 370 | notify |
| 371 | errors: none |
| 372 | errors: none |
| 373 | EOF |
| 374 | |
| 375 | list_triggers_matches_ok "event-rule-matches, syscall event rule" "${tmp_expected_stdout}" |
| 376 | |
| 377 | lttng_remove_trigger_ok "T0" |
| 378 | lttng_remove_trigger_ok "T1" |
| 379 | lttng_remove_trigger_ok "T2" |
| 380 | lttng_remove_trigger_ok "T3" |
| 381 | lttng_remove_trigger_ok "T4" |
| 382 | } |
| 383 | |
| 384 | test_session_consumed_size_condition () |
| 385 | { |
| 386 | ${register_some_triggers_bin} test_session_consumed_size_condition |
| 387 | |
| 388 | cat > "${tmp_expected_stdout}" <<- EOF |
| 389 | - name: trigger-with-session-consumed-size-condition |
| 390 | owner uid: ${uid} |
| 391 | condition: session consumed size |
| 392 | session name: the-session-name |
| 393 | threshold: 1234 bytes |
| 394 | actions: |
| 395 | notify |
| 396 | errors: none |
| 397 | errors: none |
| 398 | EOF |
| 399 | |
| 400 | list_triggers_matches_ok "session consumed size condition" "${tmp_expected_stdout}" |
| 401 | |
| 402 | lttng_remove_trigger_ok "trigger-with-session-consumed-size-condition" |
| 403 | } |
| 404 | |
| 405 | test_buffer_usage_conditions () |
| 406 | { |
| 407 | ${register_some_triggers_bin} test_buffer_usage_conditions |
| 408 | |
| 409 | cat > "${tmp_expected_stdout}" <<- EOF |
| 410 | - name: trigger-with-buffer-usage-high-bytes-condition |
| 411 | owner uid: ${uid} |
| 412 | condition: buffer usage high |
| 413 | session name: the-session-name |
| 414 | channel name: the-channel-name |
| 415 | domain: ust |
| 416 | threshold (bytes): 1234 |
| 417 | actions: |
| 418 | notify |
| 419 | errors: none |
| 420 | errors: none |
| 421 | - name: trigger-with-buffer-usage-high-ratio-condition |
| 422 | owner uid: ${uid} |
| 423 | condition: buffer usage high |
| 424 | session name: the-session-name |
| 425 | channel name: the-channel-name |
| 426 | domain: ust |
| 427 | threshold (ratio): 0.25 |
| 428 | actions: |
| 429 | notify |
| 430 | errors: none |
| 431 | errors: none |
| 432 | - name: trigger-with-buffer-usage-low-bytes-condition |
| 433 | owner uid: ${uid} |
| 434 | condition: buffer usage low |
| 435 | session name: the-session-name |
| 436 | channel name: the-channel-name |
| 437 | domain: ust |
| 438 | threshold (bytes): 2345 |
| 439 | actions: |
| 440 | notify |
| 441 | errors: none |
| 442 | errors: none |
| 443 | - name: trigger-with-buffer-usage-low-ratio-condition |
| 444 | owner uid: ${uid} |
| 445 | condition: buffer usage low |
| 446 | session name: the-session-name |
| 447 | channel name: the-channel-name |
| 448 | domain: ust |
| 449 | threshold (ratio): 0.40 |
| 450 | actions: |
| 451 | notify |
| 452 | errors: none |
| 453 | errors: none |
| 454 | EOF |
| 455 | |
| 456 | list_triggers_matches_ok "buffer usage condition" "${tmp_expected_stdout}" |
| 457 | |
| 458 | lttng_remove_trigger_ok "trigger-with-buffer-usage-high-bytes-condition" |
| 459 | lttng_remove_trigger_ok "trigger-with-buffer-usage-high-ratio-condition" |
| 460 | lttng_remove_trigger_ok "trigger-with-buffer-usage-low-bytes-condition" |
| 461 | lttng_remove_trigger_ok "trigger-with-buffer-usage-low-ratio-condition" |
| 462 | } |
| 463 | |
| 464 | test_session_rotation_conditions () |
| 465 | { |
| 466 | ${register_some_triggers_bin} test_session_rotation_conditions |
| 467 | |
| 468 | cat > "${tmp_expected_stdout}" <<- EOF |
| 469 | - name: trigger-with-session-rotation-completed-condition |
| 470 | owner uid: ${uid} |
| 471 | condition: session rotation completed |
| 472 | session name: the-session-name |
| 473 | actions: |
| 474 | notify |
| 475 | errors: none |
| 476 | errors: none |
| 477 | - name: trigger-with-session-rotation-ongoing-condition |
| 478 | owner uid: ${uid} |
| 479 | condition: session rotation ongoing |
| 480 | session name: the-session-name |
| 481 | actions: |
| 482 | notify |
| 483 | errors: none |
| 484 | errors: none |
| 485 | EOF |
| 486 | |
| 487 | list_triggers_matches_ok "session rotation conditions" "${tmp_expected_stdout}" |
| 488 | |
| 489 | lttng_remove_trigger_ok "trigger-with-session-rotation-completed-condition" |
| 490 | lttng_remove_trigger_ok "trigger-with-session-rotation-ongoing-condition" |
| 491 | } |
| 492 | |
| 493 | test_snapshot_action () |
| 494 | { |
| 495 | diag "Listing snapshot actions" |
| 496 | |
| 497 | lttng_add_trigger_ok "T0" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session |
| 498 | lttng_add_trigger_ok "T1" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --path /some/path |
| 499 | lttng_add_trigger_ok "T2" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --url file:///some/other/path |
| 500 | lttng_add_trigger_ok "T3" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --url net://1.2.3.4 |
| 501 | lttng_add_trigger_ok "T4" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --url net://1.2.3.4:1234:1235 |
| 502 | lttng_add_trigger_ok "T5" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112 |
| 503 | lttng_add_trigger_ok "T6" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --path /some/path --max-size=1234 |
| 504 | lttng_add_trigger_ok "T7" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --path /some/path --name=meh |
| 505 | lttng_add_trigger_ok "T8" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --rate-policy=every:10 |
| 506 | lttng_add_trigger_ok "T9" --condition event-rule-matches --domain=user --name=some-event --action snapshot-session ze-session --rate-policy=once-after:10 |
| 507 | |
| 508 | cat > "${tmp_expected_stdout}" <<- EOF |
| 509 | - name: T0 |
| 510 | owner uid: ${uid} |
| 511 | condition: event rule matches |
| 512 | rule: some-event (type: tracepoint, domain: ust) |
| 513 | actions: |
| 514 | snapshot session \`ze-session\` |
| 515 | errors: none |
| 516 | errors: none |
| 517 | - name: T1 |
| 518 | owner uid: ${uid} |
| 519 | condition: event rule matches |
| 520 | rule: some-event (type: tracepoint, domain: ust) |
| 521 | actions: |
| 522 | snapshot session \`ze-session\`, path: /some/path |
| 523 | errors: none |
| 524 | errors: none |
| 525 | - name: T2 |
| 526 | owner uid: ${uid} |
| 527 | condition: event rule matches |
| 528 | rule: some-event (type: tracepoint, domain: ust) |
| 529 | actions: |
| 530 | snapshot session \`ze-session\`, path: /some/other/path |
| 531 | errors: none |
| 532 | errors: none |
| 533 | - name: T3 |
| 534 | owner uid: ${uid} |
| 535 | condition: event rule matches |
| 536 | rule: some-event (type: tracepoint, domain: ust) |
| 537 | actions: |
| 538 | snapshot session \`ze-session\`, url: net://1.2.3.4 |
| 539 | errors: none |
| 540 | errors: none |
| 541 | - name: T4 |
| 542 | owner uid: ${uid} |
| 543 | condition: event rule matches |
| 544 | rule: some-event (type: tracepoint, domain: ust) |
| 545 | actions: |
| 546 | snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235 |
| 547 | errors: none |
| 548 | errors: none |
| 549 | - name: T5 |
| 550 | owner uid: ${uid} |
| 551 | condition: event rule matches |
| 552 | rule: some-event (type: tracepoint, domain: ust) |
| 553 | actions: |
| 554 | snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112 |
| 555 | errors: none |
| 556 | errors: none |
| 557 | - name: T6 |
| 558 | owner uid: ${uid} |
| 559 | condition: event rule matches |
| 560 | rule: some-event (type: tracepoint, domain: ust) |
| 561 | actions: |
| 562 | snapshot session \`ze-session\`, path: /some/path, max size: 1234 |
| 563 | errors: none |
| 564 | errors: none |
| 565 | - name: T7 |
| 566 | owner uid: ${uid} |
| 567 | condition: event rule matches |
| 568 | rule: some-event (type: tracepoint, domain: ust) |
| 569 | actions: |
| 570 | snapshot session \`ze-session\`, path: /some/path, name: meh |
| 571 | errors: none |
| 572 | errors: none |
| 573 | - name: T8 |
| 574 | owner uid: ${uid} |
| 575 | condition: event rule matches |
| 576 | rule: some-event (type: tracepoint, domain: ust) |
| 577 | actions: |
| 578 | snapshot session \`ze-session\`, rate policy: after every 10 occurrences |
| 579 | errors: none |
| 580 | errors: none |
| 581 | - name: T9 |
| 582 | owner uid: ${uid} |
| 583 | condition: event rule matches |
| 584 | rule: some-event (type: tracepoint, domain: ust) |
| 585 | actions: |
| 586 | snapshot session \`ze-session\`, rate policy: once after 10 occurrences |
| 587 | errors: none |
| 588 | errors: none |
| 589 | EOF |
| 590 | |
| 591 | list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}" |
| 592 | |
| 593 | lttng_remove_trigger_ok "T0" |
| 594 | lttng_remove_trigger_ok "T1" |
| 595 | lttng_remove_trigger_ok "T2" |
| 596 | lttng_remove_trigger_ok "T3" |
| 597 | lttng_remove_trigger_ok "T4" |
| 598 | lttng_remove_trigger_ok "T5" |
| 599 | lttng_remove_trigger_ok "T6" |
| 600 | lttng_remove_trigger_ok "T7" |
| 601 | lttng_remove_trigger_ok "T8" |
| 602 | lttng_remove_trigger_ok "T9" |
| 603 | } |
| 604 | |
| 605 | test_notify_action () |
| 606 | { |
| 607 | lttng_add_trigger_ok "T0" --condition event-rule-matches --domain=user --name=some-event --action notify --rate-policy=once-after:5 |
| 608 | lttng_add_trigger_ok "T1" --condition event-rule-matches --domain=user --name=some-event --action notify --rate-policy=every:10 |
| 609 | |
| 610 | cat > "${tmp_expected_stdout}" <<- EOF |
| 611 | - name: T0 |
| 612 | owner uid: ${uid} |
| 613 | condition: event rule matches |
| 614 | rule: some-event (type: tracepoint, domain: ust) |
| 615 | actions: |
| 616 | notify, rate policy: once after 5 occurrences |
| 617 | errors: none |
| 618 | errors: none |
| 619 | - name: T1 |
| 620 | owner uid: ${uid} |
| 621 | condition: event rule matches |
| 622 | rule: some-event (type: tracepoint, domain: ust) |
| 623 | actions: |
| 624 | notify, rate policy: after every 10 occurrences |
| 625 | errors: none |
| 626 | errors: none |
| 627 | EOF |
| 628 | |
| 629 | list_triggers_matches_ok "notify action" "${tmp_expected_stdout}" |
| 630 | |
| 631 | lttng_remove_trigger_ok "T0" |
| 632 | lttng_remove_trigger_ok "T1" |
| 633 | } |
| 634 | |
| 635 | plan_tests $NUM_TESTS |
| 636 | |
| 637 | # shellcheck disable=SC2119 |
| 638 | start_lttng_sessiond_notap |
| 639 | |
| 640 | test_top_level_options |
| 641 | test_event_rule_matches_tracepoint |
| 642 | skip $ist_root "non-root user: skipping kprobe tests" 9 || test_event_rule_matches_probe |
| 643 | skip $ist_root "non-root user: skipping uprobe tests" 5 || test_event_rule_matches_userspace_probe_elf |
| 644 | skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_event_rule_matches_userspace_probe_sdt |
| 645 | skip $ist_root "non-root user: skipping syscall tests" 13 || test_event_rule_matches_syscall |
| 646 | test_session_consumed_size_condition |
| 647 | test_buffer_usage_conditions |
| 648 | test_session_rotation_conditions |
| 649 | test_snapshot_action |
| 650 | test_notify_action |
| 651 | |
| 652 | stop_lttng_sessiond_notap |
| 653 | |
| 654 | # Cleanup |
| 655 | rm -f "${tmp_stdout}" |
| 656 | rm -f "${tmp_stderr}" |
| 657 | rm -f "${tmp_expected_stdout}" |