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 <thomas.goodwin@laerdal.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6191>
This commit is contained in:
Thomas Goodwin 2024-03-19 08:57:43 -04:00 committed by GStreamer Marge Bot
parent 2a4b9c8dc1
commit fde2495218
2 changed files with 53 additions and 7 deletions

View file

@ -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 */

View file

@ -2171,6 +2171,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;
@ -2285,6 +2286,7 @@ real_main (int argc, char *argv[])
}
g_free (min_version);
check_exists = TRUE;
check_version = TRUE;
}
if (check_exists) {
@ -2296,9 +2298,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;
}