Commit | Line | Data |
---|---|---|
b4b7369f JR |
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 add-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 | ||
bbadb5e0 | 26 | plan_tests 234 |
b4b7369f JR |
27 | |
28 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" | |
29 | ||
30 | # shellcheck disable=SC2119 | |
31 | start_lttng_sessiond_notap | |
32 | ||
33 | tmp_stdout=$(mktemp -t test_parse_cli_trigger_stdout.XXXXXX) | |
34 | tmp_stderr=$(mktemp -t test_parse_cli_trigger_stderr.XXXXXX) | |
35 | uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary" | |
36 | ||
37 | if [ "$(id -u)" == "0" ]; then | |
38 | ist_root=1 | |
39 | else | |
40 | ist_root=0 | |
41 | fi | |
42 | ||
43 | function test_success () | |
44 | { | |
45 | local test_name="$1" | |
46 | shift | |
47 | ||
48 | diag "${FULL_LTTNG_BIN} add-trigger $*" | |
e45dd625 | 49 | set -x |
b4b7369f | 50 | "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" |
e45dd625 | 51 | set +x |
b4b7369f JR |
52 | ok $? "${test_name}: exit code is 0" |
53 | ||
54 | diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.") | |
55 | ok $? "${test_name}: expected stdout" | |
56 | ||
57 | diff -u "${tmp_stderr}" /dev/null | |
58 | ok $? "${test_name}: expected stderr" | |
59 | } | |
60 | ||
61 | function test_failure () | |
62 | { | |
63 | local test_name="$1" | |
64 | local error_msg="$2" | |
65 | ||
66 | shift 2 | |
67 | ||
68 | diag "${FULL_LTTNG_BIN} add-trigger $*" | |
69 | "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" | |
70 | isnt $? 0 "${test_name}: exit code is not 0" | |
71 | ||
72 | diff -u "${tmp_stdout}" /dev/null | |
73 | ok $? "${test_name}: expected stdout" | |
74 | ||
75 | diff -u "${tmp_stderr}" <(echo "${error_msg}") | |
76 | ok $? "${test_name}: expected stderr" | |
77 | } | |
78 | ||
79 | # top-level options | |
80 | test_success "explicit id" \ | |
81 | --id hohoho \ | |
82 | --condition on-event some-event-id -u \ | |
83 | --action notify | |
84 | ||
85 | # `--condition on-event` successes | |
86 | test_success "--condition on-event some-event -u" \ | |
87 | --condition on-event some-event -u \ | |
88 | --action notify | |
89 | ||
90 | test_success "--condition on-event -a -u" \ | |
91 | --condition on-event -a -u \ | |
92 | --action notify | |
93 | ||
e45dd625 | 94 | test_success "notify action polices" \ |
bbadb5e0 | 95 | --condition on-event -u test-rate-policy=once-after \ |
b4b7369f | 96 | --action notify \ |
bbadb5e0 | 97 | --rate-policy=every:55 \ |
e45dd625 | 98 | --action notify \ |
bbadb5e0 | 99 | --rate-policy=once-after:55 |
b4b7369f | 100 | |
e45dd625 | 101 | test_success "start session action polices" \ |
bbadb5e0 | 102 | --condition on-event -u test-rate-policy=once-after \ |
e45dd625 | 103 | --action start-session my_session \ |
bbadb5e0 | 104 | --rate-policy=every:55 \ |
e45dd625 | 105 | --action start-session my_session \ |
bbadb5e0 | 106 | --rate-policy=once-after:55 |
e45dd625 JR |
107 | |
108 | test_success "stop session action polices" \ | |
bbadb5e0 | 109 | --condition on-event -u test-rate-policy=once-after \ |
e45dd625 | 110 | --action stop-session my_session \ |
bbadb5e0 | 111 | --rate-policy=every:55 \ |
e45dd625 | 112 | --action stop-session my_session \ |
bbadb5e0 | 113 | --rate-policy=once-after:55 |
e45dd625 JR |
114 | |
115 | test_success "snapshot session action polices" \ | |
bbadb5e0 | 116 | --condition on-event -u test-rate-policy=once-after \ |
e45dd625 | 117 | --action snapshot-session my_session \ |
bbadb5e0 | 118 | --rate-policy=every:55 \ |
e45dd625 | 119 | --action snapshot-session my_session \ |
bbadb5e0 | 120 | --rate-policy=once-after:55 |
e45dd625 JR |
121 | |
122 | test_success "rotate session action polices" \ | |
bbadb5e0 | 123 | --condition on-event -u test-rate-policy=once-after \ |
e45dd625 | 124 | --action rotate-session my_session \ |
bbadb5e0 | 125 | --rate-policy=every:55 \ |
e45dd625 | 126 | --action rotate-session my_session \ |
bbadb5e0 | 127 | --rate-policy=once-after:55 |
b4b7369f JR |
128 | |
129 | skip $ist_root "non-root user: skipping kprobe tests" 9 || { | |
130 | test_success "--condition on-event probe by symbol" \ | |
131 | --condition on-event -k --probe=lttng_channel_enable my_channel_enable \ | |
132 | --action notify | |
133 | ||
134 | channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') | |
135 | channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') | |
136 | ||
137 | # We need to find a valid offset. | |
138 | base_symbol="" | |
139 | offset=0 | |
140 | if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then | |
141 | base_symbol="lttng_channel_enable" | |
142 | offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr )) | |
143 | else | |
144 | base_symbol="lttng_channel_disable" | |
145 | offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr )) | |
146 | fi | |
147 | ||
148 | offset_hex="0x$(printf '%x' $offset)" | |
149 | ||
150 | test_success "--condition on-event probe by symbol with offset" \ | |
151 | --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_$base_symbol \ | |
152 | --action notify | |
153 | ||
154 | test_success "--condition on-event probe by address" \ | |
155 | --condition on-event -k "--probe=0x${channel_enable_addr}" my_channel_enable \ | |
156 | --action notify | |
157 | } | |
158 | ||
159 | skip $ist_root "non-root user: skipping uprobe tests" 6 || { | |
160 | test_success "--condition on-event uprobe" \ | |
161 | --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe \ | |
162 | --action notify | |
163 | ||
164 | test_success "--condition on-event uprobe with elf prefix" \ | |
165 | --condition on-event -k --userspace-probe=elf:${uprobe_elf_binary}:test_function ma-probe-2 \ | |
166 | --action notify | |
167 | } | |
168 | ||
169 | skip $ist_root "non-root user: skipping syscall tests" 9 || { | |
170 | test_success "--condition on-event syscall" \ | |
171 | --condition on-event -k --syscall open \ | |
172 | --action notify | |
173 | ||
174 | test_success "--condition on-event syscall -a" \ | |
175 | --condition on-event -k --syscall -a \ | |
176 | --action notify | |
177 | ||
178 | test_success "--condition on-event syscall with filter" \ | |
179 | --condition on-event -k --syscall --filter 'a > 2' open \ | |
180 | --action notify | |
181 | } | |
182 | ||
183 | # `--action notify` successes | |
184 | test_success "--action notify" \ | |
185 | --condition on-event some-event-notify -u \ | |
186 | --action notify | |
187 | ||
20a01d15 SM |
188 | test_success "--action notify --capture foo" \ |
189 | --condition on-event some-event-notify-foo -u \ | |
190 | --capture foo --action notify | |
191 | ||
192 | test_success "--action notify --capture foo[2]" \ | |
193 | --condition on-event some-event-notify-foo2 -u \ | |
194 | --capture 'foo[2]' --action notify | |
195 | ||
196 | test_success '--action notify --capture $ctx.foo' \ | |
197 | --condition on-event some-event-notify-ctx-foo -u \ | |
198 | --capture '$ctx.foo' --action notify | |
199 | ||
200 | test_success '--action notify --capture $ctx.foo[2]' \ | |
201 | --condition on-event some-event-notify-ctx-foo2 -u \ | |
202 | --capture '$ctx.foo[2]' --action notify | |
203 | ||
204 | test_success '--action notify --capture $app.prov:type' \ | |
205 | --condition on-event some-event-notify-app-prov-type -u \ | |
206 | --capture '$app.prov:type' --action notify | |
207 | ||
208 | test_success '--action notify --capture $app.prov:type[2]' \ | |
209 | --condition on-event some-event-notify-app-prov-type-2 -u \ | |
210 | --capture '$app.prov:type[2]' --action notify | |
211 | ||
212 | test_success '--action notify multiple captures' \ | |
213 | --condition on-event some-event-notify-multiple-captures -u \ | |
214 | --capture foo --capture '$app.hello:world' --action notify | |
215 | ||
b4b7369f JR |
216 | # `--action start-session` successes |
217 | test_success "--action start-session" \ | |
218 | --condition on-event some-event-start-session -u \ | |
219 | --action start-session ze-session | |
220 | ||
221 | # `--action stop-session` successes | |
222 | test_success "--action stop-session foo" \ | |
223 | --condition on-event some-event-stop-session -u \ | |
224 | --action stop-session ze-session | |
225 | ||
226 | # `--action rotate-session` successes | |
227 | test_success "--action rotate-session foo" \ | |
228 | --condition on-event some-event-rotate-session -u \ | |
229 | --action rotate-session ze-session | |
230 | ||
231 | # `--action snapshot-session` successes | |
232 | test_success "--action snapshot-session foo" \ | |
233 | --condition on-event some-event-snapshot-session -u \ | |
234 | --action snapshot-session ze-session | |
235 | ||
236 | test_success "--action snapshot-session with file URI" \ | |
237 | --condition on-event some-event-snapshot-session2 -u \ | |
238 | --action snapshot-session ze-session --path /hello | |
239 | ||
240 | test_success "--action snapshot-session with net URI" \ | |
241 | --condition on-event some-event-snapshot-session3 -u \ | |
242 | --action snapshot-session ze-session --url net://1.2.3.4 | |
243 | ||
244 | test_success "--action snapshot-session with ctrl/data URIs" \ | |
245 | --condition on-event some-event-snapshot-session4 -u \ | |
246 | --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1234 --data-url=tcp://1.2.3.4:1235 | |
247 | ||
248 | # top-level failures | |
249 | test_failure "no args" "Error: Missing --condition." | |
250 | ||
251 | test_failure "unknown option" \ | |
252 | "Error: Unknown option \`--hello\`" \ | |
253 | --hello | |
254 | ||
255 | test_failure "missing --action" \ | |
256 | "Error: Need at least one --action." \ | |
257 | --condition on-event hello -u | |
258 | ||
259 | test_failure "two --condition" \ | |
260 | "Error: A --condition was already given." \ | |
261 | --condition on-event aaa -u \ | |
262 | --condition on-event bbb -u \ | |
263 | --action notify | |
264 | ||
265 | test_failure "missing argument to --id" \ | |
266 | "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \ | |
267 | --id | |
268 | ||
bbadb5e0 | 269 | for cmd in rate-policy=once-after rate-policy=every; do |
b4b7369f | 270 | test_failure "missing argument to --${cmd}" \ |
bbadb5e0 | 271 | "Error: Rate policy format is invalid." \ |
b4b7369f JR |
272 | --condition on-event -u -a --action notify \ |
273 | --${cmd} | |
274 | ||
275 | test_failure "invalid argument to --${cmd}: non-digit character" \ | |
bbadb5e0 | 276 | "Error: Failed to parse rate policy value \`123bob\` as an integer." \ |
b4b7369f | 277 | --condition on-event -u -a --action notify \ |
bbadb5e0 | 278 | --${cmd}:123bob |
b4b7369f JR |
279 | |
280 | test_failure "invalid argument to --${cmd}: empty string" \ | |
bbadb5e0 | 281 | "Error: Failed to parse rate policy value \`\` as an integer." \ |
b4b7369f | 282 | --condition on-event -u -a --action notify \ |
bbadb5e0 | 283 | --${cmd}":" |
b4b7369f JR |
284 | done |
285 | ||
bbadb5e0 JR |
286 | test_failure "invalid argument to --rate-policy: unknown policy type" \ |
287 | "Error: Rate policy type \`bob\` unknown." \ | |
288 | --condition on-event -u -a --action notify \ | |
289 | --rate-policy=bob:123 | |
290 | ||
b4b7369f JR |
291 | # `--condition` failures |
292 | test_failure "missing args after --condition" \ | |
293 | "Error: Missing condition name." \ | |
294 | --condition | |
295 | test_failure "unknown --condition" \ | |
296 | "Error: Unknown condition name 'zoofest'" \ | |
297 | --condition zoofest | |
298 | ||
299 | # `--condition on-event` failures | |
300 | test_failure "missing args after --condition on-event" \ | |
301 | "Error: Need to provide either a tracepoint name or -a/--all." \ | |
302 | --condition on-event | |
303 | test_failure "missing domain in --condition on-event" \ | |
304 | "Error: Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)." \ | |
305 | --condition on-event -a | |
306 | test_failure "extra args after --condition on-event" \ | |
307 | "Error: Unexpected argument 'bozo'" \ | |
308 | --condition on-event foo -u bozo | |
309 | test_failure "--condition on-event: --all with --probe" \ | |
310 | "Error: Can't use -a/--all with probe event rules." \ | |
311 | --condition on-event --probe=do_sys_open --all | |
312 | test_failure "--condition on-event: missing tracepoint name with --probe" \ | |
313 | "Error: Need to provide either a tracepoint name or -a/--all." \ | |
314 | --condition on-event -k --probe do_sys_open | |
315 | ||
316 | test_failure "--condition on-event: missing tracepoint name with --userspace-probe" \ | |
317 | "Error: Need to provide either a tracepoint name or -a/--all." \ | |
318 | --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function | |
319 | ||
320 | test_failure "--condition on-event: extra argument with --userspace-probe" \ | |
321 | "Error: Unexpected argument 'world'" \ | |
322 | --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_failure hello world | |
323 | ||
324 | test_failure "--condition on-event: missing tracepoint name with --syscall" \ | |
325 | "Error: Need to provide either a tracepoint name or -a/--all." \ | |
326 | --condition on-event -k --syscall | |
327 | ||
328 | test_failure "--condition on-event: extra argument with --syscall" \ | |
329 | "Error: Unexpected argument 'open'" \ | |
330 | --condition on-event -k --syscall open open | |
331 | ||
332 | test_failure "--condition on-event: both -a and a tracepoint name with --syscall" \ | |
333 | "Error: Can't provide a tracepoint name with -a/--all." \ | |
334 | --condition on-event -k --syscall -a open | |
335 | ||
20a01d15 SM |
336 | test_failure "--condition on-event --capture: missing argument (end of arg list)" \ |
337 | 'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \ | |
338 | --action notify \ | |
339 | --condition on-event -u -a --capture | |
340 | ||
341 | test_failure "--condition on-event --capture: missing argument (before another option)" \ | |
342 | 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \ | |
343 | --condition on-event -u -a --capture \ | |
344 | --action notify \ | |
345 | ||
346 | test_failure "--condition on-event --capture: binary operator" \ | |
347 | 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \ | |
348 | --condition on-event -u -a \ | |
349 | --capture 'foo == 2' --action notify | |
350 | ||
351 | test_failure "--condition on-event --capture: unary operator" \ | |
352 | 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \ | |
353 | --condition on-event -u -a \ | |
354 | --capture '!foo' --action notify | |
355 | ||
356 | test_failure "--condition on-event --capture: logical operator" \ | |
357 | 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \ | |
358 | --condition on-event -u -a \ | |
359 | --capture 'foo || bar' --action notify | |
360 | ||
361 | test_failure "--condition on-event --capture: accessing a sub-field" \ | |
362 | 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \ | |
363 | --condition on-event -u -a \ | |
364 | --capture 'foo.bar' --action notify | |
365 | ||
366 | test_failure "--condition on-event --capture: accessing the sub-field of an array element" \ | |
367 | 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \ | |
368 | --condition on-event -u -a \ | |
369 | --capture 'foo[3].bar' --action notify | |
370 | ||
371 | test_failure "--condition on-event --capture: missing colon in app-specific context field" \ | |
372 | 'Error: Invalid app-specific context field name: missing colon in `foo`.' \ | |
373 | --condition on-event -u -a \ | |
374 | --capture '$app.foo' --action notify | |
375 | ||
376 | test_failure "--condition on-event --capture: missing colon in app-specific context field" \ | |
377 | 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \ | |
378 | --condition on-event -u -a \ | |
379 | --capture '$app.foo:' --action notify | |
380 | ||
b4b7369f JR |
381 | # `--action` failures |
382 | test_failure "missing args after --action" \ | |
383 | "Error: Missing action name." \ | |
384 | --condition on-event -u -a \ | |
385 | --action | |
386 | ||
387 | # `--action notify` failures | |
388 | test_failure "extra arg after --action notify" \ | |
389 | "Error: Unexpected argument \`bob\`." \ | |
390 | --condition on-event -u -a \ | |
391 | --action notify bob | |
392 | ||
393 | # `--action start-session` failures | |
394 | test_failure "missing arg after --action start-session" \ | |
395 | "Error: Missing session name." \ | |
396 | --condition on-event some-event-start-session -u \ | |
397 | --action start-session | |
398 | test_failure "extra arg after --action start-session" \ | |
399 | "Error: Unexpected argument \`bob\`." \ | |
400 | --condition on-event some-event-start-session -u \ | |
401 | --action start-session ze-session bob | |
402 | ||
403 | # `--action stop-session` failures | |
404 | test_failure "missing arg after --action stop-session" \ | |
405 | "Error: Missing session name." \ | |
406 | --condition on-event some-event-stop-session -u \ | |
407 | --action stop-session | |
408 | test_failure "extra arg after --action stop-session" \ | |
409 | "Error: Unexpected argument \`bob\`." \ | |
410 | --condition on-event some-event-stop-session -u \ | |
411 | --action stop-session ze-session bob | |
412 | ||
413 | # `--action rotate-session` failures | |
414 | test_failure "missing arg after --action rotate-session" \ | |
415 | "Error: Missing session name." \ | |
416 | --condition on-event some-event-rotate-session -u \ | |
417 | --action rotate-session | |
418 | test_failure "extra arg after --action rotate-session" \ | |
419 | "Error: Unexpected argument \`bob\`." \ | |
420 | --condition on-event some-event-rotate-session -u \ | |
421 | --action rotate-session ze-session bob | |
422 | ||
423 | # `--action snapshot-session` failures | |
424 | test_failure "missing arg after --action snapshot-session" \ | |
425 | "Error: Missing session name." \ | |
426 | --condition on-event some-event-snapshot-session -u \ | |
427 | --action snapshot-session | |
428 | test_failure "extra arg after --action snapshot-session" \ | |
429 | "Error: Unexpected argument \`bob\`." \ | |
430 | --condition on-event some-event-snapshot-session -u \ | |
431 | --action snapshot-session ze-session bob | |
432 | test_failure "snapshot-session action, --max-size without destination" \ | |
433 | "Error: Can't provide a snapshot output max size without a snapshot output destination." \ | |
434 | --condition on-event some-event-snapshot-session -u \ | |
435 | --action snapshot-session ze-session --max-size 10M | |
436 | test_failure "snapshot-session action, --name without destination" \ | |
437 | "Error: Can't provide a snapshot output name without a snapshot output destination." \ | |
438 | --condition on-event some-event-snapshot-session -u \ | |
439 | --action snapshot-session ze-session --name hallo | |
440 | test_failure "snapshot-session action, --name with-local-path-instead-of-url" \ | |
441 | "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \ | |
442 | --condition on-event some-event-snapshot-session -u \ | |
443 | --action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path | |
444 | test_failure "snapshot-session action, --name with-net-url-instead-of-path" \ | |
445 | "Error: Failed to parse 'net://8.8.8.8/' as a local path." \ | |
446 | --condition on-event some-event-snapshot-session -u \ | |
447 | --action snapshot-session ze-session --name hallo --path net://8.8.8.8/ | |
448 | ||
449 | # Cleanup | |
450 | stop_lttng_sessiond_notap | |
451 | rm -f "${tmp_stdout}" | |
452 | rm -f "${tmp_stderr}" |