f5d34f967b142817d2d4e0ce2c160c1b68a47aca
[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 NUM_TESTS=84
27
28 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
30 tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
31 tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
32 tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
33 uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
34 uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary")
35
36 uid=$(id --user)
37 gid=$(id --group)
38
39 if [ "$uid" == "0" ]; then
40 ist_root=1
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
47 else
48 ist_root=0
49 hast_sdt_binary=0
50 fi
51
52
53 function list_triggers_matches_ok ()
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
68 test_top_level_options ()
69 {
70 diag "Listing top level options"
71
72 lttng_add_trigger_ok "hello" --condition event-rule-matches --domain=user --name=test-name --action notify
73
74 cat > "${tmp_expected_stdout}" <<- EOF
75 - name: hello
76 user id: ${uid}
77 condition: event rule hit
78 rule: test-name (type: tracepoint, domain: ust)
79 actions:
80 notify
81 errors: none
82 errors: none
83 EOF
84
85 list_triggers_matches_ok "top level options" "${tmp_expected_stdout}"
86
87 lttng_remove_trigger_ok "hello"
88 }
89
90 test_on_event_tracepoint ()
91 {
92 diag "Listing on-event tracepoint"
93
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
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
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
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 - name: J
188 user id: ${uid}
189 condition: event rule hit
190 rule: lemming (type: tracepoint, domain: ust)
191 actions:
192 notify
193 errors: none
194 errors: none
195 EOF
196
197 list_triggers_matches_ok "event-rule-matches, tracepoint event rule" "${tmp_expected_stdout}"
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"
208 lttng_remove_trigger_ok "J"
209 }
210
211 test_on_event_probe ()
212 {
213 local channel_enable_addr
214 local channel_disable_addr
215
216 diag "Listing on-event kernel probe"
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
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
237
238 cat > "${tmp_expected_stdout}" <<- EOF
239 - name: T0
240 user id: ${uid}
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
243 actions:
244 notify
245 errors: none
246 errors: none
247 - name: T1
248 user id: ${uid}
249 condition: event rule hit
250 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
251 actions:
252 notify
253 errors: none
254 errors: none
255 - name: T2
256 user id: ${uid}
257 condition: event rule hit
258 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
259 actions:
260 notify
261 errors: none
262 errors: none
263 EOF
264
265 list_triggers_matches_ok "event-rule-matches, probe event rule" "${tmp_expected_stdout}"
266
267 lttng_remove_trigger_ok "T0"
268 lttng_remove_trigger_ok "T1"
269 lttng_remove_trigger_ok "T2"
270 }
271
272 test_on_event_userspace_probe_elf ()
273 {
274 local elf_function_name="test_function"
275
276 diag "Listing on-event userspace-probe elf"
277
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
279
280 cat > "${tmp_expected_stdout}" <<- EOF
281 - name: T0
282 user id: ${uid}
283 condition: event rule hit
284 rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
285 actions:
286 notify
287 errors: none
288 errors: none
289 EOF
290
291 list_triggers_matches_ok "event-rule-matches, userspace-probe event rule" "${tmp_expected_stdout}"
292
293 lttng_remove_trigger_ok "T0"
294 }
295
296 test_on_event_userspace_probe_sdt ()
297 {
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
321 test_on_event_syscall ()
322 {
323 diag "Listing on-event syscall"
324
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
327
328 cat > "${tmp_expected_stdout}" <<- EOF
329 - name: T0
330 user id: ${uid}
331 condition: event rule hit
332 rule: open (type: syscall)
333 actions:
334 notify
335 errors: none
336 errors: none
337 - name: T1
338 user id: ${uid}
339 condition: event rule hit
340 rule: ptrace (type: syscall, filter: a > 2)
341 actions:
342 notify
343 errors: none
344 errors: none
345 EOF
346
347 list_triggers_matches_ok "event-rule-matches, syscall event rule" "${tmp_expected_stdout}"
348
349 lttng_remove_trigger_ok "T0"
350 lttng_remove_trigger_ok "T1"
351 }
352
353 test_snapshot_action ()
354 {
355 diag "Listing snapshot actions"
356
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
367
368 cat > "${tmp_expected_stdout}" <<- EOF
369 - name: T0
370 user id: ${uid}
371 condition: event rule hit
372 rule: some-event (type: tracepoint, domain: ust)
373 actions:
374 snapshot session \`ze-session\`
375 errors: none
376 errors: none
377 - name: T1
378 user id: ${uid}
379 condition: event rule hit
380 rule: some-event (type: tracepoint, domain: ust)
381 actions:
382 snapshot session \`ze-session\`, path: /some/path
383 errors: none
384 errors: none
385 - name: T2
386 user id: ${uid}
387 condition: event rule hit
388 rule: some-event (type: tracepoint, domain: ust)
389 actions:
390 snapshot session \`ze-session\`, path: /some/other/path
391 errors: none
392 errors: none
393 - name: T3
394 user id: ${uid}
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
399 errors: none
400 errors: none
401 - name: T4
402 user id: ${uid}
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
407 errors: none
408 errors: none
409 - name: T5
410 user id: ${uid}
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
415 errors: none
416 errors: none
417 - name: T6
418 user id: ${uid}
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
423 errors: none
424 errors: none
425 - name: T7
426 user id: ${uid}
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
431 errors: none
432 errors: none
433 - name: T8
434 user id: ${uid}
435 condition: event rule hit
436 rule: some-event (type: tracepoint, domain: ust)
437 actions:
438 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
439 errors: none
440 errors: none
441 - name: T9
442 user id: ${uid}
443 condition: event rule hit
444 rule: some-event (type: tracepoint, domain: ust)
445 actions:
446 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
447 errors: none
448 errors: none
449 EOF
450
451 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
452
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"
463 }
464
465 test_notify_action ()
466 {
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
469
470 cat > "${tmp_expected_stdout}" <<- EOF
471 - name: T0
472 user id: ${uid}
473 condition: event rule hit
474 rule: some-event (type: tracepoint, domain: ust)
475 actions:
476 notify, rate policy: once after 5 occurrences
477 errors: none
478 errors: none
479 - name: T1
480 user id: ${uid}
481 condition: event rule hit
482 rule: some-event (type: tracepoint, domain: ust)
483 actions:
484 notify, rate policy: after every 10 occurrences
485 errors: none
486 errors: none
487 EOF
488
489 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
490
491 lttng_remove_trigger_ok "T0"
492 lttng_remove_trigger_ok "T1"
493 }
494
495 plan_tests $NUM_TESTS
496
497 # shellcheck disable=SC2119
498 start_lttng_sessiond_notap
499
500 test_top_level_options
501 test_on_event_tracepoint
502 skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
503 skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
504 skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
505 skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
506 test_snapshot_action
507 test_notify_action
508
509 stop_lttng_sessiond_notap
510
511 # Cleanup
512 rm -f "${tmp_stdout}"
513 rm -f "${tmp_stderr}"
514 rm -f "${tmp_expected_stdout}"
This page took 0.06152 seconds and 4 git commands to generate.