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