Tests: cleanup: rework trigger listing tests
[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
FD
26
27NUM_TESTS=67
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")
35
36uid=$(id --user)
37gid=$(id --group)
38
39if [ "$uid" == "0" ]; then
40 ist_root=1
41else
42 ist_root=0
43fi
44
be7f9dfc
FD
45
46function list_triggers_matches_ok ()
0de2479d
SM
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
61test_top_level_options ()
62{
be7f9dfc 63 diag "Listing top level options"
0de2479d 64
70c766ac 65 lttng_add_trigger_ok "hello" --condition on-event -u test-id --action notify
0de2479d
SM
66
67 cat > "${tmp_expected_stdout}" <<- EOF
0de2479d
SM
68 - id: hello
69 user id: ${uid}
70 condition: event rule hit
71 rule: test-id (type: tracepoint, domain: ust)
72 actions:
73 notify
709fb83f
JG
74 errors: none
75 errors: none
0de2479d
SM
76 EOF
77
be7f9dfc 78 list_triggers_matches_ok "top level options" "${tmp_expected_stdout}"
0de2479d 79
be7f9dfc 80 lttng_remove_trigger_ok "hello"
0de2479d
SM
81}
82
83test_on_event_tracepoint ()
84{
be7f9dfc 85 diag "Listing on-event tracepoint"
0de2479d 86
70c766ac
FD
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
b203b4b0 96
0de2479d
SM
97
98 cat > "${tmp_expected_stdout}" <<- EOF
70c766ac 99 - id: A
0de2479d
SM
100 user id: ${uid}
101 condition: event rule hit
102 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
103 actions:
104 notify
709fb83f
JG
105 errors: none
106 errors: none
70c766ac 107 - id: B
0de2479d
SM
108 user id: ${uid}
109 condition: event rule hit
1b859ae2 110 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
0de2479d
SM
111 actions:
112 notify
709fb83f
JG
113 errors: none
114 errors: none
70c766ac 115 - id: C
0de2479d
SM
116 user id: ${uid}
117 condition: event rule hit
118 rule: * (type: tracepoint, domain: ust)
119 actions:
120 notify
709fb83f
JG
121 errors: none
122 errors: none
70c766ac 123 - id: D
0de2479d
SM
124 user id: ${uid}
125 condition: event rule hit
126 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
127 actions:
128 notify
709fb83f
JG
129 errors: none
130 errors: none
70c766ac 131 - id: E
0de2479d
SM
132 user id: ${uid}
133 condition: event rule hit
1b859ae2 134 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
0de2479d
SM
135 actions:
136 notify
709fb83f
JG
137 errors: none
138 errors: none
70c766ac 139 - id: F
b203b4b0
SM
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
709fb83f
JG
147 errors: none
148 errors: none
70c766ac 149 - id: G
b203b4b0
SM
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
709fb83f
JG
158 errors: none
159 errors: none
70c766ac 160 - id: H
b203b4b0
SM
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
709fb83f
JG
168 errors: none
169 errors: none
70c766ac 170 - id: I
b203b4b0
SM
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
709fb83f
JG
178 errors: none
179 errors: none
0de2479d
SM
180 EOF
181
be7f9dfc
FD
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"
0de2479d
SM
193}
194
195test_on_event_probe ()
196{
197 local channel_enable_addr
198 local channel_disable_addr
199
be7f9dfc 200 diag "Listing on-event kernel probe"
0de2479d
SM
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
70c766ac
FD
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
0de2479d
SM
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
709fb83f
JG
229 errors: none
230 errors: none
0de2479d
SM
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
709fb83f
JG
237 errors: none
238 errors: none
0de2479d
SM
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
709fb83f
JG
245 errors: none
246 errors: none
0de2479d
SM
247 EOF
248
be7f9dfc 249 list_triggers_matches_ok "on-event, probe event rule" "${tmp_expected_stdout}"
0de2479d 250
be7f9dfc
FD
251 lttng_remove_trigger_ok "T0"
252 lttng_remove_trigger_ok "T1"
253 lttng_remove_trigger_ok "T2"
0de2479d
SM
254}
255
256test_on_event_userspace_probe ()
257{
be7f9dfc
FD
258 local elf_function_name="test_function"
259
260 diag "Listing on-event userspace-probe elf"
0de2479d 261
be7f9dfc 262 lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:${elf_function_name} ma-probe-elf --action notify
0de2479d
SM
263
264 cat > "${tmp_expected_stdout}" <<- EOF
265 - id: T0
266 user id: ${uid}
267 condition: event rule hit
be7f9dfc 268 rule: ma-probe-elf (type: userspace probe, location: ${uprobe_elf_binary}:${elf_function_name})
0de2479d
SM
269 actions:
270 notify
709fb83f
JG
271 errors: none
272 errors: none
0de2479d
SM
273 EOF
274
be7f9dfc 275 list_triggers_matches_ok "on-event, userspace-probe event rule ELF" "${tmp_expected_stdout}"
0de2479d 276
be7f9dfc 277 lttng_remove_trigger_ok "T0"
0de2479d
SM
278}
279
280test_on_event_syscall ()
281{
be7f9dfc 282 diag "Listing on-event syscall"
0de2479d 283
70c766ac
FD
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
0de2479d
SM
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
709fb83f
JG
294 errors: none
295 errors: none
0de2479d
SM
296 - id: T1
297 user id: ${uid}
298 condition: event rule hit
299 rule: ptrace (type: syscall, filter: a > 2)
300 actions:
301 notify
709fb83f
JG
302 errors: none
303 errors: none
0de2479d
SM
304 EOF
305
be7f9dfc 306 list_triggers_matches_ok "on-event, syscall event rule" "${tmp_expected_stdout}"
0de2479d 307
be7f9dfc
FD
308 lttng_remove_trigger_ok "T0"
309 lttng_remove_trigger_ok "T1"
0de2479d
SM
310}
311
312test_snapshot_action ()
313{
be7f9dfc 314 diag "Listing snapshot actions"
0de2479d 315
70c766ac
FD
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
bbadb5e0
JR
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
0de2479d
SM
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\`
709fb83f
JG
335 errors: none
336 errors: none
0de2479d
SM
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
709fb83f
JG
343 errors: none
344 errors: none
0de2479d
SM
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
709fb83f
JG
351 errors: none
352 errors: none
0de2479d
SM
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
709fb83f
JG
359 errors: none
360 errors: none
0de2479d
SM
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
709fb83f
JG
367 errors: none
368 errors: none
0de2479d
SM
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
709fb83f
JG
375 errors: none
376 errors: none
0de2479d
SM
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
709fb83f
JG
383 errors: none
384 errors: none
0de2479d
SM
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
709fb83f
JG
391 errors: none
392 errors: none
e45dd625
JR
393 - id: T8
394 user id: ${uid}
395 condition: event rule hit
396 rule: some-event (type: tracepoint, domain: ust)
e45dd625 397 actions:
7f4d5b07 398 snapshot session \`ze-session\`, rate policy: after every 10 occurrences
709fb83f
JG
399 errors: none
400 errors: none
e45dd625
JR
401 - id: T9
402 user id: ${uid}
403 condition: event rule hit
404 rule: some-event (type: tracepoint, domain: ust)
e45dd625 405 actions:
7f4d5b07 406 snapshot session \`ze-session\`, rate policy: once after 10 occurrences
709fb83f
JG
407 errors: none
408 errors: none
e45dd625
JR
409 EOF
410
be7f9dfc 411 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
e45dd625
JR
412
413 stop_lttng_sessiond_notap
414}
415
416test_notify_action ()
417{
418 start_lttng_sessiond_notap
419
bbadb5e0
JR
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
e45dd625
JR
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)
e45dd625 429 actions:
7f4d5b07 430 notify, rate policy: once after 5 occurrences
709fb83f
JG
431 errors: none
432 errors: none
e45dd625
JR
433 - id: T1
434 user id: ${uid}
435 condition: event rule hit
436 rule: some-event (type: tracepoint, domain: ust)
e45dd625 437 actions:
7f4d5b07 438 notify, rate policy: after every 10 occurrences
709fb83f
JG
439 errors: none
440 errors: none
0de2479d
SM
441 EOF
442
be7f9dfc 443 list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
0de2479d 444
be7f9dfc
FD
445 lttng_remove_trigger_ok "T0"
446 lttng_remove_trigger_ok "T1"
0de2479d
SM
447}
448
be7f9dfc
FD
449plan_tests $NUM_TESTS
450
451# shellcheck disable=SC2119
452start_lttng_sessiond_notap
453
0de2479d
SM
454test_top_level_options
455test_on_event_tracepoint
be7f9dfc
FD
456skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
457skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe
458skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
0de2479d 459test_snapshot_action
e45dd625 460test_notify_action
0de2479d 461
be7f9dfc
FD
462stop_lttng_sessiond_notap
463
0de2479d
SM
464# Cleanup
465rm -f "${tmp_stdout}"
466rm -f "${tmp_stderr}"
467rm -f "${tmp_expected_stdout}"
This page took 0.070716 seconds and 4 git commands to generate.