lttng add-trigger: some updates to event rule to new syntax
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
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
20 CURDIR="$(dirname "$0")"
21 TESTDIR="$CURDIR/../../.."
22
23 # shellcheck source=../../../utils/utils.sh
24 source "$TESTDIR/utils/utils.sh"
25
26
27 NUM_TESTS=82
28
29 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
30
31 tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
32 tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
33 tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
34 uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
35 uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary")
36
37 uid=$(id --user)
38 gid=$(id --group)
39
40 if [ "$uid" == "0" ]; then
41 ist_root=1
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
48 else
49 ist_root=0
50 hast_sdt_binary=0
51 fi
52
53
54 function list_triggers_matches_ok ()
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
69 test_top_level_options ()
70 {
71 diag "Listing top level options"
72
73 lttng_add_trigger_ok "hello" --condition event-rule-matches -u --name=test-name --action notify
74
75 cat > "${tmp_expected_stdout}" <<- EOF
76 - name: hello
77 user id: ${uid}
78 condition: event rule hit
79 rule: test-name (type: tracepoint, domain: ust)
80 actions:
81 notify
82 errors: none
83 errors: none
84 EOF
85
86 list_triggers_matches_ok "top level options" "${tmp_expected_stdout}"
87
88 lttng_remove_trigger_ok "hello"
89 }
90
91 test_on_event_tracepoint ()
92 {
93 diag "Listing on-event tracepoint"
94
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
104
105 cat > "${tmp_expected_stdout}" <<- EOF
106 - name: A
107 user id: ${uid}
108 condition: event rule hit
109 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
110 actions:
111 notify
112 errors: none
113 errors: none
114 - name: B
115 user id: ${uid}
116 condition: event rule hit
117 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
118 actions:
119 notify
120 errors: none
121 errors: none
122 - name: C
123 user id: ${uid}
124 condition: event rule hit
125 rule: * (type: tracepoint, domain: ust)
126 actions:
127 notify
128 errors: none
129 errors: none
130 - name: D
131 user id: ${uid}
132 condition: event rule hit
133 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
134 actions:
135 notify
136 errors: none
137 errors: none
138 - name: E
139 user id: ${uid}
140 condition: event rule hit
141 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
142 actions:
143 notify
144 errors: none
145 errors: none
146 - name: F
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
154 errors: none
155 errors: none
156 - name: G
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
165 errors: none
166 errors: none
167 - name: H
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
175 errors: none
176 errors: none
177 - name: I
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
185 errors: none
186 errors: none
187 EOF
188
189 list_triggers_matches_ok "event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}"
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"
200 }
201
202 test_on_event_probe ()
203 {
204 local channel_enable_addr
205 local channel_disable_addr
206
207 diag "Listing on-event kernel probe"
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
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
228
229 cat > "${tmp_expected_stdout}" <<- EOF
230 - name: T0
231 user id: ${uid}
232 condition: event rule hit
233 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
234 actions:
235 notify
236 errors: none
237 errors: none
238 - name: T1
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
244 errors: none
245 errors: none
246 - name: T2
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
252 errors: none
253 errors: none
254 EOF
255
256 list_triggers_matches_ok "event-rule-matches, probe event rule" "${tmp_expected_stdout}"
257
258 lttng_remove_trigger_ok "T0"
259 lttng_remove_trigger_ok "T1"
260 lttng_remove_trigger_ok "T2"
261 }
262
263 test_on_event_userspace_probe_elf ()
264 {
265 local elf_function_name="test_function"
266
267 diag "Listing on-event userspace-probe elf"
268
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
270
271 cat > "${tmp_expected_stdout}" <<- EOF
272 - name: T0
273 user id: ${uid}
274 condition: event rule hit
275 rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
276 actions:
277 notify
278 errors: none
279 errors: none
280 EOF
281
282 list_triggers_matches_ok "event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}"
283
284 lttng_remove_trigger_ok "T0"
285 }
286
287 test_on_event_userspace_probe_sdt ()
288 {
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
312 test_on_event_syscall ()
313 {
314 diag "Listing on-event syscall"
315
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
318
319 cat > "${tmp_expected_stdout}" <<- EOF
320 - name: T0
321 user id: ${uid}
322 condition: event rule hit
323 rule: open (type: syscall)
324 actions:
325 notify
326 errors: none
327 errors: none
328 - name: T1
329 user id: ${uid}
330 condition: event rule hit
331 rule: ptrace (type: syscall, filter: a > 2)
332 actions:
333 notify
334 errors: none
335 errors: none
336 EOF
337
338 list_triggers_matches_ok "event-rule-matches, syscall event rule" "${tmp_expected_stdout}"
339
340 lttng_remove_trigger_ok "T0"
341 lttng_remove_trigger_ok "T1"
342 }
343
344 test_snapshot_action ()
345 {
346 diag "Listing snapshot actions"
347
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
358
359 cat > "${tmp_expected_stdout}" <<- EOF
360 - name: T0
361 user id: ${uid}
362 condition: event rule hit
363 rule: some-event (type: tracepoint, domain: ust)
364 actions:
365 snapshot session \`ze-session\`
366 errors: none
367 errors: none
368 - name: T1
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
374 errors: none
375 errors: none
376 - name: T2
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
382 errors: none
383 errors: none
384 - name: T3
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
390 errors: none
391 errors: none
392 - name: T4
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
398 errors: none
399 errors: none
400 - name: T5
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
406 errors: none
407 errors: none
408 - name: T6
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
414 errors: none
415 errors: none
416 - name: T7
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
422 errors: none
423 errors: none
424 - name: T8
425 user id: ${uid}
426 condition: event rule hit
427 rule: some-event (type: tracepoint, domain: ust)
428 actions:
429 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
430 errors: none
431 errors: none
432 - name: T9
433 user id: ${uid}
434 condition: event rule hit
435 rule: some-event (type: tracepoint, domain: ust)
436 actions:
437 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
438 errors: none
439 errors: none
440 EOF
441
442 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
443
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"
454 }
455
456 test_notify_action ()
457 {
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
460
461 cat > "${tmp_expected_stdout}" <<- EOF
462 - name: T0
463 user id: ${uid}
464 condition: event rule hit
465 rule: some-event (type: tracepoint, domain: ust)
466 actions:
467 notify, rate policy: once after 5 occurrences
468 errors: none
469 errors: none
470 - name: T1
471 user id: ${uid}
472 condition: event rule hit
473 rule: some-event (type: tracepoint, domain: ust)
474 actions:
475 notify, rate policy: after every 10 occurrences
476 errors: none
477 errors: none
478 EOF
479
480 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
481
482 lttng_remove_trigger_ok "T0"
483 lttng_remove_trigger_ok "T1"
484 }
485
486 plan_tests $NUM_TESTS
487
488 # shellcheck disable=SC2119
489 start_lttng_sessiond_notap
490
491 test_top_level_options
492 test_on_event_tracepoint
493 skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
494 skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
495 skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
496 skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
497 test_snapshot_action
498 test_notify_action
499
500 stop_lttng_sessiond_notap
501
502 # Cleanup
503 rm -f "${tmp_stdout}"
504 rm -f "${tmp_stderr}"
505 rm -f "${tmp_expected_stdout}"
This page took 0.062257 seconds and 4 git commands to generate.