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 $*"
49 "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
50 ok $?
"${test_name}: exit code is 0"
52 diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.")
53 ok $?
"${test_name}: expected stdout"
55 diff -u "${tmp_stderr}" /dev
/null
56 ok $?
"${test_name}: expected stderr"
59 function test_failure
()
66 diag
"${FULL_LTTNG_BIN} add-trigger $*"
67 "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
68 isnt $?
0 "${test_name}: exit code is not 0"
70 diff -u "${tmp_stdout}" /dev
/null
71 ok $?
"${test_name}: expected stdout"
73 diff -u "${tmp_stderr}" <(echo "${error_msg}")
74 ok $?
"${test_name}: expected stderr"
78 test_success
"explicit id" \
80 --condition on-event some-event-id
-u \
83 # `--condition on-event` successes
84 test_success
"--condition on-event some-event -u" \
85 --condition on-event some-event
-u \
88 test_success
"--condition on-event -a -u" \
89 --condition on-event
-a -u \
92 test_success
"--fire-once-after" \
93 --condition on-event
-u test-fire-once-after \
97 test_success
"--fire-every" \
98 --condition on-event
-u test-fire-every \
102 skip
$ist_root "non-root user: skipping kprobe tests" 9 ||
{
103 test_success
"--condition on-event probe by symbol" \
104 --condition on-event
-k --probe=lttng_event_container_enable my_channel_enable \
107 channel_enable_addr
=$
(grep 'lttng_event_container_enable' /proc
/kallsyms | cut
-f 1 -d ' ')
108 channel_disable_addr
=$
(grep 'lttng_event_container_disable' /proc
/kallsyms | cut
-f 1 -d ' ')
110 # We need to find a valid offset.
113 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
114 base_symbol
="lttng_event_container_enable"
115 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
117 base_symbol
="lttng_event_container_disable"
118 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
121 offset_hex
="0x$(printf '%x' $offset)"
123 test_success
"--condition on-event probe by symbol with offset" \
124 --condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_
$base_symbol \
127 test_success
"--condition on-event probe by address" \
128 --condition on-event
-k "--probe=0x${channel_enable_addr}" my_channel_enable \
132 skip
$ist_root "non-root user: skipping uprobe tests" 6 ||
{
133 test_success
"--condition on-event uprobe" \
134 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe \
137 test_success
"--condition on-event uprobe with elf prefix" \
138 --condition on-event
-k --userspace-probe=elf
:${uprobe_elf_binary}:test_function ma-probe-2 \
142 skip
$ist_root "non-root user: skipping syscall tests" 9 ||
{
143 test_success
"--condition on-event syscall" \
144 --condition on-event
-k --syscall open \
147 test_success
"--condition on-event syscall -a" \
148 --condition on-event
-k --syscall -a \
151 test_success
"--condition on-event syscall with filter" \
152 --condition on-event
-k --syscall --filter 'a > 2' open \
156 # `--action notify` successes
157 test_success
"--action notify" \
158 --condition on-event some-event-notify
-u \
161 test_success
"--action notify --capture foo" \
162 --condition on-event some-event-notify-foo
-u \
163 --capture foo
--action notify
165 test_success
"--action notify --capture foo[2]" \
166 --condition on-event some-event-notify-foo2
-u \
167 --capture 'foo[2]' --action notify
169 test_success
'--action notify --capture $ctx.foo' \
170 --condition on-event some-event-notify-ctx-foo
-u \
171 --capture '$ctx.foo' --action notify
173 test_success
'--action notify --capture $ctx.foo[2]' \
174 --condition on-event some-event-notify-ctx-foo2
-u \
175 --capture '$ctx.foo[2]' --action notify
177 test_success
'--action notify --capture $app.prov:type' \
178 --condition on-event some-event-notify-app-prov-type
-u \
179 --capture '$app.prov:type' --action notify
181 test_success
'--action notify --capture $app.prov:type[2]' \
182 --condition on-event some-event-notify-app-prov-type-2
-u \
183 --capture '$app.prov:type[2]' --action notify
185 test_success
'--action notify multiple captures' \
186 --condition on-event some-event-notify-multiple-captures
-u \
187 --capture foo
--capture '$app.hello:world' --action notify
189 # `--action start-session` successes
190 test_success
"--action start-session" \
191 --condition on-event some-event-start-session
-u \
192 --action start-session ze-session
194 # `--action stop-session` successes
195 test_success
"--action stop-session foo" \
196 --condition on-event some-event-stop-session
-u \
197 --action stop-session ze-session
199 # `--action rotate-session` successes
200 test_success
"--action rotate-session foo" \
201 --condition on-event some-event-rotate-session
-u \
202 --action rotate-session ze-session
204 # `--action snapshot-session` successes
205 test_success
"--action snapshot-session foo" \
206 --condition on-event some-event-snapshot-session
-u \
207 --action snapshot-session ze-session
209 test_success
"--action snapshot-session with file URI" \
210 --condition on-event some-event-snapshot-session2
-u \
211 --action snapshot-session ze-session
--path /hello
213 test_success
"--action snapshot-session with net URI" \
214 --condition on-event some-event-snapshot-session3
-u \
215 --action snapshot-session ze-session
--url net
://1.2.3.4
217 test_success
"--action snapshot-session with ctrl/data URIs" \
218 --condition on-event some-event-snapshot-session4
-u \
219 --action snapshot-session ze-session
--ctrl-url=tcp
://1.2.3.4:1234 --data-url=tcp
://1.2.3.4:1235
222 test_failure
"no args" "Error: Missing --condition."
224 test_failure
"unknown option" \
225 "Error: Unknown option \`--hello\`" \
228 test_failure
"missing --action" \
229 "Error: Need at least one --action." \
230 --condition on-event hello
-u
232 test_failure
"two --condition" \
233 "Error: A --condition was already given." \
234 --condition on-event aaa
-u \
235 --condition on-event bbb
-u \
238 test_failure
"missing argument to --id" \
239 "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \
242 for cmd
in fire-once-after fire-every
; do
243 test_failure
"missing argument to --${cmd}" \
244 "Error: While parsing argument #1 (\`--${cmd}\`): Missing required argument for option \`--${cmd}\`" \
245 --condition on-event
-u -a --action notify \
248 test_failure
"invalid argument to --${cmd}: non-digit character" \
249 "Error: Failed to parse \`123bob\` as an integer." \
250 --condition on-event
-u -a --action notify \
253 test_failure
"invalid argument to --${cmd}: empty string" \
254 "Error: Failed to parse \`\` as an integer." \
255 --condition on-event
-u -a --action notify \
259 # `--condition` failures
260 test_failure
"missing args after --condition" \
261 "Error: Missing condition name." \
263 test_failure
"unknown --condition" \
264 "Error: Unknown condition name 'zoofest'" \
267 # `--condition on-event` failures
268 test_failure
"missing args after --condition on-event" \
269 "Error: Need to provide either a tracepoint name or -a/--all." \
271 test_failure
"missing domain in --condition on-event" \
272 "Error: Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)." \
273 --condition on-event
-a
274 test_failure
"extra args after --condition on-event" \
275 "Error: Unexpected argument 'bozo'" \
276 --condition on-event foo
-u bozo
277 test_failure
"--condition on-event: --all with --probe" \
278 "Error: Can't use -a/--all with probe event rules." \
279 --condition on-event
--probe=do_sys_open
--all
280 test_failure
"--condition on-event: missing tracepoint name with --probe" \
281 "Error: Need to provide either a tracepoint name or -a/--all." \
282 --condition on-event
-k --probe do_sys_open
284 test_failure
"--condition on-event: missing tracepoint name with --userspace-probe" \
285 "Error: Need to provide either a tracepoint name or -a/--all." \
286 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function
288 test_failure
"--condition on-event: extra argument with --userspace-probe" \
289 "Error: Unexpected argument 'world'" \
290 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_failure hello world
292 test_failure
"--condition on-event: missing tracepoint name with --syscall" \
293 "Error: Need to provide either a tracepoint name or -a/--all." \
294 --condition on-event
-k --syscall
296 test_failure
"--condition on-event: extra argument with --syscall" \
297 "Error: Unexpected argument 'open'" \
298 --condition on-event
-k --syscall open open
300 test_failure
"--condition on-event: both -a and a tracepoint name with --syscall" \
301 "Error: Can't provide a tracepoint name with -a/--all." \
302 --condition on-event
-k --syscall -a open
304 test_failure
"--condition on-event --capture: missing argument (end of arg list)" \
305 'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \
307 --condition on-event
-u -a --capture
309 test_failure
"--condition on-event --capture: missing argument (before another option)" \
310 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
311 --condition on-event
-u -a --capture \
314 test_failure
"--condition on-event --capture: binary operator" \
315 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
316 --condition on-event
-u -a \
317 --capture 'foo == 2' --action notify
319 test_failure
"--condition on-event --capture: unary operator" \
320 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
321 --condition on-event
-u -a \
322 --capture '!foo' --action notify
324 test_failure
"--condition on-event --capture: logical operator" \
325 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
326 --condition on-event
-u -a \
327 --capture 'foo || bar' --action notify
329 test_failure
"--condition on-event --capture: accessing a sub-field" \
330 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
331 --condition on-event
-u -a \
332 --capture 'foo.bar' --action notify
334 test_failure
"--condition on-event --capture: accessing the sub-field of an array element" \
335 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
336 --condition on-event
-u -a \
337 --capture 'foo[3].bar' --action notify
339 test_failure
"--condition on-event --capture: missing colon in app-specific context field" \
340 'Error: Invalid app-specific context field name: missing colon in `foo`.' \
341 --condition on-event
-u -a \
342 --capture '$app.foo' --action notify
344 test_failure
"--condition on-event --capture: missing colon in app-specific context field" \
345 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
346 --condition on-event
-u -a \
347 --capture '$app.foo:' --action notify
349 # `--action` failures
350 test_failure
"missing args after --action" \
351 "Error: Missing action name." \
352 --condition on-event
-u -a \
355 # `--action notify` failures
356 test_failure
"extra arg after --action notify" \
357 "Error: Unexpected argument \`bob\`." \
358 --condition on-event
-u -a \
361 # `--action start-session` failures
362 test_failure
"missing arg after --action start-session" \
363 "Error: Missing session name." \
364 --condition on-event some-event-start-session
-u \
365 --action start-session
366 test_failure
"extra arg after --action start-session" \
367 "Error: Unexpected argument \`bob\`." \
368 --condition on-event some-event-start-session
-u \
369 --action start-session ze-session bob
371 # `--action stop-session` failures
372 test_failure
"missing arg after --action stop-session" \
373 "Error: Missing session name." \
374 --condition on-event some-event-stop-session
-u \
375 --action stop-session
376 test_failure
"extra arg after --action stop-session" \
377 "Error: Unexpected argument \`bob\`." \
378 --condition on-event some-event-stop-session
-u \
379 --action stop-session ze-session bob
381 # `--action rotate-session` failures
382 test_failure
"missing arg after --action rotate-session" \
383 "Error: Missing session name." \
384 --condition on-event some-event-rotate-session
-u \
385 --action rotate-session
386 test_failure
"extra arg after --action rotate-session" \
387 "Error: Unexpected argument \`bob\`." \
388 --condition on-event some-event-rotate-session
-u \
389 --action rotate-session ze-session bob
391 # `--action snapshot-session` failures
392 test_failure
"missing arg after --action snapshot-session" \
393 "Error: Missing session name." \
394 --condition on-event some-event-snapshot-session
-u \
395 --action snapshot-session
396 test_failure
"extra arg after --action snapshot-session" \
397 "Error: Unexpected argument \`bob\`." \
398 --condition on-event some-event-snapshot-session
-u \
399 --action snapshot-session ze-session bob
400 test_failure
"snapshot-session action, --max-size without destination" \
401 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
402 --condition on-event some-event-snapshot-session
-u \
403 --action snapshot-session ze-session
--max-size 10M
404 test_failure
"snapshot-session action, --name without destination" \
405 "Error: Can't provide a snapshot output name without a snapshot output destination." \
406 --condition on-event some-event-snapshot-session
-u \
407 --action snapshot-session ze-session
--name hallo
408 test_failure
"snapshot-session action, --name with-local-path-instead-of-url" \
409 "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
410 --condition on-event some-event-snapshot-session
-u \
411 --action snapshot-session ze-session
--name hallo
--url /something
/that
/looks
/like
/a
/path
412 test_failure
"snapshot-session action, --name with-net-url-instead-of-path" \
413 "Error: Failed to parse 'net://8.8.8.8/' as a local path." \
414 --condition on-event some-event-snapshot-session
-u \
415 --action snapshot-session ze-session
--name hallo
--path net
://8.8.8.8/
418 stop_lttng_sessiond_notap
419 rm -f "${tmp_stdout}"
420 rm -f "${tmp_stderr}"