lttng add-trigger: rename on-event condition to event-rule-matches
[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
bbadb5e0 26plan_tests 234
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 $*"
e45dd625 49 set -x
b4b7369f 50 "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
e45dd625 51 set +x
b4b7369f
JR
52 ok $? "${test_name}: exit code is 0"
53
54 diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.")
55 ok $? "${test_name}: expected stdout"
56
57 diff -u "${tmp_stderr}" /dev/null
58 ok $? "${test_name}: expected stderr"
59}
60
61function test_failure ()
62{
63 local test_name="$1"
64 local error_msg="$2"
65
66 shift 2
67
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"
71
72 diff -u "${tmp_stdout}" /dev/null
73 ok $? "${test_name}: expected stdout"
74
75 diff -u "${tmp_stderr}" <(echo "${error_msg}")
76 ok $? "${test_name}: expected stderr"
77}
78
79# top-level options
1d4b59f2
SM
80test_success "explicit name" \
81 --name hohoho \
665db063 82 --condition event-rule-matches some-event-id -u \
b4b7369f
JR
83 --action notify
84
665db063
SM
85# `--condition event-rule-matches` successes
86test_success "--condition event-rule-matches some-event -u" \
87 --condition event-rule-matches some-event -u \
b4b7369f
JR
88 --action notify
89
665db063
SM
90test_success "--condition event-rule-matches -a -u" \
91 --condition event-rule-matches -a -u \
b4b7369f
JR
92 --action notify
93
e45dd625 94test_success "notify action polices" \
665db063 95 --condition event-rule-matches -u test-rate-policy \
b4b7369f 96 --action notify \
bbadb5e0 97 --rate-policy=every:55 \
e45dd625 98 --action notify \
bbadb5e0 99 --rate-policy=once-after:55
b4b7369f 100
e45dd625 101test_success "start session action polices" \
665db063 102 --condition event-rule-matches -u test-rate-policy \
e45dd625 103 --action start-session my_session \
bbadb5e0 104 --rate-policy=every:55 \
e45dd625 105 --action start-session my_session \
bbadb5e0 106 --rate-policy=once-after:55
e45dd625
JR
107
108test_success "stop session action polices" \
665db063 109 --condition event-rule-matches -u test-rate-policy \
e45dd625 110 --action stop-session my_session \
bbadb5e0 111 --rate-policy=every:55 \
e45dd625 112 --action stop-session my_session \
bbadb5e0 113 --rate-policy=once-after:55
e45dd625
JR
114
115test_success "snapshot session action polices" \
665db063 116 --condition event-rule-matches -u test-rate-policy \
e45dd625 117 --action snapshot-session my_session \
bbadb5e0 118 --rate-policy=every:55 \
e45dd625 119 --action snapshot-session my_session \
bbadb5e0 120 --rate-policy=once-after:55
e45dd625
JR
121
122test_success "rotate session action polices" \
665db063 123 --condition event-rule-matches -u test-rate-policy \
e45dd625 124 --action rotate-session my_session \
bbadb5e0 125 --rate-policy=every:55 \
e45dd625 126 --action rotate-session my_session \
bbadb5e0 127 --rate-policy=once-after:55
b4b7369f
JR
128
129skip $ist_root "non-root user: skipping kprobe tests" 9 || {
665db063
SM
130 test_success "--condition event-rule-matches probe by symbol" \
131 --condition event-rule-matches -k --probe=lttng_channel_enable my_channel_enable \
b4b7369f
JR
132 --action notify
133
134 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
135 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
136
137 # We need to find a valid offset.
138 base_symbol=""
139 offset=0
140 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
141 base_symbol="lttng_channel_enable"
142 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
143 else
144 base_symbol="lttng_channel_disable"
145 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
146 fi
147
148 offset_hex="0x$(printf '%x' $offset)"
149
665db063
SM
150 test_success "--condition event-rule-matches probe by symbol with offset" \
151 --condition event-rule-matches -k --probe="${base_symbol}+${offset_hex}" my_$base_symbol \
b4b7369f
JR
152 --action notify
153
665db063
SM
154 test_success "--condition event-rule-matches probe by address" \
155 --condition event-rule-matches -k "--probe=0x${channel_enable_addr}" my_channel_enable \
b4b7369f
JR
156 --action notify
157}
158
159skip $ist_root "non-root user: skipping uprobe tests" 6 || {
665db063
SM
160 test_success "--condition event-rule-matches uprobe" \
161 --condition event-rule-matches -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe \
b4b7369f
JR
162 --action notify
163
665db063
SM
164 test_success "--condition event-rule-matches uprobe with elf prefix" \
165 --condition event-rule-matches -k --userspace-probe=elf:${uprobe_elf_binary}:test_function ma-probe-2 \
b4b7369f
JR
166 --action notify
167}
168
169skip $ist_root "non-root user: skipping syscall tests" 9 || {
665db063
SM
170 test_success "--condition event-rule-matches syscall" \
171 --condition event-rule-matches -k --syscall open \
b4b7369f
JR
172 --action notify
173
665db063
SM
174 test_success "--condition event-rule-matches syscall -a" \
175 --condition event-rule-matches -k --syscall -a \
b4b7369f
JR
176 --action notify
177
665db063
SM
178 test_success "--condition event-rule-matches syscall with filter" \
179 --condition event-rule-matches -k --syscall --filter 'a > 2' open \
b4b7369f
JR
180 --action notify
181}
182
183# `--action notify` successes
184test_success "--action notify" \
665db063 185 --condition event-rule-matches some-event-notify -u \
b4b7369f
JR
186 --action notify
187
20a01d15 188test_success "--action notify --capture foo" \
665db063 189 --condition event-rule-matches some-event-notify-foo -u \
20a01d15
SM
190 --capture foo --action notify
191
192test_success "--action notify --capture foo[2]" \
665db063 193 --condition event-rule-matches some-event-notify-foo2 -u \
20a01d15
SM
194 --capture 'foo[2]' --action notify
195
196test_success '--action notify --capture $ctx.foo' \
665db063 197 --condition event-rule-matches some-event-notify-ctx-foo -u \
20a01d15
SM
198 --capture '$ctx.foo' --action notify
199
200test_success '--action notify --capture $ctx.foo[2]' \
665db063 201 --condition event-rule-matches some-event-notify-ctx-foo2 -u \
20a01d15
SM
202 --capture '$ctx.foo[2]' --action notify
203
204test_success '--action notify --capture $app.prov:type' \
665db063 205 --condition event-rule-matches some-event-notify-app-prov-type -u \
20a01d15
SM
206 --capture '$app.prov:type' --action notify
207
208test_success '--action notify --capture $app.prov:type[2]' \
665db063 209 --condition event-rule-matches some-event-notify-app-prov-type-2 -u \
20a01d15
SM
210 --capture '$app.prov:type[2]' --action notify
211
212test_success '--action notify multiple captures' \
665db063 213 --condition event-rule-matches some-event-notify-multiple-captures -u \
20a01d15
SM
214 --capture foo --capture '$app.hello:world' --action notify
215
b4b7369f
JR
216# `--action start-session` successes
217test_success "--action start-session" \
665db063 218 --condition event-rule-matches some-event-start-session -u \
b4b7369f
JR
219 --action start-session ze-session
220
221# `--action stop-session` successes
222test_success "--action stop-session foo" \
665db063 223 --condition event-rule-matches some-event-stop-session -u \
b4b7369f
JR
224 --action stop-session ze-session
225
226# `--action rotate-session` successes
227test_success "--action rotate-session foo" \
665db063 228 --condition event-rule-matches some-event-rotate-session -u \
b4b7369f
JR
229 --action rotate-session ze-session
230
231# `--action snapshot-session` successes
232test_success "--action snapshot-session foo" \
665db063 233 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
234 --action snapshot-session ze-session
235
236test_success "--action snapshot-session with file URI" \
665db063 237 --condition event-rule-matches some-event-snapshot-session2 -u \
b4b7369f
JR
238 --action snapshot-session ze-session --path /hello
239
240test_success "--action snapshot-session with net URI" \
665db063 241 --condition event-rule-matches some-event-snapshot-session3 -u \
b4b7369f
JR
242 --action snapshot-session ze-session --url net://1.2.3.4
243
244test_success "--action snapshot-session with ctrl/data URIs" \
665db063 245 --condition event-rule-matches some-event-snapshot-session4 -u \
b4b7369f
JR
246 --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1234 --data-url=tcp://1.2.3.4:1235
247
248# top-level failures
249test_failure "no args" "Error: Missing --condition."
250
251test_failure "unknown option" \
252 "Error: Unknown option \`--hello\`" \
253 --hello
254
255test_failure "missing --action" \
256 "Error: Need at least one --action." \
665db063 257 --condition event-rule-matches hello -u
b4b7369f
JR
258
259test_failure "two --condition" \
260 "Error: A --condition was already given." \
665db063
SM
261 --condition event-rule-matches aaa -u \
262 --condition event-rule-matches bbb -u \
b4b7369f
JR
263 --action notify
264
1d4b59f2
SM
265test_failure "missing argument to --name" \
266 "Error: While parsing argument #1 (\`--name\`): Missing required argument for option \`--name\`" \
267 --name
b4b7369f 268
bbadb5e0 269for cmd in rate-policy=once-after rate-policy=every; do
b4b7369f 270 test_failure "missing argument to --${cmd}" \
bbadb5e0 271 "Error: Rate policy format is invalid." \
665db063 272 --condition event-rule-matches -u -a --action notify \
b4b7369f
JR
273 --${cmd}
274
275 test_failure "invalid argument to --${cmd}: non-digit character" \
bbadb5e0 276 "Error: Failed to parse rate policy value \`123bob\` as an integer." \
665db063 277 --condition event-rule-matches -u -a --action notify \
bbadb5e0 278 --${cmd}:123bob
b4b7369f
JR
279
280 test_failure "invalid argument to --${cmd}: empty string" \
bbadb5e0 281 "Error: Failed to parse rate policy value \`\` as an integer." \
665db063 282 --condition event-rule-matches -u -a --action notify \
bbadb5e0 283 --${cmd}":"
b4b7369f
JR
284done
285
bbadb5e0
JR
286test_failure "invalid argument to --rate-policy: unknown policy type" \
287 "Error: Rate policy type \`bob\` unknown." \
665db063 288 --condition event-rule-matches -u -a --action notify \
bbadb5e0
JR
289 --rate-policy=bob:123
290
b4b7369f
JR
291# `--condition` failures
292test_failure "missing args after --condition" \
29bcf415 293 "Error: While parsing argument #1 (\`--condition\`): Missing required argument for option \`--condition\`" \
b4b7369f
JR
294 --condition
295test_failure "unknown --condition" \
296 "Error: Unknown condition name 'zoofest'" \
297 --condition zoofest
298
665db063
SM
299# `--condition event-rule-matches` failures
300test_failure "missing args after --condition event-rule-matches" \
b4b7369f 301 "Error: Need to provide either a tracepoint name or -a/--all." \
665db063
SM
302 --condition event-rule-matches
303test_failure "missing domain in --condition event-rule-matches" \
b4b7369f 304 "Error: Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)." \
665db063
SM
305 --condition event-rule-matches -a
306test_failure "extra args after --condition event-rule-matches" \
b4b7369f 307 "Error: Unexpected argument 'bozo'" \
665db063
SM
308 --condition event-rule-matches foo -u bozo
309test_failure "--condition event-rule-matches: --all with --probe" \
b4b7369f 310 "Error: Can't use -a/--all with probe event rules." \
665db063
SM
311 --condition event-rule-matches --probe=do_sys_open --all
312test_failure "--condition event-rule-matches: missing tracepoint name with --probe" \
b4b7369f 313 "Error: Need to provide either a tracepoint name or -a/--all." \
665db063 314 --condition event-rule-matches -k --probe do_sys_open
b4b7369f 315
665db063 316test_failure "--condition event-rule-matches: missing tracepoint name with --userspace-probe" \
b4b7369f 317 "Error: Need to provide either a tracepoint name or -a/--all." \
665db063 318 --condition event-rule-matches -k --userspace-probe=${uprobe_elf_binary}:test_function
b4b7369f 319
665db063 320test_failure "--condition event-rule-matches: extra argument with --userspace-probe" \
b4b7369f 321 "Error: Unexpected argument 'world'" \
665db063 322 --condition event-rule-matches -k --userspace-probe=${uprobe_elf_binary}:test_failure hello world
b4b7369f 323
665db063 324test_failure "--condition event-rule-matches: missing tracepoint name with --syscall" \
b4b7369f 325 "Error: Need to provide either a tracepoint name or -a/--all." \
665db063 326 --condition event-rule-matches -k --syscall
b4b7369f 327
665db063 328test_failure "--condition event-rule-matches: extra argument with --syscall" \
b4b7369f 329 "Error: Unexpected argument 'open'" \
665db063 330 --condition event-rule-matches -k --syscall open open
b4b7369f 331
665db063 332test_failure "--condition event-rule-matches: both -a and a tracepoint name with --syscall" \
b4b7369f 333 "Error: Can't provide a tracepoint name with -a/--all." \
665db063 334 --condition event-rule-matches -k --syscall -a open
b4b7369f 335
665db063 336test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \
20a01d15
SM
337 'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \
338 --action notify \
665db063 339 --condition event-rule-matches -u -a --capture
20a01d15 340
665db063 341test_failure "--condition event-rule-matches --capture: missing argument (before another option)" \
20a01d15 342 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
665db063 343 --condition event-rule-matches -u -a --capture \
20a01d15
SM
344 --action notify \
345
665db063 346test_failure "--condition event-rule-matches --capture: binary operator" \
20a01d15 347 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
665db063 348 --condition event-rule-matches -u -a \
20a01d15
SM
349 --capture 'foo == 2' --action notify
350
665db063 351test_failure "--condition event-rule-matches --capture: unary operator" \
20a01d15 352 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
665db063 353 --condition event-rule-matches -u -a \
20a01d15
SM
354 --capture '!foo' --action notify
355
665db063 356test_failure "--condition event-rule-matches --capture: logical operator" \
20a01d15 357 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
665db063 358 --condition event-rule-matches -u -a \
20a01d15
SM
359 --capture 'foo || bar' --action notify
360
665db063 361test_failure "--condition event-rule-matches --capture: accessing a sub-field" \
20a01d15 362 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
665db063 363 --condition event-rule-matches -u -a \
20a01d15
SM
364 --capture 'foo.bar' --action notify
365
665db063 366test_failure "--condition event-rule-matches --capture: accessing the sub-field of an array element" \
20a01d15 367 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
665db063 368 --condition event-rule-matches -u -a \
20a01d15
SM
369 --capture 'foo[3].bar' --action notify
370
665db063 371test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
20a01d15 372 'Error: Invalid app-specific context field name: missing colon in `foo`.' \
665db063 373 --condition event-rule-matches -u -a \
20a01d15
SM
374 --capture '$app.foo' --action notify
375
665db063 376test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
20a01d15 377 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
665db063 378 --condition event-rule-matches -u -a \
20a01d15
SM
379 --capture '$app.foo:' --action notify
380
b4b7369f
JR
381# `--action` failures
382test_failure "missing args after --action" \
29bcf415 383 "Error: While parsing argument #1 (\`--action\`): Missing required argument for option \`--action\`" \
665db063 384 --condition event-rule-matches -u -a \
b4b7369f
JR
385 --action
386
387# `--action notify` failures
388test_failure "extra arg after --action notify" \
389 "Error: Unexpected argument \`bob\`." \
665db063 390 --condition event-rule-matches -u -a \
b4b7369f
JR
391 --action notify bob
392
393# `--action start-session` failures
394test_failure "missing arg after --action start-session" \
395 "Error: Missing session name." \
665db063 396 --condition event-rule-matches some-event-start-session -u \
b4b7369f
JR
397 --action start-session
398test_failure "extra arg after --action start-session" \
399 "Error: Unexpected argument \`bob\`." \
665db063 400 --condition event-rule-matches some-event-start-session -u \
b4b7369f
JR
401 --action start-session ze-session bob
402
403# `--action stop-session` failures
404test_failure "missing arg after --action stop-session" \
405 "Error: Missing session name." \
665db063 406 --condition event-rule-matches some-event-stop-session -u \
b4b7369f
JR
407 --action stop-session
408test_failure "extra arg after --action stop-session" \
409 "Error: Unexpected argument \`bob\`." \
665db063 410 --condition event-rule-matches some-event-stop-session -u \
b4b7369f
JR
411 --action stop-session ze-session bob
412
413# `--action rotate-session` failures
414test_failure "missing arg after --action rotate-session" \
415 "Error: Missing session name." \
665db063 416 --condition event-rule-matches some-event-rotate-session -u \
b4b7369f
JR
417 --action rotate-session
418test_failure "extra arg after --action rotate-session" \
419 "Error: Unexpected argument \`bob\`." \
665db063 420 --condition event-rule-matches some-event-rotate-session -u \
b4b7369f
JR
421 --action rotate-session ze-session bob
422
423# `--action snapshot-session` failures
424test_failure "missing arg after --action snapshot-session" \
425 "Error: Missing session name." \
665db063 426 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
427 --action snapshot-session
428test_failure "extra arg after --action snapshot-session" \
429 "Error: Unexpected argument \`bob\`." \
665db063 430 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
431 --action snapshot-session ze-session bob
432test_failure "snapshot-session action, --max-size without destination" \
433 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
665db063 434 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
435 --action snapshot-session ze-session --max-size 10M
436test_failure "snapshot-session action, --name without destination" \
437 "Error: Can't provide a snapshot output name without a snapshot output destination." \
665db063 438 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
439 --action snapshot-session ze-session --name hallo
440test_failure "snapshot-session action, --name with-local-path-instead-of-url" \
441 "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
665db063 442 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
443 --action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path
444test_failure "snapshot-session action, --name with-net-url-instead-of-path" \
445 "Error: Failed to parse 'net://8.8.8.8/' as a local path." \
665db063 446 --condition event-rule-matches some-event-snapshot-session -u \
b4b7369f
JR
447 --action snapshot-session ze-session --name hallo --path net://8.8.8.8/
448
449# Cleanup
450stop_lttng_sessiond_notap
451rm -f "${tmp_stdout}"
452rm -f "${tmp_stderr}"
This page took 0.045065 seconds and 4 git commands to generate.