action-executor: consider action firing policy on action execution
[lttng-tools.git] / tests / regression / tools / trigger / test_add_trigger_cli
CommitLineData
b4b7369f
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
20a01d15 26plan_tests 222
b4b7369f
JR
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/.libs/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" 9 || {
103 test_success "--condition on-event probe by symbol" \
104 --condition on-event -k --probe=lttng_channel_enable my_channel_enable \
105 --action notify
106
107 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
108 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
109
110 # We need to find a valid offset.
111 base_symbol=""
112 offset=0
113 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
114 base_symbol="lttng_channel_enable"
115 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
116 else
117 base_symbol="lttng_channel_disable"
118 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
119 fi
120
121 offset_hex="0x$(printf '%x' $offset)"
122
123 test_success "--condition on-event probe by symbol with offset" \
124 --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_$base_symbol \
125 --action notify
126
127 test_success "--condition on-event probe by address" \
128 --condition on-event -k "--probe=0x${channel_enable_addr}" my_channel_enable \
129 --action notify
130}
131
132skip $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 \
135 --action notify
136
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 \
139 --action notify
140}
141
142skip $ist_root "non-root user: skipping syscall tests" 9 || {
143 test_success "--condition on-event syscall" \
144 --condition on-event -k --syscall open \
145 --action notify
146
147 test_success "--condition on-event syscall -a" \
148 --condition on-event -k --syscall -a \
149 --action notify
150
151 test_success "--condition on-event syscall with filter" \
152 --condition on-event -k --syscall --filter 'a > 2' open \
153 --action notify
154}
155
156# `--action notify` successes
157test_success "--action notify" \
158 --condition on-event some-event-notify -u \
159 --action notify
160
20a01d15
SM
161test_success "--action notify --capture foo" \
162 --condition on-event some-event-notify-foo -u \
163 --capture foo --action notify
164
165test_success "--action notify --capture foo[2]" \
166 --condition on-event some-event-notify-foo2 -u \
167 --capture 'foo[2]' --action notify
168
169test_success '--action notify --capture $ctx.foo' \
170 --condition on-event some-event-notify-ctx-foo -u \
171 --capture '$ctx.foo' --action notify
172
173test_success '--action notify --capture $ctx.foo[2]' \
174 --condition on-event some-event-notify-ctx-foo2 -u \
175 --capture '$ctx.foo[2]' --action notify
176
177test_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
180
181test_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
184
185test_success '--action notify multiple captures' \
186 --condition on-event some-event-notify-multiple-captures -u \
187 --capture foo --capture '$app.hello:world' --action notify
188
b4b7369f
JR
189# `--action start-session` successes
190test_success "--action start-session" \
191 --condition on-event some-event-start-session -u \
192 --action start-session ze-session
193
194# `--action stop-session` successes
195test_success "--action stop-session foo" \
196 --condition on-event some-event-stop-session -u \
197 --action stop-session ze-session
198
199# `--action rotate-session` successes
200test_success "--action rotate-session foo" \
201 --condition on-event some-event-rotate-session -u \
202 --action rotate-session ze-session
203
204# `--action snapshot-session` successes
205test_success "--action snapshot-session foo" \
206 --condition on-event some-event-snapshot-session -u \
207 --action snapshot-session ze-session
208
209test_success "--action snapshot-session with file URI" \
210 --condition on-event some-event-snapshot-session2 -u \
211 --action snapshot-session ze-session --path /hello
212
213test_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
216
217test_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
220
221# top-level failures
222test_failure "no args" "Error: Missing --condition."
223
224test_failure "unknown option" \
225 "Error: Unknown option \`--hello\`" \
226 --hello
227
228test_failure "missing --action" \
229 "Error: Need at least one --action." \
230 --condition on-event hello -u
231
232test_failure "two --condition" \
233 "Error: A --condition was already given." \
234 --condition on-event aaa -u \
235 --condition on-event bbb -u \
236 --action notify
237
238test_failure "missing argument to --id" \
239 "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \
240 --id
241
242for 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 \
246 --${cmd}
247
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 \
251 --${cmd} 123bob
252
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 \
256 --${cmd} ""
257done
258
259# `--condition` failures
260test_failure "missing args after --condition" \
261 "Error: Missing condition name." \
262 --condition
263test_failure "unknown --condition" \
264 "Error: Unknown condition name 'zoofest'" \
265 --condition zoofest
266
267# `--condition on-event` failures
268test_failure "missing args after --condition on-event" \
269 "Error: Need to provide either a tracepoint name or -a/--all." \
270 --condition on-event
271test_failure "missing domain in --condition on-event" \
272 "Error: Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)." \
273 --condition on-event -a
274test_failure "extra args after --condition on-event" \
275 "Error: Unexpected argument 'bozo'" \
276 --condition on-event foo -u bozo
277test_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
280test_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
283
284test_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
287
288test_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
291
292test_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
295
296test_failure "--condition on-event: extra argument with --syscall" \
297 "Error: Unexpected argument 'open'" \
298 --condition on-event -k --syscall open open
299
300test_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
303
20a01d15
SM
304test_failure "--condition on-event --capture: missing argument (end of arg list)" \
305 'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \
306 --action notify \
307 --condition on-event -u -a --capture
308
309test_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 \
312 --action notify \
313
314test_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
318
319test_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
323
324test_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
328
329test_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
333
334test_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
338
339test_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
343
344test_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
348
b4b7369f
JR
349# `--action` failures
350test_failure "missing args after --action" \
351 "Error: Missing action name." \
352 --condition on-event -u -a \
353 --action
354
355# `--action notify` failures
356test_failure "extra arg after --action notify" \
357 "Error: Unexpected argument \`bob\`." \
358 --condition on-event -u -a \
359 --action notify bob
360
361# `--action start-session` failures
362test_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
366test_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
370
371# `--action stop-session` failures
372test_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
376test_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
380
381# `--action rotate-session` failures
382test_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
386test_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
390
391# `--action snapshot-session` failures
392test_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
396test_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
400test_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
404test_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
408test_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
412test_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/
416
417# Cleanup
418stop_lttng_sessiond_notap
419rm -f "${tmp_stdout}"
420rm -f "${tmp_stderr}"
This page took 0.038273 seconds and 4 git commands to generate.