Commit 758790ff authored by Thibault Saunier's avatar Thibault Saunier 🌵 Committed by GStreamer Marge Bot
Browse files

validate: Add private action type to check number of action type calls

Part-of: <gstreamer/gst-devtools!207>
parent 800cc245
...@@ -1018,6 +1018,10 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args) ...@@ -1018,6 +1018,10 @@ gst_validate_printf_valist (gpointer source, const gchar * format, va_list args)
GstValidateActionType *type = GST_VALIDATE_ACTION_TYPE (source); GstValidateActionType *type = GST_VALIDATE_ACTION_TYPE (source);
/* Ignore private action types */
if (g_str_has_prefix (type->name, "priv_"))
return;
g_string_append_printf (string, "\n## %s\n\n", type->name); g_string_append_printf (string, "\n## %s\n\n", type->name);
g_string_append_printf (string, "\n``` validate-scenario\n%s,", g_string_append_printf (string, "\n``` validate-scenario\n%s,",
......
...@@ -552,6 +552,11 @@ GType _gst_validate_action_type_type; ...@@ -552,6 +552,11 @@ GType _gst_validate_action_type_type;
GST_DEFINE_MINI_OBJECT_TYPE (GstValidateActionType, gst_validate_action_type); GST_DEFINE_MINI_OBJECT_TYPE (GstValidateActionType, gst_validate_action_type);
static GstValidateActionType *gst_validate_action_type_new (void); static GstValidateActionType *gst_validate_action_type_new (void);
struct _GstValidateActionTypePrivate
{
gint n_calls;
};
static void static void
_action_type_free (GstValidateActionType * type) _action_type_free (GstValidateActionType * type)
{ {
...@@ -559,6 +564,7 @@ _action_type_free (GstValidateActionType * type) ...@@ -559,6 +564,7 @@ _action_type_free (GstValidateActionType * type)
g_free (type->description); g_free (type->description);
g_free (type->name); g_free (type->name);
g_free (type->implementer_namespace); g_free (type->implementer_namespace);
g_free (type->priv);
if (type->overriden_type) if (type->overriden_type)
gst_mini_object_unref (GST_MINI_OBJECT (type->overriden_type)); gst_mini_object_unref (GST_MINI_OBJECT (type->overriden_type));
...@@ -569,6 +575,8 @@ _action_type_free (GstValidateActionType * type) ...@@ -569,6 +575,8 @@ _action_type_free (GstValidateActionType * type)
static void static void
gst_validate_action_type_init (GstValidateActionType * type) gst_validate_action_type_init (GstValidateActionType * type)
{ {
type->priv = g_new0 (GstValidateActionTypePrivate, 1);
gst_mini_object_init ((GstMiniObject *) type, 0, gst_mini_object_init ((GstMiniObject *) type, 0,
_gst_validate_action_type_type, NULL, NULL, _gst_validate_action_type_type, NULL, NULL,
(GstMiniObjectFreeFunction) _action_type_free); (GstMiniObjectFreeFunction) _action_type_free);
...@@ -2396,6 +2404,7 @@ gst_validate_execute_action (GstValidateActionType * action_type, ...@@ -2396,6 +2404,7 @@ gst_validate_execute_action (GstValidateActionType * action_type,
action->priv->execution_time = gst_util_get_timestamp (); action->priv->execution_time = gst_util_get_timestamp ();
action->priv->state = GST_VALIDATE_EXECUTE_ACTION_IN_PROGRESS; action->priv->state = GST_VALIDATE_EXECUTE_ACTION_IN_PROGRESS;
action_type->priv->n_calls++;
res = action_type->execute (scenario, action); res = action_type->execute (scenario, action);
gst_object_unref (scenario); gst_object_unref (scenario);
...@@ -2480,6 +2489,7 @@ _fill_action (GstValidateScenario * scenario, GstValidateAction * action, ...@@ -2480,6 +2489,7 @@ _fill_action (GstValidateScenario * scenario, GstValidateAction * action,
(gst_structure_get_boolean (action->structure, "as-config", (gst_structure_get_boolean (action->structure, "as-config",
&is_config) && is_config == TRUE)) { &is_config) && is_config == TRUE)) {
action_type->priv->n_calls++;
res = action_type->execute (scenario, action); res = action_type->execute (scenario, action);
gst_validate_print_action (action, NULL); gst_validate_print_action (action, NULL);
...@@ -3129,6 +3139,29 @@ _find_elements_defined_in_action (GstValidateScenario * scenario, ...@@ -3129,6 +3139,29 @@ _find_elements_defined_in_action (GstValidateScenario * scenario,
return targets; return targets;
} }
static GstValidateExecuteActionReturn
_execute_check_action_type_calls (GstValidateScenario * scenario,
GstValidateAction * action)
{
const gchar *type;
GstValidateActionType *t;
GstValidateExecuteActionReturn res = GST_VALIDATE_EXECUTE_ACTION_OK;
gint n;
REPORT_UNLESS (gst_structure_get_int (action->structure, "n", &n),
done, "No `n`!");
REPORT_UNLESS ((type = gst_structure_get_string (action->structure, "type")),
done, "No `type`!");
REPORT_UNLESS ((t =
_find_action_type (type)), done, "Can't find `%s`!", type);
REPORT_UNLESS (t->priv->n_calls == n, done,
"%s called %d times instead of expected %d", type, t->priv->n_calls, n);
done:
return res;
}
static GstValidateExecuteActionReturn static GstValidateExecuteActionReturn
_execute_check_position (GstValidateScenario * scenario, _execute_check_position (GstValidateScenario * scenario,
GstValidateAction * action) GstValidateAction * action)
...@@ -6785,7 +6818,11 @@ register_action_types (void) ...@@ -6785,7 +6818,11 @@ register_action_types (void)
{NULL} {NULL}
}), }),
"Check current pipeline position.\n", GST_VALIDATE_ACTION_TYPE_NONE); "Check current pipeline position.\n", GST_VALIDATE_ACTION_TYPE_NONE);
/* *INDENT-ON* */
/* Internal actions types to test the validate scenario implementation */
REGISTER_ACTION_TYPE("priv_check-action-type-calls",
_execute_check_action_type_calls, NULL, NULL, 0);
/* *INDENT-ON* */
} }
void void
......
...@@ -190,6 +190,8 @@ typedef enum ...@@ -190,6 +190,8 @@ typedef enum
GST_VALIDATE_ACTION_TYPE_HANDLED_IN_CONFIG = 1 << 9, GST_VALIDATE_ACTION_TYPE_HANDLED_IN_CONFIG = 1 << 9,
} GstValidateActionTypeFlags; } GstValidateActionTypeFlags;
typedef struct _GstValidateActionTypePrivate GstValidateActionTypePrivate;
/** /**
* GstValidateActionType: * GstValidateActionType:
* @name: The name of the new action type to add * @name: The name of the new action type to add
...@@ -217,9 +219,10 @@ struct _GstValidateActionType ...@@ -217,9 +219,10 @@ struct _GstValidateActionType
GstRank rank; GstRank rank;
GstValidateActionType *overriden_type; GstValidateActionType *overriden_type;
GstValidateActionTypePrivate* priv;
/*< private >*/ /*< private >*/
gpointer _gst_reserved[GST_PADDING_LARGE - sizeof (GstRank) - 1]; gpointer _gst_reserved[GST_PADDING_LARGE - sizeof (GstRank) - 2];
}; };
#define GST_TYPE_VALIDATE_ACTION_TYPE (gst_validate_action_type_get_type ()) #define GST_TYPE_VALIDATE_ACTION_TYPE (gst_validate_action_type_get_type ())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment