validate: Show the exact file line when error out in structure files

And minor stdout enhancements

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-devtools/-/merge_requests/185>
This commit is contained in:
Thibault Saunier 2020-04-28 12:51:21 -04:00
parent a99cbecd98
commit 66d29a31fd
5 changed files with 47 additions and 17 deletions

View file

@ -636,6 +636,9 @@ gst_validate_runner_add_report (GstValidateRunner * runner,
g_return_if_fail (GST_IS_VALIDATE_RUNNER (runner));
if (report->level == GST_VALIDATE_REPORT_LEVEL_IGNORE)
return;
gst_validate_send (json_boxed_serialize (GST_MINI_OBJECT_TYPE (report),
report));
gst_validate_runner_maybe_dot_pipeline (runner, report);

View file

@ -4088,7 +4088,7 @@ gst_validate_scenario_new (GstValidateRunner *
}
gst_validate_printf (NULL,
"\n**-> Running scenario %s on pipeline %s**\n\n", scenario_name,
"**-> Running scenario %s on pipeline %s**\n", scenario_name,
GST_OBJECT_NAME (pipeline));
g_weak_ref_init (&scenario->priv->ref_pipeline, pipeline);

View file

@ -570,6 +570,10 @@ _file_get_structures (GFile * file, gchar ** err)
gchar *filename = NULL;
gint lineno = 1, current_lineno;
GList *structures = NULL;
GString *errstr = NULL;
if (err)
errstr = g_string_new (NULL);
/* TODO Handle GCancellable */
if (!g_file_load_contents (file, NULL, &content, &size, NULL, &error)) {
@ -586,7 +590,7 @@ _file_get_structures (GFile * file, gchar ** err)
filename = g_file_get_path (file);
tmp = content;
while (*tmp) {
GString *l;
GString *l, *debug_line;
GstStructure *structure;
tmp = skip_spaces (tmp);
@ -607,17 +611,27 @@ _file_get_structures (GFile * file, gchar ** err)
}
l = g_string_new (NULL);
debug_line = g_string_new (NULL);
current_lineno = lineno;
while (*tmp != '\n' && *tmp) {
gchar next;
if (*tmp == '#')
while (*tmp && *tmp != '\n')
if (*tmp == '#') {
while (*tmp && *tmp != '\n') {
g_string_append_c (debug_line, *tmp);
tmp++;
}
tmp++;
g_string_append_printf (debug_line, "\n %4d | ", lineno + 1);
lineno++;
continue;
}
next = *(tmp + 1);
if (next && next == '\n'
&& strchr (GST_STRUCT_LINE_CONTINUATION_CHARS, *tmp)) {
g_string_append_c (debug_line, *tmp);
g_string_append_printf (debug_line, "\n %4d | ", lineno + 1);
if (*tmp != '\\')
g_string_append_c (l, *tmp);
@ -626,6 +640,7 @@ _file_get_structures (GFile * file, gchar ** err)
continue;
}
g_string_append_c (debug_line, *tmp);
g_string_append_c (l, *tmp);
tmp += 1;
}
@ -633,22 +648,27 @@ _file_get_structures (GFile * file, gchar ** err)
/* Blank lines at EOF */
if (!*l->str) {
g_string_free (l, TRUE);
g_string_free (debug_line, TRUE);
continue;
}
structure = gst_structure_from_string (l->str, NULL);
if (structure == NULL) {
GST_ERROR ("Could not parse structure at %s:%d\n %s", filename,
current_lineno, l->str);
if (err) {
gchar *tmp = *err;
*err =
g_strdup_printf ("%s\n%s:%d: Invalid structure\n %d | %s\n %*c|",
tmp ? tmp : "", filename, current_lineno, current_lineno, l->str,
(gint) floor (log10 (abs ((current_lineno)))) + 1, ' ');
g_free (tmp);
GST_ERROR ("Could not parse structure at %s:%d-%d\n %s", filename,
current_lineno, lineno, debug_line->str);
if (errstr) {
g_string_append_printf (errstr,
"\n%s:%d-%d: Invalid structure\n %4d | %s",
filename, current_lineno, lineno, current_lineno, debug_line->str);
if (strchr (debug_line->str, '\n'))
g_string_append_printf (errstr, "\n > %s\n", l->str);
g_string_append_c (errstr, '\n');
} else {
g_string_free (l, TRUE);
g_string_free (debug_line, TRUE);
goto failed;
}
} else {
@ -659,12 +679,15 @@ _file_get_structures (GFile * file, gchar ** err)
}
g_string_free (l, TRUE);
g_string_free (debug_line, TRUE);
lineno++;
if (*tmp)
tmp++;
}
done:
if (err)
*err = g_string_free (errstr, errstr->len ? FALSE : TRUE);
g_free (content);
g_free (filename);
return structures;

View file

@ -319,6 +319,8 @@ validate_flow_override_new (GstStructure * config)
if (g_file_test (flow->expectations_file_path, G_FILE_TEST_EXISTS)) {
flow->mode = VALIDATE_FLOW_MODE_WRITING_ACTUAL_RESULTS;
flow->output_file_path = g_strdup (flow->actual_results_file_path);
gst_validate_printf (NULL, "**-> Checking expectations file: '%s'**\n",
flow->expectations_file_path);
} else {
flow->mode = VALIDATE_FLOW_MODE_WRITING_EXPECTATIONS;
flow->output_file_path = g_strdup (flow->expectations_file_path);
@ -454,6 +456,7 @@ runner_stopping (GstValidateRunner * runner, ValidateFlowOverride * flow)
flow->expectations_file_path, error->message);
}
lines_expected = g_strsplit (contents, "\n", 0);
g_free (contents);
}
{
@ -466,6 +469,7 @@ runner_stopping (GstValidateRunner * runner, ValidateFlowOverride * flow)
flow->actual_results_file_path, error->message);
}
lines_actual = g_strsplit (contents, "\n", 0);
g_free (contents);
}
gst_validate_printf (flow, "Checking that flow %s matches expected flow %s\n"

View file

@ -552,9 +552,9 @@ main (int argc, gchar ** argv)
&bus_callback_data);
if (argc == 2)
g_print ("-> Starting pipeline");
g_print ("**-> Starting pipeline**\n");
else
g_print ("-> Starting pipeline\n");
g_print ("**-> Starting pipeline**\n");
g_free (argvn);
g_object_get (monitor, "handles-states", &monitor_handles_state, NULL);
@ -577,9 +577,9 @@ main (int argc, gchar ** argv)
default:
break;
}
g_print ("Pipeline started\n");
g_print ("**-> Pipeline started**\n");
} else {
g_print ("-> Letting scenario handle set state\n");
g_print ("**-> Letting scenario handle set state**\n");
}
g_main_loop_run (mainloop);