validateflow: Fail when a pad is not attached

Previously validateflow tests did not fail when the pad was not
attached.

This was a limitation caused by how the Validate API worked. Before, the
`notify::validate-runner` signal was not emitted until a monitor was
attached to the override. This made impossible to listen for the
runner's `stopping` signal.

This patch fixes the problem by setting `validate-runner` for all
existing overrides when the runner is initialized and adding checks in
validateflow to error in the case no pad was attached.
This commit is contained in:
Alicia Boya García 2019-03-15 17:38:15 +00:00 committed by Thibault Saunier
parent 773f2e456c
commit e536b05e5a
4 changed files with 78 additions and 0 deletions

View file

@ -461,6 +461,37 @@ GList *gst_validate_override_registry_get_override_for_names
return ret; return ret;
} }
GList *
gst_validate_override_registry_get_override_list (GstValidateOverrideRegistry *
registry)
{
GList *all_overrides = NULL;
GList *i;
GST_VALIDATE_OVERRIDE_REGISTRY_LOCK (registry);
for (i = registry->name_overrides.head; i; i = i->next) {
GstValidateOverrideRegistryNameEntry *entry =
(GstValidateOverrideRegistryNameEntry *) i->data;
if (!g_list_find (all_overrides, entry->override))
all_overrides = g_list_append (all_overrides, entry->override);
}
for (i = registry->klass_overrides.head; i; i = i->next) {
GstValidateOverrideRegistryNameEntry *entry =
(GstValidateOverrideRegistryNameEntry *) i->data;
if (!g_list_find (all_overrides, entry->override))
all_overrides = g_list_append (all_overrides, entry->override);
}
for (i = registry->name_overrides.head; i; i = i->next) {
GstValidateOverrideRegistryGTypeEntry *entry =
(GstValidateOverrideRegistryGTypeEntry *) i->data;
if (!g_list_find (all_overrides, entry->override))
all_overrides = g_list_append (all_overrides, entry->override);
}
GST_VALIDATE_OVERRIDE_REGISTRY_UNLOCK (registry);
return all_overrides;
}
void void
_priv_validate_override_registry_deinit (void) _priv_validate_override_registry_deinit (void)
{ {

View file

@ -45,6 +45,8 @@ GstValidateOverrideRegistry * gst_validate_override_registry_get (void);
GST_VALIDATE_API GList * GST_VALIDATE_API GList *
gst_validate_override_registry_get_override_for_names (GstValidateOverrideRegistry *reg, gst_validate_override_registry_get_override_for_names (GstValidateOverrideRegistry *reg,
const gchar *name, ...); const gchar *name, ...);
GST_VALIDATE_API GList *
gst_validate_override_registry_get_override_list (GstValidateOverrideRegistry *reg);
GST_VALIDATE_API GST_VALIDATE_API
void gst_validate_override_register_by_name (const gchar * name, GstValidateOverride * override); void gst_validate_override_register_by_name (const gchar * name, GstValidateOverride * override);
GST_VALIDATE_API GST_VALIDATE_API

View file

@ -35,6 +35,7 @@
#include "gst-validate-monitor-factory.h" #include "gst-validate-monitor-factory.h"
#include "gst-validate-override-registry.h" #include "gst-validate-override-registry.h"
#include "gst-validate-runner.h" #include "gst-validate-runner.h"
#include "gst-validate-reporter.h"
GST_DEBUG_CATEGORY_STATIC (gst_validate_runner_debug); GST_DEBUG_CATEGORY_STATIC (gst_validate_runner_debug);
#undef GST_CAT_DEFAULT #undef GST_CAT_DEFAULT
@ -473,6 +474,20 @@ gst_validate_runner_new (void)
runner->priv->user_created = TRUE; runner->priv->user_created = TRUE;
} }
{
GstValidateOverrideRegistry *registry =
gst_validate_override_registry_get ();
GList *all_overrides =
gst_validate_override_registry_get_override_list (registry);
GList *i;
for (i = all_overrides; i; i = i->next) {
GstValidateOverride *override = (GstValidateOverride *) i->data;
gst_validate_reporter_set_runner (GST_VALIDATE_REPORTER (override),
runner);
}
g_list_free (all_overrides);
}
return runner; return runner;
} }

View file

@ -38,6 +38,7 @@
#include <stdio.h> #include <stdio.h>
#define VALIDATE_FLOW_MISMATCH g_quark_from_static_string ("validateflow::mismatch") #define VALIDATE_FLOW_MISMATCH g_quark_from_static_string ("validateflow::mismatch")
#define VALIDATE_FLOW_NOT_ATTACHED g_quark_from_static_string ("validateflow::not-attached")
typedef enum _ValidateFlowMode typedef enum _ValidateFlowMode
{ {
@ -60,6 +61,7 @@ typedef struct _ValidateFlowOverride
gchar *expectations_file_path; gchar *expectations_file_path;
gchar *actual_results_file_path; gchar *actual_results_file_path;
ValidateFlowMode mode; ValidateFlowMode mode;
gboolean was_attached;
/* output_file will refer to the expectations file if it did not exist, /* output_file will refer to the expectations file if it did not exist,
* or to the actual results file otherwise. */ * or to the actual results file otherwise. */
@ -72,6 +74,7 @@ typedef struct _ValidateFlowOverride
GList *all_overrides = NULL; GList *all_overrides = NULL;
static void validate_flow_override_finalize (GObject * object); static void validate_flow_override_finalize (GObject * object);
static void validate_flow_override_attached (GstValidateOverride * override);
static void _runner_set (GObject * object, GParamSpec * pspec, static void _runner_set (GObject * object, GParamSpec * pspec,
gpointer user_data); gpointer user_data);
static void runner_stopping (GstValidateRunner * runner, static void runner_stopping (GstValidateRunner * runner,
@ -92,7 +95,11 @@ void
validate_flow_override_class_init (ValidateFlowOverrideClass * klass) validate_flow_override_class_init (ValidateFlowOverrideClass * klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GstValidateOverrideClass *override_class =
GST_VALIDATE_OVERRIDE_CLASS (klass);
object_class->finalize = validate_flow_override_finalize; object_class->finalize = validate_flow_override_finalize;
override_class->attached = validate_flow_override_attached;
g_assert (gst_validate_is_initialized ()); g_assert (gst_validate_is_initialized ());
@ -101,6 +108,12 @@ validate_flow_override_class_init (ValidateFlowOverrideClass * klass)
"The recorded log does not match the expectation file.", "The recorded log does not match the expectation file.",
"The recorded log does not match the expectation file.", "The recorded log does not match the expectation file.",
GST_VALIDATE_REPORT_LEVEL_CRITICAL)); GST_VALIDATE_REPORT_LEVEL_CRITICAL));
gst_validate_issue_register (gst_validate_issue_new
(VALIDATE_FLOW_NOT_ATTACHED,
"The pad to monitor was never attached.",
"The pad to monitor was never attached.",
GST_VALIDATE_REPORT_LEVEL_CRITICAL));
} }
static void static void
@ -284,6 +297,8 @@ validate_flow_override_new (GstStructure * config)
if (!flow->output_file) if (!flow->output_file)
g_error ("Could not open for writing: %s", flow->output_file_path); g_error ("Could not open for writing: %s", flow->output_file_path);
flow->was_attached = FALSE;
gst_validate_override_register_by_name (flow->pad_name, override); gst_validate_override_register_by_name (flow->pad_name, override);
override->buffer_handler = validate_flow_override_buffer_handler; override->buffer_handler = validate_flow_override_buffer_handler;
@ -306,6 +321,13 @@ _runner_set (GObject * object, GParamSpec * pspec, gpointer user_data)
gst_object_unref (runner); gst_object_unref (runner);
} }
static void
validate_flow_override_attached (GstValidateOverride * override)
{
ValidateFlowOverride *flow = VALIDATE_FLOW_OVERRIDE (override);
flow->was_attached = TRUE;
}
static void static void
run_diff (const gchar * expected_file, const gchar * actual_file) run_diff (const gchar * expected_file, const gchar * actual_file)
{ {
@ -369,6 +391,14 @@ runner_stopping (GstValidateRunner * runner, ValidateFlowOverride * flow)
fclose (flow->output_file); fclose (flow->output_file);
flow->output_file = NULL; flow->output_file = NULL;
if (!flow->was_attached) {
GST_VALIDATE_REPORT (flow, VALIDATE_FLOW_NOT_ATTACHED,
"The test ended without the pad ever being attached: %s",
flow->pad_name);
return;
}
if (flow->mode == VALIDATE_FLOW_MODE_WRITING_EXPECTATIONS) if (flow->mode == VALIDATE_FLOW_MODE_WRITING_EXPECTATIONS)
return; return;