Introduce emission site for syscall event rule
[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
57739a6b 26plan_tests 276
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 \
64c34630 82 --condition event-rule-matches --name=some-event-id --domain=user \
b4b7369f
JR
83 --action notify
84
665db063 85# `--condition event-rule-matches` successes
64c34630
SM
86test_success "--condition event-rule-matches some-event --domain=user" \
87 --condition event-rule-matches --name=some-event --domain=user \
b4b7369f
JR
88 --action notify
89
64c34630
SM
90test_success "--condition event-rule-matches --domain=user" \
91 --condition event-rule-matches --domain=user \
b4b7369f
JR
92 --action notify
93
e45dd625 94test_success "notify action polices" \
64c34630 95 --condition event-rule-matches --domain=user --name=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" \
64c34630 102 --condition event-rule-matches --domain=user --name=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" \
64c34630 109 --condition event-rule-matches --domain=user --name=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" \
64c34630 116 --condition event-rule-matches --domain=user --name=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" \
64c34630 123 --condition event-rule-matches --domain=user --name=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 128
949f049b
SM
129test_success "--log-level single level" \
130 --condition event-rule-matches --domain=user --log-level=INFO \
131 --action notify
132
133test_success "--log-level range open max" \
134 --condition event-rule-matches --domain=user --log-level=INFO.. \
135 --action notify
136
137test_success "--log-level range any" \
138 --condition event-rule-matches --domain=user --log-level=.. \
139 --action notify
140
24de704e
SM
141skip $ist_root "non-root user: skipping kprobe tests" 18 || {
142 for type in kprobe kernel-probe; do
143 test_success "--condition event-rule-matches probe by symbol" \
144 --condition event-rule-matches --domain=kernel --type=$type --location=lttng_channel_enable --event-name=my_channel_enable \
145 --action notify
146
147 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
148 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
149
150 # We need to find a valid offset.
151 base_symbol=""
152 offset=0
153 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
154 base_symbol="lttng_channel_enable"
155 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
156 else
157 base_symbol="lttng_channel_disable"
158 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
159 fi
160
161 offset_hex="0x$(printf '%x' $offset)"
162
163 test_success "--condition event-rule-matches probe by symbol with offset" \
164 --condition event-rule-matches --domain=kernel --type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \
165 --action notify
166
167 test_success "--condition event-rule-matches probe by address" \
168 --condition event-rule-matches --domain=kernel --type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \
169 --action notify
170 done
b4b7369f
JR
171}
172
24de704e
SM
173skip $ist_root "non-root user: skipping uprobe tests" 12 || {
174 for type in uprobe userspace-probe; do
175 test_success "--condition event-rule-matches uprobe" \
176 --condition event-rule-matches --domain=kernel --type=$type --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \
177 --action notify
b4b7369f 178
24de704e
SM
179 test_success "--condition event-rule-matches uprobe with elf prefix" \
180 --condition event-rule-matches --domain=kernel --type=$type --location=elf:${uprobe_elf_binary}:test_function --event-name=ma-probe-2 \
181 --action notify
182 done
b4b7369f
JR
183}
184
57739a6b 185skip $ist_root "non-root user: skipping syscall tests" 18 || {
50ad0862 186 test_success "--condition event-rule-matches one syscall" \
24de704e 187 --condition event-rule-matches --domain=kernel --type=syscall --name=open \
b4b7369f
JR
188 --action notify
189
50ad0862 190 test_success "--condition event-rule-matches all syscalls" \
24de704e 191 --condition event-rule-matches --domain=kernel --type=syscall \
b4b7369f
JR
192 --action notify
193
50ad0862 194 test_success "--condition event-rule-matches one syscall with filter" \
24de704e 195 --condition event-rule-matches --domain=kernel --type=syscall --filter 'a > 2' --name=open \
b4b7369f 196 --action notify
57739a6b
JR
197 test_success "--condition event-rule-matches one syscall:entry" \
198 --condition event-rule-matches --domain=kernel --type=syscall:entry --name=open \
199 --action notify
200 test_success "--condition event-rule-matches one syscall:exit" \
201 --condition event-rule-matches --domain=kernel --type=syscall:exit --name=open \
202 --action notify
203 test_success "--condition event-rule-matches one syscall:entry-exit" \
204 --condition event-rule-matches --domain=kernel --type=syscall:entry+exit --name=open \
205 --action notify
b4b7369f
JR
206}
207
208# `--action notify` successes
209test_success "--action notify" \
64c34630 210 --condition event-rule-matches --domain=user \
b4b7369f
JR
211 --action notify
212
20a01d15 213test_success "--action notify --capture foo" \
64c34630 214 --condition event-rule-matches --domain=user \
20a01d15
SM
215 --capture foo --action notify
216
217test_success "--action notify --capture foo[2]" \
64c34630 218 --condition event-rule-matches --domain=user \
20a01d15
SM
219 --capture 'foo[2]' --action notify
220
221test_success '--action notify --capture $ctx.foo' \
64c34630 222 --condition event-rule-matches --domain=user \
20a01d15
SM
223 --capture '$ctx.foo' --action notify
224
225test_success '--action notify --capture $ctx.foo[2]' \
64c34630 226 --condition event-rule-matches --domain=user \
20a01d15
SM
227 --capture '$ctx.foo[2]' --action notify
228
229test_success '--action notify --capture $app.prov:type' \
64c34630 230 --condition event-rule-matches --domain=user \
20a01d15
SM
231 --capture '$app.prov:type' --action notify
232
233test_success '--action notify --capture $app.prov:type[2]' \
64c34630 234 --condition event-rule-matches --domain=user \
20a01d15
SM
235 --capture '$app.prov:type[2]' --action notify
236
237test_success '--action notify multiple captures' \
64c34630 238 --condition event-rule-matches --domain=user \
20a01d15
SM
239 --capture foo --capture '$app.hello:world' --action notify
240
b4b7369f
JR
241# `--action start-session` successes
242test_success "--action start-session" \
64c34630 243 --condition event-rule-matches --domain=user \
b4b7369f
JR
244 --action start-session ze-session
245
246# `--action stop-session` successes
247test_success "--action stop-session foo" \
64c34630 248 --condition event-rule-matches --domain=user \
b4b7369f
JR
249 --action stop-session ze-session
250
251# `--action rotate-session` successes
252test_success "--action rotate-session foo" \
64c34630 253 --condition event-rule-matches --domain=user \
b4b7369f
JR
254 --action rotate-session ze-session
255
256# `--action snapshot-session` successes
257test_success "--action snapshot-session foo" \
64c34630 258 --condition event-rule-matches --domain=user \
b4b7369f
JR
259 --action snapshot-session ze-session
260
261test_success "--action snapshot-session with file URI" \
64c34630 262 --condition event-rule-matches --domain=user \
b4b7369f
JR
263 --action snapshot-session ze-session --path /hello
264
265test_success "--action snapshot-session with net URI" \
64c34630 266 --condition event-rule-matches --domain=user \
b4b7369f
JR
267 --action snapshot-session ze-session --url net://1.2.3.4
268
269test_success "--action snapshot-session with ctrl/data URIs" \
64c34630 270 --condition event-rule-matches --domain=user \
b4b7369f
JR
271 --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1234 --data-url=tcp://1.2.3.4:1235
272
273# top-level failures
274test_failure "no args" "Error: Missing --condition."
275
276test_failure "unknown option" \
277 "Error: Unknown option \`--hello\`" \
278 --hello
279
280test_failure "missing --action" \
281 "Error: Need at least one --action." \
64c34630 282 --condition event-rule-matches --domain=user
b4b7369f
JR
283
284test_failure "two --condition" \
285 "Error: A --condition was already given." \
64c34630
SM
286 --condition event-rule-matches --name=aaa --domain=user \
287 --condition event-rule-matches --name=bbb --domain=user \
b4b7369f
JR
288 --action notify
289
1d4b59f2
SM
290test_failure "missing argument to --name" \
291 "Error: While parsing argument #1 (\`--name\`): Missing required argument for option \`--name\`" \
292 --name
b4b7369f 293
bbadb5e0 294for cmd in rate-policy=once-after rate-policy=every; do
b4b7369f 295 test_failure "missing argument to --${cmd}" \
bbadb5e0 296 "Error: Rate policy format is invalid." \
64c34630 297 --condition event-rule-matches --domain=user --action notify \
b4b7369f
JR
298 --${cmd}
299
300 test_failure "invalid argument to --${cmd}: non-digit character" \
bbadb5e0 301 "Error: Failed to parse rate policy value \`123bob\` as an integer." \
64c34630 302 --condition event-rule-matches --domain=user --action notify \
bbadb5e0 303 --${cmd}:123bob
b4b7369f
JR
304
305 test_failure "invalid argument to --${cmd}: empty string" \
bbadb5e0 306 "Error: Failed to parse rate policy value \`\` as an integer." \
64c34630 307 --condition event-rule-matches --domain=user --action notify \
bbadb5e0 308 --${cmd}":"
b4b7369f
JR
309done
310
bbadb5e0
JR
311test_failure "invalid argument to --rate-policy: unknown policy type" \
312 "Error: Rate policy type \`bob\` unknown." \
64c34630 313 --condition event-rule-matches --domain=user --action notify \
bbadb5e0
JR
314 --rate-policy=bob:123
315
b4b7369f
JR
316# `--condition` failures
317test_failure "missing args after --condition" \
29bcf415 318 "Error: While parsing argument #1 (\`--condition\`): Missing required argument for option \`--condition\`" \
b4b7369f
JR
319 --condition
320test_failure "unknown --condition" \
321 "Error: Unknown condition name 'zoofest'" \
322 --condition zoofest
323
665db063
SM
324# `--condition event-rule-matches` failures
325test_failure "missing args after --condition event-rule-matches" \
64c34630 326 "Error: Please specify a domain (--domain=(kernel,user,jul,log4j,python))." \
50ad0862
SM
327 --condition event-rule-matches
328
665db063 329test_failure "extra args after --condition event-rule-matches" \
b4b7369f 330 "Error: Unexpected argument 'bozo'" \
64c34630
SM
331 --condition event-rule-matches --domain=user bozo
332
949f049b
SM
333test_failure "--log-level unknown level" \
334 "Error: Failed to parse log level string \`FOO\`." \
335 --condition event-rule-matches --domain=user --log-level=FOO
336
64c34630
SM
337test_failure "two same --domain" \
338 "Error: More than one \`--domain\` was specified." \
339 --condition event-rule-matches --domain=user --domain=user
340
341test_failure "two different --domain" \
342 "Error: More than one \`--domain\` was specified." \
343 --condition event-rule-matches --domain=user --domain=kernel
b4b7369f 344
24de704e
SM
345for type in kprobe kernel-probe; do
346 test_failure "--condition event-rule-matches: --name with --type=$type" \
347 "Error: Can't use --name with probe event rules." \
348 --condition event-rule-matches --type=$type --location=do_sys_open --name='hello'
349done
350
351test_failure "--condition event-rule-matches: --location with tracepoint event rule" \
352 "Error: Can't use --location with tracepoint event rules." \
353 --condition event-rule-matches --domain=user --location='hello'
b4b7369f 354
24de704e 355test_failure "--condition event-rule-matches: --event-name with tracepoint event rule" \
50ad0862 356 "Error: Can't use --event-name with tracepoint event rules." \
64c34630 357 --condition event-rule-matches --domain=user --event-name='hello'
50ad0862 358
24de704e
SM
359for type in uprobe userspace-probe; do
360 test_failure "--condition event-rule-matches: extra argument with --type=$type" \
361 "Error: Unexpected argument 'hello'" \
362 --condition event-rule-matches --domain=kernel --type=$type --location=${uprobe_elf_binary}:test_failure hello
363done
b4b7369f 364
24de704e 365test_failure "--condition event-rule-matches: extra argument with --type=syscall" \
b4b7369f 366 "Error: Unexpected argument 'open'" \
24de704e 367 --condition event-rule-matches --domain=kernel --type=syscall open
b4b7369f 368
57739a6b
JR
369test_failure "--condition event-rule-matches: --type=syscall:nope" \
370 "Error: Failed to parse syscall type 'syscall:nope'." \
371 --condition event-rule-matches --domain=kernel --type=syscall:nope \
372 --name=open
373
665db063 374test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \
50ad0862 375 'Error: While parsing argument #2 (`--capture`): Missing required argument for option `--capture`' \
20a01d15 376 --action notify \
64c34630 377 --condition event-rule-matches --domain=user --capture
20a01d15 378
665db063 379test_failure "--condition event-rule-matches --capture: missing argument (before another option)" \
20a01d15 380 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
64c34630 381 --condition event-rule-matches --domain=user --capture \
20a01d15
SM
382 --action notify \
383
665db063 384test_failure "--condition event-rule-matches --capture: binary operator" \
20a01d15 385 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
64c34630 386 --condition event-rule-matches --domain=user \
20a01d15
SM
387 --capture 'foo == 2' --action notify
388
665db063 389test_failure "--condition event-rule-matches --capture: unary operator" \
20a01d15 390 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
64c34630 391 --condition event-rule-matches --domain=user \
20a01d15
SM
392 --capture '!foo' --action notify
393
665db063 394test_failure "--condition event-rule-matches --capture: logical operator" \
20a01d15 395 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
64c34630 396 --condition event-rule-matches --domain=user \
20a01d15
SM
397 --capture 'foo || bar' --action notify
398
665db063 399test_failure "--condition event-rule-matches --capture: accessing a sub-field" \
20a01d15 400 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
64c34630 401 --condition event-rule-matches --domain=user \
20a01d15
SM
402 --capture 'foo.bar' --action notify
403
665db063 404test_failure "--condition event-rule-matches --capture: accessing the sub-field of an array element" \
20a01d15 405 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
64c34630 406 --condition event-rule-matches --domain=user \
20a01d15
SM
407 --capture 'foo[3].bar' --action notify
408
665db063 409test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
20a01d15 410 'Error: Invalid app-specific context field name: missing colon in `foo`.' \
64c34630 411 --condition event-rule-matches --domain=user \
20a01d15
SM
412 --capture '$app.foo' --action notify
413
665db063 414test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
20a01d15 415 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
64c34630 416 --condition event-rule-matches --domain=user \
20a01d15
SM
417 --capture '$app.foo:' --action notify
418
b4b7369f
JR
419# `--action` failures
420test_failure "missing args after --action" \
29bcf415 421 "Error: While parsing argument #1 (\`--action\`): Missing required argument for option \`--action\`" \
64c34630 422 --condition event-rule-matches --domain=user \
b4b7369f
JR
423 --action
424
425# `--action notify` failures
426test_failure "extra arg after --action notify" \
427 "Error: Unexpected argument \`bob\`." \
64c34630 428 --condition event-rule-matches --domain=user \
b4b7369f
JR
429 --action notify bob
430
431# `--action start-session` failures
432test_failure "missing arg after --action start-session" \
433 "Error: Missing session name." \
64c34630 434 --condition event-rule-matches --domain=user \
b4b7369f
JR
435 --action start-session
436test_failure "extra arg after --action start-session" \
437 "Error: Unexpected argument \`bob\`." \
64c34630 438 --condition event-rule-matches --domain=user \
b4b7369f
JR
439 --action start-session ze-session bob
440
441# `--action stop-session` failures
442test_failure "missing arg after --action stop-session" \
443 "Error: Missing session name." \
64c34630 444 --condition event-rule-matches --domain=user \
b4b7369f
JR
445 --action stop-session
446test_failure "extra arg after --action stop-session" \
447 "Error: Unexpected argument \`bob\`." \
64c34630 448 --condition event-rule-matches --domain=user \
b4b7369f
JR
449 --action stop-session ze-session bob
450
451# `--action rotate-session` failures
452test_failure "missing arg after --action rotate-session" \
453 "Error: Missing session name." \
64c34630 454 --condition event-rule-matches --domain=user \
b4b7369f
JR
455 --action rotate-session
456test_failure "extra arg after --action rotate-session" \
457 "Error: Unexpected argument \`bob\`." \
64c34630 458 --condition event-rule-matches --domain=user \
b4b7369f
JR
459 --action rotate-session ze-session bob
460
461# `--action snapshot-session` failures
462test_failure "missing arg after --action snapshot-session" \
463 "Error: Missing session name." \
64c34630 464 --condition event-rule-matches --domain=user \
b4b7369f
JR
465 --action snapshot-session
466test_failure "extra arg after --action snapshot-session" \
467 "Error: Unexpected argument \`bob\`." \
64c34630 468 --condition event-rule-matches --domain=user \
b4b7369f
JR
469 --action snapshot-session ze-session bob
470test_failure "snapshot-session action, --max-size without destination" \
471 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
64c34630 472 --condition event-rule-matches --domain=user \
b4b7369f
JR
473 --action snapshot-session ze-session --max-size 10M
474test_failure "snapshot-session action, --name without destination" \
475 "Error: Can't provide a snapshot output name without a snapshot output destination." \
64c34630 476 --condition event-rule-matches --domain=user \
b4b7369f
JR
477 --action snapshot-session ze-session --name hallo
478test_failure "snapshot-session action, --name with-local-path-instead-of-url" \
479 "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
64c34630 480 --condition event-rule-matches --domain=user \
b4b7369f
JR
481 --action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path
482test_failure "snapshot-session action, --name with-net-url-instead-of-path" \
483 "Error: Failed to parse 'net://8.8.8.8/' as a local path." \
64c34630 484 --condition event-rule-matches --domain=user \
b4b7369f
JR
485 --action snapshot-session ze-session --name hallo --path net://8.8.8.8/
486
487# Cleanup
488stop_lttng_sessiond_notap
489rm -f "${tmp_stdout}"
490rm -f "${tmp_stderr}"
This page took 0.070798 seconds and 4 git commands to generate.