lttng add-trigger: some updates to event rule to new syntax
[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
665db063 27NUM_TESTS=82
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
50ad0862 73 lttng_add_trigger_ok "hello" --condition event-rule-matches -u --name=test-name --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
50ad0862 79 rule: test-name (type: tracepoint, domain: ust)
0de2479d
SM
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
50ad0862
SM
95 lttng_add_trigger_ok "C" --condition event-rule-matches -u --action notify
96 lttng_add_trigger_ok "A" --condition event-rule-matches --name=aaa -u --filter 'p == 2' --action notify
97 lttng_add_trigger_ok "D" --condition event-rule-matches --name='hello*' -u -x 'hello2,hello3,hello4' --action notify
98 lttng_add_trigger_ok "B" --condition event-rule-matches -u --name=gerboise --loglevel INFO --action notify
99 lttng_add_trigger_ok "E" --condition event-rule-matches -u --name=lemming --loglevel-only WARNING --action notify
100 lttng_add_trigger_ok "F" --condition event-rule-matches -u --name=capture-payload-field --capture a --action notify
101 lttng_add_trigger_ok "G" --condition event-rule-matches -u --name=capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
102 lttng_add_trigger_ok "H" --condition event-rule-matches -u --name=capture-chan-ctx --capture '$ctx.vpid' --action notify
103 lttng_add_trigger_ok "I" --condition event-rule-matches -u --name=capture-app-ctx --capture '$app.iga:active_clients' --action notify
0de2479d
SM
104
105 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 106 - name: A
0de2479d
SM
107 user id: ${uid}
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
0de2479d
SM
115 user id: ${uid}
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
0de2479d
SM
123 user id: ${uid}
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
0de2479d
SM
131 user id: ${uid}
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
0de2479d
SM
139 user id: ${uid}
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
b203b4b0
SM
147 user id: ${uid}
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
b203b4b0
SM
157 user id: ${uid}
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
b203b4b0
SM
168 user id: ${uid}
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
b203b4b0
SM
178 user id: ${uid}
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
0de2479d
SM
187 EOF
188
665db063 189 list_triggers_matches_ok "event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}"
be7f9dfc
FD
190
191 lttng_remove_trigger_ok "A"
192 lttng_remove_trigger_ok "B"
193 lttng_remove_trigger_ok "C"
194 lttng_remove_trigger_ok "D"
195 lttng_remove_trigger_ok "E"
196 lttng_remove_trigger_ok "F"
197 lttng_remove_trigger_ok "G"
198 lttng_remove_trigger_ok "H"
199 lttng_remove_trigger_ok "I"
0de2479d
SM
200}
201
202test_on_event_probe ()
203{
204 local channel_enable_addr
205 local channel_disable_addr
206
be7f9dfc 207 diag "Listing on-event kernel probe"
0de2479d
SM
208
209 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
210 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
211
212 # We need to find a valid offset.
213 base_symbol=""
214 offset=0
215 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
216 base_symbol="lttng_channel_enable"
217 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
218 else
219 base_symbol="lttng_channel_disable"
220 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
221 fi
222
223 offset_hex="0x$(printf '%x' $offset)"
224
50ad0862
SM
225 lttng_add_trigger_ok "T0" --condition event-rule-matches -k --probe=lttng_channel_enable --event-name=my_channel_enable --action notify
226 lttng_add_trigger_ok "T1" --condition event-rule-matches -k --probe="${base_symbol}+${offset_hex}" --event-name=my_channel_enable --action notify
227 lttng_add_trigger_ok "T2" --condition event-rule-matches -k --probe="0x${channel_enable_addr}" --event-name=my_channel_enable --action notify
0de2479d
SM
228
229 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 230 - name: T0
0de2479d
SM
231 user id: ${uid}
232 condition: event rule hit
233 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
234 actions:
235 notify
709fb83f
JG
236 errors: none
237 errors: none
1d4b59f2 238 - name: T1
0de2479d
SM
239 user id: ${uid}
240 condition: event rule hit
241 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
242 actions:
243 notify
709fb83f
JG
244 errors: none
245 errors: none
1d4b59f2 246 - name: T2
0de2479d
SM
247 user id: ${uid}
248 condition: event rule hit
249 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
250 actions:
251 notify
709fb83f
JG
252 errors: none
253 errors: none
0de2479d
SM
254 EOF
255
665db063 256 list_triggers_matches_ok "event-rule-matches, probe event rule" "${tmp_expected_stdout}"
0de2479d 257
be7f9dfc
FD
258 lttng_remove_trigger_ok "T0"
259 lttng_remove_trigger_ok "T1"
260 lttng_remove_trigger_ok "T2"
0de2479d
SM
261}
262
8a917ae8 263test_on_event_userspace_probe_elf ()
0de2479d 264{
be7f9dfc
FD
265 local elf_function_name="test_function"
266
267 diag "Listing on-event userspace-probe elf"
0de2479d 268
50ad0862 269 lttng_add_trigger_ok "T0" --condition event-rule-matches -k --userspace-probe=${uprobe_elf_binary}:test_function --event-name=ma-probe-elf --action notify
0de2479d
SM
270
271 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 272 - name: T0
0de2479d
SM
273 user id: ${uid}
274 condition: event rule hit
8a917ae8 275 rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
0de2479d
SM
276 actions:
277 notify
709fb83f
JG
278 errors: none
279 errors: none
0de2479d
SM
280 EOF
281
665db063 282 list_triggers_matches_ok "event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}"
0de2479d 283
be7f9dfc 284 lttng_remove_trigger_ok "T0"
0de2479d
SM
285}
286
8a917ae8
FD
287test_on_event_userspace_probe_sdt ()
288{
8a917ae8
FD
289 local sdt_provider_name="foobar"
290 local sdt_probe_name="tp1"
291
292 diag "on-event userspace-probe sdt"
293
294 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
295
296 cat > "${tmp_expected_stdout}" <<- EOF
297 - id: T0
298 user id: 0
299 condition: event rule hit
300 rule: ma-probe-sdt (type: userspace probe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
301 actions:
302 notify
303 errors: none
304 errors: none
305 EOF
306
307 list_triggers_matches_ok "on-event, userspace-probe event rule SDT" "${tmp_expected_stdout}"
308
309 lttng_remove_trigger_ok "T0"
310}
311
0de2479d
SM
312test_on_event_syscall ()
313{
be7f9dfc 314 diag "Listing on-event syscall"
0de2479d 315
50ad0862
SM
316 lttng_add_trigger_ok "T0" --condition event-rule-matches -k --syscall --name=open --action notify
317 lttng_add_trigger_ok "T1" --condition event-rule-matches -k --syscall --name=ptrace --filter 'a > 2' --action notify
0de2479d
SM
318
319 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 320 - name: T0
0de2479d
SM
321 user id: ${uid}
322 condition: event rule hit
323 rule: open (type: syscall)
324 actions:
325 notify
709fb83f
JG
326 errors: none
327 errors: none
1d4b59f2 328 - name: T1
0de2479d
SM
329 user id: ${uid}
330 condition: event rule hit
331 rule: ptrace (type: syscall, filter: a > 2)
332 actions:
333 notify
709fb83f
JG
334 errors: none
335 errors: none
0de2479d
SM
336 EOF
337
665db063 338 list_triggers_matches_ok "event-rule-matches, syscall event rule" "${tmp_expected_stdout}"
0de2479d 339
be7f9dfc
FD
340 lttng_remove_trigger_ok "T0"
341 lttng_remove_trigger_ok "T1"
0de2479d
SM
342}
343
344test_snapshot_action ()
345{
be7f9dfc 346 diag "Listing snapshot actions"
0de2479d 347
50ad0862
SM
348 lttng_add_trigger_ok "T0" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session
349 lttng_add_trigger_ok "T1" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --path /some/path
350 lttng_add_trigger_ok "T2" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --url file:///some/other/path
351 lttng_add_trigger_ok "T3" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --url net://1.2.3.4
352 lttng_add_trigger_ok "T4" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --url net://1.2.3.4:1234:1235
353 lttng_add_trigger_ok "T5" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112
354 lttng_add_trigger_ok "T6" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --path /some/path --max-size=1234
355 lttng_add_trigger_ok "T7" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --path /some/path --name=meh
356 lttng_add_trigger_ok "T8" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --rate-policy=every:10
357 lttng_add_trigger_ok "T9" --condition event-rule-matches -u --name=some-event --action snapshot-session ze-session --rate-policy=once-after:10
0de2479d
SM
358
359 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 360 - name: T0
0de2479d
SM
361 user id: ${uid}
362 condition: event rule hit
363 rule: some-event (type: tracepoint, domain: ust)
364 actions:
365 snapshot session \`ze-session\`
709fb83f
JG
366 errors: none
367 errors: none
1d4b59f2 368 - name: T1
0de2479d
SM
369 user id: ${uid}
370 condition: event rule hit
371 rule: some-event (type: tracepoint, domain: ust)
372 actions:
373 snapshot session \`ze-session\`, path: /some/path
709fb83f
JG
374 errors: none
375 errors: none
1d4b59f2 376 - name: T2
0de2479d
SM
377 user id: ${uid}
378 condition: event rule hit
379 rule: some-event (type: tracepoint, domain: ust)
380 actions:
381 snapshot session \`ze-session\`, path: /some/other/path
709fb83f
JG
382 errors: none
383 errors: none
1d4b59f2 384 - name: T3
0de2479d
SM
385 user id: ${uid}
386 condition: event rule hit
387 rule: some-event (type: tracepoint, domain: ust)
388 actions:
389 snapshot session \`ze-session\`, url: net://1.2.3.4
709fb83f
JG
390 errors: none
391 errors: none
1d4b59f2 392 - name: T4
0de2479d
SM
393 user id: ${uid}
394 condition: event rule hit
395 rule: some-event (type: tracepoint, domain: ust)
396 actions:
397 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
709fb83f
JG
398 errors: none
399 errors: none
1d4b59f2 400 - name: T5
0de2479d
SM
401 user id: ${uid}
402 condition: event rule hit
403 rule: some-event (type: tracepoint, domain: ust)
404 actions:
405 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
709fb83f
JG
406 errors: none
407 errors: none
1d4b59f2 408 - name: T6
0de2479d
SM
409 user id: ${uid}
410 condition: event rule hit
411 rule: some-event (type: tracepoint, domain: ust)
412 actions:
413 snapshot session \`ze-session\`, path: /some/path, max size: 1234
709fb83f
JG
414 errors: none
415 errors: none
1d4b59f2 416 - name: T7
0de2479d
SM
417 user id: ${uid}
418 condition: event rule hit
419 rule: some-event (type: tracepoint, domain: ust)
420 actions:
421 snapshot session \`ze-session\`, path: /some/path, name: meh
709fb83f
JG
422 errors: none
423 errors: none
1d4b59f2 424 - name: T8
e45dd625
JR
425 user id: ${uid}
426 condition: event rule hit
427 rule: some-event (type: tracepoint, domain: ust)
e45dd625 428 actions:
7f4d5b07 429 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
709fb83f
JG
430 errors: none
431 errors: none
1d4b59f2 432 - name: T9
e45dd625
JR
433 user id: ${uid}
434 condition: event rule hit
435 rule: some-event (type: tracepoint, domain: ust)
e45dd625 436 actions:
7f4d5b07 437 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
709fb83f
JG
438 errors: none
439 errors: none
e45dd625
JR
440 EOF
441
be7f9dfc 442 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
e45dd625 443
665db063
SM
444 lttng_remove_trigger_ok "T0"
445 lttng_remove_trigger_ok "T1"
446 lttng_remove_trigger_ok "T2"
447 lttng_remove_trigger_ok "T3"
448 lttng_remove_trigger_ok "T4"
449 lttng_remove_trigger_ok "T5"
450 lttng_remove_trigger_ok "T6"
451 lttng_remove_trigger_ok "T7"
452 lttng_remove_trigger_ok "T8"
453 lttng_remove_trigger_ok "T9"
e45dd625
JR
454}
455
456test_notify_action ()
457{
50ad0862
SM
458 lttng_add_trigger_ok "T0" --condition event-rule-matches -u --name=some-event --action notify --rate-policy=once-after:5
459 lttng_add_trigger_ok "T1" --condition event-rule-matches -u --name=some-event --action notify --rate-policy=every:10
e45dd625
JR
460
461 cat > "${tmp_expected_stdout}" <<- EOF
1d4b59f2 462 - name: T0
e45dd625
JR
463 user id: ${uid}
464 condition: event rule hit
465 rule: some-event (type: tracepoint, domain: ust)
e45dd625 466 actions:
7f4d5b07 467 notify, rate policy: once after 5 occurrences
709fb83f
JG
468 errors: none
469 errors: none
1d4b59f2 470 - name: T1
e45dd625
JR
471 user id: ${uid}
472 condition: event rule hit
473 rule: some-event (type: tracepoint, domain: ust)
e45dd625 474 actions:
7f4d5b07 475 notify, rate policy: after every 10 occurrences
709fb83f
JG
476 errors: none
477 errors: none
0de2479d
SM
478 EOF
479
be7f9dfc 480 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
0de2479d 481
be7f9dfc
FD
482 lttng_remove_trigger_ok "T0"
483 lttng_remove_trigger_ok "T1"
0de2479d
SM
484}
485
be7f9dfc
FD
486plan_tests $NUM_TESTS
487
488# shellcheck disable=SC2119
489start_lttng_sessiond_notap
490
0de2479d
SM
491test_top_level_options
492test_on_event_tracepoint
be7f9dfc 493skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
8a917ae8
FD
494skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
495skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
be7f9dfc 496skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
0de2479d 497test_snapshot_action
e45dd625 498test_notify_action
0de2479d 499
be7f9dfc
FD
500stop_lttng_sessiond_notap
501
0de2479d
SM
502# Cleanup
503rm -f "${tmp_stdout}"
504rm -f "${tmp_stderr}"
505rm -f "${tmp_expected_stdout}"
This page took 0.075565 seconds and 4 git commands to generate.