mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-26 16:06:52 +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):
|
class MediaDescriptor(Loggable):
|
||||||
def __init__(self, xml_path):
|
def __init__(self, xml_path):
|
||||||
Loggable.__init__(self)
|
Loggable.__init__(self)
|
||||||
|
self._xml_path = xml_path
|
||||||
self.media_xml = ET.parse(xml_path).getroot()
|
self.media_xml = ET.parse(xml_path).getroot()
|
||||||
|
|
||||||
# Sanity checks
|
# Sanity checks
|
||||||
self.media_xml.attrib["duration"]
|
self.media_xml.attrib["duration"]
|
||||||
self.media_xml.attrib["seekable"]
|
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):
|
def get_caps(self):
|
||||||
return self.media_xml.findall("streams")[0].attrib["caps"]
|
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:
|
for test_pipeline in G_V_PLAYBACK_TESTS:
|
||||||
self._add_playback_test(test_pipeline)
|
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()
|
protocol = mediainfo.media_descriptor.get_protocol()
|
||||||
try:
|
try:
|
||||||
timeout = G_V_PROTOCOL_TIMEOUTS[protocol]
|
timeout = G_V_PROTOCOL_TIMEOUTS[protocol]
|
||||||
|
@ -379,7 +387,7 @@ class GstValidateManager(TestsManager, Loggable):
|
||||||
mediainfo.path,
|
mediainfo.path,
|
||||||
timeout=timeout))
|
timeout=timeout))
|
||||||
|
|
||||||
for uri, mediainfo in self._list_uris():
|
for uri, mediainfo, special_scenarios in self._list_uris():
|
||||||
if mediainfo.media_descriptor.is_image():
|
if mediainfo.media_descriptor.is_image():
|
||||||
continue
|
continue
|
||||||
for comb in G_V_ENCODING_TARGET_COMBINATIONS:
|
for comb in G_V_ENCODING_TARGET_COMBINATIONS:
|
||||||
|
@ -407,9 +415,13 @@ class GstValidateManager(TestsManager, Loggable):
|
||||||
if caps2 == caps:
|
if caps2 == caps:
|
||||||
media_descriptor.set_protocol(prot)
|
media_descriptor.set_protocol(prot)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
scenario_bname = media_descriptor.get_media_filepath()
|
||||||
|
special_scenarios = self._scenarios.find_special_scenarios(scenario_bname)
|
||||||
self._uris.append((uri,
|
self._uris.append((uri,
|
||||||
NamedDic({"path": media_info,
|
NamedDic({"path": media_info,
|
||||||
"media_descriptor": media_descriptor})))
|
"media_descriptor": media_descriptor}),
|
||||||
|
special_scenarios))
|
||||||
except ConfigParser.NoOptionError as e:
|
except ConfigParser.NoOptionError as e:
|
||||||
self.debug("Exception: %s for %s", e, media_info)
|
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 root, dirs, files in os.walk(path):
|
||||||
for f in files:
|
for f in files:
|
||||||
fpath = os.path.join(path, root, f)
|
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
|
continue
|
||||||
else:
|
else:
|
||||||
self._discover_file(path2url(fpath), fpath)
|
self._discover_file(path2url(fpath), fpath)
|
||||||
|
@ -467,7 +481,7 @@ class GstValidateManager(TestsManager, Loggable):
|
||||||
|
|
||||||
def _add_playback_test(self, pipe_descriptor):
|
def _add_playback_test(self, pipe_descriptor):
|
||||||
if pipe_descriptor.needs_uri():
|
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()
|
protocol = minfo.media_descriptor.get_protocol()
|
||||||
if self._run_defaults:
|
if self._run_defaults:
|
||||||
scenarios = [self._scenarios.get_scenario(scenario_name)
|
scenarios = [self._scenarios.get_scenario(scenario_name)
|
||||||
|
@ -475,6 +489,7 @@ class GstValidateManager(TestsManager, Loggable):
|
||||||
else:
|
else:
|
||||||
scenarios = self._scenarios.get_scenario(None)
|
scenarios = self._scenarios.get_scenario(None)
|
||||||
|
|
||||||
|
scenarios.extend(special_scenarios)
|
||||||
for scenario in scenarios:
|
for scenario in scenarios:
|
||||||
if not minfo.media_descriptor.is_compatible(scenario):
|
if not minfo.media_descriptor.is_compatible(scenario):
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -284,7 +284,8 @@ class GstValidateTest(Test):
|
||||||
|
|
||||||
def build_arguments(self):
|
def build_arguments(self):
|
||||||
if self.scenario is not None:
|
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):
|
def get_extra_log_content(self, extralog):
|
||||||
value = Test.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)
|
setattr(self, name, value)
|
||||||
|
|
||||||
class Scenario(object):
|
class Scenario(object):
|
||||||
def __init__(self, name, props):
|
def __init__(self, name, props, path=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.path = path
|
||||||
|
|
||||||
for prop, value in props:
|
for prop, value in props:
|
||||||
setattr(self, prop.replace("-", "_"), value)
|
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):
|
def seeks(self):
|
||||||
if hasattr(self, "seek"):
|
if hasattr(self, "seek"):
|
||||||
return bool(self.seek)
|
return bool(self.seek)
|
||||||
|
@ -691,6 +699,8 @@ class Scenario(object):
|
||||||
class ScenarioManager(Loggable):
|
class ScenarioManager(Loggable):
|
||||||
_instance = None
|
_instance = None
|
||||||
all_scenarios = []
|
all_scenarios = []
|
||||||
|
|
||||||
|
FILE_EXTENDION = "scenario"
|
||||||
GST_VALIDATE_COMMAND = "gst-validate-1.0"
|
GST_VALIDATE_COMMAND = "gst-validate-1.0"
|
||||||
if "win32" in sys.platform:
|
if "win32" in sys.platform:
|
||||||
GST_VALIDATE_COMMAND += ".exe"
|
GST_VALIDATE_COMMAND += ".exe"
|
||||||
|
@ -705,12 +715,31 @@ class ScenarioManager(Loggable):
|
||||||
|
|
||||||
return cls._instance
|
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")
|
scenario_defs = os.path.join(self.config.main_dir, "scenarios.def")
|
||||||
try:
|
try:
|
||||||
subprocess.check_output([self.GST_VALIDATE_COMMAND,
|
command = [self.GST_VALIDATE_COMMAND, "--scenarios-defs-output-file", scenario_defs]
|
||||||
"--scenarios-defs-output-file",
|
command.extend(scenario_paths)
|
||||||
scenario_defs])
|
subprocess.check_output(command)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -719,14 +748,28 @@ class ScenarioManager(Loggable):
|
||||||
config.readfp(f)
|
config.readfp(f)
|
||||||
|
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
self.all_scenarios.append(Scenario(section,
|
if scenario_paths:
|
||||||
config.items(section)))
|
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
|
||||||
|
|
||||||
self.discovered = True
|
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):
|
def get_scenario(self, name):
|
||||||
if self.discovered is False:
|
if self.discovered is False:
|
||||||
self._discover_scenarios()
|
self.discover_scenarios()
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
return self.all_scenarios
|
return self.all_scenarios
|
||||||
|
|
Loading…
Reference in a new issue