lttng add-trigger: parse condition / action name as option arguments
[lttng-tools.git] / tests / regression / tools / trigger / test_add_trigger_cli
index acaf456318960a0a3384ebb9f1bec003103087dd..fd962c04bae76421336e8bc43bee441fbb1111b6 100755 (executable)
@@ -23,7 +23,7 @@ TESTDIR="$CURDIR/../../.."
 # shellcheck source=../../../utils/utils.sh
 source "$TESTDIR/utils/utils.sh"
 
-plan_tests 174
+plan_tests 234
 
 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
 
@@ -46,7 +46,9 @@ function test_success ()
        shift
 
        diag "${FULL_LTTNG_BIN} add-trigger $*"
+       set -x
        "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
+       set +x
        ok $? "${test_name}: exit code is 0"
 
        diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.")
@@ -89,15 +91,40 @@ test_success "--condition on-event -a -u" \
        --condition on-event -a -u \
        --action notify
 
-test_success "--fire-once-after" \
-       --condition on-event -u test-fire-once-after \
+test_success "notify action polices" \
+       --condition on-event -u test-rate-policy=once-after \
        --action notify \
-       --fire-once-after=55
-
-test_success "--fire-every" \
-       --condition on-event -u test-fire-every \
+       --rate-policy=every:55 \
        --action notify \
-       --fire-every=55
+       --rate-policy=once-after:55
+
+test_success "start session action polices" \
+       --condition on-event -u test-rate-policy=once-after \
+       --action start-session my_session \
+       --rate-policy=every:55 \
+       --action start-session my_session \
+       --rate-policy=once-after:55
+
+test_success "stop session action polices" \
+       --condition on-event -u test-rate-policy=once-after \
+       --action stop-session my_session \
+       --rate-policy=every:55 \
+       --action stop-session my_session \
+       --rate-policy=once-after:55
+
+test_success "snapshot session action polices" \
+       --condition on-event -u test-rate-policy=once-after \
+       --action snapshot-session my_session \
+       --rate-policy=every:55 \
+       --action snapshot-session my_session \
+       --rate-policy=once-after:55
+
+test_success "rotate session action polices" \
+       --condition on-event -u test-rate-policy=once-after \
+       --action rotate-session my_session \
+       --rate-policy=every:55 \
+       --action rotate-session my_session \
+       --rate-policy=once-after:55
 
 skip $ist_root "non-root user: skipping kprobe tests" 9 || {
        test_success "--condition on-event probe by symbol" \
@@ -158,6 +185,34 @@ test_success "--action notify" \
        --condition on-event some-event-notify -u \
        --action notify
 
+test_success "--action notify --capture foo" \
+       --condition on-event some-event-notify-foo -u \
+       --capture foo --action notify
+
+test_success "--action notify --capture foo[2]" \
+       --condition on-event some-event-notify-foo2 -u \
+       --capture 'foo[2]' --action notify
+
+test_success '--action notify --capture $ctx.foo' \
+       --condition on-event some-event-notify-ctx-foo -u \
+       --capture '$ctx.foo' --action notify
+
+test_success '--action notify --capture $ctx.foo[2]' \
+       --condition on-event some-event-notify-ctx-foo2 -u \
+       --capture '$ctx.foo[2]' --action notify
+
+test_success '--action notify --capture $app.prov:type' \
+       --condition on-event some-event-notify-app-prov-type -u \
+       --capture '$app.prov:type' --action notify
+
+test_success '--action notify --capture $app.prov:type[2]' \
+       --condition on-event some-event-notify-app-prov-type-2 -u \
+       --capture '$app.prov:type[2]' --action notify
+
+test_success '--action notify multiple captures' \
+       --condition on-event some-event-notify-multiple-captures -u \
+       --capture foo --capture '$app.hello:world' --action notify
+
 # `--action start-session` successes
 test_success "--action start-session" \
        --condition on-event some-event-start-session -u \
@@ -211,26 +266,31 @@ test_failure "missing argument to --id" \
        "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \
        --id
 
-for cmd in fire-once-after fire-every; do
+for cmd in rate-policy=once-after rate-policy=every; do
        test_failure "missing argument to --${cmd}" \
-               "Error: While parsing argument #1 (\`--${cmd}\`): Missing required argument for option \`--${cmd}\`" \
+               "Error: Rate policy format is invalid." \
                --condition on-event -u -a --action notify \
                --${cmd}
 
        test_failure "invalid argument to --${cmd}: non-digit character" \
-               "Error: Failed to parse \`123bob\` as an integer." \
+               "Error: Failed to parse rate policy value \`123bob\` as an integer." \
                --condition on-event -u -a --action notify \
-               --${cmd} 123bob
+               --${cmd}:123bob
 
        test_failure "invalid argument to --${cmd}: empty string" \
-               "Error: Failed to parse \`\` as an integer." \
+               "Error: Failed to parse rate policy value \`\` as an integer." \
                --condition on-event -u -a --action notify \
-               --${cmd} ""
+               --${cmd}":"
 done
 
+test_failure "invalid argument to --rate-policy: unknown policy type" \
+       "Error: Rate policy type \`bob\` unknown." \
+       --condition on-event -u -a --action notify \
+       --rate-policy=bob:123
+
 # `--condition` failures
 test_failure "missing args after --condition" \
-       "Error: Missing condition name." \
+       "Error: While parsing argument #1 (\`--condition\`): Missing required argument for option \`--condition\`" \
        --condition
 test_failure "unknown --condition" \
        "Error: Unknown condition name 'zoofest'" \
@@ -273,9 +333,54 @@ test_failure "--condition on-event: both -a and a tracepoint name with --syscall
        "Error: Can't provide a tracepoint name with -a/--all." \
        --condition on-event -k --syscall -a open
 
+test_failure "--condition on-event --capture: missing argument (end of arg list)" \
+       'Error: While parsing argument #3 (`--capture`): Missing required argument for option `--capture`' \
+       --action notify \
+       --condition on-event -u -a --capture
+
+test_failure "--condition on-event --capture: missing argument (before another option)" \
+       'Error: While parsing expression `--action`: Unary operators are not allowed in capture expressions.' \
+       --condition on-event -u -a --capture \
+       --action notify \
+
+test_failure "--condition on-event --capture: binary operator" \
+       'Error: While parsing expression `foo == 2`: Binary operators are not allowed in capture expressions.' \
+       --condition on-event -u -a \
+       --capture 'foo == 2' --action notify
+
+test_failure "--condition on-event --capture: unary operator" \
+       'Error: While parsing expression `!foo`: Unary operators are not allowed in capture expressions.' \
+       --condition on-event -u -a \
+       --capture '!foo' --action notify
+
+test_failure "--condition on-event --capture: logical operator" \
+       'Error: While parsing expression `foo || bar`: Logical operators are not allowed in capture expressions.' \
+       --condition on-event -u -a \
+       --capture 'foo || bar' --action notify
+
+test_failure "--condition on-event --capture: accessing a sub-field" \
+       'Error: While parsing expression `foo.bar`: Capturing subfields is not supported.' \
+       --condition on-event -u -a \
+       --capture 'foo.bar' --action notify
+
+test_failure "--condition on-event --capture: accessing the sub-field of an array element" \
+       'Error: While parsing expression `foo[3].bar`: Capturing subfields is not supported.' \
+       --condition on-event -u -a \
+       --capture 'foo[3].bar' --action notify
+
+test_failure "--condition on-event --capture: missing colon in app-specific context field" \
+       'Error: Invalid app-specific context field name: missing colon in `foo`.' \
+       --condition on-event -u -a \
+       --capture '$app.foo' --action notify
+
+test_failure "--condition on-event --capture: missing colon in app-specific context field" \
+       'Error: Invalid app-specific context field name: missing type name after colon in `foo:`.' \
+       --condition on-event -u -a \
+       --capture '$app.foo:' --action notify
+
 # `--action` failures
 test_failure "missing args after --action" \
-       "Error: Missing action name." \
+       "Error: While parsing argument #1 (\`--action\`): Missing required argument for option \`--action\`" \
        --condition on-event -u -a \
        --action
 
This page took 0.025478 seconds and 4 git commands to generate.