File: test_add_trigger_cli

package info (click to toggle)
ltt-control 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,860 kB
  • sloc: cpp: 192,012; sh: 28,777; ansic: 10,960; python: 7,108; makefile: 3,520; java: 109; xml: 46
file content (639 lines) | stat: -rwxr-xr-x 24,417 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
#!/bin/bash
#
# Copyright (C) - 2020 EfficiOS, inc
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; version 2.1 of the License.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

# Test the `lttng add-trigger` command line interface.

CURDIR="$(dirname "$0")"
TESTDIR="$CURDIR/../../.."

# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"

plan_tests 295

FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"

# shellcheck disable=SC2119
start_lttng_sessiond_notap

tmp_stdout=$(mktemp -t test_parse_cli_trigger_stdout.XXXXXX)
tmp_stderr=$(mktemp -t test_parse_cli_trigger_stderr.XXXXXX)
uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary"

function test_success ()
{
	local test_name="$1"
	local trigger_name="$2"
	shift 2

	diag "${FULL_LTTNG_BIN} add-trigger $*"
	"${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
	ok $? "${test_name}: exit code is 0"

	diff -u "${tmp_stdout}" <(echo "Added trigger \`$trigger_name\`.")
	ok $? "${test_name}: expected stdout"

	diff -u "${tmp_stderr}" /dev/null
	ok $? "${test_name}: expected stderr"
}

function test_failure ()
{
	local test_name="$1"
	local error_msg="$2"

	shift 2

	diag "${FULL_LTTNG_BIN} add-trigger $*"
	"${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
	isnt $? 0 "${test_name}: exit code is not 0"

	diff -u "${tmp_stdout}" /dev/null
	ok $? "${test_name}: expected stdout"

	diff -u "${tmp_stderr}" <(echo "${error_msg}")
	ok $? "${test_name}: expected stderr"
}

function test_mi ()
{
	local tmp_stdout_raw
	local tmp_expected_stdout

	# Concretely the code used to serialize a trigger object is the same as
	# the one used by the list command. Here we simply validate that a
	# simple trigger is correctly generated.

	tmp_stdout_raw=$(mktemp -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX")
	tmp_expected_stdout=$(mktemp -t "tmp.${FUNCNAME[0]}_expected_stdout.XXXXXX")

	diag "${FULL_LTTNG_BIN} --mi=xml add-trigger"

	cat > "${tmp_expected_stdout}" <<- EOF
	<?xml version="1.0" encoding="UTF-8"?>
	<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}">
	  <name>add-trigger</name>
	  <output>
	    <trigger>
	      <name>mi_hohoho</name>
	      <owner_uid>${UID}</owner_uid>
	      <condition>
	        <condition_event_rule_matches>
	          <event_rule>
	            <event_rule_user_tracepoint>
	              <name_pattern>some-event-id</name_pattern>
	            </event_rule_user_tracepoint>
	          </event_rule>
	          <capture_descriptors/>
	        </condition_event_rule_matches>
	      </condition>
	      <action>
	        <action_list>
	          <action>
	            <action_notify>
	              <rate_policy>
	                <rate_policy_every_n>
	                  <interval>1</interval>
	                </rate_policy_every_n>
	              </rate_policy>
	            </action_notify>
	          </action>
	        </action_list>
	      </action>
	    </trigger>
	  </output>
	  <success>true</success>
	</command>
	EOF

	"${FULL_LTTNG_BIN}" --mi xml add-trigger --name mi_hohoho \
		--condition event-rule-matches --name=some-event-id --type=user \
		--action notify > "${tmp_stdout_raw}" 2> "${tmp_stderr}"

	ok $? "add-trigger mi: exit code is 0"

	# Pretty-fy xml before further test.
	$XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}"

	$MI_VALIDATE "${tmp_stdout}"
	ok $? "add-trigger mi is valid"

	diff -u "${tmp_expected_stdout}" "${tmp_stdout}"
	ok $? "mi: expected stdout"

	diff -u "${tmp_stderr}" /dev/null
	ok $? "mi: expected stderr"

	rm -f "${tmp_stdout_raw}"
}

# top-level options
test_success "explicit name" "hohoho" \
	--name hohoho \
	--condition event-rule-matches --type=user \
	--action notify

# `--condition event-rule-matches` successes
test_success "--condition event-rule-matches some-event --type=user" \
	"some-event" \
	 --name=some-event --condition event-rule-matches --type=user \
	--action notify

test_success "--condition event-rule-matches --type=user" "trigger0" \
	--condition event-rule-matches --type=user \
	--action notify

test_success "notify action policies" "test-rate-policy-1" \
	--name=test-rate-policy-1 \
	--condition event-rule-matches --type=user \
	--action notify \
	--rate-policy=every:55 \
	--action notify \
	--rate-policy=once-after:55

test_success "start session action policies" "test-rate-policy-2" \
	--name=test-rate-policy-2 \
	--condition event-rule-matches --type=user \
	--action start-session my_session \
	--rate-policy=every:55 \
	--action start-session my_session \
	--rate-policy=once-after:55

test_success "stop session action policies" "test-rate-policy-3" \
	--name=test-rate-policy-3 \
	--condition event-rule-matches --type=user \
	--action stop-session my_session \
	--rate-policy=every:55 \
	--action stop-session my_session \
	--rate-policy=once-after:55

test_success "snapshot session action policies" "test-rate-policy-4" \
	--name=test-rate-policy-4 \
	--condition event-rule-matches --type=user \
	--action snapshot-session my_session \
	--rate-policy=every:55 \
	--action snapshot-session my_session \
	--rate-policy=once-after:55

test_success "rotate session action policies" "test-rate-policy-5" \
	--name=test-rate-policy-5 \
	--condition event-rule-matches --type=user \
	--action rotate-session my_session \
	--rate-policy=every:55 \
	--action rotate-session my_session \
	--rate-policy=once-after:55

test_success "--log-level single level" "trigger1" \
	--condition event-rule-matches --type=user --log-level=INFO \
	--action notify

test_success "--log-level range open max" "trigger2" \
	--condition event-rule-matches --type=user --log-level=INFO.. \
	--action notify

test_success "--log-level range any" "trigger3" \
	--condition event-rule-matches --type=user --log-level=.. \
	--action notify

test_success "--exclude-name one" "trigger4" \
	--condition event-rule-matches --type=user --name='bernard*' --exclude-name=bernard-lermite \
	--action notify

test_success "--exclude-name two" "trigger5" \
	--condition event-rule-matches --type=user --name='jean-*' --exclude-name jean-chretien -x jean-charest \
	--action notify

check_skip_kernel_test 18 "Skipping kprobe tests." || {
	i=0

	for type in kprobe kernel:kprobe; do
		test_success "--condition event-rule-matches probe by symbol" "kprobe-trigger-$i" \
			--name="kprobe-trigger-$i" \
			--condition event-rule-matches --type=$type --location=lttng_channel_enable --event-name=my_channel_enable \
			--action notify

		channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
		channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')

		# We need to find a valid offset.
		base_symbol=""
		offset=0
		if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
			base_symbol="lttng_channel_enable"
			offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
		else
			base_symbol="lttng_channel_disable"
			offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
		fi

		offset_hex="0x$(printf '%x' $offset)"


		test_success "--condition event-rule-matches probe by symbol with offset" "kprobe-trigger-$((i+1))" \
			--name="kprobe-trigger-$((i+1))" \
			--condition event-rule-matches --type=$type --location="${base_symbol}+${offset_hex}" --event-name=my_$base_symbol \
			--action notify

		test_success "--condition event-rule-matches probe by address" "kprobe-trigger-$((i+2))" \
			--name="kprobe-trigger-$((i+2))" \
			--condition event-rule-matches --type=$type --location="0x${channel_enable_addr}" --event-name=my_channel_enable \
			--action notify
		i=$((i+3))
	done
}

check_skip_kernel_test 6 "Skipping uprobe tests." || {
	test_success "--condition event-rule-matches uprobe" "uprobe-trigger-0" \
		--name="uprobe-trigger-0" \
		--condition event-rule-matches --type=kernel:uprobe --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \
		--action notify

	test_success "--condition event-rule-matches uprobe with elf prefix" "uprobe-trigger-1" \
		--name="uprobe-trigger-1" \
		--condition event-rule-matches --type=kernel:uprobe --location=elf:${uprobe_elf_binary}:test_function --event-name=ma-probe-2 \
		--action notify
}

check_skip_kernel_test 30 "Skipping syscall tests." || {
	test_success "--condition event-rule-matches one syscall" "syscall-trigger-0" \
		--name="syscall-trigger-0" \
		--condition event-rule-matches --type=syscall --name=open \
		--action notify

	test_success "--condition event-rule-matches all syscalls" "syscall-trigger-1" \
		--name="syscall-trigger-1" \
		--condition event-rule-matches --type=syscall \
		--action notify

	test_success "--condition event-rule-matches one syscall with filter" "syscall-trigger-2" \
		--name="syscall-trigger-2" \
		--condition event-rule-matches --type=syscall --filter 'a > 2' --name=open \
		--action notify
	test_success "--condition event-rule-matches one syscall:entry" "syscall-trigger-3" \
		--name="syscall-trigger-3" \
		--condition event-rule-matches --type=syscall:entry --name=open \
		--action notify
	test_success "--condition event-rule-matches one syscall:exit" "syscall-trigger-4" \
		--name="syscall-trigger-4" \
		--condition event-rule-matches --type=syscall:exit --name=open \
		--action notify
	test_success "--condition event-rule-matches one syscall:entry-exit" "syscall-trigger-5" \
		--name="syscall-trigger-5" \
		--condition event-rule-matches --type=syscall:entry+exit --name=open \
		--action notify

	# Same thing but with "kernel:syscall" type instead:
	test_success "--condition event-rule-matches one syscall" "syscall-trigger-6" \
		--name="syscall-trigger-6" \
		--condition event-rule-matches --type=kernel:syscall --name=open \
		--action notify

	test_success "--condition event-rule-matches one kernel:syscall:entry" "syscall-trigger-7" \
		--name="syscall-trigger-7" \
		--condition event-rule-matches --type=kernel:syscall:entry --name=open \
		--action notify
	test_success "--condition event-rule-matches one kernel:syscall:exit" "syscall-trigger-8" \
		--name="syscall-trigger-8" \
		--condition event-rule-matches --type=kernel:syscall:exit --name=open \
		--action notify
	test_success "--condition event-rule-matches one kernel:syscall:entry-exit" "syscall-trigger-9" \
		--name="syscall-trigger-9" \
		--condition event-rule-matches --type=kernel:syscall:entry+exit --name=open \
		--action notify

}

# `--action notify` successes
test_success "--action notify" "notify-1" \
	--name=notify-1 \
	--condition event-rule-matches --type=user \
	--action notify

test_success "--action notify --capture foo" "notify-2" \
	--name=notify-2 \
	--condition event-rule-matches --type=user \
	--capture foo --action notify

test_success "--action notify --capture foo[2]" "notify-3" \
	--name=notify-3 \
	--condition event-rule-matches --type=user \
	--capture 'foo[2]' --action notify

test_success '--action notify --capture $ctx.foo' "notify-4" \
	--name=notify-4 \
	--condition event-rule-matches --type=user \
	--capture '$ctx.foo' --action notify

test_success '--action notify --capture $ctx.foo[2]' "notify-5" \
	--name=notify-5 \
	--condition event-rule-matches --type=user \
	--capture '$ctx.foo[2]' --action notify

test_success '--action notify --capture $app.prov:type' "notify-6" \
	--name=notify-6 \
	--condition event-rule-matches --type=user \
	--capture '$app.prov:type' --action notify

test_success '--action notify --capture $app.prov:type[2]' "notify-7" \
	--name=notify-7 \
	--condition event-rule-matches --type=user \
	--capture '$app.prov:type[2]' --action notify

test_success '--action notify multiple captures' "notify-8" \
	--name=notify-8 \
	--condition event-rule-matches --type=user \
	--capture foo --capture '$app.hello:world' --action notify

# `--action start-session` successes
test_success "--action start-session" "notify-9" \
	--name=notify-9 \
	--condition event-rule-matches --type=user \
	--action start-session ze-session

# `--action stop-session` successes
test_success "--action stop-session foo" "notify-10"\
	--name=notify-10 \
	--condition event-rule-matches --type=user \
	--action stop-session ze-session

# `--action rotate-session` successes
test_success "--action rotate-session foo" "notify-11"\
	--name=notify-11 \
	--condition event-rule-matches --type=user \
	--action rotate-session ze-session

# `--action snapshot-session` successes
test_success "--action snapshot-session foo" "notify-12"\
	--name=notify-12 \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session

test_success "--action snapshot-session with file URI" "notify-13"\
	--name=notify-13 \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --path /hello

test_success "--action snapshot-session with net URI" "notify-14"\
	--name=notify-14 \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --url net://1.2.3.4

test_success "--action snapshot-session with ctrl/data URIs" "notify-15"\
	--name=notify-15 \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1234 --data-url=tcp://1.2.3.4:1235

# top-level failures
test_failure "no args" "Error: Missing --condition."

test_failure "unknown option" \
	"Error: While parsing argument #2 (\`--hello\`): Unknown option \`--hello\`" \
	--hello

test_failure "missing --action" \
	"Error: Need at least one --action." \
	--condition event-rule-matches --type=user

test_failure "two --condition" \
	"Error: A --condition was already given." \
	--condition event-rule-matches --name=aaa --type=user \
	--condition event-rule-matches --name=bbb --type=user \
	--action notify

test_failure "missing argument to --name" \
	"Error: While parsing argument #2 (\`--name\`): Missing required argument for option \`--name\`" \
	--name

for cmd in rate-policy=once-after rate-policy=every; do
	test_failure "missing argument to --${cmd}" \
		"Error: Rate policy format is invalid." \
		--condition event-rule-matches --type=user --action notify \
		--${cmd}

	test_failure "invalid argument to --${cmd}: non-digit character" \
		"Error: Failed to parse rate policy value \`123bob\` as an integer." \
		--condition event-rule-matches --type=user --action notify \
		--${cmd}:123bob

	test_failure "invalid argument to --${cmd}: empty string" \
		"Error: Failed to parse rate policy value \`\` as an integer." \
		--condition event-rule-matches --type=user --action notify \
		--${cmd}":"
done

test_failure "invalid argument to --rate-policy: unknown policy type" \
	"Error: Rate policy type \`bob\` unknown." \
	--condition event-rule-matches --type=user --action notify \
	--rate-policy=bob:123

# `--condition` failures
test_failure "missing args after --condition" \
	"Error: While parsing argument #2 (\`--condition\`): Missing required argument for option \`--condition\`
Error: Valid condition names are:
Error:   event-rule-matches" \
	--condition
test_failure "unknown --condition" \
	"Error: While parsing argument #2 (\`--condition\`): Unknown condition name 'zoofest'
Error: Valid condition names are:
Error:   event-rule-matches" \
	--condition zoofest
test_failure "unknown --condition=" \
	"Error: While parsing argument #2 (\`--condition=zoofest\`): Unknown condition name 'zoofest'
Error: Valid condition names are:
Error:   event-rule-matches" \
	--condition=zoofest

# `--condition event-rule-matches` failures
test_failure "missing args after --condition event-rule-matches" \
	"Error: Need at least one --action." \
	--condition event-rule-matches --type=user

test_failure "extra args after --condition event-rule-matches" \
	"Error: Unexpected argument 'bozo'" \
	--condition event-rule-matches --type=user bozo

test_failure "--log-level unknown level" \
	"Error: Failed to parse log level string \`FOO\`." \
	--condition event-rule-matches --type=user --log-level=FOO

for type in kprobe kernel:kprobe; do
	test_failure "--condition event-rule-matches: --name with --type=$type" \
		"Error: Can't use --name with kernel kprobe event rules." \
		--condition event-rule-matches --type=$type --location=do_sys_open --name='hello'
done

test_failure "--condition event-rule-matches: --location with user tracepoint event rule" \
	"Error: Can't use --location with user tracepoint event rules." \
	--condition event-rule-matches --type=user --location='hello'

test_failure "--condition event-rule-matches: --event-name with user tracepoint event rule" \
	"Error: Can't use --event-name with user tracepoint event rules." \
	--condition event-rule-matches --type=user --event-name='hello'

test_failure "--condition event-rule-matches: extra argument with --type=kernel:uprobe" \
	"Error: Unexpected argument 'hello'" \
	--condition event-rule-matches --type=$type --location=${uprobe_elf_binary}:test_failure hello

test_failure "--condition event-rule-matches: extra argument with --type=syscall" \
	"Error: Unexpected argument 'open'" \
	--condition event-rule-matches --type=syscall open

test_failure "--condition event-rule-matches: --type=syscall:nope" \
	"Error: Failed to parse syscall type 'syscall:nope'." \
	--condition event-rule-matches --type=syscall:nope \
	--name=open

test_failure "--exclude-name with non-glob name" \
	"Error: Event name pattern must contain wildcard characters to use exclusions" \
	--condition event-rule-matches --type=user --name='jean' --exclude-name jean-chretien \
	--action notify

test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \
	'Error: While parsing argument #7 (`--capture`): Missing required argument for option `--capture`' \
	--action notify \
	--condition event-rule-matches --type=user --capture

test_failure "--condition event-rule-matches --capture: missing argument (before another option)" \
	'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
	--condition event-rule-matches --type=user --capture \
	--action notify \

test_failure "--condition event-rule-matches --capture: binary operator" \
	'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
	--condition event-rule-matches --type=user \
	--capture 'foo == 2' --action notify

test_failure "--condition event-rule-matches --capture: unary operator" \
	'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
	--condition event-rule-matches --type=user \
	--capture '!foo' --action notify

test_failure "--condition event-rule-matches --capture: logical operator" \
	'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
	--condition event-rule-matches --type=user \
	--capture 'foo || bar' --action notify

test_failure "--condition event-rule-matches --capture: accessing a sub-field" \
	'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
	--condition event-rule-matches --type=user \
	--capture 'foo.bar' --action notify

test_failure "--condition event-rule-matches --capture: accessing the sub-field of an array element" \
	'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
	--condition event-rule-matches --type=user \
	--capture 'foo[3].bar' --action notify

test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
	'Error: Invalid app-specific context field name: missing colon in `foo`.' \
	--condition event-rule-matches --type=user \
	--capture '$app.foo' --action notify

test_failure "--condition event-rule-matches --capture: missing colon in app-specific context field" \
	'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
	--condition event-rule-matches --type=user \
	--capture '$app.foo:' --action notify

# `--action` failures
test_failure "missing args after --action" \
	"Error: While parsing argument #5 (\`--action\`): Missing required argument for option \`--action\`
Error: Valid action names are:
Error:   notify" \
	--condition event-rule-matches --type=user \
	--action

test_failure "unknown --action" \
	"Error: While parsing argument #5 (\`--action\`): Unknown action name 'zoofest'
Error: Valid action names are:
Error:   notify" \
	--condition event-rule-matches --type=user \
	--action zoofest

test_failure "unknown --action=" \
	"Error: While parsing argument #5 (\`--action=zoofest\`): Unknown action name 'zoofest'
Error: Valid action names are:
Error:   notify" \
	--condition event-rule-matches --type=user \
	--action=zoofest

# `--action notify` failures
test_failure "extra arg after --action notify" \
	"Error: Unexpected argument \`bob\`." \
	--condition event-rule-matches --type=user \
	--action notify bob

# `--action start-session` failures
test_failure "missing arg after --action start-session" \
	"Error: Missing session name." \
	--condition event-rule-matches --type=user \
	--action start-session
test_failure "extra arg after --action start-session" \
	"Error: Unexpected argument \`bob\`." \
	--condition event-rule-matches --type=user \
	--action start-session ze-session bob

# `--action stop-session` failures
test_failure "missing arg after --action stop-session" \
	"Error: Missing session name." \
	--condition event-rule-matches --type=user \
	--action stop-session
test_failure "extra arg after --action stop-session" \
	"Error: Unexpected argument \`bob\`." \
	--condition event-rule-matches --type=user \
	--action stop-session ze-session bob

# `--action rotate-session` failures
test_failure "missing arg after --action rotate-session" \
	"Error: Missing session name." \
	--condition event-rule-matches --type=user \
	--action rotate-session
test_failure "extra arg after --action rotate-session" \
	"Error: Unexpected argument \`bob\`." \
	--condition event-rule-matches --type=user \
	--action rotate-session ze-session bob

# `--action snapshot-session` failures
test_failure "missing arg after --action snapshot-session" \
	"Error: Missing session name." \
	--condition event-rule-matches --type=user \
	--action snapshot-session
test_failure "extra arg after --action snapshot-session" \
	"Error: Unexpected argument \`bob\`." \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session bob
test_failure "snapshot-session action, --max-size without destination" \
	"Error: Can't provide a snapshot output max size without a snapshot output destination." \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --max-size 10M
test_failure "snapshot-session action, --name without destination" \
	"Error: Can't provide a snapshot output name without a snapshot output destination." \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --name hallo
test_failure "snapshot-session action, --name with-local-path-instead-of-url" \
	"Error: Failed to parse '/something/that/looks/like/a/path' as an URL." \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --name hallo --url /something/that/looks/like/a/path
test_failure "snapshot-session action, --name with-net-url-instead-of-path" \
	"Error: Failed to parse 'net://8.8.8.8/' as a local path." \
	--condition event-rule-matches --type=user \
	--action snapshot-session ze-session --name hallo --path net://8.8.8.8/

test_mi

# Cleanup
stop_lttng_sessiond_notap
rm -f "${tmp_stdout}"
rm -f "${tmp_stderr}"