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
-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")
40 if [ "$uid" == "0" ]; then
42 ls "$uprobe_sdt_binary" >/dev
/null
2>&1
54 function list_triggers_matches_ok
()
57 local expected_stdout_file
="$2"
59 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
60 ok $?
"${test_name}: exit code is 0"
62 diff -u "${expected_stdout_file}" "${tmp_stdout}"
63 ok $?
"${test_name}: expected stdout"
65 diff -u /dev
/null
"${tmp_stderr}"
66 ok $?
"${test_name}: expected stderr"
69 test_top_level_options
()
71 diag
"Listing top level options"
73 lttng_add_trigger_ok
"hello" --condition event-rule-matches
--domain=user
--name=test-name
--action notify
75 cat > "${tmp_expected_stdout}" <<- EOF
78 condition: event rule matches
79 rule: test-name (type: tracepoint, domain: ust)
86 list_triggers_matches_ok
"top level options" "${tmp_expected_stdout}"
88 lttng_remove_trigger_ok
"hello"
91 test_event_rule_matches_tracepoint
()
93 diag
"Listing event-rule-matches tracepoint"
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
106 cat > "${tmp_expected_stdout}" <<- EOF
109 condition: event rule matches
110 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
117 condition: event rule matches
118 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
125 condition: event rule matches
126 rule: * (type: tracepoint, domain: ust)
133 condition: event rule matches
134 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
141 condition: event rule matches
142 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
149 condition: event rule matches
150 rule: capture-payload-field (type: tracepoint, domain: ust)
159 condition: event rule matches
160 rule: capture-array (type: tracepoint, domain: ust)
170 condition: event rule matches
171 rule: capture-chan-ctx (type: tracepoint, domain: ust)
180 condition: event rule matches
181 rule: capture-app-ctx (type: tracepoint, domain: ust)
183 - \$app.iga:active_clients
190 condition: event rule matches
191 rule: lemming (type: tracepoint, domain: ust)
198 list_triggers_matches_ok
"event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}"
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"
212 test_event_rule_matches_probe
()
214 local channel_enable_addr
215 local channel_disable_addr
217 diag
"Listing event-rule-matches kernel probe"
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 ' ')
222 # We need to find a valid offset.
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 ))
229 base_symbol
="lttng_channel_disable"
230 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
233 offset_hex
="0x$(printf '%x' $offset)"
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
239 cat > "${tmp_expected_stdout}" <<- EOF
242 condition: event rule matches
243 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
250 condition: event rule matches
251 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
258 condition: event rule matches
259 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
266 list_triggers_matches_ok
"event-rule-matches, probe event rule" "${tmp_expected_stdout}"
268 lttng_remove_trigger_ok
"T0"
269 lttng_remove_trigger_ok
"T1"
270 lttng_remove_trigger_ok
"T2"
273 test_event_rule_matches_userspace_probe_elf
()
275 local elf_function_name
="test_function"
277 diag
"Listing event-rule-matches userspace-probe elf"
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
281 cat > "${tmp_expected_stdout}" <<- EOF
284 condition: event rule matches
285 rule: ma-probe-elf (type: userspace probe, 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
--domain=kernel
--type=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: userspace probe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
317 list_triggers_matches_ok
"event-rule-matches, userspace-probe event rule SDT" "${tmp_expected_stdout}"
319 lttng_remove_trigger_ok
"T0"
322 test_event_rule_matches_syscall
()
324 diag
"Listing event-rule-matches syscall"
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
332 cat > "${tmp_expected_stdout}" <<- EOF
335 condition: event rule matches
336 rule: open (type: syscall:entry+exit)
343 condition: event rule matches
344 rule: open (type: syscall:entry)
351 condition: event rule matches
352 rule: open (type: syscall:exit)
359 condition: event rule matches
360 rule: open (type: syscall:entry+exit)
367 condition: event rule matches
368 rule: ptrace (type: syscall:entry+exit, filter: a > 2)
375 list_triggers_matches_ok
"event-rule-matches, syscall event rule" "${tmp_expected_stdout}"
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"
384 test_session_consumed_size_condition
()
386 ${register_some_triggers_bin} test_session_consumed_size_condition
388 cat > "${tmp_expected_stdout}" <<- EOF
389 - name: trigger-with-session-consumed-size-condition
391 condition: session consumed size
392 session name: the-session-name
393 threshold: 1234 bytes
400 list_triggers_matches_ok
"session consumed size condition" "${tmp_expected_stdout}"
402 lttng_remove_trigger_ok
"trigger-with-session-consumed-size-condition"
405 test_buffer_usage_conditions
()
407 ${register_some_triggers_bin} test_buffer_usage_conditions
409 cat > "${tmp_expected_stdout}" <<- EOF
410 - name: trigger-with-buffer-usage-high-bytes-condition
412 condition: buffer usage high
413 session name: the-session-name
414 channel name: the-channel-name
416 threshold (bytes): 1234
421 - name: trigger-with-buffer-usage-high-ratio-condition
423 condition: buffer usage high
424 session name: the-session-name
425 channel name: the-channel-name
427 threshold (ratio): 0.25
432 - name: trigger-with-buffer-usage-low-bytes-condition
434 condition: buffer usage low
435 session name: the-session-name
436 channel name: the-channel-name
438 threshold (bytes): 2345
443 - name: trigger-with-buffer-usage-low-ratio-condition
445 condition: buffer usage low
446 session name: the-session-name
447 channel name: the-channel-name
449 threshold (ratio): 0.40
456 list_triggers_matches_ok
"buffer usage condition" "${tmp_expected_stdout}"
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"
464 test_session_rotation_conditions
()
466 ${register_some_triggers_bin} test_session_rotation_conditions
468 cat > "${tmp_expected_stdout}" <<- EOF
469 - name: trigger-with-session-rotation-completed-condition
471 condition: session rotation completed
472 session name: the-session-name
477 - name: trigger-with-session-rotation-ongoing-condition
479 condition: session rotation ongoing
480 session name: the-session-name
487 list_triggers_matches_ok
"session rotation conditions" "${tmp_expected_stdout}"
489 lttng_remove_trigger_ok
"trigger-with-session-rotation-completed-condition"
490 lttng_remove_trigger_ok
"trigger-with-session-rotation-ongoing-condition"
493 test_snapshot_action
()
495 diag
"Listing snapshot actions"
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
508 cat > "${tmp_expected_stdout}" <<- EOF
511 condition: event rule matches
512 rule: some-event (type: tracepoint, domain: ust)
514 snapshot session \`ze-session\`
519 condition: event rule matches
520 rule: some-event (type: tracepoint, domain: ust)
522 snapshot session \`ze-session\`, path: /some/path
527 condition: event rule matches
528 rule: some-event (type: tracepoint, domain: ust)
530 snapshot session \`ze-session\`, path: /some/other/path
535 condition: event rule matches
536 rule: some-event (type: tracepoint, domain: ust)
538 snapshot session \`ze-session\`, url: net://1.2.3.4
543 condition: event rule matches
544 rule: some-event (type: tracepoint, domain: ust)
546 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
551 condition: event rule matches
552 rule: some-event (type: tracepoint, domain: ust)
554 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
559 condition: event rule matches
560 rule: some-event (type: tracepoint, domain: ust)
562 snapshot session \`ze-session\`, path: /some/path, max size: 1234
567 condition: event rule matches
568 rule: some-event (type: tracepoint, domain: ust)
570 snapshot session \`ze-session\`, path: /some/path, name: meh
575 condition: event rule matches
576 rule: some-event (type: tracepoint, domain: ust)
578 snapshot session \`ze-session\`, rate policy: every 10 occurrences
583 condition: event rule matches
584 rule: some-event (type: tracepoint, domain: ust)
586 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
591 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
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"
605 test_notify_action
()
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
610 cat > "${tmp_expected_stdout}" <<- EOF
613 condition: event rule matches
614 rule: some-event (type: tracepoint, domain: ust)
616 notify, rate policy: once after 5 occurrences
621 condition: event rule matches
622 rule: some-event (type: tracepoint, domain: ust)
624 notify, rate policy: every 10 occurrences
629 list_triggers_matches_ok
"notify action" "${tmp_expected_stdout}"
631 lttng_remove_trigger_ok
"T0"
632 lttng_remove_trigger_ok
"T1"
635 plan_tests
$NUM_TESTS
637 # shellcheck disable=SC2119
638 start_lttng_sessiond_notap
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
652 stop_lttng_sessiond_notap
655 rm -f "${tmp_stdout}"
656 rm -f "${tmp_stderr}"
657 rm -f "${tmp_expected_stdout}"