validate: Add a way to avoid checking property value after setting it

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4485>
This commit is contained in:
Thibault Saunier 2023-04-19 13:46:31 -04:00 committed by GStreamer Marge Bot
parent aed4d31e67
commit 9dda8050f2
5 changed files with 108 additions and 15 deletions

View file

@ -1726,6 +1726,16 @@ target is in.</doc>
</array> </array>
</field> </field>
</record> </record>
<bitfield name="ObjectSetPropertyFlags" version="1.24" glib:type-name="GstValidateObjectSetPropertyFlags" glib:get-type="gst_validate_object_set_property_flags_get_type" c:type="GstValidateObjectSetPropertyFlags">
<member name="optional" value="1" c:identifier="GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL" glib:nick="optional">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-enums.h">The property is optional, if it
is not found on the object, nothing happens.</doc>
</member>
<member name="no_value_check" value="2" c:identifier="GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK" glib:nick="no-value-check">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-enums.h">Do not check that after
setting the property, the value is the one we set.</doc>
</member>
</bitfield>
<class name="Override" c:symbol-prefix="override" c:type="GstValidateOverride" parent="Gst.Object" glib:type-name="GstValidateOverride" glib:get-type="gst_validate_override_get_type" glib:type-struct="OverrideClass"> <class name="Override" c:symbol-prefix="override" c:type="GstValidateOverride" parent="Gst.Object" glib:type-name="GstValidateOverride" glib:get-type="gst_validate_override_get_type" glib:type-struct="OverrideClass">
<source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-override.h"/> <source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-override.h"/>
<implements name="Reporter"/> <implements name="Reporter"/>
@ -4092,6 +4102,34 @@ function.</doc>
</parameter> </parameter>
</parameters> </parameters>
</function> </function>
<function name="object_set_property_full" c:identifier="gst_validate_object_set_property_full" version="1.24">
<source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.h"/>
<return-value transfer-ownership="none">
<type name="ActionReturn" c:type="GstValidateActionReturn"/>
</return-value>
<parameters>
<parameter name="reporter" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The #GstValidateReporter to use to report errors</doc>
<type name="Reporter" c:type="GstValidateReporter*"/>
</parameter>
<parameter name="object" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The #GObject to set the property on</doc>
<type name="GObject.Object" c:type="GObject*"/>
</parameter>
<parameter name="property" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The name of the property to set</doc>
<type name="utf8" c:type="const gchar*"/>
</parameter>
<parameter name="value" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The value to set the property to</doc>
<type name="GObject.Value" c:type="const GValue*"/>
</parameter>
<parameter name="flags" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The #GstValidateObjectSetPropertyFlags to use</doc>
<type name="ObjectSetPropertyFlags" c:type="GstValidateObjectSetPropertyFlags"/>
</parameter>
</parameters>
</function>
<function name="override_registry_attach_overrides" c:identifier="gst_validate_override_registry_attach_overrides" moved-to="OverrideRegistry.attach_overrides"> <function name="override_registry_attach_overrides" c:identifier="gst_validate_override_registry_attach_overrides" moved-to="OverrideRegistry.attach_overrides">
<source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-override-registry.h"/> <source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-override-registry.h"/>
<return-value transfer-ownership="none"> <return-value transfer-ownership="none">

View file

@ -113,4 +113,19 @@ typedef enum {
GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION = 1 << 1, GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION = 1 << 1,
} GstValidateStructureResolveVariablesFlags; } GstValidateStructureResolveVariablesFlags;
/**
* GstValidateObjectSetPropertyFlags:
* @GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL: The property is optional, if it
* is not found on the object, nothing happens.
* @GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK: Do not check that after
* setting the property, the value is the one we set.
*
* Since: 1.24
*/
typedef enum {
GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL = (1 << 0),
GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK = (1 << 1),
} GstValidateObjectSetPropertyFlags;
#endif /* __GST_VALIDATE_ENUMS_H__ */ #endif /* __GST_VALIDATE_ENUMS_H__ */

View file

@ -1418,9 +1418,11 @@ _set_or_check_properties (GQuark field_id, const GValue * value,
GstValidateAction *action; GstValidateAction *action;
GstObject *obj = NULL; GstObject *obj = NULL;
GParamSpec *paramspec = NULL; GParamSpec *paramspec = NULL;
gboolean no_value_check = FALSE;
GstValidateObjectSetPropertyFlags flags = 0;
const gchar *field = g_quark_to_string (field_id); const gchar *field = g_quark_to_string (field_id);
const gchar *unused_fields[] = { "__scenario__", "__action__", "__res__", const gchar *unused_fields[] = { "__scenario__", "__action__", "__res__",
"playback-time", "repeat", NULL "playback-time", "repeat", "no-value-check", NULL
}; };
if (g_strv_contains (unused_fields, field)) if (g_strv_contains (unused_fields, field))
@ -1429,14 +1431,23 @@ _set_or_check_properties (GQuark field_id, const GValue * value,
gst_structure_get (structure, "__scenario__", G_TYPE_POINTER, &scenario, gst_structure_get (structure, "__scenario__", G_TYPE_POINTER, &scenario,
"__action__", G_TYPE_POINTER, &action, NULL); "__action__", G_TYPE_POINTER, &action, NULL);
gst_structure_get_boolean (structure, "no-value-check", &no_value_check);
if (no_value_check) {
flags |= GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK;
}
if (action->priv->optional)
flags |= GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL;
obj = _get_target_object_property (scenario, action, field, &paramspec); obj = _get_target_object_property (scenario, action, field, &paramspec);
if (!obj || !paramspec) { if (!obj || !paramspec) {
res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED; res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
goto done; goto done;
} }
if (gst_structure_has_name (action->structure, "set-properties")) if (gst_structure_has_name (action->structure, "set-properties"))
res = gst_validate_object_set_property (GST_VALIDATE_REPORTER (scenario), res =
G_OBJECT (obj), paramspec->name, value, action->priv->optional); gst_validate_object_set_property_full (GST_VALIDATE_REPORTER (scenario),
G_OBJECT (obj), paramspec->name, value, flags);
else else
res = _check_property (scenario, action, obj, paramspec->name, value); res = _check_property (scenario, action, obj, paramspec->name, value);

View file

@ -1032,10 +1032,20 @@ gst_validate_utils_get_clocktime (GstStructure * structure, const gchar * name,
return TRUE; return TRUE;
} }
/**
* gst_validate_object_set_property_full:
* @reporter: The #GstValidateReporter to use to report errors
* @object: The #GObject to set the property on
* @property: The name of the property to set
* @value: The value to set the property to
* @flags: The #GstValidateObjectSetPropertyFlags to use
*
* Since: 1.24
*/
GstValidateActionReturn GstValidateActionReturn
gst_validate_object_set_property (GstValidateReporter * reporter, gst_validate_object_set_property_full (GstValidateReporter * reporter,
GObject * object, const gchar * property, GObject * object, const gchar * property,
const GValue * value, gboolean optional) const GValue * value, GstValidateObjectSetPropertyFlags flags)
{ {
GParamSpec *paramspec; GParamSpec *paramspec;
GObjectClass *klass = G_OBJECT_GET_CLASS (object); GObjectClass *klass = G_OBJECT_GET_CLASS (object);
@ -1044,7 +1054,7 @@ gst_validate_object_set_property (GstValidateReporter * reporter,
paramspec = g_object_class_find_property (klass, property); paramspec = g_object_class_find_property (klass, property);
if (paramspec == NULL) { if (paramspec == NULL) {
if (optional) if (!!(flags & GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL))
return TRUE; return TRUE;
GST_ERROR ("Target doesn't have property %s", property); GST_ERROR ("Target doesn't have property %s", property);
return FALSE; return FALSE;
@ -1078,16 +1088,18 @@ gst_validate_object_set_property (GstValidateReporter * reporter,
g_value_init (&nvalue, paramspec->value_type); g_value_init (&nvalue, paramspec->value_type);
g_object_get_property (object, property, &nvalue); g_object_get_property (object, property, &nvalue);
if (gst_value_compare (&cvalue, &nvalue) != GST_VALUE_EQUAL) { if (!(flags & GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK)) {
gchar *nvalstr = gst_value_serialize (&nvalue); if (gst_value_compare (&cvalue, &nvalue) != GST_VALUE_EQUAL) {
gchar *cvalstr = gst_value_serialize (&cvalue); gchar *nvalstr = gst_value_serialize (&nvalue);
GST_VALIDATE_REPORT (reporter, SCENARIO_ACTION_EXECUTION_ERROR, gchar *cvalstr = gst_value_serialize (&cvalue);
"Setting value %" GST_PTR_FORMAT "::%s failed, expected value: %s" GST_VALIDATE_REPORT (reporter, SCENARIO_ACTION_EXECUTION_ERROR,
" value after setting %s", object, property, cvalstr, nvalstr); "Setting value %" GST_PTR_FORMAT "::%s failed, expected value: %s"
" value after setting %s", object, property, cvalstr, nvalstr);
res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED; res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
g_free (nvalstr); g_free (nvalstr);
g_free (cvalstr); g_free (cvalstr);
}
} }
g_value_reset (&cvalue); g_value_reset (&cvalue);
@ -1593,3 +1605,12 @@ gst_validate_fail_on_missing_plugin (void)
} }
return FALSE; return FALSE;
} }
GstValidateActionReturn
gst_validate_object_set_property (GstValidateReporter * reporter,
GObject * object,
const gchar * property, const GValue * value, gboolean optional)
{
return gst_validate_object_set_property_full (reporter, object, property,
value, optional ? GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL : 0);
}

View file

@ -74,6 +74,14 @@ GstValidateActionReturn gst_validate_object_set_property (GstValidateReporter *
const GValue * value, const GValue * value,
gboolean optional); gboolean optional);
GST_VALIDATE_API
GstValidateActionReturn gst_validate_object_set_property_full(GstValidateReporter * reporter,
GObject * object,
const gchar * property,
const GValue * value,
GstValidateObjectSetPropertyFlags flags);
GST_VALIDATE_API GST_VALIDATE_API
void gst_validate_spin_on_fault_signals (void); void gst_validate_spin_on_fault_signals (void);