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/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" 12 ||
{
103 test_success
"--condition on-event probe by symbol" \
104 --condition on-event
-k --probe=do_sys_open my_sys_open \
107 test_success
"--condition on-event probe by symbol with offset" \
108 --condition on-event
-k --probe=do_sys_open
+10 my_sys_open \
111 sys_open_addr
=$
(grep ' T do_sys_open$' /proc
/kallsyms | cut
-f 1 -d ' ')
113 test_success
"--condition on-event probe by address" \
114 --condition on-event
-k "--probe=${sys_open_addr}" my_sys_open \
117 test_success
"--condition on-event probe by address with offset" \
118 --condition on-event
-k "--probe=${sys_open_addr}+10" my_sys_open \
122 skip
$ist_root "non-root user: skipping uprobe tests" 6 ||
{
123 test_success
"--condition on-event uprobe" \
124 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe \
127 test_success
"--condition on-event uprobe with elf prefix" \
128 --condition on-event
-k --userspace-probe=elf
:${uprobe_elf_binary}:test_function ma-probe-2 \
132 skip
$ist_root "non-root user: skipping syscall tests" 9 ||
{
133 test_success
"--condition on-event syscall" \
134 --condition on-event
-k --syscall open \
137 test_success
"--condition on-event syscall -a" \
138 --condition on-event
-k --syscall -a \
141 test_success
"--condition on-event syscall with filter" \
142 --condition on-event
-k --syscall --filter 'a > 2' open \
146 # `--action notify` successes
147 test_success
"--action notify" \
148 --condition on-event some-event-notify
-u \
151 test_success
"--action notify --capture foo" \
152 --condition on-event some-event-notify-foo
-u \
153 --capture foo
--action notify
155 test_success
"--action notify --capture foo[2]" \
156 --condition on-event some-event-notify-foo2
-u \
157 --capture 'foo[2]' --action notify
159 test_success
'--action notify --capture $ctx.foo' \
160 --condition on-event some-event-notify-ctx-foo
-u \
161 --capture '$ctx.foo' --action notify
163 test_success
'--action notify --capture $ctx.foo[2]' \
164 --condition on-event some-event-notify-ctx-foo2
-u \
165 --capture '$ctx.foo[2]' --action notify
167 test_success
'--action notify --capture $app.prov:type' \
168 --condition on-event some-event-notify-app-prov-type
-u \
169 --capture '$app.prov:type' --action notify
171 test_success
'--action notify --capture $app.prov:type[2]' \
172 --condition on-event some-event-notify-app-prov-type-2
-u \
173 --capture '$app.prov:type[2]' --action notify
175 test_success
'--action notify multiple captures' \
176 --condition on-event some-event-notify-multiple-captures
-u \
177 --capture foo
--capture '$app.hello:world' --action notify
179 # `--action start-session` successes
180 test_success
"--action start-session" \
181 --condition on-event some-event-start-session
-u \
182 --action start-session ze-session
184 # `--action stop-session` successes
185 test_success
"--action stop-session foo" \
186 --condition on-event some-event-stop-session
-u \
187 --action stop-session ze-session
189 # `--action rotate-session` successes
190 test_success
"--action rotate-session foo" \
191 --condition on-event some-event-rotate-session
-u \
192 --action rotate-session ze-session
194 # `--action snapshot-session` successes
195 test_success
"--action snapshot-session foo" \
196 --condition on-event some-event-snapshot-session
-u \
197 --action snapshot-session ze-session
199 test_success
"--action snapshot-session with file URI" \
200 --condition on-event some-event-snapshot-session2
-u \
201 --action snapshot-session ze-session
/hello
203 test_success
"--action snapshot-session with net URI" \
204 --condition on-event some-event-snapshot-session3
-u \
205 --action snapshot-session ze-session net
://1.2.3.4
207 test_success
"--action snapshot-session with ctrl/data URIs" \
208 --condition on-event some-event-snapshot-session4
-u \
209 --action snapshot-session ze-session
--ctrl-url=tcp
://1.2.3.4:1234 --data-url=tcp
://1.2.3.4:1235
212 test_failure
"no args" "Error: Missing --condition."
214 test_failure
"unknown option" \
215 "Error: Unknown option \`--hello\`" \
218 test_failure
"missing --action" \
219 "Error: Need at least one --action." \
220 --condition on-event hello
-u
222 test_failure
"two --condition" \
223 "Error: A --condition was already given." \
224 --condition on-event aaa
-u \
225 --condition on-event bbb
-u \
228 test_failure
"missing argument to --id" \
229 "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \
232 for cmd
in fire-once-after fire-every
; do
233 test_failure
"missing argument to --${cmd}" \
234 "Error: While parsing argument #1 (\`--${cmd}\`): Missing required argument for option \`--${cmd}\`" \
235 --condition on-event
-u -a --action notify \
238 test_failure
"invalid argument to --${cmd}: non-digit character" \
239 "Error: Failed to parse \`123bob\` as an integer." \
240 --condition on-event
-u -a --action notify \
243 test_failure
"invalid argument to --${cmd}: empty string" \
244 "Error: Failed to parse \`\` as an integer." \
245 --condition on-event
-u -a --action notify \
249 # `--condition` failures
250 test_failure
"missing args after --condition" \
251 "Error: Missing condition name." \
253 test_failure
"unknown --condition" \
254 "Error: Unknown condition name: zoofest" \
257 # `--condition on-event` failures
258 test_failure
"missing args after --condition on-event" \
259 "Error: Need to provide either a tracepoint name or -a/--all." \
261 test_failure
"missing domain in --condition on-event" \
262 "Error: Please specify a domain (-k/-u/-j)." \
263 --condition on-event
-a
264 test_failure
"extra args after --condition on-event" \
265 "Error: Unexpected argument: bozo" \
266 --condition on-event foo
-u bozo
267 test_failure
"--condition on-event: --all with --probe" \
268 "Error: Can't use -a/--all with event rule of type probe." \
269 --condition on-event
--probe=do_sys_open
--all
270 test_failure
"--condition on-event: missing tracepoint name with --probe" \
271 "Error: Need to provide either a tracepoint name or -a/--all." \
272 --condition on-event
-k --probe do_sys_open
274 test_failure
"--condition on-event: missing tracepoint name with --userspace-probe" \
275 "Error: Need to provide either a tracepoint name or -a/--all." \
276 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function
278 test_failure
"--condition on-event: extra argument with --userspace-probe" \
279 "Error: Unexpected argument: world" \
280 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_failure hello world
282 test_failure
"--condition on-event: missing tracepoint name with --syscall" \
283 "Error: Need to provide either a tracepoint name or -a/--all." \
284 --condition on-event
-k --syscall
286 test_failure
"--condition on-event: extra argument with --syscall" \
287 "Error: Unexpected argument: open" \
288 --condition on-event
-k --syscall open open
290 test_failure
"--condition on-event: both -a and a tracepoint name with --syscall" \
291 "Error: Can't provide a tracepoint name with -a/--all." \
292 --condition on-event
-k --syscall -a open
294 test_failure
"--condition on-event --capture: missing argument (end of arg list)" \
295 'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \
297 --condition on-event
-u -a --capture
299 test_failure
"--condition on-event --capture: missing argument (before another option)" \
300 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
301 --condition on-event
-u -a --capture \
304 test_failure
"--condition on-event --capture: binary operator" \
305 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
306 --condition on-event
-u -a \
307 --capture 'foo == 2' --action notify
309 test_failure
"--condition on-event --capture: unary operator" \
310 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
311 --condition on-event
-u -a \
312 --capture '!foo' --action notify
314 test_failure
"--condition on-event --capture: logical operator" \
315 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
316 --condition on-event
-u -a \
317 --capture 'foo || bar' --action notify
319 test_failure
"--condition on-event --capture: accessing a sub-field" \
320 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
321 --condition on-event
-u -a \
322 --capture 'foo.bar' --action notify
324 test_failure
"--condition on-event --capture: accessing the sub-field of an array element" \
325 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
326 --condition on-event
-u -a \
327 --capture 'foo[3].bar' --action notify
329 test_failure
"--condition on-event --capture: missing colon in app-specific context field" \
330 'Invalid app-specific context field name: missing colon in `foo`.' \
331 --condition on-event
-u -a \
332 --capture '$app.foo' --action notify
334 test_failure
"--condition on-event --capture: missing colon in app-specific context field" \
335 'Invalid app-specific context field name: missing type name after colon in `foo:`.' \
336 --condition on-event
-u -a \
337 --capture '$app.foo:' --action notify
339 # `--action` failures
340 test_failure
"missing args after --action" \
341 "Error: Missing action name." \
342 --condition on-event
-u -a \
345 # `--action notify` failures
346 test_failure
"extra arg after --action notify" \
347 "Error: Unexpected argument \`bob\`." \
348 --condition on-event
-u -a \
351 # `--action start-session` failures
352 test_failure
"missing arg after --action start-session" \
353 "Error: Missing session name." \
354 --condition on-event some-event-start-session
-u \
355 --action start-session
356 test_failure
"extra arg after --action start-session" \
357 "Error: Unexpected argument \`bob\`." \
358 --condition on-event some-event-start-session
-u \
359 --action start-session ze-session bob
361 # `--action stop-session` failures
362 test_failure
"missing arg after --action stop-session" \
363 "Error: Missing session name." \
364 --condition on-event some-event-stop-session
-u \
365 --action stop-session
366 test_failure
"extra arg after --action stop-session" \
367 "Error: Unexpected argument \`bob\`." \
368 --condition on-event some-event-stop-session
-u \
369 --action stop-session ze-session bob
371 # `--action rotate-session` failures
372 test_failure
"missing arg after --action rotate-session" \
373 "Error: Missing session name." \
374 --condition on-event some-event-rotate-session
-u \
375 --action rotate-session
376 test_failure
"extra arg after --action rotate-session" \
377 "Error: Unexpected argument \`bob\`." \
378 --condition on-event some-event-rotate-session
-u \
379 --action rotate-session ze-session bob
381 # `--action snapshot-session` failures
382 test_failure
"missing arg after --action snapshot-session" \
383 "Error: Missing session name." \
384 --condition on-event some-event-snapshot-session
-u \
385 --action snapshot-session
386 test_failure
"extra arg after --action snapshot-session" \
387 "Error: Unexpected argument \`bob\`." \
388 --condition on-event some-event-snapshot-session
-u \
389 --action snapshot-session ze-session
/dest bob
390 test_failure
"snapshot-session action, --max-size without destination" \
391 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
392 --condition on-event some-event-snapshot-session
-u \
393 --action snapshot-session ze-session
--max-size 10M
394 test_failure
"snapshot-session action, --name without destination" \
395 "Error: Can't provide a snapshot output name without a snapshot output destination." \
396 --condition on-event some-event-snapshot-session
-u \
397 --action snapshot-session ze-session
--name hallo
401 stop_lttng_sessiond_notap
402 rm -f "${tmp_stdout}"
403 rm -f "${tmp_stderr}"