3 # Copyright (C) - 2020 EfficiOS, inc
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.
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
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
18 # Test the `lttng list-trigger` command line interface.
20 CURDIR
="$(dirname "$0")"
21 TESTDIR
="$CURDIR/../../.."
23 # shellcheck source=../../../utils/utils.sh
24 source "$TESTDIR/utils/utils.sh"
28 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
30 tmp_stdout
=$
(mktemp
--tmpdir -t test_list_triggers_cli_stdout.XXXXXX
)
31 tmp_stderr
=$
(mktemp
--tmpdir -t test_list_triggers_cli_stderr.XXXXXX
)
32 tmp_expected_stdout
=$
(mktemp
--tmpdir -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")
40 if [ "$uid" == "0" ]; then
42 ls "$uprobe_sdt_binary" >/dev
/null
2>&1
54 test_top_level_options
()
56 diag
"Listing top level options"
58 lttng_add_trigger_ok
"hello" --condition event-rule-matches
--type=user
--name=test-name
--action notify
60 cat > "${tmp_expected_stdout}" <<- EOF
63 condition: event rule matches
64 rule: test-name (type: user tracepoint)
72 list_triggers_matches_ok
"top level options" "${tmp_expected_stdout}"
74 lttng_remove_trigger_ok
"hello"
77 test_event_rule_matches_tracepoint
()
79 diag
"Listing event-rule-matches tracepoint"
81 lttng_add_trigger_ok
"C" --condition event-rule-matches
--type=user
--action notify
82 lttng_add_trigger_ok
"A" --condition event-rule-matches
--name=aaa
--type=user
--filter 'p == 2' --action notify
83 lttng_add_trigger_ok
"D" --condition event-rule-matches
--name='hello*' --type=user
-x hello2
--exclude-name hello3
-x hello4
--action notify
84 lttng_add_trigger_ok
"B" --condition event-rule-matches
--type=user
--name=gerboise
--log-level INFO..
--action notify
85 lttng_add_trigger_ok
"E" --condition event-rule-matches
--type=user
--name=lemming
--log-level WARNING
--action notify
86 lttng_add_trigger_ok
"J" --condition event-rule-matches
--type=user
--name=lemming
--log-level ..
--action notify
87 lttng_add_trigger_ok
"F" --condition event-rule-matches
--type=user
--name=capture-payload-field
--capture a
--action notify
88 lttng_add_trigger_ok
"G" --condition event-rule-matches
--type=user
--name=capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
89 lttng_add_trigger_ok
"H" --condition event-rule-matches
--type=user
--name=capture-chan-ctx
--capture '$ctx.vpid' --action notify
90 lttng_add_trigger_ok
"I" --condition event-rule-matches
--type=user
--name=capture-app-ctx
--capture '$app.iga:active_clients' --action notify
92 cat > "${tmp_expected_stdout}" <<- EOF
95 condition: event rule matches
96 rule: aaa (type: user tracepoint, filter: p == 2)
104 condition: event rule matches
105 rule: gerboise (type: user tracepoint, log level at least INFO)
113 condition: event rule matches
114 rule: * (type: user tracepoint)
122 condition: event rule matches
123 rule: hello* (type: user tracepoint, exclusions: hello2,hello3,hello4)
131 condition: event rule matches
132 rule: lemming (type: user tracepoint, log level is WARNING)
140 condition: event rule matches
141 rule: capture-payload-field (type: user tracepoint)
151 condition: event rule matches
152 rule: capture-array (type: user tracepoint)
163 condition: event rule matches
164 rule: capture-chan-ctx (type: user tracepoint)
174 condition: event rule matches
175 rule: capture-app-ctx (type: user tracepoint)
177 - \$app.iga:active_clients
185 condition: event rule matches
186 rule: lemming (type: user tracepoint)
194 list_triggers_matches_ok
"event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}"
196 lttng_remove_trigger_ok
"A"
197 lttng_remove_trigger_ok
"B"
198 lttng_remove_trigger_ok
"C"
199 lttng_remove_trigger_ok
"D"
200 lttng_remove_trigger_ok
"E"
201 lttng_remove_trigger_ok
"F"
202 lttng_remove_trigger_ok
"G"
203 lttng_remove_trigger_ok
"H"
204 lttng_remove_trigger_ok
"I"
205 lttng_remove_trigger_ok
"J"
208 test_event_rule_matches_probe
()
210 local channel_enable_addr
211 local channel_disable_addr
213 diag
"Listing event-rule-matches kernel probe"
215 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
216 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
218 # We need to find a valid offset.
221 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
222 base_symbol
="lttng_channel_enable"
223 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
225 base_symbol
="lttng_channel_disable"
226 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
229 offset_hex
="0x$(printf '%x' $offset)"
231 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=kprobe
--location=lttng_channel_enable
--event-name=my_channel_enable
--action notify
232 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=kprobe
--location="${base_symbol}+${offset_hex}" --event-name=my_channel_enable
--action notify
233 lttng_add_trigger_ok
"T2" --condition event-rule-matches
--type=kprobe
--location="0x${channel_enable_addr}" --event-name=my_channel_enable
--action notify
235 cat > "${tmp_expected_stdout}" <<- EOF
238 condition: event rule matches
239 rule: my_channel_enable (type: kernel:kprobe, location: lttng_channel_enable)
247 condition: event rule matches
248 rule: my_channel_enable (type: kernel:kprobe, location: ${base_symbol}+${offset_hex})
256 condition: event rule matches
257 rule: my_channel_enable (type: kernel:kprobe, location: 0x${channel_enable_addr})
265 list_triggers_matches_ok
"event-rule-matches, probe event rule" "${tmp_expected_stdout}"
267 lttng_remove_trigger_ok
"T0"
268 lttng_remove_trigger_ok
"T1"
269 lttng_remove_trigger_ok
"T2"
272 test_event_rule_matches_userspace_probe_elf
()
274 local elf_function_name
="test_function"
276 diag
"Listing event-rule-matches userspace-probe elf"
278 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=kernel
:uprobe
--location=${uprobe_elf_binary}:test_function
--event-name=ma-probe-elf
--action notify
280 cat > "${tmp_expected_stdout}" <<- EOF
283 condition: event rule matches
284 rule: ma-probe-elf (type: kernel:uprobe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
292 list_triggers_matches_ok
"event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}"
294 lttng_remove_trigger_ok
"T0"
297 test_event_rule_matches_userspace_probe_sdt
()
299 local sdt_provider_name
="foobar"
300 local sdt_probe_name
="tp1"
302 diag
"Listing event-rule-matches userspace-probe sdt"
304 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=kernel
:uprobe
--location=sdt
:${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name} --event-name=ma-probe-sdt
--action notify
306 cat > "${tmp_expected_stdout}" <<- EOF
309 condition: event rule matches
310 rule: ma-probe-sdt (type: kernel:uprobe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
318 list_triggers_matches_ok
"event-rule-matches, userspace-probe event rule SDT" "${tmp_expected_stdout}"
320 lttng_remove_trigger_ok
"T0"
323 test_event_rule_matches_syscall
()
325 diag
"Listing event-rule-matches syscall"
327 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=syscall
--name=open
--action notify
328 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=syscall
:entry
--name=open
--action notify
329 lttng_add_trigger_ok
"T2" --condition event-rule-matches
--type=syscall
:exit --name=open
--action notify
330 lttng_add_trigger_ok
"T3" --condition event-rule-matches
--type=syscall
:entry
+exit --name=open
--action notify
331 lttng_add_trigger_ok
"T4" --condition event-rule-matches
--type=syscall
--name=ptrace
--filter 'a > 2' --action notify
333 cat > "${tmp_expected_stdout}" <<- EOF
336 condition: event rule matches
337 rule: open (type: kernel:syscall:entry+exit)
345 condition: event rule matches
346 rule: open (type: kernel:syscall:entry)
354 condition: event rule matches
355 rule: open (type: kernel:syscall:exit)
363 condition: event rule matches
364 rule: open (type: kernel:syscall:entry+exit)
372 condition: event rule matches
373 rule: ptrace (type: kernel:syscall:entry+exit, filter: a > 2)
381 list_triggers_matches_ok
"event-rule-matches, syscall event rule" "${tmp_expected_stdout}"
383 lttng_remove_trigger_ok
"T0"
384 lttng_remove_trigger_ok
"T1"
385 lttng_remove_trigger_ok
"T2"
386 lttng_remove_trigger_ok
"T3"
387 lttng_remove_trigger_ok
"T4"
390 test_session_consumed_size_condition
()
392 ${register_some_triggers_bin} test_session_consumed_size_condition
394 cat > "${tmp_expected_stdout}" <<- EOF
395 - name: trigger-with-session-consumed-size-condition
397 condition: session consumed size
398 session name: the-session-name
399 threshold: 1234 bytes
407 list_triggers_matches_ok
"session consumed size condition" "${tmp_expected_stdout}"
409 lttng_remove_trigger_ok
"trigger-with-session-consumed-size-condition"
412 test_buffer_usage_conditions
()
414 ${register_some_triggers_bin} test_buffer_usage_conditions
416 cat > "${tmp_expected_stdout}" <<- EOF
417 - name: trigger-with-buffer-usage-high-bytes-condition
419 condition: buffer usage high
420 session name: the-session-name
421 channel name: the-channel-name
423 threshold (bytes): 1234
429 - name: trigger-with-buffer-usage-high-ratio-condition
431 condition: buffer usage high
432 session name: the-session-name
433 channel name: the-channel-name
435 threshold (ratio): 0.25
441 - name: trigger-with-buffer-usage-low-bytes-condition
443 condition: buffer usage low
444 session name: the-session-name
445 channel name: the-channel-name
447 threshold (bytes): 2345
453 - name: trigger-with-buffer-usage-low-ratio-condition
455 condition: buffer usage low
456 session name: the-session-name
457 channel name: the-channel-name
459 threshold (ratio): 0.40
467 list_triggers_matches_ok
"buffer usage condition" "${tmp_expected_stdout}"
469 lttng_remove_trigger_ok
"trigger-with-buffer-usage-high-bytes-condition"
470 lttng_remove_trigger_ok
"trigger-with-buffer-usage-high-ratio-condition"
471 lttng_remove_trigger_ok
"trigger-with-buffer-usage-low-bytes-condition"
472 lttng_remove_trigger_ok
"trigger-with-buffer-usage-low-ratio-condition"
475 test_session_rotation_conditions
()
477 ${register_some_triggers_bin} test_session_rotation_conditions
479 cat > "${tmp_expected_stdout}" <<- EOF
480 - name: trigger-with-session-rotation-completed-condition
482 condition: session rotation completed
483 session name: the-session-name
489 - name: trigger-with-session-rotation-ongoing-condition
491 condition: session rotation ongoing
492 session name: the-session-name
500 list_triggers_matches_ok
"session rotation conditions" "${tmp_expected_stdout}"
502 lttng_remove_trigger_ok
"trigger-with-session-rotation-completed-condition"
503 lttng_remove_trigger_ok
"trigger-with-session-rotation-ongoing-condition"
506 test_snapshot_action
()
508 diag
"Listing snapshot actions"
510 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
511 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--path /some
/path
512 lttng_add_trigger_ok
"T2" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
513 lttng_add_trigger_ok
"T3" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
514 lttng_add_trigger_ok
"T4" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
515 lttng_add_trigger_ok
"T5" --condition event-rule-matches
--type=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
516 lttng_add_trigger_ok
"T6" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
517 lttng_add_trigger_ok
"T7" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
518 lttng_add_trigger_ok
"T8" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--rate-policy=every
:10
519 lttng_add_trigger_ok
"T9" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--rate-policy=once-after
:10
521 cat > "${tmp_expected_stdout}" <<- EOF
524 condition: event rule matches
525 rule: some-event (type: user tracepoint)
528 snapshot session \`ze-session\`
533 condition: event rule matches
534 rule: some-event (type: user tracepoint)
537 snapshot session \`ze-session\`, path: /some/path
542 condition: event rule matches
543 rule: some-event (type: user tracepoint)
546 snapshot session \`ze-session\`, path: /some/other/path
551 condition: event rule matches
552 rule: some-event (type: user tracepoint)
555 snapshot session \`ze-session\`, url: net://1.2.3.4
560 condition: event rule matches
561 rule: some-event (type: user tracepoint)
564 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
569 condition: event rule matches
570 rule: some-event (type: user tracepoint)
573 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
578 condition: event rule matches
579 rule: some-event (type: user tracepoint)
582 snapshot session \`ze-session\`, path: /some/path, max size: 1234
587 condition: event rule matches
588 rule: some-event (type: user tracepoint)
591 snapshot session \`ze-session\`, path: /some/path, name: meh
596 condition: event rule matches
597 rule: some-event (type: user tracepoint)
600 snapshot session \`ze-session\`, rate policy: every 10 occurrences
605 condition: event rule matches
606 rule: some-event (type: user tracepoint)
609 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
614 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
616 lttng_remove_trigger_ok
"T0"
617 lttng_remove_trigger_ok
"T1"
618 lttng_remove_trigger_ok
"T2"
619 lttng_remove_trigger_ok
"T3"
620 lttng_remove_trigger_ok
"T4"
621 lttng_remove_trigger_ok
"T5"
622 lttng_remove_trigger_ok
"T6"
623 lttng_remove_trigger_ok
"T7"
624 lttng_remove_trigger_ok
"T8"
625 lttng_remove_trigger_ok
"T9"
628 test_notify_action
()
630 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=user
--name=some-event
--action notify
--rate-policy=once-after
:5
631 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=user
--name=some-event
--action notify
--rate-policy=every
:10
633 cat > "${tmp_expected_stdout}" <<- EOF
636 condition: event rule matches
637 rule: some-event (type: user tracepoint)
640 notify, rate policy: once after 5 occurrences
645 condition: event rule matches
646 rule: some-event (type: user tracepoint)
649 notify, rate policy: every 10 occurrences
654 list_triggers_matches_ok
"notify action" "${tmp_expected_stdout}"
656 lttng_remove_trigger_ok
"T0"
657 lttng_remove_trigger_ok
"T1"
660 plan_tests
$NUM_TESTS
662 # shellcheck disable=SC2119
663 start_lttng_sessiond_notap
665 test_top_level_options
666 test_event_rule_matches_tracepoint
667 skip
$ist_root "non-root user: skipping kprobe tests" 9 || test_event_rule_matches_probe
668 skip
$ist_root "non-root user: skipping uprobe tests" 5 || test_event_rule_matches_userspace_probe_elf
669 skip $
(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_event_rule_matches_userspace_probe_sdt
670 skip
$ist_root "non-root user: skipping syscall tests" 13 || test_event_rule_matches_syscall
671 test_session_consumed_size_condition
672 test_buffer_usage_conditions
673 test_session_rotation_conditions
677 stop_lttng_sessiond_notap
680 rm -f "${tmp_stdout}"
681 rm -f "${tmp_stderr}"
682 rm -f "${tmp_expected_stdout}"