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")
38 if [ "$uid" == "0" ]; then
44 function list_triggers
()
47 local expected_stdout_file
="$2"
49 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
50 ok $?
"${test_name}: exit code is 0"
52 diff -u "${expected_stdout_file}" "${tmp_stdout}"
53 ok $?
"${test_name}: expected stdout"
55 diff -u /dev
/null
"${tmp_stderr}"
56 ok $?
"${test_name}: expected stderr"
59 test_top_level_options
()
61 # shellcheck disable=SC2119
62 start_lttng_sessiond_notap
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
"top level options" "${tmp_expected_stdout}"
80 stop_lttng_sessiond_notap
83 test_on_event_tracepoint
()
85 # shellcheck disable=SC2119
86 start_lttng_sessiond_notap
88 lttng_add_trigger_ok
"C" --condition on-event
-u -a --action notify
89 lttng_add_trigger_ok
"A" --condition on-event aaa
-u --filter 'p == 2' --action notify
90 lttng_add_trigger_ok
"D" --condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
91 lttng_add_trigger_ok
"B" --condition on-event
-u gerboise
--loglevel INFO
--action notify
92 lttng_add_trigger_ok
"E" --condition on-event
-u lemming
--loglevel-only WARNING
--action notify
93 lttng_add_trigger_ok
"F" --condition on-event
-u capture-payload-field
--capture a
--action notify
94 lttng_add_trigger_ok
"G" --condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
95 lttng_add_trigger_ok
"H" --condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
96 lttng_add_trigger_ok
"I" --condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
99 cat > "${tmp_expected_stdout}" <<- EOF
102 condition: event rule hit
103 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
110 condition: event rule hit
111 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
118 condition: event rule hit
119 rule: * (type: tracepoint, domain: ust)
126 condition: event rule hit
127 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
134 condition: event rule hit
135 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
142 condition: event rule hit
143 rule: capture-payload-field (type: tracepoint, domain: ust)
152 condition: event rule hit
153 rule: capture-array (type: tracepoint, domain: ust)
163 condition: event rule hit
164 rule: capture-chan-ctx (type: tracepoint, domain: ust)
173 condition: event rule hit
174 rule: capture-app-ctx (type: tracepoint, domain: ust)
176 - \$app.iga:active_clients
183 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
185 stop_lttng_sessiond_notap
188 test_on_event_probe
()
190 local channel_enable_addr
191 local channel_disable_addr
193 # shellcheck disable=SC2119
194 start_lttng_sessiond_notap
196 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
197 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
199 # We need to find a valid offset.
202 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
203 base_symbol
="lttng_channel_enable"
204 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
206 base_symbol
="lttng_channel_disable"
207 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
210 offset_hex
="0x$(printf '%x' $offset)"
212 lttng_add_trigger_ok
"T0" --condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
213 lttng_add_trigger_ok
"T1" --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
214 lttng_add_trigger_ok
"T2" --condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
216 cat > "${tmp_expected_stdout}" <<- EOF
219 condition: event rule hit
220 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
227 condition: event rule hit
228 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
235 condition: event rule hit
236 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
243 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
245 stop_lttng_sessiond_notap
248 test_on_event_userspace_probe
()
250 # shellcheck disable=SC2119
251 start_lttng_sessiond_notap
253 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
255 cat > "${tmp_expected_stdout}" <<- EOF
258 condition: event rule hit
259 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
266 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
268 stop_lttng_sessiond_notap
271 test_on_event_syscall
()
273 # shellcheck disable=SC2119
274 start_lttng_sessiond_notap
276 lttng_add_trigger_ok
"T0" --condition on-event
-k --syscall open
--action notify
277 lttng_add_trigger_ok
"T1" --condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
279 cat > "${tmp_expected_stdout}" <<- EOF
282 condition: event rule hit
283 rule: open (type: syscall)
290 condition: event rule hit
291 rule: ptrace (type: syscall, filter: a > 2)
298 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
300 stop_lttng_sessiond_notap
303 test_snapshot_action
()
305 start_lttng_sessiond_notap
307 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action snapshot-session ze-session
308 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
309 lttng_add_trigger_ok
"T2" --condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
310 lttng_add_trigger_ok
"T3" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
311 lttng_add_trigger_ok
"T4" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
312 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
313 lttng_add_trigger_ok
"T6" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
314 lttng_add_trigger_ok
"T7" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
315 lttng_add_trigger_ok
"T8" --condition on-event
-u some-event
--action snapshot-session ze-session
--rate-policy=every
:10
316 lttng_add_trigger_ok
"T9" --condition on-event
-u some-event
--action snapshot-session ze-session
--rate-policy=once-after
:10
319 cat > "${tmp_expected_stdout}" <<- EOF
322 condition: event rule hit
323 rule: some-event (type: tracepoint, domain: ust)
325 snapshot session \`ze-session\`
330 condition: event rule hit
331 rule: some-event (type: tracepoint, domain: ust)
333 snapshot session \`ze-session\`, path: /some/path
338 condition: event rule hit
339 rule: some-event (type: tracepoint, domain: ust)
341 snapshot session \`ze-session\`, path: /some/other/path
346 condition: event rule hit
347 rule: some-event (type: tracepoint, domain: ust)
349 snapshot session \`ze-session\`, url: net://1.2.3.4
354 condition: event rule hit
355 rule: some-event (type: tracepoint, domain: ust)
357 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
362 condition: event rule hit
363 rule: some-event (type: tracepoint, domain: ust)
365 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
370 condition: event rule hit
371 rule: some-event (type: tracepoint, domain: ust)
373 snapshot session \`ze-session\`, path: /some/path, max size: 1234
378 condition: event rule hit
379 rule: some-event (type: tracepoint, domain: ust)
381 snapshot session \`ze-session\`, path: /some/path, name: meh
386 condition: event rule hit
387 rule: some-event (type: tracepoint, domain: ust)
389 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
394 condition: event rule hit
395 rule: some-event (type: tracepoint, domain: ust)
397 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
402 list_triggers
"snapshot action" "${tmp_expected_stdout}"
404 stop_lttng_sessiond_notap
407 test_notify_action
()
409 start_lttng_sessiond_notap
411 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action notify
--rate-policy=once-after
:5
412 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action notify
--rate-policy=every
:10
415 cat > "${tmp_expected_stdout}" <<- EOF
418 condition: event rule hit
419 rule: some-event (type: tracepoint, domain: ust)
421 notify, rate policy: once after 5 occurrences
426 condition: event rule hit
427 rule: some-event (type: tracepoint, domain: ust)
429 notify, rate policy: after every 10 occurrences
434 list_triggers
"snapshot action" "${tmp_expected_stdout}"
436 stop_lttng_sessiond_notap
439 test_top_level_options
440 test_on_event_tracepoint
441 skip
$ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
442 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
443 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
448 rm -f "${tmp_stdout}"
449 rm -f "${tmp_stderr}"
450 rm -f "${tmp_expected_stdout}"