From 344ead31a689dbf318f3974b6d5f5718bb8f51fb Mon Sep 17 00:00:00 2001 From: Thomas Goodwin Date: Tue, 19 Mar 2024 08:57:43 -0400 Subject: [PATCH] gst-inspect: fix --atleast-version to be implicitly applied to --exists The --atleast-version implies --exists, but the implementation in earlier commits had the version check applied any time the --exists was checked, and the default value of the major and minor versions were set to the GStreamer major and minor versions. The resulting behavior would have gst-inspect return '1' if the plugin's version didn't match gstreamer's even when --atleast-version was not specified in the command line args. The change in this patch removes that behavior and adds tests to verify that if --exists is specified WITHOUT --atleast-version the version check will NOT be applied. If both arguments are specified and the version does not match the arg-supplied version number, a new return code of '2' is used to uniquely identify the failure. Fixes #3246 Signed-off-by: Thomas Goodwin Part-of: --- .../gstreamer/tests/check/tools/gstinspect.c | 48 +++++++++++++++++-- subprojects/gstreamer/tools/gst-inspect.c | 12 +++-- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/subprojects/gstreamer/tests/check/tools/gstinspect.c b/subprojects/gstreamer/tests/check/tools/gstinspect.c index 72e23a4225..1ea6ee2bee 100644 --- a/subprojects/gstreamer/tests/check/tools/gstinspect.c +++ b/subprojects/gstreamer/tests/check/tools/gstinspect.c @@ -30,10 +30,27 @@ static int gst_inspect_main (int argc, char **argv); #include "../../tools/gst-inspect.c" #undef main +// A plugin whose version does not match the gstreamer major/minor +// see https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6191 +#define TEST_PLUGIN_VERSION "0.1.0" +#define TEST_ELEMENT_NAME "local_test_bin" +static gboolean +test_plugin_init (G_GNUC_UNUSED GstPlugin * plugin) +{ + gst_element_register (plugin, TEST_ELEMENT_NAME, GST_RANK_NONE, GST_TYPE_BIN); + return TRUE; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, + test_plugin, "Test Plugin", test_plugin_init, TEST_PLUGIN_VERSION, + "LGPL", "gsttestplugin", "testing"); + GST_START_TEST (test_exists) { #define ARGV_LEN (G_N_ELEMENTS (argv) - 1) + gst_plugin_test_plugin_register (); + { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "foo", NULL }; @@ -44,6 +61,16 @@ GST_START_TEST (test_exists) fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 0); } + { + // --exists should work even if the plugin's version does not equal + // the gstreamer version (i.e., the --atleast-version check is not + // implicitly enforced when not present). + const gchar *argv[] = { "gst-inspect-1.0", "--exists", + TEST_ELEMENT_NAME, NULL + }; + + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 0); + } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=" VERSION, "bin", NULL @@ -77,28 +104,41 @@ GST_START_TEST (test_exists) "--atleast-version=2.0", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=2.0.0", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=1.44", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); } { const gchar *argv[] = { "gst-inspect-1.0", "--exists", "--atleast-version=1.60.4", "bin", NULL }; - fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 1); + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); + } + { + // The 'atleast-version' supplied here will not match the test plugin's + // version, above, so the test case should return "2" because the test + // plugin's 0.1.0 will not meet the minimum version specified by the arg. + gchar *atleast = g_strdup_printf ("--atleast-version=%d.%d", + GST_VERSION_MAJOR, GST_VERSION_MINOR); + const gchar *argv[] = { "gst-inspect-1.0", "--exists", + atleast, TEST_ELEMENT_NAME, NULL + }; + + fail_unless_equals_int (gst_inspect_main (ARGV_LEN, (gchar **) argv), 2); + g_free (atleast); } { /* check for plugin should fail like this */ diff --git a/subprojects/gstreamer/tools/gst-inspect.c b/subprojects/gstreamer/tools/gst-inspect.c index 06ed2dd4b9..10cba8ddb6 100644 --- a/subprojects/gstreamer/tools/gst-inspect.c +++ b/subprojects/gstreamer/tools/gst-inspect.c @@ -2139,6 +2139,7 @@ real_main (int argc, char *argv[]) gboolean print_aii = FALSE; gboolean uri_handlers = FALSE; gboolean check_exists = FALSE; + gboolean check_version = FALSE; gboolean color_always = FALSE; gchar *min_version = NULL; guint minver_maj = GST_VERSION_MAJOR; @@ -2253,6 +2254,7 @@ real_main (int argc, char *argv[]) } g_free (min_version); check_exists = TRUE; + check_version = TRUE; } if (check_exists) { @@ -2264,9 +2266,13 @@ real_main (int argc, char *argv[]) GstPluginFeature *feature; feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]); - if (feature != NULL && gst_plugin_feature_check_version (feature, - minver_maj, minver_min, minver_micro)) { - exit_code = 0; + if (feature != NULL) { + if (check_version && !gst_plugin_feature_check_version (feature, + minver_maj, minver_min, minver_micro)) { + exit_code = 2; + } else { + exit_code = 0; + } } else { exit_code = 1; }