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")
39 if [ "$uid" == "0" ]; then
46 function list_triggers_matches_ok
()
49 local expected_stdout_file
="$2"
51 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
52 ok $?
"${test_name}: exit code is 0"
54 diff -u "${expected_stdout_file}" "${tmp_stdout}"
55 ok $?
"${test_name}: expected stdout"
57 diff -u /dev
/null
"${tmp_stderr}"
58 ok $?
"${test_name}: expected stderr"
61 test_top_level_options
()
63 diag
"Listing top level options"
65 lttng_add_trigger_ok
"hello" --condition on-event
-u test-id
--action notify
67 cat > "${tmp_expected_stdout}" <<- EOF
70 condition: event rule hit
71 rule: test-id (type: tracepoint, domain: ust)
78 list_triggers_matches_ok
"top level options" "${tmp_expected_stdout}"
80 lttng_remove_trigger_ok
"hello"
83 test_on_event_tracepoint
()
85 diag
"Listing on-event tracepoint"
87 lttng_add_trigger_ok
"C" --condition on-event
-u -a --action notify
88 lttng_add_trigger_ok
"A" --condition on-event aaa
-u --filter 'p == 2' --action notify
89 lttng_add_trigger_ok
"D" --condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
90 lttng_add_trigger_ok
"B" --condition on-event
-u gerboise
--loglevel INFO
--action notify
91 lttng_add_trigger_ok
"E" --condition on-event
-u lemming
--loglevel-only WARNING
--action notify
92 lttng_add_trigger_ok
"F" --condition on-event
-u capture-payload-field
--capture a
--action notify
93 lttng_add_trigger_ok
"G" --condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
94 lttng_add_trigger_ok
"H" --condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
95 lttng_add_trigger_ok
"I" --condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
98 cat > "${tmp_expected_stdout}" <<- EOF
101 condition: event rule hit
102 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
109 condition: event rule hit
110 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
117 condition: event rule hit
118 rule: * (type: tracepoint, domain: ust)
125 condition: event rule hit
126 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
133 condition: event rule hit
134 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
141 condition: event rule hit
142 rule: capture-payload-field (type: tracepoint, domain: ust)
151 condition: event rule hit
152 rule: capture-array (type: tracepoint, domain: ust)
162 condition: event rule hit
163 rule: capture-chan-ctx (type: tracepoint, domain: ust)
172 condition: event rule hit
173 rule: capture-app-ctx (type: tracepoint, domain: ust)
175 - \$app.iga:active_clients
182 list_triggers_matches_ok
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
184 lttng_remove_trigger_ok
"A"
185 lttng_remove_trigger_ok
"B"
186 lttng_remove_trigger_ok
"C"
187 lttng_remove_trigger_ok
"D"
188 lttng_remove_trigger_ok
"E"
189 lttng_remove_trigger_ok
"F"
190 lttng_remove_trigger_ok
"G"
191 lttng_remove_trigger_ok
"H"
192 lttng_remove_trigger_ok
"I"
195 test_on_event_probe
()
197 local channel_enable_addr
198 local channel_disable_addr
200 diag
"Listing on-event kernel probe"
202 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
203 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
205 # We need to find a valid offset.
208 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
209 base_symbol
="lttng_channel_enable"
210 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
212 base_symbol
="lttng_channel_disable"
213 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
216 offset_hex
="0x$(printf '%x' $offset)"
218 lttng_add_trigger_ok
"T0" --condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
219 lttng_add_trigger_ok
"T1" --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
220 lttng_add_trigger_ok
"T2" --condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
222 cat > "${tmp_expected_stdout}" <<- EOF
225 condition: event rule hit
226 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
233 condition: event rule hit
234 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
249 list_triggers_matches_ok
"on-event, probe event rule" "${tmp_expected_stdout}"
251 lttng_remove_trigger_ok
"T0"
252 lttng_remove_trigger_ok
"T1"
253 lttng_remove_trigger_ok
"T2"
256 test_on_event_userspace_probe
()
258 local elf_function_name
="test_function"
260 diag
"Listing on-event userspace-probe elf"
262 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:${elf_function_name} ma-probe-elf
--action notify
264 cat > "${tmp_expected_stdout}" <<- EOF
267 condition: event rule hit
268 rule: ma-probe-elf (type: userspace probe, location: ${uprobe_elf_binary}:${elf_function_name})
275 list_triggers_matches_ok
"on-event, userspace-probe event rule ELF" "${tmp_expected_stdout}"
277 lttng_remove_trigger_ok
"T0"
280 test_on_event_syscall
()
282 diag
"Listing on-event syscall"
284 lttng_add_trigger_ok
"T0" --condition on-event
-k --syscall open
--action notify
285 lttng_add_trigger_ok
"T1" --condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
287 cat > "${tmp_expected_stdout}" <<- EOF
290 condition: event rule hit
291 rule: open (type: syscall)
298 condition: event rule hit
299 rule: ptrace (type: syscall, filter: a > 2)
306 list_triggers_matches_ok
"on-event, syscall event rule" "${tmp_expected_stdout}"
308 lttng_remove_trigger_ok
"T0"
309 lttng_remove_trigger_ok
"T1"
312 test_snapshot_action
()
314 diag
"Listing snapshot actions"
316 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action snapshot-session ze-session
317 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
318 lttng_add_trigger_ok
"T2" --condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
319 lttng_add_trigger_ok
"T3" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
320 lttng_add_trigger_ok
"T4" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
321 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
322 lttng_add_trigger_ok
"T6" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
323 lttng_add_trigger_ok
"T7" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
324 lttng_add_trigger_ok
"T8" --condition on-event
-u some-event
--action snapshot-session ze-session
--rate-policy=every
:10
325 lttng_add_trigger_ok
"T9" --condition on-event
-u some-event
--action snapshot-session ze-session
--rate-policy=once-after
:10
328 cat > "${tmp_expected_stdout}" <<- EOF
331 condition: event rule hit
332 rule: some-event (type: tracepoint, domain: ust)
334 snapshot session \`ze-session\`
339 condition: event rule hit
340 rule: some-event (type: tracepoint, domain: ust)
342 snapshot session \`ze-session\`, path: /some/path
347 condition: event rule hit
348 rule: some-event (type: tracepoint, domain: ust)
350 snapshot session \`ze-session\`, path: /some/other/path
355 condition: event rule hit
356 rule: some-event (type: tracepoint, domain: ust)
358 snapshot session \`ze-session\`, url: net://1.2.3.4
363 condition: event rule hit
364 rule: some-event (type: tracepoint, domain: ust)
366 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
371 condition: event rule hit
372 rule: some-event (type: tracepoint, domain: ust)
374 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
379 condition: event rule hit
380 rule: some-event (type: tracepoint, domain: ust)
382 snapshot session \`ze-session\`, path: /some/path, max size: 1234
387 condition: event rule hit
388 rule: some-event (type: tracepoint, domain: ust)
390 snapshot session \`ze-session\`, path: /some/path, name: meh
395 condition: event rule hit
396 rule: some-event (type: tracepoint, domain: ust)
398 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
403 condition: event rule hit
404 rule: some-event (type: tracepoint, domain: ust)
406 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
411 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
413 stop_lttng_sessiond_notap
416 test_notify_action
()
418 start_lttng_sessiond_notap
420 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action notify
--rate-policy=once-after
:5
421 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action notify
--rate-policy=every
:10
424 cat > "${tmp_expected_stdout}" <<- EOF
427 condition: event rule hit
428 rule: some-event (type: tracepoint, domain: ust)
430 notify, rate policy: once after 5 occurrences
435 condition: event rule hit
436 rule: some-event (type: tracepoint, domain: ust)
438 notify, rate policy: after every 10 occurrences
443 list_triggers_matches_ok
"snapshot action" "${tmp_expected_stdout}"
445 lttng_remove_trigger_ok
"T0"
446 lttng_remove_trigger_ok
"T1"
449 plan_tests
$NUM_TESTS
451 # shellcheck disable=SC2119
452 start_lttng_sessiond_notap
454 test_top_level_options
455 test_on_event_tracepoint
456 skip
$ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
457 skip
$ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe
458 skip
$ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
462 stop_lttng_sessiond_notap
465 rm -f "${tmp_stdout}"
466 rm -f "${tmp_stderr}"
467 rm -f "${tmp_expected_stdout}"