mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-01 06:01:04 +00:00
validate: Handle per file special scenarios
When a file is int the same folder as a media file and has a name like: mediafilename.mkv.scenarios_name.scenario we run that scenario on that particular file
This commit is contained in:
parent
1ffb6b4e1c
commit
804cdb5ad2
2 changed files with 73 additions and 15 deletions
|
@ -32,12 +32,20 @@ from utils import MediaFormatCombination, get_profile,\
|
|||
class MediaDescriptor(Loggable):
|
||||
def __init__(self, xml_path):
|
||||
Loggable.__init__(self)
|
||||
self._xml_path = xml_path
|
||||
self.media_xml = ET.parse(xml_path).getroot()
|
||||
|
||||
# Sanity checks
|
||||
self.media_xml.attrib["duration"]
|
||||
self.media_xml.attrib["seekable"]
|
||||
|
||||
def get_media_filepath(self):
|
||||
if self.get_protocol() == Protocols.FILE:
|
||||
return self._xml_path.replace("." + G_V_MEDIA_INFO_EXT, "")
|
||||
else:
|
||||
return self._xml_path.replace("." + G_V_STREAM_INFO_EXT, "")
|
||||
|
||||
|
||||
def get_caps(self):
|
||||
return self.media_xml.findall("streams")[0].attrib["caps"]
|
||||
|
||||
|
@ -362,7 +370,7 @@ class GstValidateManager(TestsManager, Loggable):
|
|||
for test_pipeline in G_V_PLAYBACK_TESTS:
|
||||
self._add_playback_test(test_pipeline)
|
||||
|
||||
for uri, mediainfo in self._list_uris():
|
||||
for uri, mediainfo, special_scenarios in self._list_uris():
|
||||
protocol = mediainfo.media_descriptor.get_protocol()
|
||||
try:
|
||||
timeout = G_V_PROTOCOL_TIMEOUTS[protocol]
|
||||
|
@ -379,7 +387,7 @@ class GstValidateManager(TestsManager, Loggable):
|
|||
mediainfo.path,
|
||||
timeout=timeout))
|
||||
|
||||
for uri, mediainfo in self._list_uris():
|
||||
for uri, mediainfo, special_scenarios in self._list_uris():
|
||||
if mediainfo.media_descriptor.is_image():
|
||||
continue
|
||||
for comb in G_V_ENCODING_TARGET_COMBINATIONS:
|
||||
|
@ -407,9 +415,13 @@ class GstValidateManager(TestsManager, Loggable):
|
|||
if caps2 == caps:
|
||||
media_descriptor.set_protocol(prot)
|
||||
break
|
||||
|
||||
scenario_bname = media_descriptor.get_media_filepath()
|
||||
special_scenarios = self._scenarios.find_special_scenarios(scenario_bname)
|
||||
self._uris.append((uri,
|
||||
NamedDic({"path": media_info,
|
||||
"media_descriptor": media_descriptor})))
|
||||
"media_descriptor": media_descriptor}),
|
||||
special_scenarios))
|
||||
except ConfigParser.NoOptionError as e:
|
||||
self.debug("Exception: %s for %s", e, media_info)
|
||||
|
||||
|
@ -450,7 +462,9 @@ class GstValidateManager(TestsManager, Loggable):
|
|||
for root, dirs, files in os.walk(path):
|
||||
for f in files:
|
||||
fpath = os.path.join(path, root, f)
|
||||
if os.path.isdir(fpath) or fpath.endswith(G_V_MEDIA_INFO_EXT):
|
||||
if os.path.isdir(fpath) or \
|
||||
fpath.endswith(G_V_MEDIA_INFO_EXT) or\
|
||||
fpath.endswith(ScenarioManager.FILE_EXTENDION):
|
||||
continue
|
||||
else:
|
||||
self._discover_file(path2url(fpath), fpath)
|
||||
|
@ -467,7 +481,7 @@ class GstValidateManager(TestsManager, Loggable):
|
|||
|
||||
def _add_playback_test(self, pipe_descriptor):
|
||||
if pipe_descriptor.needs_uri():
|
||||
for uri, minfo in self._list_uris():
|
||||
for uri, minfo, special_scenarios in self._list_uris():
|
||||
protocol = minfo.media_descriptor.get_protocol()
|
||||
if self._run_defaults:
|
||||
scenarios = [self._scenarios.get_scenario(scenario_name)
|
||||
|
@ -475,6 +489,7 @@ class GstValidateManager(TestsManager, Loggable):
|
|||
else:
|
||||
scenarios = self._scenarios.get_scenario(None)
|
||||
|
||||
scenarios.extend(special_scenarios)
|
||||
for scenario in scenarios:
|
||||
if not minfo.media_descriptor.is_compatible(scenario):
|
||||
continue
|
||||
|
|
|
@ -284,7 +284,8 @@ class GstValidateTest(Test):
|
|||
|
||||
def build_arguments(self):
|
||||
if self.scenario is not None:
|
||||
self.add_arguments("--set-scenario", self.scenario.name)
|
||||
self.add_arguments("--set-scenario",
|
||||
self.scenario.get_execution_name())
|
||||
|
||||
def get_extra_log_content(self, extralog):
|
||||
value = Test.get_extra_log_content(self, extralog)
|
||||
|
@ -662,12 +663,19 @@ class NamedDic(object):
|
|||
setattr(self, name, value)
|
||||
|
||||
class Scenario(object):
|
||||
def __init__(self, name, props):
|
||||
def __init__(self, name, props, path=None):
|
||||
self.name = name
|
||||
self.path = path
|
||||
|
||||
for prop, value in props:
|
||||
setattr(self, prop.replace("-", "_"), value)
|
||||
|
||||
def get_execution_name(self):
|
||||
if self.path is not None:
|
||||
return self.path
|
||||
else:
|
||||
return self.name
|
||||
|
||||
def seeks(self):
|
||||
if hasattr(self, "seek"):
|
||||
return bool(self.seek)
|
||||
|
@ -691,6 +699,8 @@ class Scenario(object):
|
|||
class ScenarioManager(Loggable):
|
||||
_instance = None
|
||||
all_scenarios = []
|
||||
|
||||
FILE_EXTENDION = "scenario"
|
||||
GST_VALIDATE_COMMAND = "gst-validate-1.0"
|
||||
if "win32" in sys.platform:
|
||||
GST_VALIDATE_COMMAND += ".exe"
|
||||
|
@ -705,12 +715,31 @@ class ScenarioManager(Loggable):
|
|||
|
||||
return cls._instance
|
||||
|
||||
def _discover_scenarios(self):
|
||||
def find_special_scenarios(self, mfile):
|
||||
scenarios = []
|
||||
mfile_bname = os.path.basename(mfile)
|
||||
for f in os.listdir(os.path.dirname(mfile)):
|
||||
if re.findall("%s\..*\.%s$" % (mfile_bname, self.FILE_EXTENDION),
|
||||
f):
|
||||
scenarios.append(os.path.join(os.path.dirname(mfile), f))
|
||||
|
||||
if scenarios:
|
||||
scenarios = self.discover_scenarios(scenarios, mfile)
|
||||
|
||||
|
||||
return scenarios
|
||||
|
||||
def discover_scenarios(self, scenario_paths=[], mfile=None):
|
||||
"""
|
||||
Discover scenarios specified in scenario_paths or the default ones
|
||||
if nothing specified there
|
||||
"""
|
||||
scenarios = []
|
||||
scenario_defs = os.path.join(self.config.main_dir, "scenarios.def")
|
||||
try:
|
||||
subprocess.check_output([self.GST_VALIDATE_COMMAND,
|
||||
"--scenarios-defs-output-file",
|
||||
scenario_defs])
|
||||
command = [self.GST_VALIDATE_COMMAND, "--scenarios-defs-output-file", scenario_defs]
|
||||
command.extend(scenario_paths)
|
||||
subprocess.check_output(command)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
|
@ -719,14 +748,28 @@ class ScenarioManager(Loggable):
|
|||
config.readfp(f)
|
||||
|
||||
for section in config.sections():
|
||||
self.all_scenarios.append(Scenario(section,
|
||||
config.items(section)))
|
||||
if scenario_paths:
|
||||
for scenario_path in scenario_paths:
|
||||
if section in scenario_path:
|
||||
# The real name of the scenario is:
|
||||
# filename.REALNAME.scenario
|
||||
name = scenario_path.replace(mfile + ".", "").replace("." + self.FILE_EXTENDION, "")
|
||||
path = scenario_path
|
||||
else:
|
||||
name = section
|
||||
path = None
|
||||
|
||||
scenarios.append(Scenario(name, config.items(section), path))
|
||||
|
||||
if not scenario_paths:
|
||||
self.discovered = True
|
||||
self.all_scenarios.extend(scenarios)
|
||||
|
||||
return scenarios
|
||||
|
||||
def get_scenario(self, name):
|
||||
if self.discovered is False:
|
||||
self._discover_scenarios()
|
||||
self.discover_scenarios()
|
||||
|
||||
if name is None:
|
||||
return self.all_scenarios
|
||||
|
|
Loading…
Reference in a new issue