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 add_trigger
()
46 "${FULL_LTTNG_BIN}" add-trigger
"$@"
47 ok $?
"add trigger \`$*\`: exit code is 0"
50 function list_triggers
()
53 local expected_stdout_file
="$2"
55 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
56 ok $?
"${test_name}: exit code is 0"
58 diff -u "${expected_stdout_file}" "${tmp_stdout}"
59 ok $?
"${test_name}: expected stdout"
61 diff -u /dev
/null
"${tmp_stderr}"
62 ok $?
"${test_name}: expected stderr"
65 test_top_level_options
()
67 # shellcheck disable=SC2119
68 start_lttng_sessiond_notap
71 add_trigger
--id hello
--condition on-event
-u test-id
--action notify
72 add_trigger
--fire-once-after 123 --condition on-event
-u test-fire-once-after
--action notify
73 add_trigger
--fire-every 124 --condition on-event
-u test-fire-every
--action notify
75 cat > "${tmp_expected_stdout}" <<- EOF
78 firing policy: once after 123 occurences
79 tracer notifications discarded: 0
80 condition: event rule hit
81 rule: test-fire-once-after (type: tracepoint, domain: ust)
86 firing policy: after every 124 occurences
87 tracer notifications discarded: 0
88 condition: event rule hit
89 rule: test-fire-every (type: tracepoint, domain: ust)
94 tracer notifications discarded: 0
95 condition: event rule hit
96 rule: test-id (type: tracepoint, domain: ust)
101 list_triggers
"top level options" "${tmp_expected_stdout}"
103 stop_lttng_sessiond_notap
106 test_on_event_tracepoint
()
108 # shellcheck disable=SC2119
109 start_lttng_sessiond_notap
111 add_trigger
--condition on-event
-u -a --action notify
112 add_trigger
--id ABC
--condition on-event aaa
-u --filter 'p == 2' --action notify
113 add_trigger
--condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
114 add_trigger
--id BCD
--condition on-event
-u gerboise
--loglevel INFO
--action notify
115 add_trigger
--condition on-event
-u lemming
--loglevel-only WARNING
--action notify
116 add_trigger
--condition on-event
-u capture-payload-field
--capture a
--action notify
117 add_trigger
--condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
118 add_trigger
--condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
119 add_trigger
--condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
122 cat > "${tmp_expected_stdout}" <<- EOF
125 tracer notifications discarded: 0
126 condition: event rule hit
127 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
132 tracer notifications discarded: 0
133 condition: event rule hit
134 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
139 tracer notifications discarded: 0
140 condition: event rule hit
141 rule: * (type: tracepoint, domain: ust)
146 tracer notifications discarded: 0
147 condition: event rule hit
148 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
153 tracer notifications discarded: 0
154 condition: event rule hit
155 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
160 tracer notifications discarded: 0
161 condition: event rule hit
162 rule: capture-payload-field (type: tracepoint, domain: ust)
169 tracer notifications discarded: 0
170 condition: event rule hit
171 rule: capture-array (type: tracepoint, domain: ust)
179 tracer notifications discarded: 0
180 condition: event rule hit
181 rule: capture-chan-ctx (type: tracepoint, domain: ust)
188 tracer notifications discarded: 0
189 condition: event rule hit
190 rule: capture-app-ctx (type: tracepoint, domain: ust)
192 - \$app.iga:active_clients
197 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
199 stop_lttng_sessiond_notap
202 test_on_event_probe
()
204 local channel_enable_addr
205 local channel_disable_addr
207 # shellcheck disable=SC2119
208 start_lttng_sessiond_notap
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 add_trigger
--condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
227 add_trigger
--condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
228 add_trigger
--condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
230 cat > "${tmp_expected_stdout}" <<- EOF
233 tracer notifications discarded: 0
234 condition: event rule hit
235 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
240 tracer notifications discarded: 0
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
247 tracer notifications discarded: 0
248 condition: event rule hit
249 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
254 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
256 stop_lttng_sessiond_notap
259 test_on_event_userspace_probe
()
261 # shellcheck disable=SC2119
262 start_lttng_sessiond_notap
264 add_trigger
--condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
266 cat > "${tmp_expected_stdout}" <<- EOF
269 tracer notifications discarded: 0
270 condition: event rule hit
271 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
276 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
278 stop_lttng_sessiond_notap
281 test_on_event_syscall
()
283 # shellcheck disable=SC2119
284 start_lttng_sessiond_notap
286 add_trigger
--condition on-event
-k --syscall open
--action notify
287 add_trigger
--condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
289 cat > "${tmp_expected_stdout}" <<- EOF
292 tracer notifications discarded: 0
293 condition: event rule hit
294 - rule: open (type: syscall)
299 tracer notifications discarded: 0
300 condition: event rule hit
301 - rule: ptrace (type: syscall, filter: a > 2)
306 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
308 stop_lttng_sessiond_notap
311 test_snapshot_action
()
313 start_lttng_sessiond_notap
315 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
316 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
/some
/path
317 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
file:///some
/other
/path
318 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session net
://1.2.3.4
319 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session net
://1.2.3.4:1234:1235
320 add_trigger
--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
321 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
/some
/path
--max-size=1234
322 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
/some
/path
--name=meh
325 cat > "${tmp_expected_stdout}" <<- EOF
328 tracer notifications discarded: 0
329 condition: event rule hit
330 rule: some-event (type: tracepoint, domain: ust)
332 snapshot session \`ze-session\`
335 tracer notifications discarded: 0
336 condition: event rule hit
337 rule: some-event (type: tracepoint, domain: ust)
339 snapshot session \`ze-session\`, path: /some/path
342 tracer notifications discarded: 0
343 condition: event rule hit
344 rule: some-event (type: tracepoint, domain: ust)
346 snapshot session \`ze-session\`, path: /some/other/path
349 tracer notifications discarded: 0
350 condition: event rule hit
351 rule: some-event (type: tracepoint, domain: ust)
353 snapshot session \`ze-session\`, url: net://1.2.3.4
356 tracer notifications discarded: 0
357 condition: event rule hit
358 rule: some-event (type: tracepoint, domain: ust)
360 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
363 tracer notifications discarded: 0
364 condition: event rule hit
365 rule: some-event (type: tracepoint, domain: ust)
367 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
370 tracer notifications discarded: 0
371 condition: event rule hit
372 rule: some-event (type: tracepoint, domain: ust)
374 snapshot session \`ze-session\`, path: /some/path, max size: 1234
377 tracer notifications discarded: 0
378 condition: event rule hit
379 rule: some-event (type: tracepoint, domain: ust)
381 snapshot session \`ze-session\`, path: /some/path, name: meh
384 list_triggers
"snapshot action" "${tmp_expected_stdout}"
386 stop_lttng_sessiond_notap
389 test_top_level_options
390 test_on_event_tracepoint
391 skip
$ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
392 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
393 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
397 rm -f "${tmp_stdout}"
398 rm -f "${tmp_stderr}"
399 rm -f "${tmp_expected_stdout}"