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)
79 firing policy: after every 124 occurences
80 condition: event rule hit
81 rule: test-fire-every (type: tracepoint, domain: ust)
86 condition: event rule hit
87 rule: test-id (type: tracepoint, domain: ust)
92 list_triggers
"top level options" "${tmp_expected_stdout}"
94 stop_lttng_sessiond_notap
97 test_on_event_tracepoint
()
99 # shellcheck disable=SC2119
100 start_lttng_sessiond_notap
102 lttng_add_trigger_ok
"C" --condition on-event
-u -a --action notify
103 lttng_add_trigger_ok
"A" --condition on-event aaa
-u --filter 'p == 2' --action notify
104 lttng_add_trigger_ok
"D" --condition on-event
'hello*' -u -x 'hello2,hello3,hello4' --action notify
105 lttng_add_trigger_ok
"B" --condition on-event
-u gerboise
--loglevel INFO
--action notify
106 lttng_add_trigger_ok
"E" --condition on-event
-u lemming
--loglevel-only WARNING
--action notify
107 lttng_add_trigger_ok
"F" --condition on-event
-u capture-payload-field
--capture a
--action notify
108 lttng_add_trigger_ok
"G" --condition on-event
-u capture-array
--capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
109 lttng_add_trigger_ok
"H" --condition on-event
-u capture-chan-ctx
--capture '$ctx.vpid' --action notify
110 lttng_add_trigger_ok
"I" --condition on-event
-u capture-app-ctx
--capture '$app.iga:active_clients' --action notify
113 cat > "${tmp_expected_stdout}" <<- EOF
116 condition: event rule hit
117 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
122 condition: event rule hit
123 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
128 condition: event rule hit
129 rule: * (type: tracepoint, domain: ust)
134 condition: event rule hit
135 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
140 condition: event rule hit
141 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
146 condition: event rule hit
147 rule: capture-payload-field (type: tracepoint, domain: ust)
154 condition: event rule hit
155 rule: capture-array (type: tracepoint, domain: ust)
163 condition: event rule hit
164 rule: capture-chan-ctx (type: tracepoint, domain: ust)
171 condition: event rule hit
172 rule: capture-app-ctx (type: tracepoint, domain: ust)
174 - \$app.iga:active_clients
179 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
181 stop_lttng_sessiond_notap
184 test_on_event_probe
()
186 local channel_enable_addr
187 local channel_disable_addr
189 # shellcheck disable=SC2119
190 start_lttng_sessiond_notap
192 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
193 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
195 # We need to find a valid offset.
198 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
199 base_symbol
="lttng_channel_enable"
200 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
202 base_symbol
="lttng_channel_disable"
203 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
206 offset_hex
="0x$(printf '%x' $offset)"
208 lttng_add_trigger_ok
"T0" --condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
209 lttng_add_trigger_ok
"T1" --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
210 lttng_add_trigger_ok
"T2" --condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
212 cat > "${tmp_expected_stdout}" <<- EOF
215 condition: event rule hit
216 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
221 condition: event rule hit
222 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
227 condition: event rule hit
228 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
233 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
235 stop_lttng_sessiond_notap
238 test_on_event_userspace_probe
()
240 # shellcheck disable=SC2119
241 start_lttng_sessiond_notap
243 lttng_add_trigger_ok
"T0" --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
245 cat > "${tmp_expected_stdout}" <<- EOF
248 condition: event rule hit
249 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
254 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
256 stop_lttng_sessiond_notap
259 test_on_event_syscall
()
261 # shellcheck disable=SC2119
262 start_lttng_sessiond_notap
264 lttng_add_trigger_ok
"T0" --condition on-event
-k --syscall open
--action notify
265 lttng_add_trigger_ok
"T1" --condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
267 cat > "${tmp_expected_stdout}" <<- EOF
270 condition: event rule hit
271 rule: open (type: syscall)
276 condition: event rule hit
277 rule: ptrace (type: syscall, filter: a > 2)
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
301 cat > "${tmp_expected_stdout}" <<- EOF
304 condition: event rule hit
305 rule: some-event (type: tracepoint, domain: ust)
307 snapshot session \`ze-session\`
310 condition: event rule hit
311 rule: some-event (type: tracepoint, domain: ust)
313 snapshot session \`ze-session\`, path: /some/path
316 condition: event rule hit
317 rule: some-event (type: tracepoint, domain: ust)
319 snapshot session \`ze-session\`, path: /some/other/path
322 condition: event rule hit
323 rule: some-event (type: tracepoint, domain: ust)
325 snapshot session \`ze-session\`, url: net://1.2.3.4
328 condition: event rule hit
329 rule: some-event (type: tracepoint, domain: ust)
331 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
334 condition: event rule hit
335 rule: some-event (type: tracepoint, domain: ust)
337 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
340 condition: event rule hit
341 rule: some-event (type: tracepoint, domain: ust)
343 snapshot session \`ze-session\`, path: /some/path, max size: 1234
346 condition: event rule hit
347 rule: some-event (type: tracepoint, domain: ust)
349 snapshot session \`ze-session\`, path: /some/path, name: meh
352 list_triggers
"snapshot action" "${tmp_expected_stdout}"
354 stop_lttng_sessiond_notap
357 test_top_level_options
358 test_on_event_tracepoint
359 skip
$ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
360 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
361 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
365 rm -f "${tmp_stdout}"
366 rm -f "${tmp_stderr}"
367 rm -f "${tmp_expected_stdout}"