From: Simon Marchi Date: Wed, 20 Nov 2019 17:01:18 +0000 (-0500) Subject: tests: add test for list-plugins CLI command X-Git-Tag: v2.0.0~52 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=370d150fb2b09e1398e59a3c9998572047842460 tests: add test for list-plugins CLI command 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2421 Tested-by: jenkins --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 6db5cd48..c36feb87 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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/list-plugins/test_list_plugins \ 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/list-plugins/test_list_plugins \ 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 index 00000000..378a1b29 --- /dev/null +++ b/tests/cli/list-plugins/test_list_plugins @@ -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 index 00000000..7ca71dad --- /dev/null +++ b/tests/data/cli/list-plugins/bt_plugin_list_plugins.py @@ -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', +)