validate: tools: Implement the notion of hard timeout

Allowing to define timeout that is not relative to the last observed number.
This commit is contained in:
Thibault Saunier 2014-01-24 13:59:56 +01:00
parent 2391a56714
commit 2520f4f110
2 changed files with 34 additions and 7 deletions

View file

@ -78,7 +78,9 @@ class GstValidateLaunchTest(GstValidateTest):
super(GstValidateLaunchTest, self).__init__(DEFAULT_GST_VALIDATE, classname,
options, reporter,
scenario=scenario,)
scenario=scenario,
timeout=timeout)
self.pipeline_desc = pipeline_desc
self.file_infos = file_infos
@ -105,11 +107,26 @@ class GstValidateMediaCheckTest(Test):
class GstValidateTranscodingTest(GstValidateTest):
def __init__(self, classname, options, reporter,
combination, uri, file_infos):
combination, uri, file_infos, timeout=DEFAULT_TIMEOUT,
scenario=Scenario.get_scenario("play_15s")):
try:
timeout = PROTOCOL_TIMEOUTS[file_infos.get("file-info", "protocol")]
except KeyError:
pass
try:
# FIXME Come up with a less arbitrary calculation!
hard_timeout = 4 * scenario.max_duration + timeout
except AttributeError:
hard_timeout = None
pass
super(GstValidateTranscodingTest, self).__init__(
DEFAULT_GST_VALIDATE_TRANSCODING, classname,
options, reporter, scenario=None)
options, reporter, scenario=scenario, timeout=timeout,
hard_timeout=hard_timeout)
self.file_infos = file_infos
self.uri = uri
self.combination = combination

View file

@ -36,9 +36,15 @@ class Test(Loggable):
""" A class representing a particular test. """
def __init__(self, application_name, classname, options,
reporter, timeout=DEFAULT_TIMEOUT):
reporter, timeout=DEFAULT_TIMEOUT, hard_timeout=None):
"""
@timeout: The timeout during which the value return by get_current_value
keeps being exactly equal
@hard_timeout: Max time the test can take in absolute
"""
Loggable.__init__(self)
self.timeout = timeout
self.hard_timeout = hard_timeout
self.classname = classname
self.options = options
self.application = application_name
@ -111,6 +117,7 @@ class Test(Loggable):
def wait_process(self):
last_val = 0
last_change_ts = time.time()
start_ts = time.time()
while True:
self.process.poll()
if self.process.returncode is not None:
@ -137,10 +144,13 @@ class Test(Loggable):
if val == last_val:
delta = time.time() - last_change_ts
self.debug("Same value for %d seconds" % delta)
self.debug("%s: Same value for %d/%d seconds" % (self, delta, self.timeout))
if delta > self.timeout:
self.result = Result.TIMEOUT
break
elif self.hard_timeout and time.time() - start_ts > self.hard_timeout:
self.result = Result.TIMEOUT
break
else:
last_change_ts = time.time()
last_val = val
@ -192,10 +202,10 @@ class GstValidateTest(Test):
def __init__(self, application_name, classname,
options, reporter, timeout=DEFAULT_TIMEOUT,
scenario=None):
scenario=None, hard_timeout=None):
super(GstValidateTest, self).__init__(application_name, classname, options,
reporter, timeout=DEFAULT_TIMEOUT)
reporter, timeout=timeout, hard_timeout=hard_timeout)
if scenario is None or scenario.name.lower() == "none":
self.scenario = None