lttng {add,list}-triggers: use `name` instead of `id`
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
index ac7f099251a13781eef3d76bec511225c216c934..42893f5d6c45c8e41c388c31c3db08fb0be9d4ad 100755 (executable)
@@ -23,7 +23,8 @@ TESTDIR="$CURDIR/../../.."
 # shellcheck source=../../../utils/utils.sh
 source "$TESTDIR/utils/utils.sh"
 
-plan_tests 49
+
+NUM_TESTS=72
 
 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
 
@@ -31,17 +32,26 @@ tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
 tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
 tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
 uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
+uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binary/.libs/userspace-probe-sdt-binary")
 
 uid=$(id --user)
 gid=$(id --group)
 
 if [ "$uid" == "0" ]; then
        ist_root=1
+       ls "$uprobe_sdt_binary" >/dev/null 2>&1
+       if test $? == 0; then
+               hast_sdt_binary=1
+       else
+               hast_sdt_binary=0
+       fi
 else
        ist_root=0
+       hast_sdt_binary=0
 fi
 
-function list_triggers ()
+
+function list_triggers_matches_ok ()
 {
        local test_name="$1"
        local expected_stdout_file="$2"
@@ -58,31 +68,29 @@ function list_triggers ()
 
 test_top_level_options ()
 {
-       # shellcheck disable=SC2119
-       start_lttng_sessiond_notap
-
+       diag "Listing top level options"
 
        lttng_add_trigger_ok "hello" --condition on-event -u test-id --action notify
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: hello
+       - name: hello
          user id: ${uid}
          condition: event rule hit
            rule: test-id (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "top level options" "${tmp_expected_stdout}"
+       list_triggers_matches_ok "top level options" "${tmp_expected_stdout}"
 
-       stop_lttng_sessiond_notap
+       lttng_remove_trigger_ok "hello"
 }
 
 test_on_event_tracepoint ()
 {
-       # shellcheck disable=SC2119
-       start_lttng_sessiond_notap
+       diag "Listing on-event tracepoint"
 
        lttng_add_trigger_ok "C" --condition on-event -u -a --action notify
        lttng_add_trigger_ok "A" --condition on-event aaa -u --filter 'p == 2' --action notify
@@ -96,83 +104,100 @@ test_on_event_tracepoint ()
 
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: A
+       - name: A
          user id: ${uid}
          condition: event rule hit
            rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: B
+             errors: none
+         errors: none
+       - name: B
          user id: ${uid}
          condition: event rule hit
            rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: C
+             errors: none
+         errors: none
+       - name: C
          user id: ${uid}
          condition: event rule hit
            rule: * (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: D
+             errors: none
+         errors: none
+       - name: D
          user id: ${uid}
          condition: event rule hit
            rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: E
+             errors: none
+         errors: none
+       - name: E
          user id: ${uid}
          condition: event rule hit
            rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: F
+             errors: none
+         errors: none
+       - name: F
          user id: ${uid}
          condition: event rule hit
            rule: capture-payload-field (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - a
          actions:
            notify
-       - id: G
+             errors: none
+         errors: none
+       - name: G
          user id: ${uid}
          condition: event rule hit
            rule: capture-array (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - a[2]
              - \$ctx.tourlou[18]
          actions:
            notify
-       - id: H
+             errors: none
+         errors: none
+       - name: H
          user id: ${uid}
          condition: event rule hit
            rule: capture-chan-ctx (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - \$ctx.vpid
          actions:
            notify
-       - id: I
+             errors: none
+         errors: none
+       - name: I
          user id: ${uid}
          condition: event rule hit
            rule: capture-app-ctx (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
            captures:
              - \$app.iga:active_clients
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
-
-       stop_lttng_sessiond_notap
+       list_triggers_matches_ok "on-event, tracepoint event rule" "${tmp_expected_stdout}"
+
+       lttng_remove_trigger_ok "A"
+       lttng_remove_trigger_ok "B"
+       lttng_remove_trigger_ok "C"
+       lttng_remove_trigger_ok "D"
+       lttng_remove_trigger_ok "E"
+       lttng_remove_trigger_ok "F"
+       lttng_remove_trigger_ok "G"
+       lttng_remove_trigger_ok "H"
+       lttng_remove_trigger_ok "I"
 }
 
 test_on_event_probe ()
@@ -180,8 +205,7 @@ test_on_event_probe ()
        local channel_enable_addr
        local channel_disable_addr
 
-       # shellcheck disable=SC2119
-       start_lttng_sessiond_notap
+       diag "Listing on-event kernel probe"
 
        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 ' ')
@@ -204,89 +228,124 @@ test_on_event_probe ()
        lttng_add_trigger_ok "T2" --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: T0
+       - name: T0
          user id: ${uid}
          condition: event rule hit
            rule: my_channel_enable (type: probe, location: lttng_channel_enable)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: T1
+             errors: none
+         errors: none
+       - name: T1
          user id: ${uid}
          condition: event rule hit
            rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: T2
+             errors: none
+         errors: none
+       - name: T2
          user id: ${uid}
          condition: event rule hit
            rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
+       list_triggers_matches_ok "on-event, probe event rule" "${tmp_expected_stdout}"
 
-       stop_lttng_sessiond_notap
+       lttng_remove_trigger_ok "T0"
+       lttng_remove_trigger_ok "T1"
+       lttng_remove_trigger_ok "T2"
 }
 
-test_on_event_userspace_probe ()
+test_on_event_userspace_probe_elf ()
 {
-       # shellcheck disable=SC2119
-       start_lttng_sessiond_notap
+       local elf_function_name="test_function"
 
-       lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
+       diag "Listing on-event userspace-probe elf"
+
+       lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:${elf_function_name} ma-probe-elf --action notify
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: T0
+       - name: T0
          user id: ${uid}
          condition: event rule hit
-           rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
-           tracer notifications discarded: 0
+           rule: ma-probe-elf (type: userspace probe, location type: ELF, location: ${uprobe_elf_binary}:${elf_function_name})
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
+       list_triggers_matches_ok "on-event, userspace-probe event rule ELF" "${tmp_expected_stdout}"
 
-       stop_lttng_sessiond_notap
+       lttng_remove_trigger_ok "T0"
+}
+
+test_on_event_userspace_probe_sdt ()
+{
+
+       local sdt_provider_name="foobar"
+       local sdt_probe_name="tp1"
+
+       diag "on-event userspace-probe sdt"
+
+       lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=sdt:${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name} ma-probe-sdt --action notify
+
+       cat > "${tmp_expected_stdout}" <<- EOF
+       - id: T0
+         user id: 0
+         condition: event rule hit
+           rule: ma-probe-sdt (type: userspace probe, location type: SDT, location: ${uprobe_sdt_binary}:${sdt_provider_name}:${sdt_probe_name})
+         actions:
+           notify
+             errors: none
+         errors: none
+       EOF
+
+       list_triggers_matches_ok "on-event, userspace-probe event rule SDT" "${tmp_expected_stdout}"
+
+       lttng_remove_trigger_ok "T0"
 }
 
 test_on_event_syscall ()
 {
-       # shellcheck disable=SC2119
-       start_lttng_sessiond_notap
+       diag "Listing on-event syscall"
 
        lttng_add_trigger_ok "T0" --condition on-event -k --syscall open --action notify
        lttng_add_trigger_ok "T1" --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: T0
+       - name: T0
          user id: ${uid}
          condition: event rule hit
            rule: open (type: syscall)
-           tracer notifications discarded: 0
          actions:
            notify
-       - id: T1
+             errors: none
+         errors: none
+       - name: T1
          user id: ${uid}
          condition: event rule hit
            rule: ptrace (type: syscall, filter: a > 2)
-           tracer notifications discarded: 0
          actions:
            notify
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
+       list_triggers_matches_ok "on-event, syscall event rule" "${tmp_expected_stdout}"
 
-       stop_lttng_sessiond_notap
+       lttng_remove_trigger_ok "T0"
+       lttng_remove_trigger_ok "T1"
 }
 
 test_snapshot_action ()
 {
-       start_lttng_sessiond_notap
+       diag "Listing snapshot actions"
 
        lttng_add_trigger_ok "T0" --condition on-event -u some-event --action snapshot-session ze-session
        lttng_add_trigger_ok "T1" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path
@@ -296,84 +355,94 @@ test_snapshot_action ()
        lttng_add_trigger_ok "T5" --condition on-event -u some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112
        lttng_add_trigger_ok "T6" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --max-size=1234
        lttng_add_trigger_ok "T7" --condition on-event -u some-event --action snapshot-session ze-session --path /some/path --name=meh
-       lttng_add_trigger_ok "T8" --condition on-event -u some-event --action snapshot-session ze-session --fire-every 10
-       lttng_add_trigger_ok "T9" --condition on-event -u some-event --action snapshot-session ze-session --fire-once-after 10
+       lttng_add_trigger_ok "T8" --condition on-event -u some-event --action snapshot-session ze-session --rate-policy=every:10
+       lttng_add_trigger_ok "T9" --condition on-event -u some-event --action snapshot-session ze-session --rate-policy=once-after:10
 
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: T0
+       - name: T0
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`
-       - id: T1
+             errors: none
+         errors: none
+       - name: T1
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/path
-       - id: T2
+             errors: none
+         errors: none
+       - name: T2
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/other/path
-       - id: T3
+             errors: none
+         errors: none
+       - name: T3
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, url: net://1.2.3.4
-       - id: T4
+             errors: none
+         errors: none
+       - name: T4
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
-       - id: T5
+             errors: none
+         errors: none
+       - name: T5
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
-       - id: T6
+             errors: none
+         errors: none
+       - name: T6
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/path, max size: 1234
-       - id: T7
+             errors: none
+         errors: none
+       - name: T7
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
            snapshot session \`ze-session\`, path: /some/path, name: meh
-       - id: T8
+             errors: none
+         errors: none
+       - name: T8
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
-           snapshot session \`ze-session\`, firing policy: after every 10 occurrences
-       - id: T9
+           snapshot session \`ze-session\`, rate policy: after every 10 occurrences
+             errors: none
+         errors: none
+       - name: T9
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
-           snapshot session \`ze-session\`, firing policy: once after 10 occurrences
+           snapshot session \`ze-session\`, rate policy: once after 10 occurrences
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "snapshot action" "${tmp_expected_stdout}"
+       list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
 
        stop_lttng_sessiond_notap
 }
@@ -382,40 +451,51 @@ test_notify_action ()
 {
        start_lttng_sessiond_notap
 
-       lttng_add_trigger_ok "T0" --condition on-event -u some-event --action notify --fire-once-after 5
-       lttng_add_trigger_ok "T1" --condition on-event -u some-event --action notify --fire-every 10
+       lttng_add_trigger_ok "T0" --condition on-event -u some-event --action notify --rate-policy=once-after:5
+       lttng_add_trigger_ok "T1" --condition on-event -u some-event --action notify --rate-policy=every:10
 
 
        cat > "${tmp_expected_stdout}" <<- EOF
-       - id: T0
+       - name: T0
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
-           notify, firing policy: once after 5 occurrences
-       - id: T1
+           notify, rate policy: once after 5 occurrences
+             errors: none
+         errors: none
+       - name: T1
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
-           tracer notifications discarded: 0
          actions:
-           notify, firing policy: after every 10 occurrences
+           notify, rate policy: after every 10 occurrences
+             errors: none
+         errors: none
        EOF
 
-       list_triggers "snapshot action" "${tmp_expected_stdout}"
+       list_triggers_matches_ok "snapshot action" "${tmp_expected_stdout}"
 
-       stop_lttng_sessiond_notap
+       lttng_remove_trigger_ok "T0"
+       lttng_remove_trigger_ok "T1"
 }
 
+plan_tests $NUM_TESTS
+
+# shellcheck disable=SC2119
+start_lttng_sessiond_notap
+
 test_top_level_options
 test_on_event_tracepoint
-skip $ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
-skip $ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
-skip $ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
+skip $ist_root "non-root user: skipping kprobe tests" 9 || test_on_event_probe
+skip $ist_root "non-root user: skipping userspace probe elf tests" 5 || test_on_event_userspace_probe_elf
+skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 5 || test_on_event_userspace_probe_sdt
+skip $ist_root "non-root user: skipping syscall tests" 7 || test_on_event_syscall
 test_snapshot_action
 test_notify_action
 
+stop_lttng_sessiond_notap
+
 # Cleanup
 rm -f "${tmp_stdout}"
 rm -f "${tmp_stderr}"
This page took 0.029355 seconds and 4 git commands to generate.