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