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