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