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
66 lttng_add_trigger_ok
"T0" --fire-once-after 123 --condition on-event
-u test-fire-once-after
--action notify
67 lttng_add_trigger_ok
"T1" --fire-every 124 --condition on-event
-u test-fire-every
--action notify
69 cat > "${tmp_expected_stdout}" <<- EOF
72 firing policy: once after 123 occurences
73 condition: event rule hit
74 rule: test-fire-once-after (type: tracepoint, domain: ust)
75 tracer notifications discarded: 0
80 firing policy: after every 124 occurences
81 condition: event rule hit
82 rule: test-fire-every (type: tracepoint, domain: ust)
83 tracer notifications discarded: 0
88 condition: event rule hit
89 rule: test-id (type: tracepoint, domain: ust)
90 tracer notifications discarded: 0
95 list_triggers
"top level options" "${tmp_expected_stdout}"
97 stop_lttng_sessiond_notap
100 test_on_event_tracepoint
()
102 # shellcheck disable=SC2119
103 start_lttng_sessiond_notap
105 lttng_add_trigger_ok
"C" --condition on-event
-u -a --action notify
106 lttng_add_trigger_ok
"A" --condition on-event aaa
-u --filter 'p == 2' --action notify
107 lttng_add_trigger_ok
"D" --condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
108 lttng_add_trigger_ok
"B" --condition on-event
-u gerboise
--loglevel INFO
--action notify
109 lttng_add_trigger_ok
"E" --condition on-event
-u lemming
--loglevel-only WARNING
--action notify
110 lttng_add_trigger_ok
"F" --condition on-event
-u capture-payload-field
--capture a
--action notify
111 lttng_add_trigger_ok
"G" --condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
112 lttng_add_trigger_ok
"H" --condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
113 lttng_add_trigger_ok
"I" --condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
116 cat > "${tmp_expected_stdout}" <<- EOF
119 condition: event rule hit
120 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
121 tracer notifications discarded: 0
126 condition: event rule hit
127 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
128 tracer notifications discarded: 0
133 condition: event rule hit
134 rule: * (type: tracepoint, domain: ust)
135 tracer notifications discarded: 0
140 condition: event rule hit
141 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
142 tracer notifications discarded: 0
147 condition: event rule hit
148 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
149 tracer notifications discarded: 0
154 condition: event rule hit
155 rule: capture-payload-field (type: tracepoint, domain: ust)
156 tracer notifications discarded: 0
163 condition: event rule hit
164 rule: capture-array (type: tracepoint, domain: ust)
165 tracer notifications discarded: 0
173 condition: event rule hit
174 rule: capture-chan-ctx (type: tracepoint, domain: ust)
175 tracer notifications discarded: 0
182 condition: event rule hit
183 rule: capture-app-ctx (type: tracepoint, domain: ust)
184 tracer notifications discarded: 0
186 - \$app.iga:active_clients
191 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
193 stop_lttng_sessiond_notap
196 test_on_event_probe
()
198 local channel_enable_addr
199 local channel_disable_addr
201 # shellcheck disable=SC2119
202 start_lttng_sessiond_notap
204 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
205 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
207 # We need to find a valid offset.
210 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
211 base_symbol
="lttng_channel_enable"
212 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
214 base_symbol
="lttng_channel_disable"
215 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
218 offset_hex
="0x$(printf '%x' $offset)"
220 lttng_add_trigger_ok
"T0" --condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
221 lttng_add_trigger_ok
"T1" --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
222 lttng_add_trigger_ok
"T2" --condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
224 cat > "${tmp_expected_stdout}" <<- EOF
227 condition: event rule hit
228 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
229 tracer notifications discarded: 0
234 condition: event rule hit
235 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
236 tracer notifications discarded: 0
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
243 tracer notifications discarded: 0
248 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
250 stop_lttng_sessiond_notap
253 test_on_event_userspace_probe
()
255 # shellcheck disable=SC2119
256 start_lttng_sessiond_notap
258 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
260 cat > "${tmp_expected_stdout}" <<- EOF
263 condition: event rule hit
264 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
265 tracer notifications discarded: 0
270 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
272 stop_lttng_sessiond_notap
275 test_on_event_syscall
()
277 # shellcheck disable=SC2119
278 start_lttng_sessiond_notap
280 lttng_add_trigger_ok
"T0" --condition on-event
-k --syscall open
--action notify
281 lttng_add_trigger_ok
"T1" --condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
283 cat > "${tmp_expected_stdout}" <<- EOF
286 condition: event rule hit
287 rule: open (type: syscall)
288 tracer notifications discarded: 0
293 condition: event rule hit
294 rule: ptrace (type: syscall, filter: a > 2)
295 tracer notifications discarded: 0
300 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
302 stop_lttng_sessiond_notap
305 test_snapshot_action
()
307 start_lttng_sessiond_notap
309 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action snapshot-session ze-session
310 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
311 lttng_add_trigger_ok
"T2" --condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
312 lttng_add_trigger_ok
"T3" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
313 lttng_add_trigger_ok
"T4" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
314 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
315 lttng_add_trigger_ok
"T6" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
316 lttng_add_trigger_ok
"T7" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
319 cat > "${tmp_expected_stdout}" <<- EOF
322 condition: event rule hit
323 rule: some-event (type: tracepoint, domain: ust)
324 tracer notifications discarded: 0
326 snapshot session \`ze-session\`
329 condition: event rule hit
330 rule: some-event (type: tracepoint, domain: ust)
331 tracer notifications discarded: 0
333 snapshot session \`ze-session\`, path: /some/path
336 condition: event rule hit
337 rule: some-event (type: tracepoint, domain: ust)
338 tracer notifications discarded: 0
340 snapshot session \`ze-session\`, path: /some/other/path
343 condition: event rule hit
344 rule: some-event (type: tracepoint, domain: ust)
345 tracer notifications discarded: 0
347 snapshot session \`ze-session\`, url: net://1.2.3.4
350 condition: event rule hit
351 rule: some-event (type: tracepoint, domain: ust)
352 tracer notifications discarded: 0
354 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
357 condition: event rule hit
358 rule: some-event (type: tracepoint, domain: ust)
359 tracer notifications discarded: 0
361 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
364 condition: event rule hit
365 rule: some-event (type: tracepoint, domain: ust)
366 tracer notifications discarded: 0
368 snapshot session \`ze-session\`, path: /some/path, max size: 1234
371 condition: event rule hit
372 rule: some-event (type: tracepoint, domain: ust)
373 tracer notifications discarded: 0
375 snapshot session \`ze-session\`, path: /some/path, name: meh
378 list_triggers
"snapshot action" "${tmp_expected_stdout}"
380 stop_lttng_sessiond_notap
383 test_top_level_options
384 test_on_event_tracepoint
385 skip
$ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
386 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
387 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
391 rm -f "${tmp_stdout}"
392 rm -f "${tmp_stderr}"
393 rm -f "${tmp_expected_stdout}"