lttng {add,list}-triggers: use `name` instead of `id`
[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
be7f9dfc 26
8a917ae8 27NUM_TESTS=72
0de2479d
SM
28
29FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
30
31tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
32tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
33tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
34uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
8a917ae8 35uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary")
0de2479d
SM
36
37uid=$(id --user)
38gid=$(id --group)
39
40if [ "$uid" == "0" ]; then
41 ist_root=1
8a917ae8
FD
42 ls "$uprobe_sdt_binary" >/dev/null 2>&1
43 if test $? == 0; then
44 hast_sdt_binary=1
45 else
46 hast_sdt_binary=0
47 fi
0de2479d
SM
48else
49 ist_root=0
8a917ae8 50 hast_sdt_binary=0
0de2479d
SM
51fi
52
be7f9dfc
FD
53
54function list_triggers_matches_ok ()
0de2479d
SM
55{
56 local test_name="$1"
57 local expected_stdout_file="$2"
58
59 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
60 ok $? "${test_name}: exit code is 0"
61
62 diff -u "${expected_stdout_file}" "${tmp_stdout}"
63 ok $? "${test_name}: expected stdout"
64
65 diff -u /dev/null "${tmp_stderr}"
66 ok $? "${test_name}: expected stderr"
67}
68
69test_top_level_options ()
70{
be7f9dfc 71 diag "Listing top level options"
0de2479d 72
70c766ac 73 lttng_add_trigger_ok "hello" --condition on-event -u test-id --action notify
0de2479d
SM
74
75 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 76 - name: hello
0de2479d
SM
77 user id: ${uid}
78 condition: event rule hit
79 rule: test-id (type: tracepoint, domain: ust)
80 actions:
81 notify
709fb83f
JG
82 errors: none
83 errors: none
0de2479d
SM
84 EOF
85
be7f9dfc 86 list_triggers_matches_ok "top level options" "${tmp_expected_stdout}"
0de2479d 87
be7f9dfc 88 lttng_remove_trigger_ok "hello"
0de2479d
SM
89}
90
91test_on_event_tracepoint ()
92{
be7f9dfc 93 diag "Listing on-event tracepoint"
0de2479d 94
70c766ac
FD
95 lttng_add_trigger_ok "C" --condition on-event -u -a --action notify
96 lttng_add_trigger_ok "A" --condition on-event aaa -u --filter 'p == 2' --action notify
97 lttng_add_trigger_ok "D" --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify
98 lttng_add_trigger_ok "B" --condition on-event -u gerboise --loglevel INFO --action notify
99 lttng_add_trigger_ok "E" --condition on-event -u lemming --loglevel-only WARNING --action notify
100 lttng_add_trigger_ok "F" --condition on-event -u capture-payload-field --capture a --action notify
101 lttng_add_trigger_ok "G" --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
102 lttng_add_trigger_ok "H" --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify
103 lttng_add_trigger_ok "I" --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify
b203b4b0 104
0de2479d
SM
105
106 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 107 - name: A
0de2479d
SM
108 user id: ${uid}
109 condition: event rule hit
110 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
111 actions:
112 notify
709fb83f
JG
113 errors: none
114 errors: none
1d4b59f2 115 - name: B
0de2479d
SM
116 user id: ${uid}
117 condition: event rule hit
1b859ae2 118 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
0de2479d
SM
119 actions:
120 notify
709fb83f
JG
121 errors: none
122 errors: none
1d4b59f2 123 - name: C
0de2479d
SM
124 user id: ${uid}
125 condition: event rule hit
126 rule: * (type: tracepoint, domain: ust)
127 actions:
128 notify
709fb83f
JG
129 errors: none
130 errors: none
1d4b59f2 131 - name: D
0de2479d
SM
132 user id: ${uid}
133 condition: event rule hit
134 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
135 actions:
136 notify
709fb83f
JG
137 errors: none
138 errors: none
1d4b59f2 139 - name: E
0de2479d
SM
140 user id: ${uid}
141 condition: event rule hit
1b859ae2 142 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
0de2479d
SM
143 actions:
144 notify
709fb83f
JG
145 errors: none
146 errors: none
1d4b59f2 147 - name: F
b203b4b0
SM
148 user id: ${uid}
149 condition: event rule hit
150 rule: capture-payload-field (type: tracepoint, domain: ust)
151 captures:
152 - a
153 actions:
154 notify
709fb83f
JG
155 errors: none
156 errors: none
1d4b59f2 157 - name: G
b203b4b0
SM
158 user id: ${uid}
159 condition: event rule hit
160 rule: capture-array (type: tracepoint, domain: ust)
161 captures:
162 - a[2]
163 - \$ctx.tourlou[18]
164 actions:
165 notify
709fb83f
JG
166 errors: none
167 errors: none
1d4b59f2 168 - name: H
b203b4b0
SM
169 user id: ${uid}
170 condition: event rule hit
171 rule: capture-chan-ctx (type: tracepoint, domain: ust)
172 captures:
173 - \$ctx.vpid
174 actions:
175 notify
709fb83f
JG
176 errors: none
177 errors: none
1d4b59f2 178 - name: I
b203b4b0
SM
179 user id: ${uid}
180 condition: event rule hit
181 rule: capture-app-ctx (type: tracepoint, domain: ust)
182 captures:
183 - \$app.iga:active_clients
184 actions:
185 notify
709fb83f
JG
186 errors: none
187 errors: none
0de2479d
SM
188 EOF
189
be7f9dfc
FD
190 list_triggers_matches_ok "on-event, tracepoint event rule" "${tmp_expected_stdout}"
191
192 lttng_remove_trigger_ok "A"
193 lttng_remove_trigger_ok "B"
194 lttng_remove_trigger_ok "C"
195 lttng_remove_trigger_ok "D"
196 lttng_remove_trigger_ok "E"
197 lttng_remove_trigger_ok "F"
198 lttng_remove_trigger_ok "G"
199 lttng_remove_trigger_ok "H"
200 lttng_remove_trigger_ok "I"
0de2479d
SM
201}
202
203test_on_event_probe ()
204{
205 local channel_enable_addr
206 local channel_disable_addr
207
be7f9dfc 208 diag "Listing on-event kernel probe"
0de2479d
SM
209
210 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
211 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
212
213 # We need to find a valid offset.
214 base_symbol=""
215 offset=0
216 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
217 base_symbol="lttng_channel_enable"
218 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
219 else
220 base_symbol="lttng_channel_disable"
221 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
222 fi
223
224 offset_hex="0x$(printf '%x' $offset)"
225
70c766ac
FD
226 lttng_add_trigger_ok "T0" --condition on-event -k --probe=lttng_channel_enable my_channel_enable --action notify
227 lttng_add_trigger_ok "T1" --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_channel_enable --action notify
228 lttng_add_trigger_ok "T2" --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify
0de2479d
SM
229
230 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 231 - name: T0
0de2479d
SM
232 user id: ${uid}
233 condition: event rule hit
234 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
235 actions:
236 notify
709fb83f
JG
237 errors: none
238 errors: none
1d4b59f2 239 - name: T1
0de2479d
SM
240 user id: ${uid}
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
243 actions:
244 notify
709fb83f
JG
245 errors: none
246 errors: none
1d4b59f2 247 - name: T2
0de2479d
SM
248 user id: ${uid}
249 condition: event rule hit
250 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
251 actions:
252 notify
709fb83f
JG
253 errors: none
254 errors: none
0de2479d
SM
255 EOF
256
be7f9dfc 257 list_triggers_matches_ok "on-event, probe event rule" "${tmp_expected_stdout}"
0de2479d 258
be7f9dfc
FD
259 lttng_remove_trigger_ok "T0"
260 lttng_remove_trigger_ok "T1"
261 lttng_remove_trigger_ok "T2"
0de2479d
SM
262}
263
8a917ae8 264test_on_event_userspace_probe_elf ()
0de2479d 265{
be7f9dfc
FD
266 local elf_function_name="test_function"
267
268 diag "Listing on-event userspace-probe elf"
0de2479d 269
be7f9dfc 270 lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:${elf_function_name} ma-probe-elf --action notify
0de2479d
SM
271
272 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 273 - name: T0
0de2479d
SM
274 user id: ${uid}
275 condition: event rule hit
8a917ae8 276 rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
0de2479d
SM
277 actions:
278 notify
709fb83f
JG
279 errors: none
280 errors: none
0de2479d
SM
281 EOF
282
be7f9dfc 283 list_triggers_matches_ok "on-event, userspace-probe event rule ELF" "${tmp_expected_stdout}"
0de2479d 284
be7f9dfc 285 lttng_remove_trigger_ok "T0"
0de2479d
SM
286}
287
8a917ae8
FD
288test_on_event_userspace_probe_sdt ()
289{
290
291 local sdt_provider_name="foobar"
292 local sdt_probe_name="tp1"
293
294 diag "on-event userspace-probe sdt"
295
296 lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=sdt:${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name} ma-probe-sdt --action notify
297
298 cat > "${tmp_expected_stdout}" <<- EOF
299 - id: T0
300 user id: 0
301 condition: event rule hit
302 rule: ma-probe-sdt (type: userspace probe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
303 actions:
304 notify
305 errors: none
306 errors: none
307 EOF
308
309 list_triggers_matches_ok "on-event, userspace-probe event rule SDT" "${tmp_expected_stdout}"
310
311 lttng_remove_trigger_ok "T0"
312}
313
0de2479d
SM
314test_on_event_syscall ()
315{
be7f9dfc 316 diag "Listing on-event syscall"
0de2479d 317
70c766ac
FD
318 lttng_add_trigger_ok "T0" --condition on-event -k --syscall open --action notify
319 lttng_add_trigger_ok "T1" --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify
0de2479d
SM
320
321 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 322 - name: T0
0de2479d
SM
323 user id: ${uid}
324 condition: event rule hit
325 rule: open (type: syscall)
326 actions:
327 notify
709fb83f
JG
328 errors: none
329 errors: none
1d4b59f2 330 - name: T1
0de2479d
SM
331 user id: ${uid}
332 condition: event rule hit
333 rule: ptrace (type: syscall, filter: a > 2)
334 actions:
335 notify
709fb83f
JG
336 errors: none
337 errors: none
0de2479d
SM
338 EOF
339
be7f9dfc 340 list_triggers_matches_ok "on-event, syscall event rule" "${tmp_expected_stdout}"
0de2479d 341
be7f9dfc
FD
342 lttng_remove_trigger_ok "T0"
343 lttng_remove_trigger_ok "T1"
0de2479d
SM
344}
345
346test_snapshot_action ()
347{
be7f9dfc 348 diag "Listing snapshot actions"
0de2479d 349
70c766ac
FD
350 lttng_add_trigger_ok "T0" --condition on-event -u some-event --action snapshot-session ze-session
351 lttng_add_trigger_ok "T1" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path
352 lttng_add_trigger_ok "T2" --condition on-event -u some-event --action snapshot-session ze-session --url file:///some/other/path
353 lttng_add_trigger_ok "T3" --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4
354 lttng_add_trigger_ok "T4" --condition on-event -u some-event --action snapshot-session ze-session --url net://1.2.3.4:1234:1235
355 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
356 lttng_add_trigger_ok "T6" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --max-size=1234
357 lttng_add_trigger_ok "T7" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --name=meh
bbadb5e0
JR
358 lttng_add_trigger_ok "T8" --condition on-event -u some-event --action snapshot-session ze-session --rate-policy=every:10
359 lttng_add_trigger_ok "T9" --condition on-event -u some-event --action snapshot-session ze-session --rate-policy=once-after:10
0de2479d
SM
360
361
362 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 363 - name: T0
0de2479d
SM
364 user id: ${uid}
365 condition: event rule hit
366 rule: some-event (type: tracepoint, domain: ust)
367 actions:
368 snapshot session \`ze-session\`
709fb83f
JG
369 errors: none
370 errors: none
1d4b59f2 371 - name: T1
0de2479d
SM
372 user id: ${uid}
373 condition: event rule hit
374 rule: some-event (type: tracepoint, domain: ust)
375 actions:
376 snapshot session \`ze-session\`, path: /some/path
709fb83f
JG
377 errors: none
378 errors: none
1d4b59f2 379 - name: T2
0de2479d
SM
380 user id: ${uid}
381 condition: event rule hit
382 rule: some-event (type: tracepoint, domain: ust)
383 actions:
384 snapshot session \`ze-session\`, path: /some/other/path
709fb83f
JG
385 errors: none
386 errors: none
1d4b59f2 387 - name: T3
0de2479d
SM
388 user id: ${uid}
389 condition: event rule hit
390 rule: some-event (type: tracepoint, domain: ust)
391 actions:
392 snapshot session \`ze-session\`, url: net://1.2.3.4
709fb83f
JG
393 errors: none
394 errors: none
1d4b59f2 395 - name: T4
0de2479d
SM
396 user id: ${uid}
397 condition: event rule hit
398 rule: some-event (type: tracepoint, domain: ust)
399 actions:
400 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
709fb83f
JG
401 errors: none
402 errors: none
1d4b59f2 403 - name: T5
0de2479d
SM
404 user id: ${uid}
405 condition: event rule hit
406 rule: some-event (type: tracepoint, domain: ust)
407 actions:
408 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
709fb83f
JG
409 errors: none
410 errors: none
1d4b59f2 411 - name: T6
0de2479d
SM
412 user id: ${uid}
413 condition: event rule hit
414 rule: some-event (type: tracepoint, domain: ust)
415 actions:
416 snapshot session \`ze-session\`, path: /some/path, max size: 1234
709fb83f
JG
417 errors: none
418 errors: none
1d4b59f2 419 - name: T7
0de2479d
SM
420 user id: ${uid}
421 condition: event rule hit
422 rule: some-event (type: tracepoint, domain: ust)
423 actions:
424 snapshot session \`ze-session\`, path: /some/path, name: meh
709fb83f
JG
425 errors: none
426 errors: none
1d4b59f2 427 - name: T8
e45dd625
JR
428 user id: ${uid}
429 condition: event rule hit
430 rule: some-event (type: tracepoint, domain: ust)
e45dd625 431 actions:
7f4d5b07 432 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
709fb83f
JG
433 errors: none
434 errors: none
1d4b59f2 435 - name: T9
e45dd625
JR
436 user id: ${uid}
437 condition: event rule hit
438 rule: some-event (type: tracepoint, domain: ust)
e45dd625 439 actions:
7f4d5b07 440 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
709fb83f
JG
441 errors: none
442 errors: none
e45dd625
JR
443 EOF
444
be7f9dfc 445 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
e45dd625
JR
446
447 stop_lttng_sessiond_notap
448}
449
450test_notify_action ()
451{
452 start_lttng_sessiond_notap
453
bbadb5e0
JR
454 lttng_add_trigger_ok "T0" --condition on-event -u some-event --action notify --rate-policy=once-after:5
455 lttng_add_trigger_ok "T1" --condition on-event -u some-event --action notify --rate-policy=every:10
e45dd625
JR
456
457
458 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 459 - name: T0
e45dd625
JR
460 user id: ${uid}
461 condition: event rule hit
462 rule: some-event (type: tracepoint, domain: ust)
e45dd625 463 actions:
7f4d5b07 464 notify, rate policy: once after 5 occurrences
709fb83f
JG
465 errors: none
466 errors: none
1d4b59f2 467 - name: T1
e45dd625
JR
468 user id: ${uid}
469 condition: event rule hit
470 rule: some-event (type: tracepoint, domain: ust)
e45dd625 471 actions:
7f4d5b07 472 notify, rate policy: after every 10 occurrences
709fb83f
JG
473 errors: none
474 errors: none
0de2479d
SM
475 EOF
476
be7f9dfc 477 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
0de2479d 478
be7f9dfc
FD
479 lttng_remove_trigger_ok "T0"
480 lttng_remove_trigger_ok "T1"
0de2479d
SM
481}
482
be7f9dfc
FD
483plan_tests $NUM_TESTS
484
485# shellcheck disable=SC2119
486start_lttng_sessiond_notap
487
0de2479d
SM
488test_top_level_options
489test_on_event_tracepoint
be7f9dfc 490skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
8a917ae8
FD
491skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
492skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
be7f9dfc 493skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
0de2479d 494test_snapshot_action
e45dd625 495test_notify_action
0de2479d 496
be7f9dfc
FD
497stop_lttng_sessiond_notap
498
0de2479d
SM
499# Cleanup
500rm -f "${tmp_stdout}"
501rm -f "${tmp_stderr}"
502rm -f "${tmp_expected_stdout}"
This page took 0.07514 seconds and 4 git commands to generate.