lttng add-trigger: some updates to event rule to new syntax
[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 222
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 -u \
83 --action notify
84
85# `--condition event-rule-matches` successes
86test_success "--condition event-rule-matches some-event -u" \
87 --condition event-rule-matches --name=some-event -u \
88 --action notify
89
90test_success "--condition event-rule-matches -u" \
91 --condition event-rule-matches -u \
92 --action notify
93
94test_success "notify action polices" \
95 --condition event-rule-matches -u --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 -u --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 -u --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 -u --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 -u --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
129skip $ist_root "non-root user: skipping kprobe tests" 9 || {
130 test_success "--condition event-rule-matches probe by symbol" \
131 --condition event-rule-matches -k --probe=lttng_channel_enable --event-name=my_channel_enable \
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
150 test_success "--condition event-rule-matches probe by symbol with offset" \
151 --condition event-rule-matches -k --probe="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \
152 --action notify
153
154 test_success "--condition event-rule-matches probe by address" \
155 --condition event-rule-matches -k "--probe=0x${channel_enable_addr}" --event-name=my_channel_enable \
156 --action notify
157}
158
159skip $ist_root "non-root user: skipping uprobe tests" 6 || {
160 test_success "--condition event-rule-matches uprobe" \
161 --condition event-rule-matches -k --userspace-probe=${uprobe_elf_binary}:test_function --event-name=ma-probe \
162 --action notify
163
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 --event-name=ma-probe-2 \
166 --action notify
167}
168
169skip $ist_root "non-root user: skipping syscall tests" 9 || {
170 test_success "--condition event-rule-matches one syscall" \
171 --condition event-rule-matches -k --syscall --name=open \
172 --action notify
173
174 test_success "--condition event-rule-matches all syscalls" \
175 --condition event-rule-matches -k --syscall \
176 --action notify
177
178 test_success "--condition event-rule-matches one syscall with filter" \
179 --condition event-rule-matches -k --syscall --filter 'a > 2' --name=open \
180 --action notify
181}
182
183# `--action notify` successes
184test_success "--action notify" \
185 --condition event-rule-matches -u \
186 --action notify
187
188test_success "--action notify --capture foo" \
189 --condition event-rule-matches -u \
190 --capture foo --action notify
191
192test_success "--action notify --capture foo[2]" \
193 --condition event-rule-matches -u \
194 --capture 'foo[2]' --action notify
195
196test_success '--action notify --capture $ctx.foo' \
197 --condition event-rule-matches -u \
198 --capture '$ctx.foo' --action notify
199
200test_success '--action notify --capture $ctx.foo[2]' \
201 --condition event-rule-matches -u \
202 --capture '$ctx.foo[2]' --action notify
203
204test_success '--action notify --capture $app.prov:type' \
205 --condition event-rule-matches -u \
206 --capture '$app.prov:type' --action notify
207
208test_success '--action notify --capture $app.prov:type[2]' \
209 --condition event-rule-matches -u \
210 --capture '$app.prov:type[2]' --action notify
211
212test_success '--action notify multiple captures' \
213 --condition event-rule-matches -u \
214 --capture foo --capture '$app.hello:world' --action notify
215
216# `--action start-session` successes
217test_success "--action start-session" \
218 --condition event-rule-matches -u \
219 --action start-session ze-session
220
221# `--action stop-session` successes
222test_success "--action stop-session foo" \
223 --condition event-rule-matches -u \
224 --action stop-session ze-session
225
226# `--action rotate-session` successes
227test_success "--action rotate-session foo" \
228 --condition event-rule-matches -u \
229 --action rotate-session ze-session
230
231# `--action snapshot-session` successes
232test_success "--action snapshot-session foo" \
233 --condition event-rule-matches -u \
234 --action snapshot-session ze-session
235
236test_success "--action snapshot-session with file URI" \
237 --condition event-rule-matches -u \
238 --action snapshot-session ze-session --path /hello
239
240test_success "--action snapshot-session with net URI" \
241 --condition event-rule-matches -u \
242 --action snapshot-session ze-session --url net://1.2.3.4
243
244test_success "--action snapshot-session with ctrl/data URIs" \
245 --condition event-rule-matches -u \
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." \
257 --condition event-rule-matches -u
258
259test_failure "two --condition" \
260 "Error: A --condition was already given." \
261 --condition event-rule-matches --name=aaa -u \
262 --condition event-rule-matches --name=bbb -u \
263 --action notify
264
265test_failure "missing argument to --name" \
266 "Error: While parsing argument #1 (\`--name\`): Missing required argument for option \`--name\`" \
267 --name
268
269for cmd in rate-policy=once-after rate-policy=every; do
270 test_failure "missing argument to --${cmd}" \
271 "Error: Rate policy format is invalid." \
272 --condition event-rule-matches -u --action notify \
273 --${cmd}
274
275 test_failure "invalid argument to --${cmd}: non-digit character" \
276 "Error: Failed to parse rate policy value \`123bob\` as an integer." \
277 --condition event-rule-matches -u --action notify \
278 --${cmd}:123bob
279
280 test_failure "invalid argument to --${cmd}: empty string" \
281 "Error: Failed to parse rate policy value \`\` as an integer." \
282 --condition event-rule-matches -u --action notify \
283 --${cmd}":"
284done
285
286test_failure "invalid argument to --rate-policy: unknown policy type" \
287 "Error: Rate policy type \`bob\` unknown." \
288 --condition event-rule-matches -u --action notify \
289 --rate-policy=bob:123
290
291# `--condition` failures
292test_failure "missing args after --condition" \
293 "Error: While parsing argument #1 (\`--condition\`): Missing required argument for option \`--condition\`" \
294 --condition
295test_failure "unknown --condition" \
296 "Error: Unknown condition name 'zoofest'" \
297 --condition zoofest
298
299# `--condition event-rule-matches` failures
300test_failure "missing args after --condition event-rule-matches" \
301 "Error: Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)." \
302 --condition event-rule-matches
303
304test_failure "extra args after --condition event-rule-matches" \
305 "Error: Unexpected argument 'bozo'" \
306 --condition event-rule-matches -u bozo
307
308test_failure "--condition event-rule-matches: --name with --probe" \
309 "Error: Can't use --name with probe event rules." \
310 --condition event-rule-matches --probe=do_sys_open --name='hello'
311
312test_failure "--condition event-rule-matches: --event-name with tracepoint" \
313 "Error: Can't use --event-name with tracepoint event rules." \
314 --condition event-rule-matches -u --event-name='hello'
315
316test_failure "--condition event-rule-matches: extra argument with --userspace-probe" \
317 "Error: Unexpected argument 'hello'" \
318 --condition event-rule-matches -k --userspace-probe=${uprobe_elf_binary}:test_failure hello
319
320test_failure "--condition event-rule-matches: extra argument with --syscall" \
321 "Error: Unexpected argument 'open'" \
322 --condition event-rule-matches -k --syscall open
323
324test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \
325 'Error: While parsing argument #2 (`--capture`): Missing required argument for option `--capture`' \
326 --action notify \
327 --condition event-rule-matches -u --capture
328
329test_failure "--condition event-rule-matches --capture: missing argument (before another option)" \
330 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
331 --condition event-rule-matches -u --capture \
332 --action notify \
333
334test_failure "--condition event-rule-matches --capture: binary operator" \
335 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
336 --condition event-rule-matches -u \
337 --capture 'foo == 2' --action notify
338
339test_failure "--condition event-rule-matches --capture: unary operator" \
340 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
341 --condition event-rule-matches -u \
342 --capture '!foo' --action notify
343
344test_failure "--condition event-rule-matches --capture: logical operator" \
345 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
346 --condition event-rule-matches -u \
347 --capture 'foo || bar' --action notify
348
349test_failure "--condition event-rule-matches --capture: accessing a sub-field" \
350 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
351 --condition event-rule-matches -u \
352 --capture 'foo.bar' --action notify
353
354test_failure "--condition event-rule-matches --capture: accessing the sub-field of an array element" \
355 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
356 --condition event-rule-matches -u \
357 --capture 'foo[3].bar' --action notify
358
359test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
360 'Error: Invalid app-specific context field name: missing colon in `foo`.' \
361 --condition event-rule-matches -u \
362 --capture '$app.foo' --action notify
363
364test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
365 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
366 --condition event-rule-matches -u \
367 --capture '$app.foo:' --action notify
368
369# `--action` failures
370test_failure "missing args after --action" \
371 "Error: While parsing argument #1 (\`--action\`): Missing required argument for option \`--action\`" \
372 --condition event-rule-matches -u \
373 --action
374
375# `--action notify` failures
376test_failure "extra arg after --action notify" \
377 "Error: Unexpected argument \`bob\`." \
378 --condition event-rule-matches -u \
379 --action notify bob
380
381# `--action start-session` failures
382test_failure "missing arg after --action start-session" \
383 "Error: Missing session name." \
384 --condition event-rule-matches -u \
385 --action start-session
386test_failure "extra arg after --action start-session" \
387 "Error: Unexpected argument \`bob\`." \
388 --condition event-rule-matches -u \
389 --action start-session ze-session bob
390
391# `--action stop-session` failures
392test_failure "missing arg after --action stop-session" \
393 "Error: Missing session name." \
394 --condition event-rule-matches -u \
395 --action stop-session
396test_failure "extra arg after --action stop-session" \
397 "Error: Unexpected argument \`bob\`." \
398 --condition event-rule-matches -u \
399 --action stop-session ze-session bob
400
401# `--action rotate-session` failures
402test_failure "missing arg after --action rotate-session" \
403 "Error: Missing session name." \
404 --condition event-rule-matches -u \
405 --action rotate-session
406test_failure "extra arg after --action rotate-session" \
407 "Error: Unexpected argument \`bob\`." \
408 --condition event-rule-matches -u \
409 --action rotate-session ze-session bob
410
411# `--action snapshot-session` failures
412test_failure "missing arg after --action snapshot-session" \
413 "Error: Missing session name." \
414 --condition event-rule-matches -u \
415 --action snapshot-session
416test_failure "extra arg after --action snapshot-session" \
417 "Error: Unexpected argument \`bob\`." \
418 --condition event-rule-matches -u \
419 --action snapshot-session ze-session bob
420test_failure "snapshot-session action, --max-size without destination" \
421 "Error: Can't provide a snapshot output max size without a snapshot output destination." \
422 --condition event-rule-matches -u \
423 --action snapshot-session ze-session --max-size 10M
424test_failure "snapshot-session action, --name without destination" \
425 "Error: Can't provide a snapshot output name without a snapshot output destination." \
426 --condition event-rule-matches -u \
427 --action snapshot-session ze-session --name hallo
428test_failure "snapshot-session action, --name with-local-path-instead-of-url" \
429 "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
430 --condition event-rule-matches -u \
431 --action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path
432test_failure "snapshot-session action, --name with-net-url-instead-of-path" \
433 "Error: Failed to parse 'net://8.8.8.8/' as a local path." \
434 --condition event-rule-matches -u \
435 --action snapshot-session ze-session --name hallo --path net://8.8.8.8/
436
437# Cleanup
438stop_lttng_sessiond_notap
439rm -f "${tmp_stdout}"
440rm -f "${tmp_stderr}"
This page took 0.023776 seconds and 4 git commands to generate.