action-executor: consider action firing policy on action execution
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
CommitLineData
0de2479d
SM
1#!/bin/bash
2#
3# Copyright (C) - 2020 EfficiOS, inc
4#
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.
8#
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
12# details.
13#
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
17
18# Test the `lttng list-trigger` command line interface.
19
20CURDIR="$(dirname "$0")"
21TESTDIR="$CURDIR/../../.."
22
23# shellcheck source=../../../utils/utils.sh
24source "$TESTDIR/utils/utils.sh"
25
b203b4b0 26plan_tests 44
0de2479d
SM
27
28FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
30tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
31tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
32tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
33uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
34
35uid=$(id --user)
36gid=$(id --group)
37
38if [ "$uid" == "0" ]; then
39 ist_root=1
40else
41 ist_root=0
42fi
43
0de2479d
SM
44function list_triggers ()
45{
46 local test_name="$1"
47 local expected_stdout_file="$2"
48
49 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
50 ok $? "${test_name}: exit code is 0"
51
52 diff -u "${expected_stdout_file}" "${tmp_stdout}"
53 ok $? "${test_name}: expected stdout"
54
55 diff -u /dev/null "${tmp_stderr}"
56 ok $? "${test_name}: expected stderr"
57}
58
59test_top_level_options ()
60{
61 # shellcheck disable=SC2119
62 start_lttng_sessiond_notap
63
64
70c766ac
FD
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
0de2479d
SM
68
69 cat > "${tmp_expected_stdout}" <<- EOF
70 - id: T0
71 user id: ${uid}
72 firing policy: once after 123 occurences
73 condition: event rule hit
74 rule: test-fire-once-after (type: tracepoint, domain: ust)
90aa04a1 75 tracer notifications discarded: 0
0de2479d
SM
76 actions:
77 notify
78 - id: T1
79 user id: ${uid}
80 firing policy: after every 124 occurences
81 condition: event rule hit
82 rule: test-fire-every (type: tracepoint, domain: ust)
90aa04a1 83 tracer notifications discarded: 0
0de2479d
SM
84 actions:
85 notify
86 - id: hello
87 user id: ${uid}
88 condition: event rule hit
89 rule: test-id (type: tracepoint, domain: ust)
90aa04a1 90 tracer notifications discarded: 0
0de2479d
SM
91 actions:
92 notify
93 EOF
94
95 list_triggers "top level options" "${tmp_expected_stdout}"
96
97 stop_lttng_sessiond_notap
98}
99
100test_on_event_tracepoint ()
101{
102 # shellcheck disable=SC2119
103 start_lttng_sessiond_notap
104
70c766ac
FD
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
b203b4b0 114
0de2479d
SM
115
116 cat > "${tmp_expected_stdout}" <<- EOF
70c766ac 117 - id: A
0de2479d
SM
118 user id: ${uid}
119 condition: event rule hit
120 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
90aa04a1 121 tracer notifications discarded: 0
0de2479d
SM
122 actions:
123 notify
70c766ac 124 - id: B
0de2479d
SM
125 user id: ${uid}
126 condition: event rule hit
1b859ae2 127 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
90aa04a1 128 tracer notifications discarded: 0
0de2479d
SM
129 actions:
130 notify
70c766ac 131 - id: C
0de2479d
SM
132 user id: ${uid}
133 condition: event rule hit
134 rule: * (type: tracepoint, domain: ust)
90aa04a1 135 tracer notifications discarded: 0
0de2479d
SM
136 actions:
137 notify
70c766ac 138 - id: D
0de2479d
SM
139 user id: ${uid}
140 condition: event rule hit
141 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
90aa04a1 142 tracer notifications discarded: 0
0de2479d
SM
143 actions:
144 notify
70c766ac 145 - id: E
0de2479d
SM
146 user id: ${uid}
147 condition: event rule hit
1b859ae2 148 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
90aa04a1 149 tracer notifications discarded: 0
0de2479d
SM
150 actions:
151 notify
70c766ac 152 - id: F
b203b4b0
SM
153 user id: ${uid}
154 condition: event rule hit
155 rule: capture-payload-field (type: tracepoint, domain: ust)
90aa04a1 156 tracer notifications discarded: 0
b203b4b0
SM
157 captures:
158 - a
159 actions:
160 notify
70c766ac 161 - id: G
b203b4b0
SM
162 user id: ${uid}
163 condition: event rule hit
164 rule: capture-array (type: tracepoint, domain: ust)
90aa04a1 165 tracer notifications discarded: 0
b203b4b0
SM
166 captures:
167 - a[2]
168 - \$ctx.tourlou[18]
169 actions:
170 notify
70c766ac 171 - id: H
b203b4b0
SM
172 user id: ${uid}
173 condition: event rule hit
174 rule: capture-chan-ctx (type: tracepoint, domain: ust)
90aa04a1 175 tracer notifications discarded: 0
b203b4b0
SM
176 captures:
177 - \$ctx.vpid
178 actions:
179 notify
70c766ac 180 - id: I
b203b4b0
SM
181 user id: ${uid}
182 condition: event rule hit
183 rule: capture-app-ctx (type: tracepoint, domain: ust)
90aa04a1 184 tracer notifications discarded: 0
b203b4b0
SM
185 captures:
186 - \$app.iga:active_clients
187 actions:
188 notify
0de2479d
SM
189 EOF
190
191 list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
192
193 stop_lttng_sessiond_notap
194}
195
196test_on_event_probe ()
197{
198 local channel_enable_addr
199 local channel_disable_addr
200
201 # shellcheck disable=SC2119
202 start_lttng_sessiond_notap
203
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 ' ')
206
207 # We need to find a valid offset.
208 base_symbol=""
209 offset=0
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 ))
213 else
214 base_symbol="lttng_channel_disable"
215 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
216 fi
217
218 offset_hex="0x$(printf '%x' $offset)"
219
70c766ac
FD
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
0de2479d
SM
223
224 cat > "${tmp_expected_stdout}" <<- EOF
225 - id: T0
226 user id: ${uid}
227 condition: event rule hit
228 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
90aa04a1 229 tracer notifications discarded: 0
0de2479d
SM
230 actions:
231 notify
232 - id: T1
233 user id: ${uid}
234 condition: event rule hit
235 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
90aa04a1 236 tracer notifications discarded: 0
0de2479d
SM
237 actions:
238 notify
239 - id: T2
240 user id: ${uid}
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
90aa04a1 243 tracer notifications discarded: 0
0de2479d
SM
244 actions:
245 notify
246 EOF
247
248 list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
249
250 stop_lttng_sessiond_notap
251}
252
253test_on_event_userspace_probe ()
254{
255 # shellcheck disable=SC2119
256 start_lttng_sessiond_notap
257
70c766ac 258 lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
0de2479d
SM
259
260 cat > "${tmp_expected_stdout}" <<- EOF
261 - id: T0
262 user id: ${uid}
263 condition: event rule hit
264 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
90aa04a1 265 tracer notifications discarded: 0
0de2479d
SM
266 actions:
267 notify
268 EOF
269
270 list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
271
272 stop_lttng_sessiond_notap
273}
274
275test_on_event_syscall ()
276{
277 # shellcheck disable=SC2119
278 start_lttng_sessiond_notap
279
70c766ac
FD
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
0de2479d
SM
282
283 cat > "${tmp_expected_stdout}" <<- EOF
284 - id: T0
285 user id: ${uid}
286 condition: event rule hit
287 rule: open (type: syscall)
90aa04a1 288 tracer notifications discarded: 0
0de2479d
SM
289 actions:
290 notify
291 - id: T1
292 user id: ${uid}
293 condition: event rule hit
294 rule: ptrace (type: syscall, filter: a > 2)
90aa04a1 295 tracer notifications discarded: 0
0de2479d
SM
296 actions:
297 notify
298 EOF
299
300 list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
301
302 stop_lttng_sessiond_notap
303}
304
305test_snapshot_action ()
306{
307 start_lttng_sessiond_notap
308
70c766ac
FD
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
0de2479d
SM
317
318
319 cat > "${tmp_expected_stdout}" <<- EOF
320 - id: T0
321 user id: ${uid}
322 condition: event rule hit
323 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 324 tracer notifications discarded: 0
0de2479d
SM
325 actions:
326 snapshot session \`ze-session\`
327 - id: T1
328 user id: ${uid}
329 condition: event rule hit
330 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 331 tracer notifications discarded: 0
0de2479d
SM
332 actions:
333 snapshot session \`ze-session\`, path: /some/path
334 - id: T2
335 user id: ${uid}
336 condition: event rule hit
337 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 338 tracer notifications discarded: 0
0de2479d
SM
339 actions:
340 snapshot session \`ze-session\`, path: /some/other/path
341 - id: T3
342 user id: ${uid}
343 condition: event rule hit
344 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 345 tracer notifications discarded: 0
0de2479d
SM
346 actions:
347 snapshot session \`ze-session\`, url: net://1.2.3.4
348 - id: T4
349 user id: ${uid}
350 condition: event rule hit
351 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 352 tracer notifications discarded: 0
0de2479d
SM
353 actions:
354 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
355 - id: T5
356 user id: ${uid}
357 condition: event rule hit
358 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 359 tracer notifications discarded: 0
0de2479d
SM
360 actions:
361 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
362 - id: T6
363 user id: ${uid}
364 condition: event rule hit
365 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 366 tracer notifications discarded: 0
0de2479d
SM
367 actions:
368 snapshot session \`ze-session\`, path: /some/path, max size: 1234
369 - id: T7
370 user id: ${uid}
371 condition: event rule hit
372 rule: some-event (type: tracepoint, domain: ust)
90aa04a1 373 tracer notifications discarded: 0
0de2479d
SM
374 actions:
375 snapshot session \`ze-session\`, path: /some/path, name: meh
376 EOF
377
378 list_triggers "snapshot action" "${tmp_expected_stdout}"
379
380 stop_lttng_sessiond_notap
381}
382
383test_top_level_options
384test_on_event_tracepoint
385skip $ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
386skip $ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
387skip $ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
388test_snapshot_action
389
390# Cleanup
391rm -f "${tmp_stdout}"
392rm -f "${tmp_stderr}"
393rm -f "${tmp_expected_stdout}"
This page took 0.063066 seconds and 4 git commands to generate.