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 skip
$ist_root "non-root user: skipping kprobe tests" 18 ||
{
130 for type in kprobe kernel-probe
; do
131 test_success
"--condition event-rule-matches probe by symbol" \
132 --condition event-rule-matches
--domain=kernel
--type=$type --location=lttng_channel_enable
--event-name=my_channel_enable \
135 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
136 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
138 # We need to find a valid offset.
141 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
142 base_symbol
="lttng_channel_enable"
143 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
145 base_symbol
="lttng_channel_disable"
146 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
149 offset_hex
="0x$(printf '%x' $offset)"
151 test_success
"--condition event-rule-matches probe by symbol with offset" \
152 --condition event-rule-matches
--domain=kernel
--type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_
$base_symbol \
155 test_success
"--condition event-rule-matches probe by address" \
156 --condition event-rule-matches
--domain=kernel
--type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \
161 skip
$ist_root "non-root user: skipping uprobe tests" 12 ||
{
162 for type in uprobe userspace-probe
; do
163 test_success
"--condition event-rule-matches uprobe" \
164 --condition event-rule-matches
--domain=kernel
--type=$type --location=${uprobe_elf_binary}:test_function
--event-name=ma-probe \
167 test_success
"--condition event-rule-matches uprobe with elf prefix" \
168 --condition event-rule-matches
--domain=kernel
--type=$type --location=elf
:${uprobe_elf_binary}:test_function
--event-name=ma-probe-2 \
173 skip
$ist_root "non-root user: skipping syscall tests" 9 ||
{
174 test_success
"--condition event-rule-matches one syscall" \
175 --condition event-rule-matches
--domain=kernel
--type=syscall
--name=open \
178 test_success
"--condition event-rule-matches all syscalls" \
179 --condition event-rule-matches
--domain=kernel
--type=syscall \
182 test_success
"--condition event-rule-matches one syscall with filter" \
183 --condition event-rule-matches
--domain=kernel
--type=syscall
--filter 'a > 2' --name=open \
187 # `--action notify` successes
188 test_success
"--action notify" \
189 --condition event-rule-matches
--domain=user \
192 test_success
"--action notify --capture foo" \
193 --condition event-rule-matches
--domain=user \
194 --capture foo
--action notify
196 test_success
"--action notify --capture foo[2]" \
197 --condition event-rule-matches
--domain=user \
198 --capture 'foo[2]' --action notify
200 test_success
'--action notify --capture $ctx.foo' \
201 --condition event-rule-matches
--domain=user \
202 --capture '$ctx.foo' --action notify
204 test_success
'--action notify --capture $ctx.foo[2]' \
205 --condition event-rule-matches
--domain=user \
206 --capture '$ctx.foo[2]' --action notify
208 test_success
'--action notify --capture $app.prov:type' \
209 --condition event-rule-matches
--domain=user \
210 --capture '$app.prov:type' --action notify
212 test_success
'--action notify --capture $app.prov:type[2]' \
213 --condition event-rule-matches
--domain=user \
214 --capture '$app.prov:type[2]' --action notify
216 test_success
'--action notify multiple captures' \
217 --condition event-rule-matches
--domain=user \
218 --capture foo
--capture '$app.hello:world' --action notify
220 # `--action start-session` successes
221 test_success
"--action start-session" \
222 --condition event-rule-matches
--domain=user \
223 --action start-session ze-session
225 # `--action stop-session` successes
226 test_success
"--action stop-session foo" \
227 --condition event-rule-matches
--domain=user \
228 --action stop-session ze-session
230 # `--action rotate-session` successes
231 test_success
"--action rotate-session foo" \
232 --condition event-rule-matches
--domain=user \
233 --action rotate-session ze-session
235 # `--action snapshot-session` successes
236 test_success
"--action snapshot-session foo" \
237 --condition event-rule-matches
--domain=user \
238 --action snapshot-session ze-session
240 test_success
"--action snapshot-session with file URI" \
241 --condition event-rule-matches
--domain=user \
242 --action snapshot-session ze-session
--path /hello
244 test_success
"--action snapshot-session with net URI" \
245 --condition event-rule-matches
--domain=user \
246 --action snapshot-session ze-session
--url net
://1.2.3.4
248 test_success
"--action snapshot-session with ctrl/data URIs" \
249 --condition event-rule-matches
--domain=user \
250 --action snapshot-session ze-session
--ctrl-url=tcp
://1.2.3.4:1234 --data-url=tcp
://1.2.3.4:1235
253 test_failure
"no args" "Error: Missing --condition."
255 test_failure
"unknown option" \
256 "Error: Unknown option \`--hello\`" \
259 test_failure
"missing --action" \
260 "Error: Need at least one --action." \
261 --condition event-rule-matches
--domain=user
263 test_failure
"two --condition" \
264 "Error: A --condition was already given." \
265 --condition event-rule-matches
--name=aaa
--domain=user \
266 --condition event-rule-matches
--name=bbb
--domain=user \
269 test_failure
"missing argument to --name" \
270 "Error: While parsing argument #1 (\`--name\`): Missing required argument for option \`--name\`" \
273 for cmd
in rate-policy
=once-after rate-policy
=every
; do
274 test_failure
"missing argument to --${cmd}" \
275 "Error: Rate policy format is invalid." \
276 --condition event-rule-matches
--domain=user
--action notify \
279 test_failure
"invalid argument to --${cmd}: non-digit character" \
280 "Error: Failed to parse rate policy value \`123bob\` as an integer." \
281 --condition event-rule-matches
--domain=user
--action notify \
284 test_failure
"invalid argument to --${cmd}: empty string" \
285 "Error: Failed to parse rate policy value \`\` as an integer." \
286 --condition event-rule-matches
--domain=user
--action notify \
290 test_failure
"invalid argument to --rate-policy: unknown policy type" \
291 "Error: Rate policy type \`bob\` unknown." \
292 --condition event-rule-matches
--domain=user
--action notify \
293 --rate-policy=bob
:123
295 # `--condition` failures
296 test_failure
"missing args after --condition" \
297 "Error: While parsing argument #1 (\`--condition\`): Missing required argument for option \`--condition\`" \
299 test_failure
"unknown --condition" \
300 "Error: Unknown condition name 'zoofest'" \
303 # `--condition event-rule-matches` failures
304 test_failure
"missing args after --condition event-rule-matches" \
305 "Error: Please specify a domain (--domain=(kernel,user,jul,log4j,python))." \
306 --condition event-rule-matches
308 test_failure
"extra args after --condition event-rule-matches" \
309 "Error: Unexpected argument 'bozo'" \
310 --condition event-rule-matches
--domain=user bozo
312 test_failure
"two same --domain" \
313 "Error: More than one \`--domain\` was specified." \
314 --condition event-rule-matches
--domain=user
--domain=user
316 test_failure
"two different --domain" \
317 "Error: More than one \`--domain\` was specified." \
318 --condition event-rule-matches
--domain=user
--domain=kernel
320 for type in kprobe kernel-probe
; do
321 test_failure
"--condition event-rule-matches: --name with --type=$type" \
322 "Error: Can't use --name with probe event rules." \
323 --condition event-rule-matches
--type=$type --location=do_sys_open
--name='hello'
326 test_failure
"--condition event-rule-matches: --location with tracepoint event rule" \
327 "Error: Can't use --location with tracepoint event rules." \
328 --condition event-rule-matches
--domain=user
--location='hello'
330 test_failure
"--condition event-rule-matches: --event-name with tracepoint event rule" \
331 "Error: Can't use --event-name with tracepoint event rules." \
332 --condition event-rule-matches
--domain=user
--event-name='hello'
334 for type in uprobe userspace-probe
; do
335 test_failure
"--condition event-rule-matches: extra argument with --type=$type" \
336 "Error: Unexpected argument 'hello'" \
337 --condition event-rule-matches
--domain=kernel
--type=$type --location=${uprobe_elf_binary}:test_failure hello
340 test_failure
"--condition event-rule-matches: extra argument with --type=syscall" \
341 "Error: Unexpected argument 'open'" \
342 --condition event-rule-matches
--domain=kernel
--type=syscall open
344 test_failure
"--condition event-rule-matches --capture: missing argument (end of arg list)" \
345 'Error: While parsing argument #2 (`--capture`): Missing required argument for option `--capture`' \
347 --condition event-rule-matches
--domain=user
--capture
349 test_failure
"--condition event-rule-matches --capture: missing argument (before another option)" \
350 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
351 --condition event-rule-matches
--domain=user
--capture \
354 test_failure
"--condition event-rule-matches --capture: binary operator" \
355 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
356 --condition event-rule-matches
--domain=user \
357 --capture 'foo == 2' --action notify
359 test_failure
"--condition event-rule-matches --capture: unary operator" \
360 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
361 --condition event-rule-matches
--domain=user \
362 --capture '!foo' --action notify
364 test_failure
"--condition event-rule-matches --capture: logical operator" \
365 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
366 --condition event-rule-matches
--domain=user \
367 --capture 'foo || bar' --action notify
369 test_failure
"--condition event-rule-matches --capture: accessing a sub-field" \
370 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
371 --condition event-rule-matches
--domain=user \
372 --capture 'foo.bar' --action notify
374 test_failure
"--condition event-rule-matches --capture: accessing the sub-field of an array element" \
375 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
376 --condition event-rule-matches
--domain=user \
377 --capture 'foo[3].bar' --action notify
379 test_failure
"--condition event-rule-matches --capture: missing colon in app-specific context field" \
380 'Error: Invalid app-specific context field name: missing colon in `foo`.' \
381 --condition event-rule-matches
--domain=user \
382 --capture '$app.foo' --action notify
384 test_failure
"--condition event-rule-matches --capture: missing colon in app-specific context field" \
385 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
386 --condition event-rule-matches
--domain=user \
387 --capture '$app.foo:' --action notify
389 # `--action` failures
390 test_failure
"missing args after --action" \
391 "Error: While parsing argument #1 (\`--action\`): Missing required argument for option \`--action\`" \
392 --condition event-rule-matches
--domain=user \
395 # `--action notify` failures
396 test_failure
"extra arg after --action notify" \
397 "Error: Unexpected argument \`bob\`." \
398 --condition event-rule-matches
--domain=user \
401 # `--action start-session` failures
402 test_failure
"missing arg after --action start-session" \
403 "Error: Missing session name." \
404 --condition event-rule-matches
--domain=user \
405 --action start-session
406 test_failure
"extra arg after --action start-session" \
407 "Error: Unexpected argument \`bob\`." \
408 --condition event-rule-matches
--domain=user \
409 --action start-session ze-session bob
411 # `--action stop-session` failures
412 test_failure
"missing arg after --action stop-session" \
413 "Error: Missing session name." \
414 --condition event-rule-matches
--domain=user \
415 --action stop-session
416 test_failure
"extra arg after --action stop-session" \
417 "Error: Unexpected argument \`bob\`." \
418 --condition event-rule-matches
--domain=user \
419 --action stop-session ze-session bob
421 # `--action rotate-session` failures
422 test_failure
"missing arg after --action rotate-session" \
423 "Error: Missing session name." \
424 --condition event-rule-matches
--domain=user \
425 --action rotate-session
426 test_failure
"extra arg after --action rotate-session" \
427 "Error: Unexpected argument \`bob\`." \
428 --condition event-rule-matches
--domain=user \
429 --action rotate-session ze-session bob
431 # `--action snapshot-session` failures
432 test_failure
"missing arg after --action snapshot-session" \
433 "Error: Missing session name." \
434 --condition event-rule-matches
--domain=user \
435 --action snapshot-session
436 test_failure
"extra arg after --action snapshot-session" \
437 "Error: Unexpected argument \`bob\`." \
438 --condition event-rule-matches
--domain=user \
439 --action snapshot-session ze-session bob
440 test_failure
"snapshot-session action, --max-size without destination" \
441 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
442 --condition event-rule-matches
--domain=user \
443 --action snapshot-session ze-session
--max-size 10M
444 test_failure
"snapshot-session action, --name without destination" \
445 "Error: Can't provide a snapshot output name without a snapshot output destination." \
446 --condition event-rule-matches
--domain=user \
447 --action snapshot-session ze-session
--name hallo
448 test_failure
"snapshot-session action, --name with-local-path-instead-of-url" \
449 "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
450 --condition event-rule-matches
--domain=user \
451 --action snapshot-session ze-session
--name hallo
--url /something
/that
/looks
/like
/a
/path
452 test_failure
"snapshot-session action, --name with-net-url-instead-of-path" \
453 "Error: Failed to parse 'net://8.8.8.8/' as a local path." \
454 --condition event-rule-matches
--domain=user \
455 --action snapshot-session ze-session
--name hallo
--path net
://8.8.8.8/
458 stop_lttng_sessiond_notap
459 rm -f "${tmp_stdout}"
460 rm -f "${tmp_stderr}"