Commit | Line | Data |
---|---|---|
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 | ||
20 | CURDIR="$(dirname "$0")" | |
21 | TESTDIR="$CURDIR/../../.." | |
22 | ||
23 | # shellcheck source=../../../utils/utils.sh | |
24 | source "$TESTDIR/utils/utils.sh" | |
25 | ||
ef9ff9cb | 26 | plan_tests 295 |
b4b7369f JR |
27 | |
28 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" | |
29 | ||
30 | # shellcheck disable=SC2119 | |
31 | start_lttng_sessiond_notap | |
32 | ||
8d5a3312 MJ |
33 | tmp_stdout=$(mktemp -t test_parse_cli_trigger_stdout.XXXXXX) |
34 | tmp_stderr=$(mktemp -t test_parse_cli_trigger_stderr.XXXXXX) | |
b4b7369f JR |
35 | uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary" |
36 | ||
b4b7369f JR |
37 | function test_success () |
38 | { | |
39 | local test_name="$1" | |
f674361c JG |
40 | local trigger_name="$2" |
41 | shift 2 | |
b4b7369f JR |
42 | |
43 | diag "${FULL_LTTNG_BIN} add-trigger $*" | |
44 | "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" | |
45 | ok $? "${test_name}: exit code is 0" | |
46 | ||
f674361c | 47 | diff -u "${tmp_stdout}" <(echo "Added trigger \`$trigger_name\`.") |
b4b7369f JR |
48 | ok $? "${test_name}: expected stdout" |
49 | ||
50 | diff -u "${tmp_stderr}" /dev/null | |
51 | ok $? "${test_name}: expected stderr" | |
52 | } | |
53 | ||
54 | function test_failure () | |
55 | { | |
56 | local test_name="$1" | |
57 | local error_msg="$2" | |
58 | ||
59 | shift 2 | |
60 | ||
61 | diag "${FULL_LTTNG_BIN} add-trigger $*" | |
62 | "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}" | |
63 | isnt $? 0 "${test_name}: exit code is not 0" | |
64 | ||
65 | diff -u "${tmp_stdout}" /dev/null | |
66 | ok $? "${test_name}: expected stdout" | |
67 | ||
68 | diff -u "${tmp_stderr}" <(echo "${error_msg}") | |
69 | ok $? "${test_name}: expected stderr" | |
70 | } | |
71 | ||
dceffc9e JR |
72 | function test_mi () |
73 | { | |
74 | local tmp_stdout_raw | |
75 | local tmp_expected_stdout | |
76 | ||
77 | # Concretely the code used to serialize a trigger object is the same as | |
78 | # the one used by the list command. Here we simply validate that a | |
79 | # simple trigger is correctly generated. | |
80 | ||
8d5a3312 MJ |
81 | tmp_stdout_raw=$(mktemp -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") |
82 | tmp_expected_stdout=$(mktemp -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX") | |
dceffc9e JR |
83 | |
84 | diag "${FULL_LTTNG_BIN} --mi=xml add-trigger" | |
85 | ||
86 | cat > "${tmp_expected_stdout}" <<- EOF | |
87 | <?xml version="1.0" encoding="UTF-8"?> | |
dcd975d1 | 88 | <command xmlns="https://lttng.org/xml/ns/lttng-mi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://lttng.org/xml/ns/lttng-mi https://lttng.org/xml/schemas/lttng-mi/${MI_XSD_MAJOR_VERSION}/lttng-mi-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd" schemaVersion="${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}"> |
dceffc9e JR |
89 | <name>add-trigger</name> |
90 | <output> | |
91 | <trigger> | |
92 | <name>mi_hohoho</name> | |
93 | <owner_uid>${UID}</owner_uid> | |
94 | <condition> | |
95 | <condition_event_rule_matches> | |
96 | <event_rule> | |
97 | <event_rule_user_tracepoint> | |
98 | <name_pattern>some-event-id</name_pattern> | |
99 | </event_rule_user_tracepoint> | |
100 | </event_rule> | |
101 | <capture_descriptors/> | |
102 | </condition_event_rule_matches> | |
103 | </condition> | |
104 | <action> | |
105 | <action_list> | |
106 | <action> | |
107 | <action_notify> | |
108 | <rate_policy> | |
109 | <rate_policy_every_n> | |
110 | <interval>1</interval> | |
111 | </rate_policy_every_n> | |
112 | </rate_policy> | |
113 | </action_notify> | |
114 | </action> | |
115 | </action_list> | |
116 | </action> | |
117 | </trigger> | |
118 | </output> | |
119 | <success>true</success> | |
120 | </command> | |
121 | EOF | |
122 | ||
123 | "${FULL_LTTNG_BIN}" --mi xml add-trigger --name mi_hohoho \ | |
124 | --condition event-rule-matches --name=some-event-id --type=user \ | |
125 | --action notify > "${tmp_stdout_raw}" 2> "${tmp_stderr}" | |
126 | ||
127 | ok $? "add-trigger mi: exit code is 0" | |
128 | ||
129 | # Pretty-fy xml before further test. | |
fa182fe0 | 130 | $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}" |
dceffc9e | 131 | |
fa182fe0 | 132 | $MI_VALIDATE "${tmp_stdout}" |
dceffc9e JR |
133 | ok $? "add-trigger mi is valid" |
134 | ||
135 | diff -u "${tmp_expected_stdout}" "${tmp_stdout}" | |
136 | ok $? "mi: expected stdout" | |
137 | ||
138 | diff -u "${tmp_stderr}" /dev/null | |
139 | ok $? "mi: expected stderr" | |
140 | ||
141 | rm -f "${tmp_stdout_raw}" | |
142 | } | |
143 | ||
b4b7369f | 144 | # top-level options |
f674361c | 145 | test_success "explicit name" "hohoho" \ |
1d4b59f2 | 146 | --name hohoho \ |
f674361c | 147 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
148 | --action notify |
149 | ||
665db063 | 150 | # `--condition event-rule-matches` successes |
695f7044 | 151 | test_success "--condition event-rule-matches some-event --type=user" \ |
f674361c JG |
152 | "some-event" \ |
153 | --name=some-event --condition event-rule-matches --type=user \ | |
b4b7369f JR |
154 | --action notify |
155 | ||
f674361c | 156 | test_success "--condition event-rule-matches --type=user" "trigger0" \ |
695f7044 | 157 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
158 | --action notify |
159 | ||
f674361c JG |
160 | test_success "notify action policies" "test-rate-policy-1" \ |
161 | --name=test-rate-policy-1 \ | |
162 | --condition event-rule-matches --type=user \ | |
b4b7369f | 163 | --action notify \ |
bbadb5e0 | 164 | --rate-policy=every:55 \ |
e45dd625 | 165 | --action notify \ |
bbadb5e0 | 166 | --rate-policy=once-after:55 |
b4b7369f | 167 | |
f674361c JG |
168 | test_success "start session action policies" "test-rate-policy-2" \ |
169 | --name=test-rate-policy-2 \ | |
170 | --condition event-rule-matches --type=user \ | |
e45dd625 | 171 | --action start-session my_session \ |
bbadb5e0 | 172 | --rate-policy=every:55 \ |
e45dd625 | 173 | --action start-session my_session \ |
bbadb5e0 | 174 | --rate-policy=once-after:55 |
e45dd625 | 175 | |
f674361c JG |
176 | test_success "stop session action policies" "test-rate-policy-3" \ |
177 | --name=test-rate-policy-3 \ | |
178 | --condition event-rule-matches --type=user \ | |
e45dd625 | 179 | --action stop-session my_session \ |
bbadb5e0 | 180 | --rate-policy=every:55 \ |
e45dd625 | 181 | --action stop-session my_session \ |
bbadb5e0 | 182 | --rate-policy=once-after:55 |
e45dd625 | 183 | |
f674361c JG |
184 | test_success "snapshot session action policies" "test-rate-policy-4" \ |
185 | --name=test-rate-policy-4 \ | |
186 | --condition event-rule-matches --type=user \ | |
e45dd625 | 187 | --action snapshot-session my_session \ |
bbadb5e0 | 188 | --rate-policy=every:55 \ |
e45dd625 | 189 | --action snapshot-session my_session \ |
bbadb5e0 | 190 | --rate-policy=once-after:55 |
e45dd625 | 191 | |
f674361c JG |
192 | test_success "rotate session action policies" "test-rate-policy-5" \ |
193 | --name=test-rate-policy-5 \ | |
194 | --condition event-rule-matches --type=user \ | |
e45dd625 | 195 | --action rotate-session my_session \ |
bbadb5e0 | 196 | --rate-policy=every:55 \ |
e45dd625 | 197 | --action rotate-session my_session \ |
bbadb5e0 | 198 | --rate-policy=once-after:55 |
b4b7369f | 199 | |
f674361c | 200 | test_success "--log-level single level" "trigger1" \ |
695f7044 | 201 | --condition event-rule-matches --type=user --log-level=INFO \ |
949f049b SM |
202 | --action notify |
203 | ||
f674361c | 204 | test_success "--log-level range open max" "trigger2" \ |
695f7044 | 205 | --condition event-rule-matches --type=user --log-level=INFO.. \ |
949f049b SM |
206 | --action notify |
207 | ||
f674361c | 208 | test_success "--log-level range any" "trigger3" \ |
695f7044 | 209 | --condition event-rule-matches --type=user --log-level=.. \ |
949f049b SM |
210 | --action notify |
211 | ||
f674361c | 212 | test_success "--exclude-name one" "trigger4" \ |
695f7044 | 213 | --condition event-rule-matches --type=user --name='bernard*' --exclude-name=bernard-lermite \ |
b03a81fb SM |
214 | --action notify |
215 | ||
f674361c | 216 | test_success "--exclude-name two" "trigger5" \ |
695f7044 | 217 | --condition event-rule-matches --type=user --name='jean-*' --exclude-name jean-chretien -x jean-charest \ |
b03a81fb SM |
218 | --action notify |
219 | ||
3a174400 | 220 | check_skip_kernel_test 18 "Skipping kprobe tests." || { |
f674361c JG |
221 | i=0 |
222 | ||
85522de5 | 223 | for type in kprobe kernel:kprobe; do |
f674361c JG |
224 | test_success "--condition event-rule-matches probe by symbol" "kprobe-trigger-$i" \ |
225 | --name="kprobe-trigger-$i" \ | |
695f7044 | 226 | --condition event-rule-matches --type=$type --location=lttng_channel_enable --event-name=my_channel_enable \ |
24de704e SM |
227 | --action notify |
228 | ||
229 | channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') | |
230 | channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ') | |
231 | ||
232 | # We need to find a valid offset. | |
233 | base_symbol="" | |
234 | offset=0 | |
235 | if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then | |
236 | base_symbol="lttng_channel_enable" | |
237 | offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr )) | |
238 | else | |
239 | base_symbol="lttng_channel_disable" | |
240 | offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr )) | |
241 | fi | |
242 | ||
243 | offset_hex="0x$(printf '%x' $offset)" | |
244 | ||
f674361c JG |
245 | |
246 | test_success "--condition event-rule-matches probe by symbol with offset" "kprobe-trigger-$((i+1))" \ | |
247 | --name="kprobe-trigger-$((i+1))" \ | |
695f7044 | 248 | --condition event-rule-matches --type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \ |
24de704e SM |
249 | --action notify |
250 | ||
f674361c JG |
251 | test_success "--condition event-rule-matches probe by address" "kprobe-trigger-$((i+2))" \ |
252 | --name="kprobe-trigger-$((i+2))" \ | |
695f7044 | 253 | --condition event-rule-matches --type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \ |
24de704e | 254 | --action notify |
f674361c | 255 | i=$((i+3)) |
24de704e | 256 | done |
b4b7369f JR |
257 | } |
258 | ||
3a174400 | 259 | check_skip_kernel_test 6 "Skipping uprobe tests." || { |
f674361c JG |
260 | test_success "--condition event-rule-matches uprobe" "uprobe-trigger-0" \ |
261 | --name="uprobe-trigger-0" \ | |
695f7044 | 262 | --condition event-rule-matches --type=kernel:uprobe --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \ |
46fd07ac | 263 | --action notify |
b4b7369f | 264 | |
f674361c JG |
265 | test_success "--condition event-rule-matches uprobe with elf prefix" "uprobe-trigger-1" \ |
266 | --name="uprobe-trigger-1" \ | |
695f7044 | 267 | --condition event-rule-matches --type=kernel:uprobe --location=elf:${uprobe_elf_binary}:test_function --event-name=ma-probe-2 \ |
46fd07ac | 268 | --action notify |
b4b7369f JR |
269 | } |
270 | ||
3a174400 | 271 | check_skip_kernel_test 30 "Skipping syscall tests." || { |
f674361c JG |
272 | test_success "--condition event-rule-matches one syscall" "syscall-trigger-0" \ |
273 | --name="syscall-trigger-0" \ | |
695f7044 | 274 | --condition event-rule-matches --type=syscall --name=open \ |
b4b7369f JR |
275 | --action notify |
276 | ||
f674361c JG |
277 | test_success "--condition event-rule-matches all syscalls" "syscall-trigger-1" \ |
278 | --name="syscall-trigger-1" \ | |
695f7044 | 279 | --condition event-rule-matches --type=syscall \ |
b4b7369f JR |
280 | --action notify |
281 | ||
f674361c JG |
282 | test_success "--condition event-rule-matches one syscall with filter" "syscall-trigger-2" \ |
283 | --name="syscall-trigger-2" \ | |
695f7044 | 284 | --condition event-rule-matches --type=syscall --filter 'a > 2' --name=open \ |
b4b7369f | 285 | --action notify |
f674361c JG |
286 | test_success "--condition event-rule-matches one syscall:entry" "syscall-trigger-3" \ |
287 | --name="syscall-trigger-3" \ | |
695f7044 | 288 | --condition event-rule-matches --type=syscall:entry --name=open \ |
57739a6b | 289 | --action notify |
f674361c JG |
290 | test_success "--condition event-rule-matches one syscall:exit" "syscall-trigger-4" \ |
291 | --name="syscall-trigger-4" \ | |
695f7044 | 292 | --condition event-rule-matches --type=syscall:exit --name=open \ |
57739a6b | 293 | --action notify |
f674361c JG |
294 | test_success "--condition event-rule-matches one syscall:entry-exit" "syscall-trigger-5" \ |
295 | --name="syscall-trigger-5" \ | |
695f7044 | 296 | --condition event-rule-matches --type=syscall:entry+exit --name=open \ |
57739a6b | 297 | --action notify |
4f7da553 JR |
298 | |
299 | # Same thing but with "kernel:syscall" type instead: | |
f674361c JG |
300 | test_success "--condition event-rule-matches one syscall" "syscall-trigger-6" \ |
301 | --name="syscall-trigger-6" \ | |
695f7044 | 302 | --condition event-rule-matches --type=kernel:syscall --name=open \ |
4f7da553 JR |
303 | --action notify |
304 | ||
f674361c JG |
305 | test_success "--condition event-rule-matches one kernel:syscall:entry" "syscall-trigger-7" \ |
306 | --name="syscall-trigger-7" \ | |
695f7044 | 307 | --condition event-rule-matches --type=kernel:syscall:entry --name=open \ |
4f7da553 | 308 | --action notify |
f674361c JG |
309 | test_success "--condition event-rule-matches one kernel:syscall:exit" "syscall-trigger-8" \ |
310 | --name="syscall-trigger-8" \ | |
695f7044 | 311 | --condition event-rule-matches --type=kernel:syscall:exit --name=open \ |
4f7da553 | 312 | --action notify |
f674361c JG |
313 | test_success "--condition event-rule-matches one kernel:syscall:entry-exit" "syscall-trigger-9" \ |
314 | --name="syscall-trigger-9" \ | |
695f7044 | 315 | --condition event-rule-matches --type=kernel:syscall:entry+exit --name=open \ |
4f7da553 JR |
316 | --action notify |
317 | ||
b4b7369f JR |
318 | } |
319 | ||
320 | # `--action notify` successes | |
f674361c JG |
321 | test_success "--action notify" "notify-1" \ |
322 | --name=notify-1 \ | |
695f7044 | 323 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
324 | --action notify |
325 | ||
f674361c JG |
326 | test_success "--action notify --capture foo" "notify-2" \ |
327 | --name=notify-2 \ | |
695f7044 | 328 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
329 | --capture foo --action notify |
330 | ||
f674361c JG |
331 | test_success "--action notify --capture foo[2]" "notify-3" \ |
332 | --name=notify-3 \ | |
695f7044 | 333 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
334 | --capture 'foo[2]' --action notify |
335 | ||
f674361c JG |
336 | test_success '--action notify --capture $ctx.foo' "notify-4" \ |
337 | --name=notify-4 \ | |
695f7044 | 338 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
339 | --capture '$ctx.foo' --action notify |
340 | ||
f674361c JG |
341 | test_success '--action notify --capture $ctx.foo[2]' "notify-5" \ |
342 | --name=notify-5 \ | |
695f7044 | 343 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
344 | --capture '$ctx.foo[2]' --action notify |
345 | ||
f674361c JG |
346 | test_success '--action notify --capture $app.prov:type' "notify-6" \ |
347 | --name=notify-6 \ | |
695f7044 | 348 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
349 | --capture '$app.prov:type' --action notify |
350 | ||
f674361c JG |
351 | test_success '--action notify --capture $app.prov:type[2]' "notify-7" \ |
352 | --name=notify-7 \ | |
695f7044 | 353 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
354 | --capture '$app.prov:type[2]' --action notify |
355 | ||
f674361c JG |
356 | test_success '--action notify multiple captures' "notify-8" \ |
357 | --name=notify-8 \ | |
695f7044 | 358 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
359 | --capture foo --capture '$app.hello:world' --action notify |
360 | ||
b4b7369f | 361 | # `--action start-session` successes |
f674361c JG |
362 | test_success "--action start-session" "notify-9" \ |
363 | --name=notify-9 \ | |
695f7044 | 364 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
365 | --action start-session ze-session |
366 | ||
367 | # `--action stop-session` successes | |
f674361c JG |
368 | test_success "--action stop-session foo" "notify-10"\ |
369 | --name=notify-10 \ | |
695f7044 | 370 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
371 | --action stop-session ze-session |
372 | ||
373 | # `--action rotate-session` successes | |
f674361c JG |
374 | test_success "--action rotate-session foo" "notify-11"\ |
375 | --name=notify-11 \ | |
695f7044 | 376 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
377 | --action rotate-session ze-session |
378 | ||
379 | # `--action snapshot-session` successes | |
f674361c JG |
380 | test_success "--action snapshot-session foo" "notify-12"\ |
381 | --name=notify-12 \ | |
695f7044 | 382 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
383 | --action snapshot-session ze-session |
384 | ||
f674361c JG |
385 | test_success "--action snapshot-session with file URI" "notify-13"\ |
386 | --name=notify-13 \ | |
695f7044 | 387 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
388 | --action snapshot-session ze-session --path /hello |
389 | ||
f674361c JG |
390 | test_success "--action snapshot-session with net URI" "notify-14"\ |
391 | --name=notify-14 \ | |
695f7044 | 392 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
393 | --action snapshot-session ze-session --url net://1.2.3.4 |
394 | ||
f674361c JG |
395 | test_success "--action snapshot-session with ctrl/data URIs" "notify-15"\ |
396 | --name=notify-15 \ | |
695f7044 | 397 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
398 | --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1234 --data-url=tcp://1.2.3.4:1235 |
399 | ||
400 | # top-level failures | |
401 | test_failure "no args" "Error: Missing --condition." | |
402 | ||
403 | test_failure "unknown option" \ | |
35c4b2b3 | 404 | "Error: While parsing argument #2 (\`--hello\`): Unknown option \`--hello\`" \ |
b4b7369f JR |
405 | --hello |
406 | ||
407 | test_failure "missing --action" \ | |
408 | "Error: Need at least one --action." \ | |
695f7044 | 409 | --condition event-rule-matches --type=user |
b4b7369f JR |
410 | |
411 | test_failure "two --condition" \ | |
412 | "Error: A --condition was already given." \ | |
695f7044 JR |
413 | --condition event-rule-matches --name=aaa --type=user \ |
414 | --condition event-rule-matches --name=bbb --type=user \ | |
b4b7369f JR |
415 | --action notify |
416 | ||
1d4b59f2 | 417 | test_failure "missing argument to --name" \ |
35c4b2b3 | 418 | "Error: While parsing argument #2 (\`--name\`): Missing required argument for option \`--name\`" \ |
1d4b59f2 | 419 | --name |
b4b7369f | 420 | |
bbadb5e0 | 421 | for cmd in rate-policy=once-after rate-policy=every; do |
b4b7369f | 422 | test_failure "missing argument to --${cmd}" \ |
bbadb5e0 | 423 | "Error: Rate policy format is invalid." \ |
695f7044 | 424 | --condition event-rule-matches --type=user --action notify \ |
b4b7369f JR |
425 | --${cmd} |
426 | ||
427 | test_failure "invalid argument to --${cmd}: non-digit character" \ | |
bbadb5e0 | 428 | "Error: Failed to parse rate policy value \`123bob\` as an integer." \ |
695f7044 | 429 | --condition event-rule-matches --type=user --action notify \ |
bbadb5e0 | 430 | --${cmd}:123bob |
b4b7369f JR |
431 | |
432 | test_failure "invalid argument to --${cmd}: empty string" \ | |
bbadb5e0 | 433 | "Error: Failed to parse rate policy value \`\` as an integer." \ |
695f7044 | 434 | --condition event-rule-matches --type=user --action notify \ |
bbadb5e0 | 435 | --${cmd}":" |
b4b7369f JR |
436 | done |
437 | ||
bbadb5e0 JR |
438 | test_failure "invalid argument to --rate-policy: unknown policy type" \ |
439 | "Error: Rate policy type \`bob\` unknown." \ | |
695f7044 | 440 | --condition event-rule-matches --type=user --action notify \ |
bbadb5e0 JR |
441 | --rate-policy=bob:123 |
442 | ||
b4b7369f JR |
443 | # `--condition` failures |
444 | test_failure "missing args after --condition" \ | |
ef9ff9cb SM |
445 | "Error: While parsing argument #2 (\`--condition\`): Missing required argument for option \`--condition\` |
446 | Error: Valid condition names are: | |
447 | Error: event-rule-matches" \ | |
b4b7369f JR |
448 | --condition |
449 | test_failure "unknown --condition" \ | |
ef9ff9cb SM |
450 | "Error: While parsing argument #2 (\`--condition\`): Unknown condition name 'zoofest' |
451 | Error: Valid condition names are: | |
452 | Error: event-rule-matches" \ | |
b4b7369f | 453 | --condition zoofest |
e776cf47 | 454 | test_failure "unknown --condition=" \ |
ef9ff9cb SM |
455 | "Error: While parsing argument #2 (\`--condition=zoofest\`): Unknown condition name 'zoofest' |
456 | Error: Valid condition names are: | |
457 | Error: event-rule-matches" \ | |
e776cf47 | 458 | --condition=zoofest |
b4b7369f | 459 | |
665db063 SM |
460 | # `--condition event-rule-matches` failures |
461 | test_failure "missing args after --condition event-rule-matches" \ | |
695f7044 | 462 | "Error: Need at least one --action." \ |
0b621ec1 | 463 | --condition event-rule-matches --type=user |
50ad0862 | 464 | |
665db063 | 465 | test_failure "extra args after --condition event-rule-matches" \ |
b4b7369f | 466 | "Error: Unexpected argument 'bozo'" \ |
695f7044 | 467 | --condition event-rule-matches --type=user bozo |
64c34630 | 468 | |
949f049b SM |
469 | test_failure "--log-level unknown level" \ |
470 | "Error: Failed to parse log level string \`FOO\`." \ | |
695f7044 | 471 | --condition event-rule-matches --type=user --log-level=FOO |
b4b7369f | 472 | |
85522de5 | 473 | for type in kprobe kernel:kprobe; do |
24de704e | 474 | test_failure "--condition event-rule-matches: --name with --type=$type" \ |
85522de5 | 475 | "Error: Can't use --name with kernel kprobe event rules." \ |
24de704e SM |
476 | --condition event-rule-matches --type=$type --location=do_sys_open --name='hello' |
477 | done | |
478 | ||
695f7044 JR |
479 | test_failure "--condition event-rule-matches: --location with user tracepoint event rule" \ |
480 | "Error: Can't use --location with user tracepoint event rules." \ | |
481 | --condition event-rule-matches --type=user --location='hello' | |
b4b7369f | 482 | |
695f7044 JR |
483 | test_failure "--condition event-rule-matches: --event-name with user tracepoint event rule" \ |
484 | "Error: Can't use --event-name with user tracepoint event rules." \ | |
485 | --condition event-rule-matches --type=user --event-name='hello' | |
50ad0862 | 486 | |
46fd07ac JR |
487 | test_failure "--condition event-rule-matches: extra argument with --type=kernel:uprobe" \ |
488 | "Error: Unexpected argument 'hello'" \ | |
695f7044 | 489 | --condition event-rule-matches --type=$type --location=${uprobe_elf_binary}:test_failure hello |
b4b7369f | 490 | |
24de704e | 491 | test_failure "--condition event-rule-matches: extra argument with --type=syscall" \ |
b4b7369f | 492 | "Error: Unexpected argument 'open'" \ |
695f7044 | 493 | --condition event-rule-matches --type=syscall open |
b4b7369f | 494 | |
57739a6b JR |
495 | test_failure "--condition event-rule-matches: --type=syscall:nope" \ |
496 | "Error: Failed to parse syscall type 'syscall:nope'." \ | |
695f7044 | 497 | --condition event-rule-matches --type=syscall:nope \ |
57739a6b JR |
498 | --name=open |
499 | ||
b03a81fb | 500 | test_failure "--exclude-name with non-glob name" \ |
13c25a5c | 501 | "Error: Event name pattern must contain wildcard characters to use exclusions" \ |
695f7044 | 502 | --condition event-rule-matches --type=user --name='jean' --exclude-name jean-chretien \ |
b03a81fb SM |
503 | --action notify |
504 | ||
665db063 | 505 | test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \ |
35c4b2b3 | 506 | 'Error: While parsing argument #7 (`--capture`): Missing required argument for option `--capture`' \ |
20a01d15 | 507 | --action notify \ |
695f7044 | 508 | --condition event-rule-matches --type=user --capture |
20a01d15 | 509 | |
665db063 | 510 | test_failure "--condition event-rule-matches --capture: missing argument (before another option)" \ |
20a01d15 | 511 | 'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \ |
695f7044 | 512 | --condition event-rule-matches --type=user --capture \ |
20a01d15 SM |
513 | --action notify \ |
514 | ||
665db063 | 515 | test_failure "--condition event-rule-matches --capture: binary operator" \ |
20a01d15 | 516 | 'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \ |
695f7044 | 517 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
518 | --capture 'foo == 2' --action notify |
519 | ||
665db063 | 520 | test_failure "--condition event-rule-matches --capture: unary operator" \ |
20a01d15 | 521 | 'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \ |
695f7044 | 522 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
523 | --capture '!foo' --action notify |
524 | ||
665db063 | 525 | test_failure "--condition event-rule-matches --capture: logical operator" \ |
20a01d15 | 526 | 'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \ |
695f7044 | 527 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
528 | --capture 'foo || bar' --action notify |
529 | ||
665db063 | 530 | test_failure "--condition event-rule-matches --capture: accessing a sub-field" \ |
20a01d15 | 531 | 'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \ |
695f7044 | 532 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
533 | --capture 'foo.bar' --action notify |
534 | ||
665db063 | 535 | test_failure "--condition event-rule-matches --capture: accessing the sub-field of an array element" \ |
20a01d15 | 536 | 'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \ |
695f7044 | 537 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
538 | --capture 'foo[3].bar' --action notify |
539 | ||
665db063 | 540 | test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \ |
20a01d15 | 541 | 'Error: Invalid app-specific context field name: missing colon in `foo`.' \ |
695f7044 | 542 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
543 | --capture '$app.foo' --action notify |
544 | ||
665db063 | 545 | test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \ |
20a01d15 | 546 | 'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \ |
695f7044 | 547 | --condition event-rule-matches --type=user \ |
20a01d15 SM |
548 | --capture '$app.foo:' --action notify |
549 | ||
b4b7369f JR |
550 | # `--action` failures |
551 | test_failure "missing args after --action" \ | |
ef9ff9cb SM |
552 | "Error: While parsing argument #5 (\`--action\`): Missing required argument for option \`--action\` |
553 | Error: Valid action names are: | |
554 | Error: notify" \ | |
695f7044 | 555 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
556 | --action |
557 | ||
ef9ff9cb SM |
558 | test_failure "unknown --action" \ |
559 | "Error: While parsing argument #5 (\`--action\`): Unknown action name 'zoofest' | |
560 | Error: Valid action names are: | |
561 | Error: notify" \ | |
562 | --condition event-rule-matches --type=user \ | |
563 | --action zoofest | |
564 | ||
565 | test_failure "unknown --action=" \ | |
566 | "Error: While parsing argument #5 (\`--action=zoofest\`): Unknown action name 'zoofest' | |
567 | Error: Valid action names are: | |
568 | Error: notify" \ | |
569 | --condition event-rule-matches --type=user \ | |
570 | --action=zoofest | |
571 | ||
b4b7369f JR |
572 | # `--action notify` failures |
573 | test_failure "extra arg after --action notify" \ | |
574 | "Error: Unexpected argument \`bob\`." \ | |
695f7044 | 575 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
576 | --action notify bob |
577 | ||
578 | # `--action start-session` failures | |
579 | test_failure "missing arg after --action start-session" \ | |
580 | "Error: Missing session name." \ | |
695f7044 | 581 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
582 | --action start-session |
583 | test_failure "extra arg after --action start-session" \ | |
584 | "Error: Unexpected argument \`bob\`." \ | |
695f7044 | 585 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
586 | --action start-session ze-session bob |
587 | ||
588 | # `--action stop-session` failures | |
589 | test_failure "missing arg after --action stop-session" \ | |
590 | "Error: Missing session name." \ | |
695f7044 | 591 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
592 | --action stop-session |
593 | test_failure "extra arg after --action stop-session" \ | |
594 | "Error: Unexpected argument \`bob\`." \ | |
695f7044 | 595 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
596 | --action stop-session ze-session bob |
597 | ||
598 | # `--action rotate-session` failures | |
599 | test_failure "missing arg after --action rotate-session" \ | |
600 | "Error: Missing session name." \ | |
695f7044 | 601 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
602 | --action rotate-session |
603 | test_failure "extra arg after --action rotate-session" \ | |
604 | "Error: Unexpected argument \`bob\`." \ | |
695f7044 | 605 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
606 | --action rotate-session ze-session bob |
607 | ||
608 | # `--action snapshot-session` failures | |
609 | test_failure "missing arg after --action snapshot-session" \ | |
610 | "Error: Missing session name." \ | |
695f7044 | 611 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
612 | --action snapshot-session |
613 | test_failure "extra arg after --action snapshot-session" \ | |
614 | "Error: Unexpected argument \`bob\`." \ | |
695f7044 | 615 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
616 | --action snapshot-session ze-session bob |
617 | test_failure "snapshot-session action, --max-size without destination" \ | |
618 | "Error: Can't provide a snapshot output max size without a snapshot output destination." \ | |
695f7044 | 619 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
620 | --action snapshot-session ze-session --max-size 10M |
621 | test_failure "snapshot-session action, --name without destination" \ | |
622 | "Error: Can't provide a snapshot output name without a snapshot output destination." \ | |
695f7044 | 623 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
624 | --action snapshot-session ze-session --name hallo |
625 | test_failure "snapshot-session action, --name with-local-path-instead-of-url" \ | |
626 | "Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \ | |
695f7044 | 627 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
628 | --action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path |
629 | test_failure "snapshot-session action, --name with-net-url-instead-of-path" \ | |
630 | "Error: Failed to parse 'net://8.8.8.8/' as a local path." \ | |
695f7044 | 631 | --condition event-rule-matches --type=user \ |
b4b7369f JR |
632 | --action snapshot-session ze-session --name hallo --path net://8.8.8.8/ |
633 | ||
dceffc9e JR |
634 | test_mi |
635 | ||
b4b7369f JR |
636 | # Cleanup |
637 | stop_lttng_sessiond_notap | |
638 | rm -f "${tmp_stdout}" | |
639 | rm -f "${tmp_stderr}" |