From bc622ec6585807419336eb9f2195255e44973660 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 7 Jan 2020 19:29:05 -0300 Subject: [PATCH] validate:launcher: Batch inspecting scenarios Removing almost 1 second to start running tests with the default testsuite --- validate/gst/validate/gst-validate-scenario.c | 12 ++++---- validate/launcher/apps/gstvalidate.py | 8 +++++ validate/launcher/baseclasses.py | 29 ++++++++++++++----- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/validate/gst/validate/gst-validate-scenario.c b/validate/gst/validate/gst-validate-scenario.c index ff6eb2aebc..7aa69dfea2 100644 --- a/validate/gst/validate/gst-validate-scenario.c +++ b/validate/gst/validate/gst-validate-scenario.c @@ -4056,13 +4056,12 @@ static gboolean _parse_scenario (GFile * f, GKeyFile * kf) { gboolean ret = FALSE; - gchar *fname = g_file_get_basename (f); + gchar *path = g_file_get_path (f); - if (g_str_has_suffix (fname, GST_VALIDATE_SCENARIO_SUFFIX)) { + if (g_str_has_suffix (path, GST_VALIDATE_SCENARIO_SUFFIX)) { gboolean needs_clock_sync = FALSE; GstStructure *desc = NULL; - gchar **name = g_strsplit (fname, GST_VALIDATE_SCENARIO_SUFFIX, 0); GList *tmp, *structures = gst_validate_structs_parse_from_gfile (f); for (tmp = structures; tmp; tmp = tmp->next) { @@ -4088,22 +4087,21 @@ _parse_scenario (GFile * f, GKeyFile * kf) if (desc) { KeyFileGroupName kfg; - kfg.group_name = name[0]; + kfg.group_name = g_file_get_path (f); kfg.kf = kf; gst_structure_foreach (desc, (GstStructureForeachFunc) _add_description, &kfg); gst_structure_free (desc); } else { - g_key_file_set_string (kf, name[0], "noinfo", "nothing"); + g_key_file_set_string (kf, path, "noinfo", "nothing"); } g_list_free_full (structures, (GDestroyNotify) gst_structure_free); - g_strfreev (name); ret = TRUE; } - g_free (fname); + g_free (path); return ret; } diff --git a/validate/launcher/apps/gstvalidate.py b/validate/launcher/apps/gstvalidate.py index aac329650e..a156d3c3ee 100644 --- a/validate/launcher/apps/gstvalidate.py +++ b/validate/launcher/apps/gstvalidate.py @@ -314,6 +314,14 @@ class GstValidatePipelineTestsGenerator(GstValidateTestsGenerator): uri_minfo_special_scenarios, scenarios) def populate_tests(self, uri_minfo_special_scenarios, scenarios): + + special_scenarios = [] + for description in self._pipelines_descriptions: + for s in description.get('extra_data', {}).get('scenarios', []): + if os.path.isabs(s): + special_scenarios.append(s) + + self.test_manager.scenarios_manager.discover_scenarios(special_scenarios) for description in self._pipelines_descriptions: pipeline = description['pipeline'] extra_data = description.get('extra_data', {}) diff --git a/validate/launcher/baseclasses.py b/validate/launcher/baseclasses.py index ed51940ebc..2b6b9bd8f9 100644 --- a/validate/launcher/baseclasses.py +++ b/validate/launcher/baseclasses.py @@ -2187,7 +2187,8 @@ class Scenario(object): class ScenarioManager(Loggable): _instance = None - all_scenarios = [] + system_scenarios = [] + special_scenarios = {} FILE_EXTENSION = "scenario" @@ -2239,11 +2240,12 @@ class ScenarioManager(Loggable): config.readfp(f) for section in config.sections(): + name = None if scenario_paths: for scenario_path in scenario_paths: - if section in os.path.splitext(os.path.basename(scenario_path))[0]: + if section == scenario_path: if mfile is None: - name = section + name = os.path.basename(section).replace("." + self.FILE_EXTENSION, "") path = scenario_path else: # The real name of the scenario is: @@ -2251,22 +2253,33 @@ class ScenarioManager(Loggable): name = scenario_path.replace(mfile + ".", "").replace( "." + self.FILE_EXTENSION, "") path = scenario_path + break else: - name = section + name = os.path.basename(section).replace("." + self.FILE_EXTENSION, "") path = None + assert name + props = config.items(section) - scenarios.append(Scenario(name, props, path)) + scenario = Scenario(name, props, path) + if scenario_paths: + self.special_scenarios[path] = scenario + scenarios.append(scenario) if not scenario_paths: self.discovered = True - self.all_scenarios.extend(scenarios) + self.system_scenarios.extend(scenarios) return scenarios def get_scenario(self, name): if name is not None and os.path.isabs(name) and name.endswith(self.FILE_EXTENSION): + scenario = self.special_scenarios.get(name) + if scenario: + return scenario + scenarios = self.discover_scenarios([name]) + self.special_scenarios[name] = scenarios if scenarios: return scenarios[0] @@ -2275,10 +2288,10 @@ class ScenarioManager(Loggable): self.discover_scenarios() if name is None: - return self.all_scenarios + return self.system_scenarios try: - return [scenario for scenario in self.all_scenarios if scenario.name == name][0] + return [scenario for scenario in self.system_scenarios if scenario.name == name][0] except IndexError: self.warning("Scenario: %s not found" % name) return None