SoW-2019-0007-2: Dynamic Snapshot: Triggers send partial event payload with notifications
[lttng-tools.git] / tests / regression / tools / trigger / test_add_trigger_cli
CommitLineData
5024c2ac
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
20CURDIR="$(dirname "$0")"
21TESTDIR="$CURDIR/../../.."
22
23# shellcheck source=../../../utils/utils.sh
24source "$TESTDIR/utils/utils.sh"
25
26plan_tests 219
27
28FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
30# shellcheck disable=SC2119
31start_lttng_sessiond_notap
32
33tmp_stdout=$(mktemp -t test_parse_cli_trigger_stdout.XXXXXX)
34tmp_stderr=$(mktemp -t test_parse_cli_trigger_stderr.XXXXXX)
35uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/userspace-probe-elf-binary"
36
37if [ "$(id -u)" == "0" ]; then
38 ist_root=1
39else
40 ist_root=0
41fi
42
43function test_success ()
44{
45 local test_name="$1"
46 shift
47
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"
51
52 diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.")
53 ok $? "${test_name}: expected stdout"
54
55 diff -u "${tmp_stderr}" /dev/null
56 ok $? "${test_name}: expected stderr"
57}
58
59function test_failure ()
60{
61 local test_name="$1"
62 local error_msg="$2"
63
64 shift 2
65
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"
69
70 diff -u "${tmp_stdout}" /dev/null
71 ok $? "${test_name}: expected stdout"
72
73 diff -u "${tmp_stderr}" <(echo "${error_msg}")
74 ok $? "${test_name}: expected stderr"
75}
76
77# top-level options
78test_success "explicit id" \
79 --id hohoho \
80 --condition on-event some-event-id -u \
81 --action notify
82
83# `--condition on-event` successes
84test_success "--condition on-event some-event -u" \
85 --condition on-event some-event -u \
86 --action notify
87
88test_success "--condition on-event -a -u" \
89 --condition on-event -a -u \
90 --action notify
91
92test_success "--fire-once-after" \
93 --condition on-event -u test-fire-once-after \
94 --action notify \
95 --fire-once-after=55
96
97test_success "--fire-every" \
98 --condition on-event -u test-fire-every \
99 --action notify \
100 --fire-every=55
101
102skip $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 \
105 --action notify
106
107 test_success "--condition on-event probe by symbol with offset" \
108 --condition on-event -k --probe=do_sys_open+10 my_sys_open \
109 --action notify
110
111 sys_open_addr=$(grep ' T do_sys_open$' /proc/kallsyms | cut -f 1 -d ' ')
112
113 test_success "--condition on-event probe by address" \
114 --condition on-event -k "--probe=${sys_open_addr}" my_sys_open \
115 --action notify
116
117 test_success "--condition on-event probe by address with offset" \
118 --condition on-event -k "--probe=${sys_open_addr}+10" my_sys_open \
119 --action notify
120}
121
122skip $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 \
125 --action notify
126
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 \
129 --action notify
130}
131
132skip $ist_root "non-root user: skipping syscall tests" 9 || {
133 test_success "--condition on-event syscall" \
134 --condition on-event -k --syscall open \
135 --action notify
136
137 test_success "--condition on-event syscall -a" \
138 --condition on-event -k --syscall -a \
139 --action notify
140
141 test_success "--condition on-event syscall with filter" \
142 --condition on-event -k --syscall --filter 'a > 2' open \
143 --action notify
144}
145
146# `--action notify` successes
147test_success "--action notify" \
148 --condition on-event some-event-notify -u \
149 --action notify
150
151test_success "--action notify --capture foo" \
152 --condition on-event some-event-notify-foo -u \
153 --capture foo --action notify
154
155test_success "--action notify --capture foo[2]" \
156 --condition on-event some-event-notify-foo2 -u \
157 --capture 'foo[2]' --action notify
158
159test_success '--action notify --capture $ctx.foo' \
160 --condition on-event some-event-notify-ctx-foo -u \
161 --capture '$ctx.foo' --action notify
162
163test_success '--action notify --capture $ctx.foo[2]' \
164 --condition on-event some-event-notify-ctx-foo2 -u \
165 --capture '$ctx.foo[2]' --action notify
166
167test_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
170
171test_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
174
175test_success '--action notify multiple captures' \
176 --condition on-event some-event-notify-multiple-captures -u \
177 --capture foo --capture '$app.hello:world' --action notify
178
179# `--action start-session` successes
180test_success "--action start-session" \
181 --condition on-event some-event-start-session -u \
182 --action start-session ze-session
183
184# `--action stop-session` successes
185test_success "--action stop-session foo" \
186 --condition on-event some-event-stop-session -u \
187 --action stop-session ze-session
188
189# `--action rotate-session` successes
190test_success "--action rotate-session foo" \
191 --condition on-event some-event-rotate-session -u \
192 --action rotate-session ze-session
193
194# `--action snapshot-session` successes
195test_success "--action snapshot-session foo" \
196 --condition on-event some-event-snapshot-session -u \
197 --action snapshot-session ze-session
198
199test_success "--action snapshot-session with file URI" \
200 --condition on-event some-event-snapshot-session2 -u \
201 --action snapshot-session ze-session /hello
202
203test_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
206
207test_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
210
211# top-level failures
212test_failure "no args" "Error: Missing --condition."
213
214test_failure "unknown option" \
215 "Error: Unknown option \`--hello\`" \
216 --hello
217
218test_failure "missing --action" \
219 "Error: Need at least one --action." \
220 --condition on-event hello -u
221
222test_failure "two --condition" \
223 "Error: A --condition was already given." \
224 --condition on-event aaa -u \
225 --condition on-event bbb -u \
226 --action notify
227
228test_failure "missing argument to --id" \
229 "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \
230 --id
231
232for 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 \
236 --${cmd}
237
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 \
241 --${cmd} 123bob
242
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 \
246 --${cmd} ""
247done
248
249# `--condition` failures
250test_failure "missing args after --condition" \
251 "Error: Missing condition name." \
252 --condition
253test_failure "unknown --condition" \
254 "Error: Unknown condition name: zoofest" \
255 --condition zoofest
256
257# `--condition on-event` failures
258test_failure "missing args after --condition on-event" \
259 "Error: Need to provide either a tracepoint name or -a/--all." \
260 --condition on-event
261test_failure "missing domain in --condition on-event" \
262 "Error: Please specify a domain (-k/-u/-j)." \
263 --condition on-event -a
264test_failure "extra args after --condition on-event" \
265 "Error: Unexpected argument: bozo" \
266 --condition on-event foo -u bozo
267test_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
270test_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
273
274test_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
277
278test_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
281
282test_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
285
286test_failure "--condition on-event: extra argument with --syscall" \
287 "Error: Unexpected argument: open" \
288 --condition on-event -k --syscall open open
289
290test_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
293
294test_failure "--condition on-event --capture: missing argument (end of arg list)" \
295 'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \
296 --action notify \
297 --condition on-event -u -a --capture
298
299test_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 \
302 --action notify \
303
304test_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
308
309test_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
313
314test_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
318
319test_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
323
324test_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
328
329test_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
333
334test_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
338
339# `--action` failures
340test_failure "missing args after --action" \
341 "Error: Missing action name." \
342 --condition on-event -u -a \
343 --action
344
345# `--action notify` failures
346test_failure "extra arg after --action notify" \
347 "Error: Unexpected argument \`bob\`." \
348 --condition on-event -u -a \
349 --action notify bob
350
351# `--action start-session` failures
352test_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
356test_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
360
361# `--action stop-session` failures
362test_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
366test_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
370
371# `--action rotate-session` failures
372test_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
376test_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
380
381# `--action snapshot-session` failures
382test_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
386test_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
390test_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
394test_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
398
399
400# Cleanup
401stop_lttng_sessiond_notap
402rm -f "${tmp_stdout}"
403rm -f "${tmp_stderr}"
This page took 0.041502 seconds and 5 git commands to generate.