Tests: Add add-trigger CLI tests
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 29 Oct 2020 17:59:05 +0000 (13:59 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 24 Feb 2021 20:00:21 +0000 (15:00 -0500)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I30e463084a9a664aabe98f84e8e07eea1007cc2e
Depends-on: lttng-ust: I5a800fc92e588c2a6a0e26282b0ad5f31c044479

configure.ac
tests/regression/Makefile.am
tests/regression/tools/Makefile.am
tests/regression/tools/trigger/Makefile.am [new file with mode: 0644]
tests/regression/tools/trigger/test_add_trigger_cli [new file with mode: 0755]

index ef6fc47afd424ba497d9a9802f713f2565a54993..e2a085853c63db14c1d2aa0af9d184cfd4da6bd0 100644 (file)
@@ -1156,6 +1156,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/working-directory/Makefile
        tests/regression/tools/relayd-grouping/Makefile
        tests/regression/tools/clear/Makefile
+       tests/regression/tools/trigger/Makefile
        tests/regression/ust/Makefile
        tests/regression/ust/nprocesses/Makefile
        tests/regression/ust/high-throughput/Makefile
index c76a519de4ab382bffd3164b103357426656be7c..193f730d64d2f9cae9ba52dd3f2cd9d142240e16 100644 (file)
@@ -39,7 +39,8 @@ TESTS = tools/filtering/test_invalid_filter \
        tools/notification/test_notification_multi_app \
        tools/clear/test_ust \
        tools/clear/test_kernel \
-       tools/tracker/test_event_tracker
+       tools/tracker/test_event_tracker \
+       tools/trigger/test_add_trigger_cli
 
 if HAVE_LIBLTTNG_UST_CTL
 SUBDIRS += ust
index 22691e5e2d1b0053794872502e866d0462868970..d561a647959e6a12d3769379fbdb84a33a523aaa 100644 (file)
@@ -2,4 +2,4 @@
 
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
                wildcard crash regen-metadata regen-statedump notification rotation \
-               base-path metadata working-directory relayd-grouping clear tracker
+               base-path metadata working-directory relayd-grouping clear tracker trigger
diff --git a/tests/regression/tools/trigger/Makefile.am b/tests/regression/tools/trigger/Makefile.am
new file mode 100644 (file)
index 0000000..8d911ea
--- /dev/null
@@ -0,0 +1,16 @@
+noinst_SCRIPTS = test_add_trigger_cli
+EXTRA_DIST = test_add_trigger_cli
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/trigger/test_add_trigger_cli b/tests/regression/tools/trigger/test_add_trigger_cli
new file mode 100755 (executable)
index 0000000..acaf456
--- /dev/null
@@ -0,0 +1,347 @@
+#!/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 174
+
+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"
+
+if [ "$(id -u)" == "0" ]; then
+       ist_root=1
+else
+       ist_root=0
+fi
+
+function test_success ()
+{
+       local test_name="$1"
+       shift
+
+       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 "Trigger registered successfully.")
+       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"
+}
+
+# top-level options
+test_success "explicit id" \
+       --id hohoho \
+       --condition on-event some-event-id -u \
+       --action notify
+
+# `--condition on-event` successes
+test_success "--condition on-event some-event -u" \
+       --condition on-event some-event -u \
+       --action notify
+
+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 \
+       --action notify \
+       --fire-once-after=55
+
+test_success "--fire-every" \
+       --condition on-event -u test-fire-every \
+       --action notify \
+       --fire-every=55
+
+skip $ist_root "non-root user: skipping kprobe tests" 9 || {
+       test_success "--condition on-event probe by symbol" \
+               --condition on-event -k --probe=lttng_channel_enable 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 on-event probe by symbol with offset" \
+               --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_$base_symbol \
+               --action notify
+
+       test_success "--condition on-event probe by address" \
+               --condition on-event -k "--probe=0x${channel_enable_addr}" my_channel_enable \
+               --action notify
+}
+
+skip $ist_root "non-root user: skipping uprobe tests" 6 || {
+       test_success "--condition on-event uprobe" \
+               --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe \
+               --action notify
+
+       test_success "--condition on-event uprobe with elf prefix" \
+               --condition on-event -k --userspace-probe=elf:${uprobe_elf_binary}:test_function ma-probe-2 \
+               --action notify
+}
+
+skip $ist_root "non-root user: skipping syscall tests" 9 || {
+       test_success "--condition on-event syscall" \
+               --condition on-event -k --syscall open \
+               --action notify
+
+       test_success "--condition on-event syscall -a" \
+               --condition on-event -k --syscall -a \
+               --action notify
+
+       test_success "--condition on-event syscall with filter" \
+               --condition on-event -k --syscall --filter 'a > 2' open \
+               --action notify
+}
+
+# `--action notify` successes
+test_success "--action notify" \
+       --condition on-event some-event-notify -u \
+       --action notify
+
+# `--action start-session` successes
+test_success "--action start-session" \
+       --condition on-event some-event-start-session -u \
+       --action start-session ze-session
+
+# `--action stop-session` successes
+test_success "--action stop-session foo" \
+       --condition on-event some-event-stop-session -u \
+       --action stop-session ze-session
+
+# `--action rotate-session` successes
+test_success "--action rotate-session foo" \
+       --condition on-event some-event-rotate-session -u \
+       --action rotate-session ze-session
+
+# `--action snapshot-session` successes
+test_success "--action snapshot-session foo" \
+       --condition on-event some-event-snapshot-session -u \
+       --action snapshot-session ze-session
+
+test_success "--action snapshot-session with file URI" \
+       --condition on-event some-event-snapshot-session2 -u \
+       --action snapshot-session ze-session --path /hello
+
+test_success "--action snapshot-session with net URI" \
+       --condition on-event some-event-snapshot-session3 -u \
+       --action snapshot-session ze-session --url net://1.2.3.4
+
+test_success "--action snapshot-session with ctrl/data URIs" \
+       --condition on-event some-event-snapshot-session4 -u \
+       --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: Unknown option \`--hello\`" \
+       --hello
+
+test_failure "missing --action" \
+       "Error: Need at least one --action." \
+       --condition on-event hello -u
+
+test_failure "two --condition" \
+       "Error: A --condition was already given." \
+       --condition on-event aaa -u \
+       --condition on-event bbb -u \
+       --action notify
+
+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
+       test_failure "missing argument to --${cmd}" \
+               "Error: While parsing argument #1 (\`--${cmd}\`): Missing required argument for option \`--${cmd}\`" \
+               --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." \
+               --condition on-event -u -a --action notify \
+               --${cmd} 123bob
+
+       test_failure "invalid argument to --${cmd}: empty string" \
+               "Error: Failed to parse \`\` as an integer." \
+               --condition on-event -u -a --action notify \
+               --${cmd} ""
+done
+
+# `--condition` failures
+test_failure "missing args after --condition" \
+       "Error: Missing condition name." \
+       --condition
+test_failure "unknown --condition" \
+       "Error: Unknown condition name 'zoofest'" \
+       --condition zoofest
+
+# `--condition on-event` failures
+test_failure "missing args after --condition on-event" \
+       "Error: Need to provide either a tracepoint name or -a/--all." \
+       --condition on-event
+test_failure "missing domain in --condition on-event" \
+       "Error: Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)." \
+       --condition on-event -a
+test_failure "extra args after --condition on-event" \
+       "Error: Unexpected argument 'bozo'" \
+       --condition on-event foo -u bozo
+test_failure "--condition on-event: --all with --probe" \
+       "Error: Can't use -a/--all with probe event rules." \
+       --condition on-event --probe=do_sys_open --all
+test_failure "--condition on-event: missing tracepoint name with --probe" \
+       "Error: Need to provide either a tracepoint name or -a/--all." \
+       --condition on-event -k --probe do_sys_open
+
+test_failure "--condition on-event: missing tracepoint name with --userspace-probe" \
+       "Error: Need to provide either a tracepoint name or -a/--all." \
+       --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function
+
+test_failure "--condition on-event: extra argument with --userspace-probe" \
+       "Error: Unexpected argument 'world'" \
+       --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_failure hello world
+
+test_failure "--condition on-event: missing tracepoint name with --syscall" \
+       "Error: Need to provide either a tracepoint name or -a/--all." \
+       --condition on-event -k --syscall
+
+test_failure "--condition on-event: extra argument with --syscall" \
+       "Error: Unexpected argument 'open'" \
+       --condition on-event -k --syscall open open
+
+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
+
+# `--action` failures
+test_failure "missing args after --action" \
+       "Error: Missing action name." \
+       --condition on-event -u -a \
+       --action
+
+# `--action notify` failures
+test_failure "extra arg after --action notify" \
+       "Error: Unexpected argument \`bob\`." \
+       --condition on-event -u -a \
+       --action notify bob
+
+# `--action start-session` failures
+test_failure "missing arg after --action start-session" \
+       "Error: Missing session name." \
+       --condition on-event some-event-start-session -u \
+       --action start-session
+test_failure "extra arg after --action start-session" \
+       "Error: Unexpected argument \`bob\`." \
+       --condition on-event some-event-start-session -u \
+       --action start-session ze-session bob
+
+# `--action stop-session` failures
+test_failure "missing arg after --action stop-session" \
+       "Error: Missing session name." \
+       --condition on-event some-event-stop-session -u \
+       --action stop-session
+test_failure "extra arg after --action stop-session" \
+       "Error: Unexpected argument \`bob\`." \
+       --condition on-event some-event-stop-session -u \
+       --action stop-session ze-session bob
+
+# `--action rotate-session` failures
+test_failure "missing arg after --action rotate-session" \
+       "Error: Missing session name." \
+       --condition on-event some-event-rotate-session -u \
+       --action rotate-session
+test_failure "extra arg after --action rotate-session" \
+       "Error: Unexpected argument \`bob\`." \
+       --condition on-event some-event-rotate-session -u \
+       --action rotate-session ze-session bob
+
+# `--action snapshot-session` failures
+test_failure "missing arg after --action snapshot-session" \
+       "Error: Missing session name." \
+       --condition on-event some-event-snapshot-session -u \
+       --action snapshot-session
+test_failure "extra arg after --action snapshot-session" \
+       "Error: Unexpected argument \`bob\`." \
+       --condition on-event some-event-snapshot-session -u \
+       --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 on-event some-event-snapshot-session -u \
+       --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 on-event some-event-snapshot-session -u \
+       --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 on-event some-event-snapshot-session -u \
+       --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 on-event some-event-snapshot-session -u \
+       --action snapshot-session ze-session --name hallo --path net://8.8.8.8/
+
+# Cleanup
+stop_lttng_sessiond_notap
+rm -f "${tmp_stdout}"
+rm -f "${tmp_stderr}"
This page took 0.0301 seconds and 4 git commands to generate.