lttng {add,list}-triggers: use `name` instead of `id`
[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=72
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 on-event -u test-id --action notify
74
75 cat > "${tmp_expected_stdout}" <<- EOF
76 - name: hello
77 user id: ${uid}
78 condition: event rule hit
79 rule: test-id (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 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
104
105
106 cat > "${tmp_expected_stdout}" <<- EOF
107 - name: A
108 user id: ${uid}
109 condition: event rule hit
110 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
111 actions:
112 notify
113 errors: none
114 errors: none
115 - name: B
116 user id: ${uid}
117 condition: event rule hit
118 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
119 actions:
120 notify
121 errors: none
122 errors: none
123 - name: C
124 user id: ${uid}
125 condition: event rule hit
126 rule: * (type: tracepoint, domain: ust)
127 actions:
128 notify
129 errors: none
130 errors: none
131 - name: D
132 user id: ${uid}
133 condition: event rule hit
134 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
135 actions:
136 notify
137 errors: none
138 errors: none
139 - name: E
140 user id: ${uid}
141 condition: event rule hit
142 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
143 actions:
144 notify
145 errors: none
146 errors: none
147 - name: F
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
155 errors: none
156 errors: none
157 - name: G
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
166 errors: none
167 errors: none
168 - name: H
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
176 errors: none
177 errors: none
178 - name: I
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
186 errors: none
187 errors: none
188 EOF
189
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"
201 }
202
203 test_on_event_probe ()
204 {
205 local channel_enable_addr
206 local channel_disable_addr
207
208 diag "Listing on-event kernel probe"
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
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
229
230 cat > "${tmp_expected_stdout}" <<- EOF
231 - name: T0
232 user id: ${uid}
233 condition: event rule hit
234 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
235 actions:
236 notify
237 errors: none
238 errors: none
239 - name: T1
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
245 errors: none
246 errors: none
247 - name: T2
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
253 errors: none
254 errors: none
255 EOF
256
257 list_triggers_matches_ok "on-event, probe event rule" "${tmp_expected_stdout}"
258
259 lttng_remove_trigger_ok "T0"
260 lttng_remove_trigger_ok "T1"
261 lttng_remove_trigger_ok "T2"
262 }
263
264 test_on_event_userspace_probe_elf ()
265 {
266 local elf_function_name="test_function"
267
268 diag "Listing on-event userspace-probe elf"
269
270 lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:${elf_function_name} ma-probe-elf --action notify
271
272 cat > "${tmp_expected_stdout}" <<- EOF
273 - name: T0
274 user id: ${uid}
275 condition: event rule hit
276 rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
277 actions:
278 notify
279 errors: none
280 errors: none
281 EOF
282
283 list_triggers_matches_ok "on-event, userspace-probe event rule ELF" "${tmp_expected_stdout}"
284
285 lttng_remove_trigger_ok "T0"
286 }
287
288 test_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
314 test_on_event_syscall ()
315 {
316 diag "Listing on-event syscall"
317
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
320
321 cat > "${tmp_expected_stdout}" <<- EOF
322 - name: T0
323 user id: ${uid}
324 condition: event rule hit
325 rule: open (type: syscall)
326 actions:
327 notify
328 errors: none
329 errors: none
330 - name: T1
331 user id: ${uid}
332 condition: event rule hit
333 rule: ptrace (type: syscall, filter: a > 2)
334 actions:
335 notify
336 errors: none
337 errors: none
338 EOF
339
340 list_triggers_matches_ok "on-event, syscall event rule" "${tmp_expected_stdout}"
341
342 lttng_remove_trigger_ok "T0"
343 lttng_remove_trigger_ok "T1"
344 }
345
346 test_snapshot_action ()
347 {
348 diag "Listing snapshot actions"
349
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
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
360
361
362 cat > "${tmp_expected_stdout}" <<- EOF
363 - name: T0
364 user id: ${uid}
365 condition: event rule hit
366 rule: some-event (type: tracepoint, domain: ust)
367 actions:
368 snapshot session \`ze-session\`
369 errors: none
370 errors: none
371 - name: T1
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
377 errors: none
378 errors: none
379 - name: T2
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
385 errors: none
386 errors: none
387 - name: T3
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
393 errors: none
394 errors: none
395 - name: T4
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
401 errors: none
402 errors: none
403 - name: T5
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
409 errors: none
410 errors: none
411 - name: T6
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
417 errors: none
418 errors: none
419 - name: T7
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
425 errors: none
426 errors: none
427 - name: T8
428 user id: ${uid}
429 condition: event rule hit
430 rule: some-event (type: tracepoint, domain: ust)
431 actions:
432 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
433 errors: none
434 errors: none
435 - name: T9
436 user id: ${uid}
437 condition: event rule hit
438 rule: some-event (type: tracepoint, domain: ust)
439 actions:
440 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
441 errors: none
442 errors: none
443 EOF
444
445 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
446
447 stop_lttng_sessiond_notap
448 }
449
450 test_notify_action ()
451 {
452 start_lttng_sessiond_notap
453
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
456
457
458 cat > "${tmp_expected_stdout}" <<- EOF
459 - name: T0
460 user id: ${uid}
461 condition: event rule hit
462 rule: some-event (type: tracepoint, domain: ust)
463 actions:
464 notify, rate policy: once after 5 occurrences
465 errors: none
466 errors: none
467 - name: T1
468 user id: ${uid}
469 condition: event rule hit
470 rule: some-event (type: tracepoint, domain: ust)
471 actions:
472 notify, rate policy: after every 10 occurrences
473 errors: none
474 errors: none
475 EOF
476
477 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
478
479 lttng_remove_trigger_ok "T0"
480 lttng_remove_trigger_ok "T1"
481 }
482
483 plan_tests $NUM_TESTS
484
485 # shellcheck disable=SC2119
486 start_lttng_sessiond_notap
487
488 test_top_level_options
489 test_on_event_tracepoint
490 skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
491 skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
492 skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
493 skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
494 test_snapshot_action
495 test_notify_action
496
497 stop_lttng_sessiond_notap
498
499 # Cleanup
500 rm -f "${tmp_stdout}"
501 rm -f "${tmp_stderr}"
502 rm -f "${tmp_expected_stdout}"
This page took 0.060489 seconds and 4 git commands to generate.