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 condition: event rule hit
80 rule: test-fire-once-after (type: tracepoint, domain: ust)
85 firing policy: after every 124 occurences
86 condition: event rule hit
87 rule: test-fire-every (type: tracepoint, domain: ust)
92 condition: event rule hit
93 rule: test-id (type: tracepoint, domain: ust)
98 list_triggers
"top level options" "${tmp_expected_stdout}"
100 stop_lttng_sessiond_notap
103 test_on_event_tracepoint
()
105 # shellcheck disable=SC2119
106 start_lttng_sessiond_notap
108 add_trigger
--condition on-event
-u -a --action notify
109 add_trigger
--id ABC
--condition on-event aaa
-u --filter 'p == 2' --action notify
110 add_trigger
--condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
111 add_trigger
--id BCD
--condition on-event
-u gerboise
--loglevel INFO
--action notify
112 add_trigger
--condition on-event
-u lemming
--loglevel-only WARNING
--action notify
113 add_trigger
--condition on-event
-u capture-payload-field
--capture a
--action notify
114 add_trigger
--condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
115 add_trigger
--condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
116 add_trigger
--condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
119 cat > "${tmp_expected_stdout}" <<- EOF
122 condition: event rule hit
123 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
128 condition: event rule hit
129 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
134 condition: event rule hit
135 rule: * (type: tracepoint, domain: ust)
140 condition: event rule hit
141 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
146 condition: event rule hit
147 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
152 condition: event rule hit
153 rule: capture-payload-field (type: tracepoint, domain: ust)
160 condition: event rule hit
161 rule: capture-array (type: tracepoint, domain: ust)
169 condition: event rule hit
170 rule: capture-chan-ctx (type: tracepoint, domain: ust)
177 condition: event rule hit
178 rule: capture-app-ctx (type: tracepoint, domain: ust)
180 - \$app.iga:active_clients
185 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
187 stop_lttng_sessiond_notap
190 test_on_event_probe
()
192 local channel_enable_addr
193 local channel_disable_addr
195 # shellcheck disable=SC2119
196 start_lttng_sessiond_notap
198 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
199 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
201 # We need to find a valid offset.
204 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
205 base_symbol
="lttng_channel_enable"
206 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
208 base_symbol
="lttng_channel_disable"
209 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
212 offset_hex
="0x$(printf '%x' $offset)"
214 add_trigger
--condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
215 add_trigger
--condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
216 add_trigger
--condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
218 cat > "${tmp_expected_stdout}" <<- EOF
221 condition: event rule hit
222 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})
233 condition: event rule hit
234 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
239 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
241 stop_lttng_sessiond_notap
244 test_on_event_userspace_probe
()
246 # shellcheck disable=SC2119
247 start_lttng_sessiond_notap
249 add_trigger
--condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
251 cat > "${tmp_expected_stdout}" <<- EOF
254 condition: event rule hit
255 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
260 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
262 stop_lttng_sessiond_notap
265 test_on_event_syscall
()
267 # shellcheck disable=SC2119
268 start_lttng_sessiond_notap
270 add_trigger
--condition on-event
-k --syscall open
--action notify
271 add_trigger
--condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
273 cat > "${tmp_expected_stdout}" <<- EOF
276 condition: event rule hit
277 rule: open (type: syscall)
282 condition: event rule hit
283 rule: ptrace (type: syscall, filter: a > 2)
288 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
290 stop_lttng_sessiond_notap
293 test_snapshot_action
()
295 start_lttng_sessiond_notap
297 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
298 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
299 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
300 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
301 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
302 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
303 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
304 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
307 cat > "${tmp_expected_stdout}" <<- EOF
310 condition: event rule hit
311 rule: some-event (type: tracepoint, domain: ust)
313 snapshot session \`ze-session\`
316 condition: event rule hit
317 rule: some-event (type: tracepoint, domain: ust)
319 snapshot session \`ze-session\`, path: /some/path
322 condition: event rule hit
323 rule: some-event (type: tracepoint, domain: ust)
325 snapshot session \`ze-session\`, path: /some/other/path
328 condition: event rule hit
329 rule: some-event (type: tracepoint, domain: ust)
331 snapshot session \`ze-session\`, url: net://1.2.3.4
334 condition: event rule hit
335 rule: some-event (type: tracepoint, domain: ust)
337 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
340 condition: event rule hit
341 rule: some-event (type: tracepoint, domain: ust)
343 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
346 condition: event rule hit
347 rule: some-event (type: tracepoint, domain: ust)
349 snapshot session \`ze-session\`, path: /some/path, max size: 1234
352 condition: event rule hit
353 rule: some-event (type: tracepoint, domain: ust)
355 snapshot session \`ze-session\`, path: /some/path, name: meh
358 list_triggers
"snapshot action" "${tmp_expected_stdout}"
360 stop_lttng_sessiond_notap
363 test_top_level_options
364 test_on_event_tracepoint
365 skip
$ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
366 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
367 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
371 rm -f "${tmp_stdout}"
372 rm -f "${tmp_stderr}"
373 rm -f "${tmp_expected_stdout}"