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)
71 list_triggers_matches_ok
"top level options" "${tmp_expected_stdout}"
73 lttng_remove_trigger_ok
"hello"
76 test_event_rule_matches_tracepoint
()
78 diag
"Listing event-rule-matches tracepoint"
80 lttng_add_trigger_ok
"C" --condition event-rule-matches
--type=user
--action notify
81 lttng_add_trigger_ok
"A" --condition event-rule-matches
--name=aaa
--type=user
--filter 'p == 2' --action notify
82 lttng_add_trigger_ok
"D" --condition event-rule-matches
--name='hello*' --type=user
-x hello2
--exclude-name hello3
-x hello4
--action notify
83 lttng_add_trigger_ok
"B" --condition event-rule-matches
--type=user
--name=gerboise
--log-level INFO..
--action notify
84 lttng_add_trigger_ok
"E" --condition event-rule-matches
--type=user
--name=lemming
--log-level WARNING
--action notify
85 lttng_add_trigger_ok
"J" --condition event-rule-matches
--type=user
--name=lemming
--log-level ..
--action notify
86 lttng_add_trigger_ok
"F" --condition event-rule-matches
--type=user
--name=capture-payload-field
--capture a
--action notify
87 lttng_add_trigger_ok
"G" --condition event-rule-matches
--type=user
--name=capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
88 lttng_add_trigger_ok
"H" --condition event-rule-matches
--type=user
--name=capture-chan-ctx
--capture '$ctx.vpid' --action notify
89 lttng_add_trigger_ok
"I" --condition event-rule-matches
--type=user
--name=capture-app-ctx
--capture '$app.iga:active_clients' --action notify
91 cat > "${tmp_expected_stdout}" <<- EOF
94 condition: event rule matches
95 rule: aaa (type: user tracepoint, filter: p == 2)
102 condition: event rule matches
103 rule: gerboise (type: user tracepoint, log level at least INFO)
110 condition: event rule matches
111 rule: * (type: user tracepoint)
118 condition: event rule matches
119 rule: hello* (type: user tracepoint, exclusions: hello2,hello3,hello4)
126 condition: event rule matches
127 rule: lemming (type: user tracepoint, log level is WARNING)
134 condition: event rule matches
135 rule: capture-payload-field (type: user tracepoint)
144 condition: event rule matches
145 rule: capture-array (type: user tracepoint)
155 condition: event rule matches
156 rule: capture-chan-ctx (type: user tracepoint)
165 condition: event rule matches
166 rule: capture-app-ctx (type: user tracepoint)
168 - \$app.iga:active_clients
175 condition: event rule matches
176 rule: lemming (type: user tracepoint)
183 list_triggers_matches_ok
"event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}"
185 lttng_remove_trigger_ok
"A"
186 lttng_remove_trigger_ok
"B"
187 lttng_remove_trigger_ok
"C"
188 lttng_remove_trigger_ok
"D"
189 lttng_remove_trigger_ok
"E"
190 lttng_remove_trigger_ok
"F"
191 lttng_remove_trigger_ok
"G"
192 lttng_remove_trigger_ok
"H"
193 lttng_remove_trigger_ok
"I"
194 lttng_remove_trigger_ok
"J"
197 test_event_rule_matches_probe
()
199 local channel_enable_addr
200 local channel_disable_addr
202 diag
"Listing event-rule-matches kernel probe"
204 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
205 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
207 # We need to find a valid offset.
210 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
211 base_symbol
="lttng_channel_enable"
212 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
214 base_symbol
="lttng_channel_disable"
215 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
218 offset_hex
="0x$(printf '%x' $offset)"
220 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=kprobe
--location=lttng_channel_enable
--event-name=my_channel_enable
--action notify
221 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=kprobe
--location="${base_symbol}+${offset_hex}" --event-name=my_channel_enable
--action notify
222 lttng_add_trigger_ok
"T2" --condition event-rule-matches
--type=kprobe
--location="0x${channel_enable_addr}" --event-name=my_channel_enable
--action notify
224 cat > "${tmp_expected_stdout}" <<- EOF
227 condition: event rule matches
228 rule: my_channel_enable (type: kernel:kprobe, location: lttng_channel_enable)
235 condition: event rule matches
236 rule: my_channel_enable (type: kernel:kprobe, location: ${base_symbol}+${offset_hex})
243 condition: event rule matches
244 rule: my_channel_enable (type: kernel:kprobe, location: 0x${channel_enable_addr})
251 list_triggers_matches_ok
"event-rule-matches, probe event rule" "${tmp_expected_stdout}"
253 lttng_remove_trigger_ok
"T0"
254 lttng_remove_trigger_ok
"T1"
255 lttng_remove_trigger_ok
"T2"
258 test_event_rule_matches_userspace_probe_elf
()
260 local elf_function_name
="test_function"
262 diag
"Listing event-rule-matches userspace-probe elf"
264 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
266 cat > "${tmp_expected_stdout}" <<- EOF
269 condition: event rule matches
270 rule: ma-probe-elf (type: kernel:uprobe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
277 list_triggers_matches_ok
"event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}"
279 lttng_remove_trigger_ok
"T0"
282 test_event_rule_matches_userspace_probe_sdt
()
284 local sdt_provider_name
="foobar"
285 local sdt_probe_name
="tp1"
287 diag
"Listing event-rule-matches userspace-probe sdt"
289 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
291 cat > "${tmp_expected_stdout}" <<- EOF
294 condition: event rule matches
295 rule: ma-probe-sdt (type: kernel:uprobe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
302 list_triggers_matches_ok
"event-rule-matches, userspace-probe event rule SDT" "${tmp_expected_stdout}"
304 lttng_remove_trigger_ok
"T0"
307 test_event_rule_matches_syscall
()
309 diag
"Listing event-rule-matches syscall"
311 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=syscall
--name=open
--action notify
312 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=syscall
:entry
--name=open
--action notify
313 lttng_add_trigger_ok
"T2" --condition event-rule-matches
--type=syscall
:exit --name=open
--action notify
314 lttng_add_trigger_ok
"T3" --condition event-rule-matches
--type=syscall
:entry
+exit --name=open
--action notify
315 lttng_add_trigger_ok
"T4" --condition event-rule-matches
--type=syscall
--name=ptrace
--filter 'a > 2' --action notify
317 cat > "${tmp_expected_stdout}" <<- EOF
320 condition: event rule matches
321 rule: open (type: kernel:syscall:entry+exit)
328 condition: event rule matches
329 rule: open (type: kernel:syscall:entry)
336 condition: event rule matches
337 rule: open (type: kernel:syscall:exit)
344 condition: event rule matches
345 rule: open (type: kernel:syscall:entry+exit)
352 condition: event rule matches
353 rule: ptrace (type: kernel:syscall:entry+exit, filter: a > 2)
360 list_triggers_matches_ok
"event-rule-matches, syscall event rule" "${tmp_expected_stdout}"
362 lttng_remove_trigger_ok
"T0"
363 lttng_remove_trigger_ok
"T1"
364 lttng_remove_trigger_ok
"T2"
365 lttng_remove_trigger_ok
"T3"
366 lttng_remove_trigger_ok
"T4"
369 test_session_consumed_size_condition
()
371 ${register_some_triggers_bin} test_session_consumed_size_condition
373 cat > "${tmp_expected_stdout}" <<- EOF
374 - name: trigger-with-session-consumed-size-condition
376 condition: session consumed size
377 session name: the-session-name
378 threshold: 1234 bytes
385 list_triggers_matches_ok
"session consumed size condition" "${tmp_expected_stdout}"
387 lttng_remove_trigger_ok
"trigger-with-session-consumed-size-condition"
390 test_buffer_usage_conditions
()
392 ${register_some_triggers_bin} test_buffer_usage_conditions
394 cat > "${tmp_expected_stdout}" <<- EOF
395 - name: trigger-with-buffer-usage-high-bytes-condition
397 condition: buffer usage high
398 session name: the-session-name
399 channel name: the-channel-name
401 threshold (bytes): 1234
406 - name: trigger-with-buffer-usage-high-ratio-condition
408 condition: buffer usage high
409 session name: the-session-name
410 channel name: the-channel-name
412 threshold (ratio): 0.25
417 - name: trigger-with-buffer-usage-low-bytes-condition
419 condition: buffer usage low
420 session name: the-session-name
421 channel name: the-channel-name
423 threshold (bytes): 2345
428 - name: trigger-with-buffer-usage-low-ratio-condition
430 condition: buffer usage low
431 session name: the-session-name
432 channel name: the-channel-name
434 threshold (ratio): 0.40
441 list_triggers_matches_ok
"buffer usage condition" "${tmp_expected_stdout}"
443 lttng_remove_trigger_ok
"trigger-with-buffer-usage-high-bytes-condition"
444 lttng_remove_trigger_ok
"trigger-with-buffer-usage-high-ratio-condition"
445 lttng_remove_trigger_ok
"trigger-with-buffer-usage-low-bytes-condition"
446 lttng_remove_trigger_ok
"trigger-with-buffer-usage-low-ratio-condition"
449 test_session_rotation_conditions
()
451 ${register_some_triggers_bin} test_session_rotation_conditions
453 cat > "${tmp_expected_stdout}" <<- EOF
454 - name: trigger-with-session-rotation-completed-condition
456 condition: session rotation completed
457 session name: the-session-name
462 - name: trigger-with-session-rotation-ongoing-condition
464 condition: session rotation ongoing
465 session name: the-session-name
472 list_triggers_matches_ok
"session rotation conditions" "${tmp_expected_stdout}"
474 lttng_remove_trigger_ok
"trigger-with-session-rotation-completed-condition"
475 lttng_remove_trigger_ok
"trigger-with-session-rotation-ongoing-condition"
478 test_snapshot_action
()
480 diag
"Listing snapshot actions"
482 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
483 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--path /some
/path
484 lttng_add_trigger_ok
"T2" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
485 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
486 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
487 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
488 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
489 lttng_add_trigger_ok
"T7" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
490 lttng_add_trigger_ok
"T8" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--rate-policy=every
:10
491 lttng_add_trigger_ok
"T9" --condition event-rule-matches
--type=user
--name=some-event
--action snapshot-session ze-session
--rate-policy=once-after
:10
493 cat > "${tmp_expected_stdout}" <<- EOF
496 condition: event rule matches
497 rule: some-event (type: user tracepoint)
499 snapshot session \`ze-session\`
504 condition: event rule matches
505 rule: some-event (type: user tracepoint)
507 snapshot session \`ze-session\`, path: /some/path
512 condition: event rule matches
513 rule: some-event (type: user tracepoint)
515 snapshot session \`ze-session\`, path: /some/other/path
520 condition: event rule matches
521 rule: some-event (type: user tracepoint)
523 snapshot session \`ze-session\`, url: net://1.2.3.4
528 condition: event rule matches
529 rule: some-event (type: user tracepoint)
531 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
536 condition: event rule matches
537 rule: some-event (type: user tracepoint)
539 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
544 condition: event rule matches
545 rule: some-event (type: user tracepoint)
547 snapshot session \`ze-session\`, path: /some/path, max size: 1234
552 condition: event rule matches
553 rule: some-event (type: user tracepoint)
555 snapshot session \`ze-session\`, path: /some/path, name: meh
560 condition: event rule matches
561 rule: some-event (type: user tracepoint)
563 snapshot session \`ze-session\`, rate policy: every 10 occurrences
568 condition: event rule matches
569 rule: some-event (type: user tracepoint)
571 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
576 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
578 lttng_remove_trigger_ok
"T0"
579 lttng_remove_trigger_ok
"T1"
580 lttng_remove_trigger_ok
"T2"
581 lttng_remove_trigger_ok
"T3"
582 lttng_remove_trigger_ok
"T4"
583 lttng_remove_trigger_ok
"T5"
584 lttng_remove_trigger_ok
"T6"
585 lttng_remove_trigger_ok
"T7"
586 lttng_remove_trigger_ok
"T8"
587 lttng_remove_trigger_ok
"T9"
590 test_notify_action
()
592 lttng_add_trigger_ok
"T0" --condition event-rule-matches
--type=user
--name=some-event
--action notify
--rate-policy=once-after
:5
593 lttng_add_trigger_ok
"T1" --condition event-rule-matches
--type=user
--name=some-event
--action notify
--rate-policy=every
:10
595 cat > "${tmp_expected_stdout}" <<- EOF
598 condition: event rule matches
599 rule: some-event (type: user tracepoint)
601 notify, rate policy: once after 5 occurrences
606 condition: event rule matches
607 rule: some-event (type: user tracepoint)
609 notify, rate policy: every 10 occurrences
614 list_triggers_matches_ok
"notify action" "${tmp_expected_stdout}"
616 lttng_remove_trigger_ok
"T0"
617 lttng_remove_trigger_ok
"T1"
620 plan_tests
$NUM_TESTS
622 # shellcheck disable=SC2119
623 start_lttng_sessiond_notap
625 test_top_level_options
626 test_event_rule_matches_tracepoint
627 skip
$ist_root "non-root user: skipping kprobe tests" 9 || test_event_rule_matches_probe
628 skip
$ist_root "non-root user: skipping uprobe tests" 5 || test_event_rule_matches_userspace_probe_elf
629 skip $
(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_event_rule_matches_userspace_probe_sdt
630 skip
$ist_root "non-root user: skipping syscall tests" 13 || test_event_rule_matches_syscall
631 test_session_consumed_size_condition
632 test_buffer_usage_conditions
633 test_session_rotation_conditions
637 stop_lttng_sessiond_notap
640 rm -f "${tmp_stdout}"
641 rm -f "${tmp_stderr}"
642 rm -f "${tmp_expected_stdout}"