summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@igalia.com>2021-05-24 01:19:13 -0400
committerThibault Saunier <tsaunier@igalia.com>2021-05-27 12:23:05 -0400
commit8b8a6c8a18d239a16a7f5cae73001f29587266d1 (patch)
treeafde2188c57ca88913dcf7980d9fa219fd66cbf9
parentb3065bb9ec59ce7bb36791752cb720134986dcef (diff)
validate: Add a flag to allow defining how to resolve variables in structs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-devtools/-/merge_requests/248>
-rw-r--r--validate/gst/validate/gst-validate-enums.h14
-rw-r--r--validate/gst/validate/gst-validate-scenario.c6
-rw-r--r--validate/gst/validate/gst-validate-utils.c28
-rw-r--r--validate/gst/validate/gst-validate-utils.h6
-rw-r--r--validate/gst/validate/validate.c6
-rw-r--r--validate/tests/check/validate/utilities.c2
6 files changed, 42 insertions, 20 deletions
diff --git a/validate/gst/validate/gst-validate-enums.h b/validate/gst/validate/gst-validate-enums.h
index 217b6da..3dbf994 100644
--- a/validate/gst/validate/gst-validate-enums.h
+++ b/validate/gst/validate/gst-validate-enums.h
@@ -101,4 +101,16 @@ typedef enum
GST_VALIDATE_VERBOSITY_ALL = GST_VALIDATE_VERBOSITY_POSITION | GST_VALIDATE_VERBOSITY_MESSAGES | GST_VALIDATE_VERBOSITY_PROPS_CHANGES | GST_VALIDATE_VERBOSITY_NEW_ELEMENTS
} GstValidateVerbosityFlags;
-#endif /* __GST_VALIDATE_RUNNER_H__ */
+/**
+ * GstValidateStructureResolveVariablesFlags:
+ *
+ * Since: 1.20
+ */
+typedef enum {
+ GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL = 0,
+ GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_LOCAL_ONLY = 1 << 0,
+ GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_FAILURE = 1 << 1,
+ GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION = 1 << 1,
+} GstValidateStructureResolveVariablesFlags;
+
+#endif /* __GST_VALIDATE_ENUMS_H__ */
diff --git a/validate/gst/validate/gst-validate-scenario.c b/validate/gst/validate/gst-validate-scenario.c
index 0f12ab4..86de5a4 100644
--- a/validate/gst/validate/gst-validate-scenario.c
+++ b/validate/gst/validate/gst-validate-scenario.c
@@ -875,7 +875,7 @@ gst_validate_action_get_clocktime (GstValidateScenario * scenario,
_update_well_known_vars (scenario);
strval =
gst_validate_replace_variables_in_string (action, scenario->priv->vars,
- tmpvalue);
+ tmpvalue, GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL);
if (!strval)
return FALSE;
@@ -3676,7 +3676,7 @@ gst_validate_action_setup_repeat (GstValidateScenario * scenario,
repeat_expr = gst_validate_replace_variables_in_string (action,
scenario->priv->vars, gst_structure_get_string (action->structure,
- "repeat"));
+ "repeat"), GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL);
if (!repeat_expr) {
gst_validate_error_structure (action, "Invalid value for 'repeat'");
return FALSE;
@@ -3731,7 +3731,7 @@ gst_validate_action_default_prepare_func (GstValidateAction * action)
GST_VALIDATE_ACTION_RANGE_NAME (action) : "repeat", G_TYPE_INT,
action->repeat, NULL);
gst_validate_structure_resolve_variables (action, action->structure,
- scenario->priv->vars);
+ scenario->priv->vars, GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_ALL);
for (i = 0; type->parameters[i].name; i++) {
if (type->parameters[i].types
&& g_str_has_suffix (type->parameters[i].types, "(GstClockTime)"))
diff --git a/validate/gst/validate/gst-validate-utils.c b/validate/gst/validate/gst-validate-utils.c
index 29157f0..d57de65 100644
--- a/validate/gst/validate/gst-validate-utils.c
+++ b/validate/gst/validate/gst-validate-utils.c
@@ -1216,7 +1216,8 @@ gst_structure_get_value_as_string (GstStructure * structure,
gchar *
gst_validate_replace_variables_in_string (gpointer source,
- GstStructure * local_vars, const gchar * in_string)
+ GstStructure * local_vars, const gchar * in_string,
+ GstValidateStructureResolveVariablesFlags flags)
{
gint varname_len;
GMatchInfo *match_info = NULL;
@@ -1246,20 +1247,24 @@ gst_validate_replace_variables_in_string (gpointer source,
if (local_vars)
var_value = gst_structure_get_value_as_string (local_vars, varname);
- if (!var_value)
+ if (!var_value
+ && !(flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_LOCAL_ONLY))
var_value = gst_structure_get_value_as_string (global_vars, varname);
+ }
- if (!var_value) {
+ if (!var_value) {
+ if (!(flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_FAILURE)) {
gst_validate_error_structure (source,
"Trying to use undefined variable `%s`.\n"
" Available vars:\n"
" - locals%s\n"
" - globals%s\n",
varname, gst_structure_to_string (local_vars),
- gst_structure_to_string (global_vars));
-
- return NULL;
+ (flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_LOCAL_ONLY) ?
+ ": unused" : gst_structure_to_string (global_vars));
}
+
+ return NULL;
}
tmp = g_strdup_printf ("\\$\\(%s\\)", varname);
@@ -1290,6 +1295,7 @@ typedef struct
{
gpointer source;
GstStructure *local_vars;
+ GstValidateStructureResolveVariablesFlags flags;
} ReplaceData;
static void
@@ -1354,22 +1360,24 @@ _structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
str =
gst_validate_replace_variables_in_string (data->source, data->local_vars,
- g_value_get_string (value));
+ g_value_get_string (value), data->flags);
if (str) {
g_value_set_string (value, str);
g_free (str);
}
- _resolve_expression (data->source, value);
+ if (!(data->flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION))
+ _resolve_expression (data->source, value);
return TRUE;
}
void
gst_validate_structure_resolve_variables (gpointer source,
- GstStructure * structure, GstStructure * local_variables)
+ GstStructure * structure, GstStructure * local_variables,
+ GstValidateStructureResolveVariablesFlags flags)
{
- ReplaceData d = { source ? source : structure, local_variables };
+ ReplaceData d = { source ? source : structure, local_variables, flags };
gst_structure_filter_and_map_in_place (structure,
(GstStructureFilterMapFunc) _structure_set_variables, &d);
diff --git a/validate/gst/validate/gst-validate-utils.h b/validate/gst/validate/gst-validate-utils.h
index 34cdefe..2589f18 100644
--- a/validate/gst/validate/gst-validate-utils.h
+++ b/validate/gst/validate/gst-validate-utils.h
@@ -79,9 +79,11 @@ void gst_validate_spin_on_fault_signals (void);
GST_VALIDATE_API
gboolean gst_validate_element_matches_target (GstElement * element, GstStructure * s);
-gchar * gst_validate_replace_variables_in_string (gpointer incom, GstStructure * local_vars, const gchar * in_string);
+gchar * gst_validate_replace_variables_in_string (gpointer incom, GstStructure * local_vars, const gchar * in_string,
+ GstValidateStructureResolveVariablesFlags flags);
GST_VALIDATE_API
-void gst_validate_structure_resolve_variables (gpointer source, GstStructure *structure, GstStructure *local_variables);
+void gst_validate_structure_resolve_variables (gpointer source, GstStructure *structure, GstStructure *local_variables,
+ GstValidateStructureResolveVariablesFlags flags);
void gst_validate_structure_set_variables_from_struct_file(GstStructure* vars, const gchar* struct_file);
void gst_validate_set_globals(GstStructure* structure);
GST_VALIDATE_API
diff --git a/validate/gst/validate/validate.c b/validate/gst/validate/validate.c
index 4097b92..e96f063 100644
--- a/validate/gst/validate/validate.c
+++ b/validate/gst/validate/validate.c
@@ -202,11 +202,11 @@ create_config (const gchar * config)
gst_structure_free (structure);
} else if (!loaded_globals
&& gst_structure_has_name (structure, "set-globals")) {
- gst_validate_structure_resolve_variables (NULL, structure, local_vars);
+ gst_validate_structure_resolve_variables (NULL, structure, local_vars, 0);
gst_validate_set_globals (structure);
gst_structure_free (structure);
} else {
- gst_validate_structure_resolve_variables (NULL, structure, local_vars);
+ gst_validate_structure_resolve_variables (NULL, structure, local_vars, 0);
all_configs = g_list_append (all_configs, structure);
}
}
@@ -621,7 +621,7 @@ gst_validate_setup_test_file (const gchar * testfile, gboolean use_fakesinks)
gst_validate_scenario_check_and_set_needs_clock_sync (testfile_structs, &res);
gst_validate_set_test_file_globals (res, testfile, use_fakesinks);
- gst_validate_structure_resolve_variables (NULL, res, NULL);
+ gst_validate_structure_resolve_variables (NULL, res, NULL, 0);
tool = gst_structure_get_string (res, "tool");
if (!tool)
diff --git a/validate/tests/check/validate/utilities.c b/validate/tests/check/validate/utilities.c
index f1b6d19..e6c420a 100644
--- a/validate/tests/check/validate/utilities.c
+++ b/validate/tests/check/validate/utilities.c
@@ -8,7 +8,7 @@ GST_START_TEST (test_resolve_variables)
gst_structure_from_string ("vars, a=(string)1, b=(string)2", NULL);
GstStructure *s2 = gst_structure_from_string ("test, n=\"$(a)/$(b)\"", NULL);
- gst_validate_structure_resolve_variables (NULL, s2, s1);
+ gst_validate_structure_resolve_variables (NULL, s2, s1, 0);
fail_unless_equals_string (gst_structure_get_string (s2, "n"), "1/2");
gst_structure_free (s1);
gst_structure_free (s2);