tests: add test for list-plugins CLI command
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 20 Nov 2019 17:01:18 +0000 (12:01 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 Nov 2019 19:24:17 +0000 (14:24 -0500)
The test provides a custom Python plugin, then checks for a
corresponding entry in the "list-plugins" output.

Change-Id: I65fff2d4d22f21a89fa1ad7e747c5e15677212b9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2421
Tested-by: jenkins <jenkins@lttng.org>
tests/Makefile.am
tests/cli/list-plugins/test_list_plugins [new file with mode: 0755]
tests/data/cli/list-plugins/bt_plugin_list_plugins.py [new file with mode: 0644]

index 6db5cd480e4b86b967e90abbe84f8f839122d81e..c36feb87401f1417da99bfdf0f5f31f57f13070f 100644 (file)
@@ -41,6 +41,7 @@ dist_check_SCRIPTS = \
        cli/convert/test_auto_source_discovery_params \
        cli/convert/test_auto_source_discovery_log_level \
        cli/convert/test_convert_args \
        cli/convert/test_auto_source_discovery_params \
        cli/convert/test_auto_source_discovery_log_level \
        cli/convert/test_convert_args \
+       cli/list-plugins/test_list_plugins \
        cli/params/test_params \
        cli/query/test_query \
        cli/test_exit_status \
        cli/params/test_params \
        cli/query/test_query \
        cli/test_exit_status \
@@ -128,6 +129,7 @@ TESTS_CLI += \
        cli/convert/test_auto_source_discovery_grouping \
        cli/convert/test_auto_source_discovery_log_level \
        cli/convert/test_auto_source_discovery_params \
        cli/convert/test_auto_source_discovery_grouping \
        cli/convert/test_auto_source_discovery_log_level \
        cli/convert/test_auto_source_discovery_params \
+       cli/list-plugins/test_list_plugins \
        cli/params/test_params \
        cli/query/test_query \
        cli/test_exit_status
        cli/params/test_params \
        cli/query/test_query \
        cli/test_exit_status
diff --git a/tests/cli/list-plugins/test_list_plugins b/tests/cli/list-plugins/test_list_plugins
new file mode 100755 (executable)
index 0000000..378a1b2
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/bash
+#
+# Copyright (C) 2019 EfficiOS Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
+       UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
+else
+       UTILSSH="$(dirname "$0")/../../utils/utils.sh"
+fi
+
+# shellcheck source=../../utils/utils.sh
+SH_TAP=1 source "$UTILSSH"
+
+plan_tests 3
+
+data_dir="${BT_TESTS_DATADIR}/cli/list-plugins"
+plugin_dir="${data_dir}"
+
+stdout_file=$(mktemp -t test_cli_list_plugins_stdout.XXXXXX)
+stderr_file=$(mktemp -t test_cli_list_plugins_stderr.XXXXXX)
+grep_stdout_file=$(mktemp -t test_cli_list_plugins_grep_stdout.XXXXXX)
+py_plugin_expected_stdout_file=$(mktemp -t test_cli_list_plugins_expected_py_plugin_stdout.XXXXXX)
+
+# Run list-plugins.
+bt_cli "$stdout_file" "$stderr_file" \
+       --plugin-path "$plugin_dir" \
+       list-plugins
+ok "$?" "exit code is 0"
+
+# Extract the section about our custom this-is-a-plugin Python plugin.
+grep --after-context=11 '^this-is-a-plugin:$' "${stdout_file}" > "${grep_stdout_file}"
+ok "$?" "entry for this-is-a-plugin is present"
+
+if [ "$BT_OS_TYPE" = "mingw" ]; then
+       platform_plugin_dir=$(cygpath -m "${plugin_dir}")
+else
+       platform_plugin_dir="${plugin_dir}"
+fi
+
+# Generate the expected output file for that plugin.
+cat <<- EOF > "${py_plugin_expected_stdout_file}"
+       this-is-a-plugin:
+         Path: ${platform_plugin_dir}/bt_plugin_list_plugins.py
+         Version: 1.2.3bob
+         Description: A plugin
+         Author: Jorge Mario Bergoglio
+         License: The license
+         Source component classes:
+           'source.this-is-a-plugin.ThisIsASource'
+         Filter component classes:
+           'filter.this-is-a-plugin.ThisIsAFilter'
+         Sink component classes:
+           'sink.this-is-a-plugin.ThisIsASink'
+EOF
+
+# Compare the entry for this-is-a-plugin with the expected version.
+bt_diff "${py_plugin_expected_stdout_file}" "${grep_stdout_file}"
+ok "$?" "entry for this-is-a-plugin is as expected"
+
+rm -f "${stdout_file}"
+rm -f "${stderr_file}"
+rm -f "${grep_stdout_file}"
+rm -f "${py_plugin_expected_stdout_file}"
diff --git a/tests/data/cli/list-plugins/bt_plugin_list_plugins.py b/tests/data/cli/list-plugins/bt_plugin_list_plugins.py
new file mode 100644 (file)
index 0000000..7ca71da
--- /dev/null
@@ -0,0 +1,49 @@
+#
+# Copyright (C) 2019 EfficiOS Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; only version 2
+# of the License.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+import bt2
+
+
+@bt2.plugin_component_class
+class ThisIsASource(
+    bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator
+):
+    pass
+
+
+@bt2.plugin_component_class
+class ThisIsAFilter(
+    bt2._UserFilterComponent, message_iterator_class=bt2._UserMessageIterator
+):
+    pass
+
+
+@bt2.plugin_component_class
+class ThisIsASink(bt2._UserSinkComponent):
+    def _user_consume(self):
+        pass
+
+
+bt2.register_plugin(
+    __name__,
+    "this-is-a-plugin",
+    version=(1, 2, 3, 'bob'),
+    description='A plugin',
+    author='Jorge Mario Bergoglio',
+    license='The license',
+)
This page took 0.026159 seconds and 4 git commands to generate.