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"
29 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
31 tmp_stdout
=$
(mktemp
-t test_list_triggers_cli_stdout.XXXXXX
)
32 tmp_stderr
=$
(mktemp
-t test_list_triggers_cli_stderr.XXXXXX
)
33 tmp_expected_stdout
=$
(mktemp
-t test_list_triggers_cli_expected_stdout.XXXXXX
)
34 uprobe_elf_binary
=$
(realpath
"${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
35 uprobe_sdt_binary
=$
(realpath
"${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary")
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 on-event
-u test-id
--action notify
75 cat > "${tmp_expected_stdout}" <<- EOF
78 condition: event rule hit
79 rule: test-id (type: tracepoint, domain: ust)
86 list_triggers_matches_ok
"top level options" "${tmp_expected_stdout}"
88 lttng_remove_trigger_ok
"hello"
91 test_on_event_tracepoint
()
93 diag
"Listing on-event tracepoint"
95 lttng_add_trigger_ok
"C" --condition on-event
-u -a --action notify
96 lttng_add_trigger_ok
"A" --condition on-event aaa
-u --filter 'p == 2' --action notify
97 lttng_add_trigger_ok
"D" --condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
98 lttng_add_trigger_ok
"B" --condition on-event
-u gerboise
--loglevel INFO
--action notify
99 lttng_add_trigger_ok
"E" --condition on-event
-u lemming
--loglevel-only WARNING
--action notify
100 lttng_add_trigger_ok
"F" --condition on-event
-u capture-payload-field
--capture a
--action notify
101 lttng_add_trigger_ok
"G" --condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
102 lttng_add_trigger_ok
"H" --condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
103 lttng_add_trigger_ok
"I" --condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
106 cat > "${tmp_expected_stdout}" <<- EOF
109 condition: event rule hit
110 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
117 condition: event rule hit
118 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
125 condition: event rule hit
126 rule: * (type: tracepoint, domain: ust)
133 condition: event rule hit
134 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
141 condition: event rule hit
142 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
149 condition: event rule hit
150 rule: capture-payload-field (type: tracepoint, domain: ust)
159 condition: event rule hit
160 rule: capture-array (type: tracepoint, domain: ust)
170 condition: event rule hit
171 rule: capture-chan-ctx (type: tracepoint, domain: ust)
180 condition: event rule hit
181 rule: capture-app-ctx (type: tracepoint, domain: ust)
183 - \$app.iga:active_clients
190 list_triggers_matches_ok
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
192 lttng_remove_trigger_ok
"A"
193 lttng_remove_trigger_ok
"B"
194 lttng_remove_trigger_ok
"C"
195 lttng_remove_trigger_ok
"D"
196 lttng_remove_trigger_ok
"E"
197 lttng_remove_trigger_ok
"F"
198 lttng_remove_trigger_ok
"G"
199 lttng_remove_trigger_ok
"H"
200 lttng_remove_trigger_ok
"I"
203 test_on_event_probe
()
205 local channel_enable_addr
206 local channel_disable_addr
208 diag
"Listing on-event kernel probe"
210 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
211 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
213 # We need to find a valid offset.
216 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
217 base_symbol
="lttng_channel_enable"
218 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
220 base_symbol
="lttng_channel_disable"
221 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
224 offset_hex
="0x$(printf '%x' $offset)"
226 lttng_add_trigger_ok
"T0" --condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
227 lttng_add_trigger_ok
"T1" --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
228 lttng_add_trigger_ok
"T2" --condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
230 cat > "${tmp_expected_stdout}" <<- EOF
233 condition: event rule hit
234 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
249 condition: event rule hit
250 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
257 list_triggers_matches_ok
"on-event, probe event rule" "${tmp_expected_stdout}"
259 lttng_remove_trigger_ok
"T0"
260 lttng_remove_trigger_ok
"T1"
261 lttng_remove_trigger_ok
"T2"
264 test_on_event_userspace_probe_elf
()
266 local elf_function_name
="test_function"
268 diag
"Listing on-event userspace-probe elf"
270 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:${elf_function_name} ma-probe-elf
--action notify
272 cat > "${tmp_expected_stdout}" <<- EOF
275 condition: event rule hit
276 rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
283 list_triggers_matches_ok
"on-event, userspace-probe event rule ELF" "${tmp_expected_stdout}"
285 lttng_remove_trigger_ok
"T0"
288 test_on_event_userspace_probe_sdt
()
291 local sdt_provider_name
="foobar"
292 local sdt_probe_name
="tp1"
294 diag
"on-event userspace-probe sdt"
296 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=sdt
:${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name} ma-probe-sdt
--action notify
298 cat > "${tmp_expected_stdout}" <<- EOF
301 condition: event rule hit
302 rule: ma-probe-sdt (type: userspace probe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
309 list_triggers_matches_ok
"on-event, userspace-probe event rule SDT" "${tmp_expected_stdout}"
311 lttng_remove_trigger_ok
"T0"
314 test_on_event_syscall
()
316 diag
"Listing on-event syscall"
318 lttng_add_trigger_ok
"T0" --condition on-event
-k --syscall open
--action notify
319 lttng_add_trigger_ok
"T1" --condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
321 cat > "${tmp_expected_stdout}" <<- EOF
324 condition: event rule hit
325 rule: open (type: syscall)
332 condition: event rule hit
333 rule: ptrace (type: syscall, filter: a > 2)
340 list_triggers_matches_ok
"on-event, syscall event rule" "${tmp_expected_stdout}"
342 lttng_remove_trigger_ok
"T0"
343 lttng_remove_trigger_ok
"T1"
346 test_snapshot_action
()
348 diag
"Listing snapshot actions"
350 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action snapshot-session ze-session
351 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
352 lttng_add_trigger_ok
"T2" --condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
353 lttng_add_trigger_ok
"T3" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
354 lttng_add_trigger_ok
"T4" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
355 lttng_add_trigger_ok
"T5" --condition on-event
-u some-event
--action snapshot-session ze-session
--ctrl-url=tcp
://1.2.3.4:1111 --data-url=tcp
://1.2.3.4:1112
356 lttng_add_trigger_ok
"T6" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
357 lttng_add_trigger_ok
"T7" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
358 lttng_add_trigger_ok
"T8" --condition on-event
-u some-event
--action snapshot-session ze-session
--rate-policy=every
:10
359 lttng_add_trigger_ok
"T9" --condition on-event
-u some-event
--action snapshot-session ze-session
--rate-policy=once-after
:10
362 cat > "${tmp_expected_stdout}" <<- EOF
365 condition: event rule hit
366 rule: some-event (type: tracepoint, domain: ust)
368 snapshot session \`ze-session\`
373 condition: event rule hit
374 rule: some-event (type: tracepoint, domain: ust)
376 snapshot session \`ze-session\`, path: /some/path
381 condition: event rule hit
382 rule: some-event (type: tracepoint, domain: ust)
384 snapshot session \`ze-session\`, path: /some/other/path
389 condition: event rule hit
390 rule: some-event (type: tracepoint, domain: ust)
392 snapshot session \`ze-session\`, url: net://1.2.3.4
397 condition: event rule hit
398 rule: some-event (type: tracepoint, domain: ust)
400 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
405 condition: event rule hit
406 rule: some-event (type: tracepoint, domain: ust)
408 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
413 condition: event rule hit
414 rule: some-event (type: tracepoint, domain: ust)
416 snapshot session \`ze-session\`, path: /some/path, max size: 1234
421 condition: event rule hit
422 rule: some-event (type: tracepoint, domain: ust)
424 snapshot session \`ze-session\`, path: /some/path, name: meh
429 condition: event rule hit
430 rule: some-event (type: tracepoint, domain: ust)
432 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
437 condition: event rule hit
438 rule: some-event (type: tracepoint, domain: ust)
440 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
445 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
447 stop_lttng_sessiond_notap
450 test_notify_action
()
452 start_lttng_sessiond_notap
454 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action notify
--rate-policy=once-after
:5
455 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action notify
--rate-policy=every
:10
458 cat > "${tmp_expected_stdout}" <<- EOF
461 condition: event rule hit
462 rule: some-event (type: tracepoint, domain: ust)
464 notify, rate policy: once after 5 occurrences
469 condition: event rule hit
470 rule: some-event (type: tracepoint, domain: ust)
472 notify, rate policy: after every 10 occurrences
477 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
479 lttng_remove_trigger_ok
"T0"
480 lttng_remove_trigger_ok
"T1"
483 plan_tests
$NUM_TESTS
485 # shellcheck disable=SC2119
486 start_lttng_sessiond_notap
488 test_top_level_options
489 test_on_event_tracepoint
490 skip
$ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
491 skip
$ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
492 skip $
(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
493 skip
$ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
497 stop_lttng_sessiond_notap
500 rm -f "${tmp_stdout}"
501 rm -f "${tmp_stderr}"
502 rm -f "${tmp_expected_stdout}"