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)
72 tracer notifications discarded: 0
77 list_triggers
"top level options" "${tmp_expected_stdout}"
79 stop_lttng_sessiond_notap
82 test_on_event_tracepoint
()
84 # shellcheck disable=SC2119
85 start_lttng_sessiond_notap
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)
103 tracer notifications discarded: 0
108 condition: event rule hit
109 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
110 tracer notifications discarded: 0
115 condition: event rule hit
116 rule: * (type: tracepoint, domain: ust)
117 tracer notifications discarded: 0
122 condition: event rule hit
123 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
124 tracer notifications discarded: 0
129 condition: event rule hit
130 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
131 tracer notifications discarded: 0
136 condition: event rule hit
137 rule: capture-payload-field (type: tracepoint, domain: ust)
138 tracer notifications discarded: 0
145 condition: event rule hit
146 rule: capture-array (type: tracepoint, domain: ust)
147 tracer notifications discarded: 0
155 condition: event rule hit
156 rule: capture-chan-ctx (type: tracepoint, domain: ust)
157 tracer notifications discarded: 0
164 condition: event rule hit
165 rule: capture-app-ctx (type: tracepoint, domain: ust)
166 tracer notifications discarded: 0
168 - \$app.iga:active_clients
173 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
175 stop_lttng_sessiond_notap
178 test_on_event_probe
()
180 local channel_enable_addr
181 local channel_disable_addr
183 # shellcheck disable=SC2119
184 start_lttng_sessiond_notap
186 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
187 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
189 # We need to find a valid offset.
192 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
193 base_symbol
="lttng_channel_enable"
194 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
196 base_symbol
="lttng_channel_disable"
197 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
200 offset_hex
="0x$(printf '%x' $offset)"
202 lttng_add_trigger_ok
"T0" --condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
203 lttng_add_trigger_ok
"T1" --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
204 lttng_add_trigger_ok
"T2" --condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
206 cat > "${tmp_expected_stdout}" <<- EOF
209 condition: event rule hit
210 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
211 tracer notifications discarded: 0
216 condition: event rule hit
217 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
218 tracer notifications discarded: 0
223 condition: event rule hit
224 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
225 tracer notifications discarded: 0
230 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
232 stop_lttng_sessiond_notap
235 test_on_event_userspace_probe
()
237 # shellcheck disable=SC2119
238 start_lttng_sessiond_notap
240 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
242 cat > "${tmp_expected_stdout}" <<- EOF
245 condition: event rule hit
246 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
247 tracer notifications discarded: 0
252 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
254 stop_lttng_sessiond_notap
257 test_on_event_syscall
()
259 # shellcheck disable=SC2119
260 start_lttng_sessiond_notap
262 lttng_add_trigger_ok
"T0" --condition on-event
-k --syscall open
--action notify
263 lttng_add_trigger_ok
"T1" --condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
265 cat > "${tmp_expected_stdout}" <<- EOF
268 condition: event rule hit
269 rule: open (type: syscall)
270 tracer notifications discarded: 0
275 condition: event rule hit
276 rule: ptrace (type: syscall, filter: a > 2)
277 tracer notifications discarded: 0
282 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
284 stop_lttng_sessiond_notap
287 test_snapshot_action
()
289 start_lttng_sessiond_notap
291 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action snapshot-session ze-session
292 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
293 lttng_add_trigger_ok
"T2" --condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
294 lttng_add_trigger_ok
"T3" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
295 lttng_add_trigger_ok
"T4" --condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
296 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
297 lttng_add_trigger_ok
"T6" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
298 lttng_add_trigger_ok
"T7" --condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
299 lttng_add_trigger_ok
"T8" --condition on-event
-u some-event
--action snapshot-session ze-session
--fire-every 10
300 lttng_add_trigger_ok
"T9" --condition on-event
-u some-event
--action snapshot-session ze-session
--fire-once-after 10
303 cat > "${tmp_expected_stdout}" <<- EOF
306 condition: event rule hit
307 rule: some-event (type: tracepoint, domain: ust)
308 tracer notifications discarded: 0
310 snapshot session \`ze-session\`
313 condition: event rule hit
314 rule: some-event (type: tracepoint, domain: ust)
315 tracer notifications discarded: 0
317 snapshot session \`ze-session\`, path: /some/path
320 condition: event rule hit
321 rule: some-event (type: tracepoint, domain: ust)
322 tracer notifications discarded: 0
324 snapshot session \`ze-session\`, path: /some/other/path
327 condition: event rule hit
328 rule: some-event (type: tracepoint, domain: ust)
329 tracer notifications discarded: 0
331 snapshot session \`ze-session\`, url: net://1.2.3.4
334 condition: event rule hit
335 rule: some-event (type: tracepoint, domain: ust)
336 tracer notifications discarded: 0
338 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
341 condition: event rule hit
342 rule: some-event (type: tracepoint, domain: ust)
343 tracer notifications discarded: 0
345 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
348 condition: event rule hit
349 rule: some-event (type: tracepoint, domain: ust)
350 tracer notifications discarded: 0
352 snapshot session \`ze-session\`, path: /some/path, max size: 1234
355 condition: event rule hit
356 rule: some-event (type: tracepoint, domain: ust)
357 tracer notifications discarded: 0
359 snapshot session \`ze-session\`, path: /some/path, name: meh
362 condition: event rule hit
363 rule: some-event (type: tracepoint, domain: ust)
364 tracer notifications discarded: 0
366 snapshot session \`ze-session\`, firing policy: after every 10 occurrences
369 condition: event rule hit
370 rule: some-event (type: tracepoint, domain: ust)
371 tracer notifications discarded: 0
373 snapshot session \`ze-session\`, firing policy: once after 10 occurrences
376 list_triggers
"snapshot action" "${tmp_expected_stdout}"
378 stop_lttng_sessiond_notap
381 test_notify_action
()
383 start_lttng_sessiond_notap
385 lttng_add_trigger_ok
"T0" --condition on-event
-u some-event
--action notify
--fire-once-after 5
386 lttng_add_trigger_ok
"T1" --condition on-event
-u some-event
--action notify
--fire-every 10
389 cat > "${tmp_expected_stdout}" <<- EOF
392 condition: event rule hit
393 rule: some-event (type: tracepoint, domain: ust)
394 tracer notifications discarded: 0
396 notify, firing policy: once after 5 occurrences
399 condition: event rule hit
400 rule: some-event (type: tracepoint, domain: ust)
401 tracer notifications discarded: 0
403 notify, firing policy: after every 10 occurrences
406 list_triggers
"snapshot action" "${tmp_expected_stdout}"
408 stop_lttng_sessiond_notap
411 test_top_level_options
412 test_on_event_tracepoint
413 skip
$ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
414 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
415 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
420 rm -f "${tmp_stdout}"
421 rm -f "${tmp_stderr}"
422 rm -f "${tmp_expected_stdout}"