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