3 # Copyright (C) - 2020 EfficiOS, inc
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.
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
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
18 # Test the `lttng add-trigger` command line interface.
20 CURDIR
="$(dirname "$0")"
21 TESTDIR
="$CURDIR/../../.."
23 # shellcheck source=../../../utils/utils.sh
24 source "$TESTDIR/utils/utils.sh"
28 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
30 # shellcheck disable=SC2119
31 start_lttng_sessiond_notap
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"
37 if [ "$(id -u)" == "0" ]; then
43 function test_success
()
48 diag
"${FULL_LTTNG_BIN} add-trigger $*"
50 "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
52 ok $?
"${test_name}: exit code is 0"
54 diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.")
55 ok $?
"${test_name}: expected stdout"
57 diff -u "${tmp_stderr}" /dev
/null
58 ok $?
"${test_name}: expected stderr"
61 function test_failure
()
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"
72 diff -u "${tmp_stdout}" /dev
/null
73 ok $?
"${test_name}: expected stdout"
75 diff -u "${tmp_stderr}" <(echo "${error_msg}")
76 ok $?
"${test_name}: expected stderr"
80 test_success
"explicit name" \
82 --condition event-rule-matches
--name=some-event-id
--domain=user \
85 # `--condition event-rule-matches` successes
86 test_success
"--condition event-rule-matches some-event --domain=user" \
87 --condition event-rule-matches
--name=some-event
--domain=user \
90 test_success
"--condition event-rule-matches --domain=user" \
91 --condition event-rule-matches
--domain=user \
94 test_success
"notify action polices" \
95 --condition event-rule-matches
--domain=user
--name=test-rate-policy \
97 --rate-policy=every
:55 \
99 --rate-policy=once-after
:55
101 test_success
"start session action polices" \
102 --condition event-rule-matches
--domain=user
--name=test-rate-policy \
103 --action start-session my_session \
104 --rate-policy=every
:55 \
105 --action start-session my_session \
106 --rate-policy=once-after
:55
108 test_success
"stop session action polices" \
109 --condition event-rule-matches
--domain=user
--name=test-rate-policy \
110 --action stop-session my_session \
111 --rate-policy=every
:55 \
112 --action stop-session my_session \
113 --rate-policy=once-after
:55
115 test_success
"snapshot session action polices" \
116 --condition event-rule-matches
--domain=user
--name=test-rate-policy \
117 --action snapshot-session my_session \
118 --rate-policy=every
:55 \
119 --action snapshot-session my_session \
120 --rate-policy=once-after
:55
122 test_success
"rotate session action polices" \
123 --condition event-rule-matches
--domain=user
--name=test-rate-policy \
124 --action rotate-session my_session \
125 --rate-policy=every
:55 \
126 --action rotate-session my_session \
127 --rate-policy=once-after
:55
129 test_success
"--log-level single level" \
130 --condition event-rule-matches
--domain=user
--log-level=INFO \
133 test_success
"--log-level range open max" \
134 --condition event-rule-matches
--domain=user
--log-level=INFO.. \
137 test_success
"--log-level range any" \
138 --condition event-rule-matches
--domain=user
--log-level=.. \
141 skip
$ist_root "non-root user: skipping kprobe tests" 18 ||
{
142 for type in kprobe kernel-probe
; do
143 test_success
"--condition event-rule-matches probe by symbol" \
144 --condition event-rule-matches
--domain=kernel
--type=$type --location=lttng_channel_enable
--event-name=my_channel_enable \
147 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
148 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
150 # We need to find a valid offset.
153 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
154 base_symbol
="lttng_channel_enable"
155 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
157 base_symbol
="lttng_channel_disable"
158 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
161 offset_hex
="0x$(printf '%x' $offset)"
163 test_success
"--condition event-rule-matches probe by symbol with offset" \
164 --condition event-rule-matches
--domain=kernel
--type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_
$base_symbol \
167 test_success
"--condition event-rule-matches probe by address" \
168 --condition event-rule-matches
--domain=kernel
--type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \
173 skip
$ist_root "non-root user: skipping uprobe tests" 12 ||
{
174 for type in uprobe userspace-probe
; do
175 test_success
"--condition event-rule-matches uprobe" \
176 --condition event-rule-matches
--domain=kernel
--type=$type --location=${uprobe_elf_binary}:test_function
--event-name=ma-probe \
179 test_success
"--condition event-rule-matches uprobe with elf prefix" \
180 --condition event-rule-matches
--domain=kernel
--type=$type --location=elf
:${uprobe_elf_binary}:test_function
--event-name=ma-probe-2 \
185 skip
$ist_root "non-root user: skipping syscall tests" 18 ||
{
186 test_success
"--condition event-rule-matches one syscall" \
187 --condition event-rule-matches
--domain=kernel
--type=syscall
--name=open \
190 test_success
"--condition event-rule-matches all syscalls" \
191 --condition event-rule-matches
--domain=kernel
--type=syscall \
194 test_success
"--condition event-rule-matches one syscall with filter" \
195 --condition event-rule-matches
--domain=kernel
--type=syscall
--filter 'a > 2' --name=open \
197 test_success
"--condition event-rule-matches one syscall:entry" \
198 --condition event-rule-matches
--domain=kernel
--type=syscall
:entry
--name=open \
200 test_success
"--condition event-rule-matches one syscall:exit" \
201 --condition event-rule-matches
--domain=kernel
--type=syscall
:exit --name=open \
203 test_success
"--condition event-rule-matches one syscall:entry-exit" \
204 --condition event-rule-matches
--domain=kernel
--type=syscall
:entry
+exit --name=open \
208 # `--action notify` successes
209 test_success
"--action notify" \
210 --condition event-rule-matches
--domain=user \
213 test_success
"--action notify --capture foo" \
214 --condition event-rule-matches
--domain=user \
215 --capture foo
--action notify
217 test_success
"--action notify --capture foo[2]" \
218 --condition event-rule-matches
--domain=user \
219 --capture 'foo[2]' --action notify
221 test_success
'--action notify --capture $ctx.foo' \
222 --condition event-rule-matches
--domain=user \
223 --capture '$ctx.foo' --action notify
225 test_success
'--action notify --capture $ctx.foo[2]' \
226 --condition event-rule-matches
--domain=user \
227 --capture '$ctx.foo[2]' --action notify
229 test_success
'--action notify --capture $app.prov:type' \
230 --condition event-rule-matches
--domain=user \
231 --capture '$app.prov:type' --action notify
233 test_success
'--action notify --capture $app.prov:type[2]' \
234 --condition event-rule-matches
--domain=user \
235 --capture '$app.prov:type[2]' --action notify
237 test_success
'--action notify multiple captures' \
238 --condition event-rule-matches
--domain=user \
239 --capture foo
--capture '$app.hello:world' --action notify
241 # `--action start-session` successes
242 test_success
"--action start-session" \
243 --condition event-rule-matches
--domain=user \
244 --action start-session ze-session
246 # `--action stop-session` successes
247 test_success
"--action stop-session foo" \
248 --condition event-rule-matches
--domain=user \
249 --action stop-session ze-session
251 # `--action rotate-session` successes
252 test_success
"--action rotate-session foo" \
253 --condition event-rule-matches
--domain=user \
254 --action rotate-session ze-session
256 # `--action snapshot-session` successes
257 test_success
"--action snapshot-session foo" \
258 --condition event-rule-matches
--domain=user \
259 --action snapshot-session ze-session
261 test_success
"--action snapshot-session with file URI" \
262 --condition event-rule-matches
--domain=user \
263 --action snapshot-session ze-session
--path /hello
265 test_success
"--action snapshot-session with net URI" \
266 --condition event-rule-matches
--domain=user \
267 --action snapshot-session ze-session
--url net
://1.2.3.4
269 test_success
"--action snapshot-session with ctrl/data URIs" \
270 --condition event-rule-matches
--domain=user \
271 --action snapshot-session ze-session
--ctrl-url=tcp
://1.2.3.4:1234 --data-url=tcp
://1.2.3.4:1235
274 test_failure
"no args" "Error: Missing --condition."
276 test_failure
"unknown option" \
277 "Error: Unknown option \`--hello\`" \
280 test_failure
"missing --action" \
281 "Error: Need at least one --action." \
282 --condition event-rule-matches
--domain=user
284 test_failure
"two --condition" \
285 "Error: A --condition was already given." \
286 --condition event-rule-matches
--name=aaa
--domain=user \
287 --condition event-rule-matches
--name=bbb
--domain=user \
290 test_failure
"missing argument to --name" \
291 "Error: While parsing argument #1 (\`--name\`): Missing required argument for option \`--name\`" \
294 for cmd
in rate-policy
=once-after rate-policy
=every
; do
295 test_failure
"missing argument to --${cmd}" \
296 "Error: Rate policy format is invalid." \
297 --condition event-rule-matches
--domain=user
--action notify \
300 test_failure
"invalid argument to --${cmd}: non-digit character" \
301 "Error: Failed to parse rate policy value \`123bob\` as an integer." \
302 --condition event-rule-matches
--domain=user
--action notify \
305 test_failure
"invalid argument to --${cmd}: empty string" \
306 "Error: Failed to parse rate policy value \`\` as an integer." \
307 --condition event-rule-matches
--domain=user
--action notify \
311 test_failure
"invalid argument to --rate-policy: unknown policy type" \
312 "Error: Rate policy type \`bob\` unknown." \
313 --condition event-rule-matches
--domain=user
--action notify \
314 --rate-policy=bob
:123
316 # `--condition` failures
317 test_failure
"missing args after --condition" \
318 "Error: While parsing argument #1 (\`--condition\`): Missing required argument for option \`--condition\`" \
320 test_failure
"unknown --condition" \
321 "Error: Unknown condition name 'zoofest'" \
324 # `--condition event-rule-matches` failures
325 test_failure
"missing args after --condition event-rule-matches" \
326 "Error: Please specify a domain (--domain=(kernel,user,jul,log4j,python))." \
327 --condition event-rule-matches
329 test_failure
"extra args after --condition event-rule-matches" \
330 "Error: Unexpected argument 'bozo'" \
331 --condition event-rule-matches
--domain=user bozo
333 test_failure
"--log-level unknown level" \
334 "Error: Failed to parse log level string \`FOO\`." \
335 --condition event-rule-matches
--domain=user
--log-level=FOO
337 test_failure
"two same --domain" \
338 "Error: More than one \`--domain\` was specified." \
339 --condition event-rule-matches
--domain=user
--domain=user
341 test_failure
"two different --domain" \
342 "Error: More than one \`--domain\` was specified." \
343 --condition event-rule-matches
--domain=user
--domain=kernel
345 for type in kprobe kernel-probe
; do
346 test_failure
"--condition event-rule-matches: --name with --type=$type" \
347 "Error: Can't use --name with probe event rules." \
348 --condition event-rule-matches
--type=$type --location=do_sys_open
--name='hello'
351 test_failure
"--condition event-rule-matches: --location with tracepoint event rule" \
352 "Error: Can't use --location with tracepoint event rules." \
353 --condition event-rule-matches
--domain=user
--location='hello'
355 test_failure
"--condition event-rule-matches: --event-name with tracepoint event rule" \
356 "Error: Can't use --event-name with tracepoint event rules." \
357 --condition event-rule-matches
--domain=user
--event-name='hello'
359 for type in uprobe userspace-probe
; do
360 test_failure
"--condition event-rule-matches: extra argument with --type=$type" \
361 "Error: Unexpected argument 'hello'" \
362 --condition event-rule-matches
--domain=kernel
--type=$type --location=${uprobe_elf_binary}:test_failure hello
365 test_failure
"--condition event-rule-matches: extra argument with --type=syscall" \
366 "Error: Unexpected argument 'open'" \
367 --condition event-rule-matches
--domain=kernel
--type=syscall open
369 test_failure
"--condition event-rule-matches: --type=syscall:nope" \
370 "Error: Failed to parse syscall type 'syscall:nope'." \
371 --condition event-rule-matches
--domain=kernel
--type=syscall
:nope \
374 test_failure
"--condition event-rule-matches --capture: missing argument (end of arg list)" \
375 'Error: While parsing argument #2 (`--capture`): Missing required argument for option `--capture`' \
377 --condition event-rule-matches
--domain=user
--capture
379 test_failure
"--condition event-rule-matches --capture: missing argument (before another option)" \
380 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
381 --condition event-rule-matches
--domain=user
--capture \
384 test_failure
"--condition event-rule-matches --capture: binary operator" \
385 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
386 --condition event-rule-matches
--domain=user \
387 --capture 'foo == 2' --action notify
389 test_failure
"--condition event-rule-matches --capture: unary operator" \
390 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
391 --condition event-rule-matches
--domain=user \
392 --capture '!foo' --action notify
394 test_failure
"--condition event-rule-matches --capture: logical operator" \
395 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
396 --condition event-rule-matches
--domain=user \
397 --capture 'foo || bar' --action notify
399 test_failure
"--condition event-rule-matches --capture: accessing a sub-field" \
400 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
401 --condition event-rule-matches
--domain=user \
402 --capture 'foo.bar' --action notify
404 test_failure
"--condition event-rule-matches --capture: accessing the sub-field of an array element" \
405 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
406 --condition event-rule-matches
--domain=user \
407 --capture 'foo[3].bar' --action notify
409 test_failure
"--condition event-rule-matches --capture: missing colon in app-specific context field" \
410 'Error: Invalid app-specific context field name: missing colon in `foo`.' \
411 --condition event-rule-matches
--domain=user \
412 --capture '$app.foo' --action notify
414 test_failure
"--condition event-rule-matches --capture: missing colon in app-specific context field" \
415 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
416 --condition event-rule-matches
--domain=user \
417 --capture '$app.foo:' --action notify
419 # `--action` failures
420 test_failure
"missing args after --action" \
421 "Error: While parsing argument #1 (\`--action\`): Missing required argument for option \`--action\`" \
422 --condition event-rule-matches
--domain=user \
425 # `--action notify` failures
426 test_failure
"extra arg after --action notify" \
427 "Error: Unexpected argument \`bob\`." \
428 --condition event-rule-matches
--domain=user \
431 # `--action start-session` failures
432 test_failure
"missing arg after --action start-session" \
433 "Error: Missing session name." \
434 --condition event-rule-matches
--domain=user \
435 --action start-session
436 test_failure
"extra arg after --action start-session" \
437 "Error: Unexpected argument \`bob\`." \
438 --condition event-rule-matches
--domain=user \
439 --action start-session ze-session bob
441 # `--action stop-session` failures
442 test_failure
"missing arg after --action stop-session" \
443 "Error: Missing session name." \
444 --condition event-rule-matches
--domain=user \
445 --action stop-session
446 test_failure
"extra arg after --action stop-session" \
447 "Error: Unexpected argument \`bob\`." \
448 --condition event-rule-matches
--domain=user \
449 --action stop-session ze-session bob
451 # `--action rotate-session` failures
452 test_failure
"missing arg after --action rotate-session" \
453 "Error: Missing session name." \
454 --condition event-rule-matches
--domain=user \
455 --action rotate-session
456 test_failure
"extra arg after --action rotate-session" \
457 "Error: Unexpected argument \`bob\`." \
458 --condition event-rule-matches
--domain=user \
459 --action rotate-session ze-session bob
461 # `--action snapshot-session` failures
462 test_failure
"missing arg after --action snapshot-session" \
463 "Error: Missing session name." \
464 --condition event-rule-matches
--domain=user \
465 --action snapshot-session
466 test_failure
"extra arg after --action snapshot-session" \
467 "Error: Unexpected argument \`bob\`." \
468 --condition event-rule-matches
--domain=user \
469 --action snapshot-session ze-session bob
470 test_failure
"snapshot-session action, --max-size without destination" \
471 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
472 --condition event-rule-matches
--domain=user \
473 --action snapshot-session ze-session
--max-size 10M
474 test_failure
"snapshot-session action, --name without destination" \
475 "Error: Can't provide a snapshot output name without a snapshot output destination." \
476 --condition event-rule-matches
--domain=user \
477 --action snapshot-session ze-session
--name hallo
478 test_failure
"snapshot-session action, --name with-local-path-instead-of-url" \
479 "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
480 --condition event-rule-matches
--domain=user \
481 --action snapshot-session ze-session
--name hallo
--url /something
/that
/looks
/like
/a
/path
482 test_failure
"snapshot-session action, --name with-net-url-instead-of-path" \
483 "Error: Failed to parse 'net://8.8.8.8/' as a local path." \
484 --condition event-rule-matches
--domain=user \
485 --action snapshot-session ze-session
--name hallo
--path net
://8.8.8.8/
488 stop_lttng_sessiond_notap
489 rm -f "${tmp_stdout}"
490 rm -f "${tmp_stderr}"