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)); 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), gst_validate_send (json_boxed_serialize (GST_MINI_OBJECT_TYPE (report),
report)); report));
gst_validate_runner_maybe_dot_pipeline (runner, report); gst_validate_runner_maybe_dot_pipeline (runner, report);

View file

@ -4088,7 +4088,7 @@ gst_validate_scenario_new (GstValidateRunner *
} }
gst_validate_printf (NULL, 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)); GST_OBJECT_NAME (pipeline));
g_weak_ref_init (&scenario->priv->ref_pipeline, 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; gchar *filename = NULL;
gint lineno = 1, current_lineno; gint lineno = 1, current_lineno;
GList *structures = NULL; GList *structures = NULL;
GString *errstr = NULL;
if (err)
errstr = g_string_new (NULL);
/* TODO Handle GCancellable */ /* TODO Handle GCancellable */
if (!g_file_load_contents (file, NULL, &content, &size, NULL, &error)) { 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); filename = g_file_get_path (file);
tmp = content; tmp = content;
while (*tmp) { while (*tmp) {
GString *l; GString *l, *debug_line;
GstStructure *structure; GstStructure *structure;
tmp = skip_spaces (tmp); tmp = skip_spaces (tmp);
@ -607,17 +611,27 @@ _file_get_structures (GFile * file, gchar ** err)
} }
l = g_string_new (NULL); l = g_string_new (NULL);
debug_line = g_string_new (NULL);
current_lineno = lineno; current_lineno = lineno;
while (*tmp != '\n' && *tmp) { while (*tmp != '\n' && *tmp) {
gchar next; gchar next;
if (*tmp == '#') if (*tmp == '#') {
while (*tmp && *tmp != '\n') while (*tmp && *tmp != '\n') {
g_string_append_c (debug_line, *tmp);
tmp++; tmp++;
}
tmp++;
g_string_append_printf (debug_line, "\n %4d | ", lineno + 1);
lineno++;
continue;
}
next = *(tmp + 1); next = *(tmp + 1);
if (next && next == '\n' if (next && next == '\n'
&& strchr (GST_STRUCT_LINE_CONTINUATION_CHARS, *tmp)) { && 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 != '\\') if (*tmp != '\\')
g_string_append_c (l, *tmp); g_string_append_c (l, *tmp);
@ -626,6 +640,7 @@ _file_get_structures (GFile * file, gchar ** err)
continue; continue;
} }
g_string_append_c (debug_line, *tmp);
g_string_append_c (l, *tmp); g_string_append_c (l, *tmp);
tmp += 1; tmp += 1;
} }
@ -633,22 +648,27 @@ _file_get_structures (GFile * file, gchar ** err)
/* Blank lines at EOF */ /* Blank lines at EOF */
if (!*l->str) { if (!*l->str) {
g_string_free (l, TRUE); g_string_free (l, TRUE);
g_string_free (debug_line, TRUE);
continue; continue;
} }
structure = gst_structure_from_string (l->str, NULL); structure = gst_structure_from_string (l->str, NULL);
if (structure == NULL) { if (structure == NULL) {
GST_ERROR ("Could not parse structure at %s:%d\n %s", filename, GST_ERROR ("Could not parse structure at %s:%d-%d\n %s", filename,
current_lineno, l->str); current_lineno, lineno, debug_line->str);
if (err) {
gchar *tmp = *err; if (errstr) {
*err = g_string_append_printf (errstr,
g_strdup_printf ("%s\n%s:%d: Invalid structure\n %d | %s\n %*c|", "\n%s:%d-%d: Invalid structure\n %4d | %s",
tmp ? tmp : "", filename, current_lineno, current_lineno, l->str, filename, current_lineno, lineno, current_lineno, debug_line->str);
(gint) floor (log10 (abs ((current_lineno)))) + 1, ' ');
g_free (tmp); if (strchr (debug_line->str, '\n'))
g_string_append_printf (errstr, "\n > %s\n", l->str);
g_string_append_c (errstr, '\n');
} else { } else {
g_string_free (l, TRUE); g_string_free (l, TRUE);
g_string_free (debug_line, TRUE);
goto failed; goto failed;
} }
} else { } else {
@ -659,12 +679,15 @@ _file_get_structures (GFile * file, gchar ** err)
} }
g_string_free (l, TRUE); g_string_free (l, TRUE);
g_string_free (debug_line, TRUE);
lineno++; lineno++;
if (*tmp) if (*tmp)
tmp++; tmp++;
} }
done: done:
if (err)
*err = g_string_free (errstr, errstr->len ? FALSE : TRUE);
g_free (content); g_free (content);
g_free (filename); g_free (filename);
return structures; 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)) { if (g_file_test (flow->expectations_file_path, G_FILE_TEST_EXISTS)) {
flow->mode = VALIDATE_FLOW_MODE_WRITING_ACTUAL_RESULTS; flow->mode = VALIDATE_FLOW_MODE_WRITING_ACTUAL_RESULTS;
flow->output_file_path = g_strdup (flow->actual_results_file_path); 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 { } else {
flow->mode = VALIDATE_FLOW_MODE_WRITING_EXPECTATIONS; flow->mode = VALIDATE_FLOW_MODE_WRITING_EXPECTATIONS;
flow->output_file_path = g_strdup (flow->expectations_file_path); 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); flow->expectations_file_path, error->message);
} }
lines_expected = g_strsplit (contents, "\n", 0); 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); flow->actual_results_file_path, error->message);
} }
lines_actual = g_strsplit (contents, "\n", 0); lines_actual = g_strsplit (contents, "\n", 0);
g_free (contents);
} }
gst_validate_printf (flow, "Checking that flow %s matches expected flow %s\n" 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); &bus_callback_data);
if (argc == 2) if (argc == 2)
g_print ("-> Starting pipeline"); g_print ("**-> Starting pipeline**\n");
else else
g_print ("-> Starting pipeline\n"); g_print ("**-> Starting pipeline**\n");
g_free (argvn); g_free (argvn);
g_object_get (monitor, "handles-states", &monitor_handles_state, NULL); g_object_get (monitor, "handles-states", &monitor_handles_state, NULL);
@ -577,9 +577,9 @@ main (int argc, gchar ** argv)
default: default:
break; break;
} }
g_print ("Pipeline started\n"); g_print ("**-> Pipeline started**\n");
} else { } else {
g_print ("-> Letting scenario handle set state\n"); g_print ("**-> Letting scenario handle set state**\n");
} }
g_main_loop_run (mainloop); g_main_loop_run (mainloop);