summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Goodwin <thomas.goodwin@laerdal.com>2024-03-19 08:57:43 -0400
committerTim-Philipp Müller <tim@centricular.com>2024-03-21 00:13:59 +0100
commit5a80a146f0d8905f5a92dbe58985ab46e5d407fe (patch)
tree77bbc0c523301ebaaf113e9b55f7036daf9eaf75
parent11c6432cca8e7c5a117d260336b211aabf8b3fda (diff)
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/6414>
-rw-r--r--subprojects/gstreamer/tests/check/tools/gstinspect.c48
-rw-r--r--subprojects/gstreamer/tools/gst-inspect.c12
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 };
@@ -45,6 +62,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 7edd8634a5..18b260b129 100644
--- a/subprojects/gstreamer/tools/gst-inspect.c
+++ b/subprojects/gstreamer/tools/gst-inspect.c
@@ -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;
}