From ec2a139246b3f09542e12fda885aa84be1f8706b Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 28 Apr 2020 23:06:24 -0400 Subject: [PATCH] validate: Allow overidding issue severity from configs Refactoring sensibly to allow getting configs outside the `core` namespace and outside plugin names. The `GST_VALIDATE_OVERRIDE` env variable should probably be removed all together at some point. Part-of: --- docs/gst-validate-config.md | 21 ++++++-- validate/gst/validate/gst-validate-internal.h | 1 + .../validate/gst-validate-override-registry.c | 20 +++++--- validate/gst/validate/validate.c | 51 +++++++++++-------- 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/docs/gst-validate-config.md b/docs/gst-validate-config.md index a4bcea268b..c2f5e0784b 100644 --- a/docs/gst-validate-config.md +++ b/docs/gst-validate-config.md @@ -27,7 +27,7 @@ See [GstValidateVerbosityFlags](GstValidateVerbosityFlags) for possible values. The [action type](gst-validate-action-types.md) to execute, the action type must be a CONFIG action or the action type must have a `as-config` argument. When the `action` -is specified in a parametter, a validate action is executed using the other parametters of the +is specified in a parameter, a validate action is executed using the other parameters of the config as configuration for the validate scenario action. #### Example: @@ -72,7 +72,7 @@ Defaults variables are: - `$(CONFIG_DIR)`: The directory the running scenario is in. - `$(CONFIG_NAME)`: The name of the config file - `$(LOGSDIR)`: The directory where to place log files. This uses the - `GST_VALIDATE_LOGSDIR` environment variable if avalaible or `$(TMPDIR)` if + `GST_VALIDATE_LOGSDIR` environment variable if available or `$(TMPDIR)` if the variables hasn't been set. (Note that the [gst-validate-launcher](gst-validate-launcher.md) set the environment variables). @@ -88,4 +88,19 @@ It is also possible to set global variables (also usable from ``` yaml set-globals, TESTSUITE_ROOT_DIR=$(CONFIG_DIR) -``` \ No newline at end of file +``` + +## `change-issue-severity` settings parameters + +You can change issues severity with the `change-issue-severity` configuration +with the following parameters: + +* `issue-id`: The GQuark name of the issue, for example: `event::segment-has-wrong-start`, + You can use `gst-validate-1.0 --print-issue-types` to list all issue types. +* `new-severity`: The new [`severity`](GstValidateReportLevel) of the issue +* `element-name` (*optional*): The name of the element the severity + change applies to +* `element-factory-name` (*optional*): The element factory name of the elements the + severity change applies to +* `element-classification` (*optional*): The classification of the elements the + severity change applies to diff --git a/validate/gst/validate/gst-validate-internal.h b/validate/gst/validate/gst-validate-internal.h index 962d0b2285..07912a2164 100644 --- a/validate/gst/validate/gst-validate-internal.h +++ b/validate/gst/validate/gst-validate-internal.h @@ -62,4 +62,5 @@ G_GNUC_INTERNAL void gst_validate_set_test_file_globals (GstStructure* meta, con G_GNUC_INTERNAL gboolean gst_validate_get_test_file_scenario (GList** structs, const gchar** scenario_name, gchar** original_name); G_GNUC_INTERNAL GstValidateScenario* gst_validate_scenario_from_structs (GstValidateRunner* runner, GstElement* pipeline, GList* structures, gchar* origin_file); +G_GNUC_INTERNAL GList* gst_validate_get_config(const gchar *structname); #endif diff --git a/validate/gst/validate/gst-validate-override-registry.c b/validate/gst/validate/gst-validate-override-registry.c index 9a5ce1217e..1506366d49 100644 --- a/validate/gst/validate/gst-validate-override-registry.c +++ b/validate/gst/validate/gst-validate-override-registry.c @@ -263,39 +263,42 @@ _add_override_from_struct (GstStructure * soverride) gboolean registered = FALSE; - if (!gst_structure_has_name (soverride, "change-severity")) { - GST_ERROR ("Currently only 'change-severity' overrides are supported"); + if (!gst_structure_has_name (soverride, "change-severity") + && !gst_structure_has_name (soverride, "change-issue-severity")) { + g_error ("Currently only 'change-severity' overrides are supported"); return FALSE; } str_issue_id = gst_structure_get_string (soverride, "issue-id"); if (!str_issue_id) { - GST_ERROR ("No issue id provided in override: %" GST_PTR_FORMAT, soverride); + g_error ("No issue id provided in override: %" GST_PTR_FORMAT, soverride); return FALSE; } issue_id = g_quark_from_string (str_issue_id); if (gst_validate_issue_from_id (issue_id) == NULL) { - GST_ERROR ("No GstValidateIssue registered for %s", str_issue_id); + g_error ("No GstValidateIssue registered for %s", str_issue_id); return FALSE; } str_new_severity = gst_structure_get_string (soverride, "new-severity"); if (str_new_severity == NULL) { - GST_ERROR ("No 'new-severity' field found in %" GST_PTR_FORMAT, soverride); + g_error ("No 'new-severity' field found in %" GST_PTR_FORMAT, soverride); return FALSE; } level = gst_validate_report_level_from_name (str_new_severity); if (level == GST_VALIDATE_REPORT_LEVEL_UNKNOWN) { - GST_ERROR ("Unknown level name %s", str_new_severity); + g_error ("Unknown level name %s", str_new_severity); return FALSE; } + gst_validate_printf (NULL, "**-> Changing issue '%s' severity to: '%s'\n", + str_issue_id, str_new_severity); override = gst_validate_override_new (); gst_validate_override_change_severity (override, issue_id, level); @@ -385,6 +388,11 @@ gst_validate_override_registry_preload (void) GModule *module; int ret, nloaded = 0; gpointer ext_create_overrides; + GList *tmp, *overrides = gst_validate_get_config ("change-issue-severity"); + + for (tmp = overrides; tmp; tmp = tmp->next) + _add_override_from_struct (tmp->data); + g_list_free_full (overrides, (GDestroyNotify) gst_structure_free); sos = g_getenv ("GST_VALIDATE_OVERRIDE"); if (!sos) { diff --git a/validate/gst/validate/validate.c b/validate/gst/validate/validate.c index 8770927a36..dfeebfdd08 100644 --- a/validate/gst/validate/validate.c +++ b/validate/gst/validate/validate.c @@ -287,11 +287,8 @@ gst_validate_get_testfile_configs (const gchar * suffix) GList * gst_validate_plugin_get_config (GstPlugin * plugin) { - GList *plugin_conf = NULL; const gchar *suffix; - const gchar *config; - GStrv tmp; - guint i; + GList *plugin_conf = NULL; if (plugin) { if ((plugin_conf = @@ -306,22 +303,7 @@ gst_validate_plugin_get_config (GstPlugin * plugin) suffix = "core"; } - plugin_conf = gst_validate_get_testfile_configs (suffix); - config = g_getenv ("GST_VALIDATE_CONFIG"); - if (!config) { - return plugin_conf; - } - - tmp = g_strsplit (config, G_SEARCHPATH_SEPARATOR_S, -1); - for (i = 0; tmp[i] != NULL; i++) { - GList *l; - - l = create_config (tmp[i], suffix); - if (l) - plugin_conf = g_list_concat (plugin_conf, l); - } - g_strfreev (tmp); - + plugin_conf = gst_validate_get_config (suffix); if (plugin) g_object_set_data_full (G_OBJECT (plugin), GST_VALIDATE_PLUGIN_CONFIG, plugin_conf, _free_plugin_config); @@ -331,6 +313,35 @@ gst_validate_plugin_get_config (GstPlugin * plugin) return plugin_conf; } +GList * +gst_validate_get_config (const gchar * structname) +{ + + const gchar *config; + GStrv tmp; + guint i; + GList *configs; + + + configs = gst_validate_get_testfile_configs (structname); + config = g_getenv ("GST_VALIDATE_CONFIG"); + if (!config) { + return configs; + } + + tmp = g_strsplit (config, G_SEARCHPATH_SEPARATOR_S, -1); + for (i = 0; tmp[i] != NULL; i++) { + GList *l; + + l = create_config (tmp[i], structname); + if (l) + configs = g_list_concat (configs, l); + } + g_strfreev (tmp); + + return configs; +} + static void gst_validate_init_plugins (void) {