validate:scenario: Enhance failures messages
authorThibault Saunier <tsaunier@igalia.com>
Sat, 25 Apr 2020 03:32:59 +0000 (23:32 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Mon, 27 Apr 2020 21:00:12 +0000 (17:00 -0400)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-devtools/-/merge_requests/182>

validate/gst/validate/gst-validate-scenario.c
validate/gst/validate/gst-validate-scenario.h

index e095ff3..0e0dba2 100644 (file)
@@ -46,6 +46,7 @@
 #include <gio/gio.h>
 #include <string.h>
 #include <errno.h>
+#include <math.h>
 
 #include <gst/check/gsttestclock.h>
 #include "gst-validate-internal.h"
@@ -220,6 +221,38 @@ gst_validate_g_enum_to_string (GType g_enum_type, gint value)
 }
 #endif
 
+static void
+g_error_action (gpointer action, const gchar * format, ...)
+{
+  const gchar *filename = NULL;
+  gint lineno = -1;
+  gchar *f, *tmp;
+  va_list var_args;
+
+  if (action) {
+    if (GST_IS_STRUCTURE (action)) {
+      filename = gst_structure_get_string (action, "__filename__");
+      gst_structure_get_int (action, "__lineno__", &lineno);
+    } else {
+      filename = GST_VALIDATE_ACTION_FILENAME (action);
+      lineno = GST_VALIDATE_ACTION_LINENO (action);
+    }
+  }
+
+  f = filename ? g_strdup_printf ("\n> %s:%d\n> %d | %s\n>  %*c|\n",
+      filename, lineno, lineno, format,
+      (gint) floor (log10 (abs ((lineno)))) + 1, ' ')
+      : g_strdup (format);
+
+  va_start (var_args, format);
+  tmp = gst_info_strdup_vprintf (f, var_args);
+  va_end (var_args);
+  g_free (f);
+
+  g_error ("%s", tmp);
+  g_free (tmp);
+}
+
 static GstValidateInterceptionReturn
 gst_validate_scenario_intercept_report (GstValidateReporter * reporter,
     GstValidateReport * report)
@@ -1793,10 +1826,8 @@ _set_action_playback_time (GstValidateScenario * scenario,
 {
   if (!gst_validate_action_get_clocktime (scenario, action,
           "playback-time", &action->playback_time)) {
-    gchar *str = gst_structure_to_string (action->structure);
-
-    g_error ("Could not parse playback-time on structure: %s", str);
-    g_free (str);
+    g_error_action (action, "Could not parse playback-time in %" GST_PTR_FORMAT,
+        action->structure);
 
     return FALSE;
   }
@@ -2100,7 +2131,8 @@ execute_next_action_full (GstValidateScenario * scenario, GstMessage * message)
       priv->actions = g_list_remove_link (priv->actions, tmp);
 
       if (!gst_validate_parse_next_action_playback_time (scenario)) {
-        g_error ("Could not determine next action playback time!");
+        g_error_action (priv->actions ? priv->actions->data : NULL,
+            "Could not determine next action playback time!");
 
         return G_SOURCE_REMOVE;
       }
@@ -2190,7 +2222,8 @@ execute_next_action_full (GstValidateScenario * scenario, GstMessage * message)
     priv->actions = g_list_remove_link (priv->actions, tmp);
 
     if (!gst_validate_parse_next_action_playback_time (scenario)) {
-      g_error ("Could not determine next action playback time!");
+      g_error_action (priv->actions ? priv->actions->data : NULL,
+          "Could not determine next action playback time!");
 
       return G_SOURCE_REMOVE;
     }
@@ -3048,9 +3081,7 @@ gst_validate_action_default_prepare_func (GstValidateAction * action)
   repeat_expr =
       g_strdup (gst_structure_get_string (action->structure, "repeat"));
   if (!repeat_expr) {
-    g_error ("Invalid value for 'repeat' in %s",
-        gst_structure_to_string (action->structure));
-
+    g_error_action (action, "Invalid value for 'repeat'");
     goto err;
   }
 
@@ -3058,9 +3089,7 @@ gst_validate_action_default_prepare_func (GstValidateAction * action)
       gst_validate_utils_parse_expression (repeat_expr, _set_variable_func,
       scenario, &error);
   if (error) {
-    g_error ("Invalid value for 'repeat' in %s: %s",
-        gst_structure_to_string (action->structure), error);
-
+    g_error_action (action, "Invalid value for 'repeat'");
     goto err;
   }
   g_free (repeat_expr);
@@ -3515,7 +3544,7 @@ gst_validate_scenario_load_structures (GstValidateScenario * scenario,
         continue;
       }
 
-      GST_ERROR_OBJECT (scenario, "We do not handle action types %s", type);
+      g_error_action (structure, "We do not handle action types %s", type);
       goto failed;
     }
 
@@ -3529,7 +3558,7 @@ gst_validate_scenario_load_structures (GstValidateScenario * scenario,
         if (action_type->parameters[i].mandatory &&
             gst_structure_has_field (structure,
                 action_type->parameters[i].name) == FALSE) {
-          GST_ERROR_OBJECT (scenario,
+          g_error_action (structure,
               "Mandatory field '%s' not present in structure: %" GST_PTR_FORMAT,
               action_type->parameters[i].name, structure);
           goto failed;
@@ -5222,7 +5251,8 @@ init_scenarios (void)
       GstValidateActionType *atype = _find_action_type (action_typename);
 
       if (!atype) {
-        g_error ("[CONFIG ERROR] Action type %s not found", action_typename);
+        g_error_action (plug_conf, "[CONFIG ERROR] Action type %s not found",
+            action_typename);
 
         continue;
       }
@@ -5236,7 +5266,8 @@ init_scenarios (void)
 
       if (!(atype->flags & GST_VALIDATE_ACTION_TYPE_CONFIG) &&
           !(_action_type_has_parameter (atype, "as-config"))) {
-        g_error ("[CONFIG ERROR] Action '%s' is not a config action",
+        g_error_action (plug_conf,
+            "[CONFIG ERROR] Action '%s' is not a config action",
             action_typename);
 
         continue;
index e09973b..ac4ca37 100644 (file)
@@ -89,8 +89,8 @@ typedef GstValidateExecuteActionReturn (*GstValidatePrepareAction) (GstValidateA
 
 typedef struct _GstValidateActionPrivate          GstValidateActionPrivate;
 
-#define GST_VALIDATE_ACTION_LINENO(action) (action->ABI.abi.lineno)
-#define GST_VALIDATE_ACTION_FILENAME(action) (action->ABI.abi.filename)
+#define GST_VALIDATE_ACTION_LINENO(action) (((GstValidateAction*) action)->ABI.abi.lineno)
+#define GST_VALIDATE_ACTION_FILENAME(action) (((GstValidateAction*) action)->ABI.abi.filename)
 
 /**
  * GstValidateAction: