2013-12-31 10:45:07 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013,Thibault Saunier <thibault.saunier@collabora.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
""" Class representing tests and test managers. """
|
|
|
|
|
|
|
|
import os
|
2014-03-28 14:00:01 +00:00
|
|
|
import sys
|
2013-12-31 10:45:07 +00:00
|
|
|
import re
|
|
|
|
import time
|
2014-01-15 15:11:39 +00:00
|
|
|
import utils
|
2014-04-22 08:49:10 +00:00
|
|
|
import signal
|
2014-01-30 11:42:25 +00:00
|
|
|
import urlparse
|
2013-12-31 10:45:07 +00:00
|
|
|
import subprocess
|
|
|
|
import reporters
|
2014-02-12 10:18:14 +00:00
|
|
|
import ConfigParser
|
2014-01-09 08:39:05 +00:00
|
|
|
from loggable import Loggable
|
2013-12-31 10:45:07 +00:00
|
|
|
from optparse import OptionGroup
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-02-13 14:31:58 +00:00
|
|
|
from utils import mkdir, Result, Colors, printc, DEFAULT_TIMEOUT, GST_SECOND
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
|
2014-01-08 17:51:14 +00:00
|
|
|
class Test(Loggable):
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
""" A class representing a particular test. """
|
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
def __init__(self, application_name, classname, options,
|
2014-01-24 12:59:56 +00:00
|
|
|
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
|
|
|
|
"""
|
2014-01-08 17:51:14 +00:00
|
|
|
Loggable.__init__(self)
|
2013-12-31 10:45:07 +00:00
|
|
|
self.timeout = timeout
|
2014-01-24 12:59:56 +00:00
|
|
|
self.hard_timeout = hard_timeout
|
2013-12-31 10:45:07 +00:00
|
|
|
self.classname = classname
|
|
|
|
self.options = options
|
|
|
|
self.application = application_name
|
|
|
|
self.command = ""
|
|
|
|
self.reporter = reporter
|
|
|
|
self.process = None
|
|
|
|
|
2014-02-19 12:07:03 +00:00
|
|
|
self.clean()
|
|
|
|
|
|
|
|
def clean(self):
|
2013-12-31 10:45:07 +00:00
|
|
|
self.message = ""
|
2014-01-22 23:15:54 +00:00
|
|
|
self.error_str = ""
|
2013-12-31 10:45:07 +00:00
|
|
|
self.time_taken = 0.0
|
2013-12-31 10:45:07 +00:00
|
|
|
self._starting_time = None
|
|
|
|
self.result = Result.NOT_RUN
|
2014-01-10 14:30:38 +00:00
|
|
|
self.logfile = None
|
2014-03-26 19:09:12 +00:00
|
|
|
self.extra_logfiles = []
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
string = self.classname
|
2013-12-31 10:45:07 +00:00
|
|
|
if self.result != Result.NOT_RUN:
|
2013-12-31 10:45:07 +00:00
|
|
|
string += ": " + self.result
|
2014-01-09 08:27:50 +00:00
|
|
|
if self.result in [Result.FAILED, Result.TIMEOUT]:
|
2014-03-26 19:09:12 +00:00
|
|
|
string += " '%s'\n" \
|
|
|
|
" You can reproduce with: %s\n" \
|
|
|
|
" You can find logs in:\n" \
|
|
|
|
" - %s" % (self.message, self.command,
|
|
|
|
self.logfile)
|
|
|
|
for log in self.extra_logfiles:
|
|
|
|
string += "\n - %s" % log
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
return string
|
|
|
|
|
2014-04-23 09:47:10 +00:00
|
|
|
def get_extra_log_content(self, extralog):
|
|
|
|
if extralog not in self.extra_logfiles:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
f = open(extralog, 'r+')
|
|
|
|
value = f.read()
|
|
|
|
f.close()
|
|
|
|
|
2014-04-26 07:16:26 +00:00
|
|
|
return value
|
2014-04-23 09:47:10 +00:00
|
|
|
|
|
|
|
|
2014-01-10 15:46:00 +00:00
|
|
|
def get_classname(self):
|
|
|
|
name = self.classname.split('.')[-1]
|
|
|
|
classname = self.classname.replace('.%s' % name, '')
|
|
|
|
|
|
|
|
return classname
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return self.classname.split('.')[-1]
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def add_arguments(self, *args):
|
|
|
|
for arg in args:
|
|
|
|
self.command += " " + arg
|
|
|
|
|
|
|
|
def build_arguments(self):
|
2014-01-09 08:14:27 +00:00
|
|
|
pass
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def set_result(self, result, message="", error=""):
|
2014-02-19 09:31:15 +00:00
|
|
|
self.debug("Setting result: %s (message: %s, error: %s", result,
|
|
|
|
message, error)
|
2014-03-26 18:37:44 +00:00
|
|
|
if result is Result.TIMEOUT and self.options.debug is True:
|
|
|
|
pname = subprocess.check_output(("readlink -e /proc/%s/exe"
|
|
|
|
% self.process.pid).split(' ')).replace('\n', '')
|
|
|
|
raw_input("%sTimeout happened you can attach gdb doing: $gdb %s %d%s\n"
|
|
|
|
"Press enter to continue" %(Colors.FAIL, pname, self.process.pid,
|
|
|
|
Colors.ENDC))
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
self.result = result
|
|
|
|
self.message = message
|
2014-01-22 23:15:54 +00:00
|
|
|
self.error_str = error
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def check_results(self):
|
2014-01-09 08:14:27 +00:00
|
|
|
if self.result is Result.FAILED:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.debug("%s returncode: %s", self, self.process.returncode)
|
2013-12-31 10:45:07 +00:00
|
|
|
if self.result == Result.TIMEOUT:
|
|
|
|
self.set_result(Result.TIMEOUT, "Application timed out", "timeout")
|
|
|
|
elif self.process.returncode == 0:
|
2014-02-19 09:31:15 +00:00
|
|
|
self.set_result(Result.PASSED)
|
2013-12-31 10:45:07 +00:00
|
|
|
else:
|
2014-01-09 08:28:02 +00:00
|
|
|
self.set_result(Result.FAILED,
|
|
|
|
"Application returned %d" % (
|
|
|
|
self.process.returncode))
|
2014-01-09 08:14:27 +00:00
|
|
|
|
|
|
|
def get_current_value(self):
|
|
|
|
"""
|
|
|
|
Lets subclasses implement a nicer timeout measurement method
|
|
|
|
They should return some value with which we will compare
|
|
|
|
the previous and timeout if they are egual during self.timeout
|
|
|
|
seconds
|
|
|
|
"""
|
|
|
|
return Result.NOT_RUN
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def wait_process(self):
|
2014-01-09 08:14:27 +00:00
|
|
|
last_val = 0
|
2013-12-31 10:45:07 +00:00
|
|
|
last_change_ts = time.time()
|
2014-01-24 12:59:56 +00:00
|
|
|
start_ts = time.time()
|
2013-12-31 10:45:07 +00:00
|
|
|
while True:
|
|
|
|
self.process.poll()
|
|
|
|
if self.process.returncode is not None:
|
|
|
|
break
|
|
|
|
|
|
|
|
# Dirty way to avoid eating to much CPU...
|
|
|
|
# good enough for us anyway.
|
|
|
|
time.sleep(1)
|
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
val = self.get_current_value()
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-14 17:07:46 +00:00
|
|
|
self.debug("Got value: %s" % val)
|
2014-01-09 08:14:27 +00:00
|
|
|
if val is Result.NOT_RUN:
|
|
|
|
# The get_current_value logic is not implemented... dumb timeout
|
|
|
|
if time.time() - last_change_ts > self.timeout:
|
2014-03-26 18:37:44 +00:00
|
|
|
self.set_result(Result.TIMEOUT)
|
2014-01-09 08:14:27 +00:00
|
|
|
break
|
|
|
|
continue
|
|
|
|
elif val is Result.FAILED:
|
|
|
|
break
|
2014-02-13 14:31:58 +00:00
|
|
|
elif val is Result.KNOWN_ERROR:
|
|
|
|
break
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
self.log("New val %s" % val)
|
|
|
|
|
|
|
|
if val == last_val:
|
|
|
|
delta = time.time() - last_change_ts
|
2014-01-24 12:59:56 +00:00
|
|
|
self.debug("%s: Same value for %d/%d seconds" % (self, delta, self.timeout))
|
2014-01-09 08:14:27 +00:00
|
|
|
if delta > self.timeout:
|
2014-03-26 18:37:44 +00:00
|
|
|
self.set_result(Result.TIMEOUT)
|
2014-01-09 08:14:27 +00:00
|
|
|
break
|
2014-01-24 12:59:56 +00:00
|
|
|
elif self.hard_timeout and time.time() - start_ts > self.hard_timeout:
|
2014-04-25 11:19:19 +00:00
|
|
|
self.set_result(Result.TIMEOUT, "Hard timeout reached: %d", self.hard_timeout)
|
2014-01-24 12:59:56 +00:00
|
|
|
break
|
2014-01-09 08:14:27 +00:00
|
|
|
else:
|
|
|
|
last_change_ts = time.time()
|
|
|
|
last_val = val
|
|
|
|
|
|
|
|
self.check_results()
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-03-26 19:09:12 +00:00
|
|
|
def get_subproc_env(self):
|
|
|
|
return os.environ
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def run(self):
|
|
|
|
self.command = "%s " % (self.application)
|
|
|
|
self._starting_time = time.time()
|
|
|
|
self.build_arguments()
|
2014-03-26 19:09:12 +00:00
|
|
|
proc_env = self.get_subproc_env()
|
|
|
|
|
|
|
|
message = "Launching: %s%s\n" \
|
|
|
|
" Command: '%s'\n" \
|
|
|
|
" Logs:\n" \
|
|
|
|
" - %s" % (Colors.ENDC, self.classname,
|
|
|
|
self.command, self.logfile)
|
|
|
|
for log in self.extra_logfiles:
|
|
|
|
message += "\n - %s" % log
|
|
|
|
|
|
|
|
printc(message, Colors.OKBLUE)
|
2014-04-02 17:14:30 +00:00
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
try:
|
2014-04-22 08:49:10 +00:00
|
|
|
self.process = subprocess.Popen("exec " + self.command,
|
2013-12-31 10:45:07 +00:00
|
|
|
stderr=self.reporter.out,
|
|
|
|
stdout=self.reporter.out,
|
2014-03-26 19:09:12 +00:00
|
|
|
shell=True,
|
|
|
|
env=proc_env)
|
2013-12-31 10:45:07 +00:00
|
|
|
self.wait_process()
|
|
|
|
except KeyboardInterrupt:
|
2014-04-22 08:49:10 +00:00
|
|
|
self.process.send_signal(signal.SIGINT)
|
2013-12-31 10:45:07 +00:00
|
|
|
raise
|
|
|
|
|
|
|
|
try:
|
2014-04-22 08:49:10 +00:00
|
|
|
self.process.send_signal(signal.SIGINT)
|
2013-12-31 10:45:07 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.time_taken = time.time() - self._starting_time
|
|
|
|
|
2014-01-10 16:21:44 +00:00
|
|
|
self.reporter.out.seek(0)
|
|
|
|
self.reporter.out.write("=================\n"
|
|
|
|
"Test name: %s\n"
|
|
|
|
"Command: '%s'\n"
|
|
|
|
"=================\n\n"
|
|
|
|
% (self.classname, self.command))
|
2014-01-15 15:11:39 +00:00
|
|
|
printc("Result: %s%s\n" % (self.result,
|
|
|
|
" (" + self.message + ")" if self.message else ""),
|
|
|
|
color=utils.get_color_for_result(self.result))
|
2014-01-10 16:21:44 +00:00
|
|
|
|
2014-01-13 16:31:57 +00:00
|
|
|
return self.result
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
class GstValidateTest(Test):
|
|
|
|
|
|
|
|
""" A class representing a particular test. """
|
2014-01-31 11:21:21 +00:00
|
|
|
findpos_regex = re.compile('.*position.*(\d+):(\d+):(\d+).(\d+).*duration.*(\d+):(\d+):(\d+).(\d+)')
|
|
|
|
findlastseek_regex = re.compile('seeking to.*(\d+):(\d+):(\d+).(\d+).*stop.*(\d+):(\d+):(\d+).(\d+).*rate.*(\d+)\.(\d+)')
|
2014-01-09 08:14:27 +00:00
|
|
|
|
|
|
|
def __init__(self, application_name, classname,
|
|
|
|
options, reporter, timeout=DEFAULT_TIMEOUT,
|
2014-02-14 15:07:51 +00:00
|
|
|
scenario=None, hard_timeout=None):
|
2014-01-09 08:14:27 +00:00
|
|
|
|
|
|
|
super(GstValidateTest, self).__init__(application_name, classname, options,
|
2014-01-24 12:59:56 +00:00
|
|
|
reporter, timeout=timeout, hard_timeout=hard_timeout)
|
2014-01-09 08:14:27 +00:00
|
|
|
|
2014-01-30 11:42:25 +00:00
|
|
|
# defines how much the process can be outside of the configured
|
|
|
|
# segment / seek
|
2014-02-13 14:31:58 +00:00
|
|
|
self._sent_eos_pos = None
|
2014-01-30 11:42:25 +00:00
|
|
|
|
2014-04-23 09:47:10 +00:00
|
|
|
self.validatelogs = None
|
2014-01-22 23:15:54 +00:00
|
|
|
if scenario is None or scenario.name.lower() == "none":
|
2014-01-09 08:14:27 +00:00
|
|
|
self.scenario = None
|
|
|
|
else:
|
|
|
|
self.scenario = scenario
|
|
|
|
|
2014-03-26 19:09:12 +00:00
|
|
|
def get_subproc_env(self):
|
|
|
|
subproc_env = os.environ.copy()
|
|
|
|
|
2014-04-23 09:47:10 +00:00
|
|
|
self.validatelogs = self.logfile + '.validate.logs'
|
|
|
|
utils.touch(self.validatelogs)
|
|
|
|
subproc_env["GST_VALIDATE_FILE"] = self.validatelogs
|
|
|
|
self.extra_logfiles.append(self.validatelogs)
|
|
|
|
|
2014-03-26 19:09:12 +00:00
|
|
|
if 'GST_DEBUG' in os.environ:
|
|
|
|
gstlogsfile = self.logfile + '.gstdebug'
|
|
|
|
self.extra_logfiles.append(gstlogsfile)
|
|
|
|
subproc_env["GST_DEBUG_FILE"] = gstlogsfile
|
|
|
|
|
|
|
|
return subproc_env
|
|
|
|
|
2014-02-19 12:07:03 +00:00
|
|
|
def clean(self):
|
|
|
|
Test.clean(self)
|
|
|
|
self._sent_eos_pos = None
|
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
def build_arguments(self):
|
|
|
|
if self.scenario is not None:
|
2014-04-30 09:06:09 +00:00
|
|
|
self.add_arguments("--set-scenario",
|
|
|
|
self.scenario.get_execution_name())
|
2014-01-09 08:14:27 +00:00
|
|
|
|
2014-04-23 09:47:10 +00:00
|
|
|
def get_extra_log_content(self, extralog):
|
2014-04-26 07:16:26 +00:00
|
|
|
value = Test.get_extra_log_content(self, extralog)
|
2014-04-23 09:47:10 +00:00
|
|
|
|
|
|
|
if extralog == self.validatelogs:
|
|
|
|
value = re.sub("<position:.*/>\r", "", value)
|
|
|
|
|
2014-04-26 07:16:26 +00:00
|
|
|
return value
|
2014-04-23 09:47:10 +00:00
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
def get_validate_criticals_errors(self):
|
|
|
|
ret = "["
|
|
|
|
errors = []
|
2014-04-23 09:47:10 +00:00
|
|
|
for l in open(self.validatelogs, 'r').readlines():
|
2014-01-09 08:14:27 +00:00
|
|
|
if "critical : " in l:
|
|
|
|
if ret != "[":
|
|
|
|
ret += ", "
|
|
|
|
error = l.split("critical : ")[1].replace("\n", '')
|
|
|
|
if error not in errors:
|
|
|
|
ret += error
|
|
|
|
errors.append(error)
|
|
|
|
|
|
|
|
if ret == "[":
|
|
|
|
return "No critical"
|
|
|
|
else:
|
|
|
|
return ret + "]"
|
|
|
|
|
2014-01-09 08:28:02 +00:00
|
|
|
def check_results(self):
|
2014-02-19 09:31:15 +00:00
|
|
|
if self.result is Result.FAILED or self.result is Result.PASSED:
|
2014-01-09 08:28:02 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
self.debug("%s returncode: %s", self, self.process.returncode)
|
|
|
|
if self.result == Result.TIMEOUT:
|
|
|
|
self.set_result(Result.TIMEOUT, "Application timed out", "timeout")
|
|
|
|
elif self.process.returncode == 0:
|
2014-03-26 18:37:44 +00:00
|
|
|
self.set_result(Result.PASSED)
|
2014-01-09 08:28:02 +00:00
|
|
|
else:
|
|
|
|
if self.process.returncode == 139:
|
2014-01-10 15:56:44 +00:00
|
|
|
# FIXME Reimplement something like that if needed
|
|
|
|
# self.get_backtrace("SEGFAULT")
|
2014-01-09 08:28:02 +00:00
|
|
|
self.set_result(Result.FAILED,
|
|
|
|
"Application segfaulted",
|
|
|
|
"segfault")
|
|
|
|
else:
|
|
|
|
self.set_result(Result.FAILED,
|
2014-02-14 15:07:51 +00:00
|
|
|
"Application returned %s (issues: %s)" % (
|
2014-01-09 08:28:02 +00:00
|
|
|
self.process.returncode,
|
|
|
|
self.get_validate_criticals_errors()
|
|
|
|
))
|
2014-01-30 11:42:25 +00:00
|
|
|
def _parse_position(self, p):
|
|
|
|
self.log("Parsing %s" % p)
|
2014-01-31 11:21:21 +00:00
|
|
|
times = self.findpos_regex.findall(p)
|
2014-01-30 11:42:25 +00:00
|
|
|
|
2014-01-31 11:21:21 +00:00
|
|
|
if len(times) != 1:
|
2014-01-30 11:42:25 +00:00
|
|
|
self.warning("Got a unparsable value: %s" % p)
|
|
|
|
return 0, 0
|
|
|
|
|
2014-01-31 11:21:21 +00:00
|
|
|
return (utils.gsttime_from_tuple(times[0][:4]),
|
|
|
|
utils.gsttime_from_tuple(times[0][4:]))
|
2014-01-30 11:42:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _parse_buffering(self, b):
|
|
|
|
return b.split("buffering... ")[1].split("%")[0], 100
|
|
|
|
|
|
|
|
|
|
|
|
def _get_position(self):
|
|
|
|
position = duration = -1
|
|
|
|
|
|
|
|
self.debug("Getting position")
|
|
|
|
m = None
|
2014-04-23 09:47:10 +00:00
|
|
|
for l in reversed(open(self.validatelogs, 'r').readlines()):
|
2014-01-30 11:42:25 +00:00
|
|
|
l = l.lower()
|
|
|
|
if "<position:" in l or "buffering" in l:
|
|
|
|
m = l
|
|
|
|
break
|
|
|
|
|
|
|
|
if m is None:
|
|
|
|
self.debug("Could not fine any positionning info")
|
|
|
|
return position, duration
|
|
|
|
|
|
|
|
for j in m.split("\r"):
|
|
|
|
j = j.lstrip().rstrip()
|
|
|
|
if j.startswith("<position:") and j.endswith("/>"):
|
|
|
|
position, duration = self._parse_position(j)
|
|
|
|
elif j.startswith("buffering") and j.endswith("%"):
|
|
|
|
position, duration = self._parse_buffering(j)
|
|
|
|
else:
|
2014-01-31 11:21:21 +00:00
|
|
|
self.log("No info in %s" % j)
|
2014-01-30 11:42:25 +00:00
|
|
|
|
|
|
|
return position, duration
|
|
|
|
|
|
|
|
def _get_last_seek_values(self):
|
|
|
|
m = None
|
|
|
|
rate = start = stop = None
|
|
|
|
|
2014-04-23 09:47:10 +00:00
|
|
|
for l in reversed(open(self.validatelogs, 'r').readlines()):
|
2014-01-30 11:42:25 +00:00
|
|
|
l = l.lower()
|
|
|
|
if "seeking to: " in l:
|
|
|
|
m = l
|
|
|
|
break
|
|
|
|
|
|
|
|
if m is None:
|
|
|
|
self.debug("Could not fine any seeking info")
|
|
|
|
return start, stop, rate
|
|
|
|
|
|
|
|
|
2014-01-31 11:21:21 +00:00
|
|
|
values = self.findlastseek_regex.findall(m)
|
|
|
|
if len(values) != 1:
|
|
|
|
self.warning("Got a unparsable value: %s" % p)
|
|
|
|
return start, stop, rate
|
|
|
|
|
|
|
|
v = values[0]
|
|
|
|
return (utils.gsttime_from_tuple(v[:4]),
|
|
|
|
utils.gsttime_from_tuple(v[4:8]),
|
|
|
|
float(str(v[8]) + "." + str(v[9])))
|
2014-01-30 11:42:25 +00:00
|
|
|
|
2014-02-13 14:31:58 +00:00
|
|
|
def sent_eos_position(self):
|
|
|
|
if self._sent_eos_pos is not None:
|
|
|
|
return self._sent_eos_pos
|
|
|
|
|
|
|
|
m = None
|
|
|
|
rate = start = stop = None
|
|
|
|
|
2014-04-23 09:47:10 +00:00
|
|
|
for l in reversed(open(self.validatelogs, 'r').readlines()):
|
2014-02-13 14:31:58 +00:00
|
|
|
l = l.lower()
|
|
|
|
if "sending eos" in l:
|
|
|
|
m = l
|
|
|
|
self._sent_eos_pos = time.time()
|
|
|
|
return self._sent_eos_pos
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2014-01-30 11:42:25 +00:00
|
|
|
def get_current_position(self):
|
|
|
|
position, duration = self._get_position()
|
2014-02-14 15:07:51 +00:00
|
|
|
if position == -1:
|
|
|
|
return position
|
2014-01-30 11:42:25 +00:00
|
|
|
|
|
|
|
return position
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_size(self):
|
|
|
|
position = self.get_current_position()
|
|
|
|
|
2014-02-06 16:23:10 +00:00
|
|
|
try:
|
|
|
|
size = os.stat(urlparse.urlparse(self.dest_file).path).st_size
|
|
|
|
except OSError as e:
|
|
|
|
return position
|
|
|
|
|
2014-01-30 11:42:25 +00:00
|
|
|
self.debug("Size: %s" % size)
|
|
|
|
return size
|
2014-01-09 08:28:02 +00:00
|
|
|
|
2014-01-09 08:14:27 +00:00
|
|
|
|
2014-01-09 15:57:54 +00:00
|
|
|
class TestsManager(Loggable):
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
""" A class responsible for managing tests. """
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
name = ""
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def __init__(self):
|
2014-01-09 15:57:54 +00:00
|
|
|
|
|
|
|
Loggable.__init__(self)
|
|
|
|
|
2014-01-22 23:15:54 +00:00
|
|
|
self.tests = set([])
|
|
|
|
self.unwanted_tests = set([])
|
2013-12-31 10:45:07 +00:00
|
|
|
self.options = None
|
|
|
|
self.args = None
|
|
|
|
self.reporter = None
|
|
|
|
self.wanted_tests_patterns = []
|
2014-01-22 23:15:54 +00:00
|
|
|
self.blacklisted_tests_patterns = []
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 14:17:53 +00:00
|
|
|
def init(self):
|
|
|
|
return False
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def list_tests(self):
|
2014-04-02 17:14:30 +00:00
|
|
|
return self.tests
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-22 23:15:54 +00:00
|
|
|
def add_test(self, test):
|
|
|
|
if self._is_test_wanted(test):
|
|
|
|
self.tests.add(test)
|
|
|
|
else:
|
|
|
|
self.unwanted_tests.add(test)
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def get_tests(self):
|
|
|
|
return self.tests
|
|
|
|
|
2014-01-30 11:20:33 +00:00
|
|
|
def get_blacklisted(self):
|
|
|
|
return []
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
def add_options(self, parser):
|
|
|
|
""" Add more arguments. """
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_settings(self, options, args, reporter):
|
|
|
|
""" Set properties after options parsing. """
|
|
|
|
self.options = options
|
|
|
|
self.args = args
|
|
|
|
self.reporter = reporter
|
|
|
|
|
|
|
|
if options.wanted_tests:
|
2014-01-22 23:15:54 +00:00
|
|
|
for patterns in options.wanted_tests:
|
|
|
|
for pattern in patterns.split(","):
|
|
|
|
self.wanted_tests_patterns.append(re.compile(pattern))
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-22 23:15:54 +00:00
|
|
|
if options.blacklisted_tests:
|
|
|
|
for patterns in options.blacklisted_tests:
|
|
|
|
for pattern in patterns.split(","):
|
|
|
|
self.blacklisted_tests_patterns.append(re.compile(pattern))
|
|
|
|
|
|
|
|
def _check_blacklisted(self, test):
|
|
|
|
for pattern in self.blacklisted_tests_patterns:
|
|
|
|
if pattern.findall(test.classname):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def _is_test_wanted(self, test):
|
2014-01-22 23:15:54 +00:00
|
|
|
if self._check_blacklisted(test):
|
|
|
|
return False
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
if not self.wanted_tests_patterns:
|
|
|
|
return True
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
for pattern in self.wanted_tests_patterns:
|
|
|
|
if pattern.findall(test.classname):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2014-04-02 17:14:30 +00:00
|
|
|
def run_tests(self, cur_test_num, total_num_tests):
|
|
|
|
i = cur_test_num
|
2013-12-31 10:45:07 +00:00
|
|
|
for test in self.tests:
|
2014-04-02 17:14:30 +00:00
|
|
|
sys.stdout.write("[%d / %d] " % (i, total_num_tests))
|
|
|
|
self.reporter.before_test(test)
|
|
|
|
res = test.run()
|
|
|
|
i += 1
|
|
|
|
self.reporter.after_test()
|
|
|
|
if res != Result.PASSED and (self.options.forever or
|
|
|
|
self.options.fatal_error):
|
|
|
|
return test.result
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-14 17:07:46 +00:00
|
|
|
return Result.PASSED
|
|
|
|
|
2014-02-19 12:07:03 +00:00
|
|
|
def clean_tests(self):
|
|
|
|
for test in self.tests:
|
|
|
|
test.clean()
|
|
|
|
|
2014-01-13 16:31:57 +00:00
|
|
|
def needs_http_server(self):
|
|
|
|
return False
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 14:17:53 +00:00
|
|
|
class _TestsLauncher(Loggable):
|
2013-12-31 10:45:07 +00:00
|
|
|
def __init__(self):
|
2014-01-09 14:17:53 +00:00
|
|
|
|
|
|
|
Loggable.__init__(self)
|
|
|
|
|
2014-01-14 17:07:46 +00:00
|
|
|
self.options = None
|
2013-12-31 10:45:07 +00:00
|
|
|
self.testers = []
|
|
|
|
self.tests = []
|
|
|
|
self.reporter = None
|
|
|
|
self._list_testers()
|
|
|
|
self.wanted_tests_patterns = []
|
|
|
|
|
|
|
|
def _list_testers(self):
|
|
|
|
def get_subclasses(c, env):
|
|
|
|
subclasses = []
|
|
|
|
for symb in env.iteritems():
|
|
|
|
try:
|
2013-12-31 10:45:07 +00:00
|
|
|
if issubclass(symb[1], c) and not symb[1] is c:
|
2013-12-31 10:45:07 +00:00
|
|
|
subclasses.append(symb[1])
|
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return subclasses
|
|
|
|
|
|
|
|
env = globals().copy()
|
|
|
|
d = os.path.dirname(__file__)
|
|
|
|
for f in os.listdir(os.path.join(d, "apps")):
|
2014-01-09 08:39:05 +00:00
|
|
|
if f.endswith(".py"):
|
|
|
|
execfile(os.path.join(d, "apps", f), env)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-09 14:17:53 +00:00
|
|
|
testers = [i() for i in get_subclasses(TestsManager, env)]
|
|
|
|
for tester in testers:
|
|
|
|
if tester.init() is True:
|
|
|
|
self.testers.append(tester)
|
|
|
|
else:
|
2014-01-10 09:27:25 +00:00
|
|
|
self.warning("Can not init tester: %s -- PATH is %s"
|
|
|
|
% (tester.name, os.environ["PATH"]))
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def add_options(self, parser):
|
|
|
|
for tester in self.testers:
|
2014-02-06 16:24:30 +00:00
|
|
|
group = OptionGroup(parser, "%s options" % tester.name,
|
2013-12-31 10:45:07 +00:00
|
|
|
"Options specific to the %s test manager"
|
|
|
|
% tester.name)
|
|
|
|
tester.add_options(group)
|
2014-02-06 16:24:30 +00:00
|
|
|
if group.option_list:
|
|
|
|
parser.add_option_group(group)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def set_settings(self, options, args):
|
|
|
|
self.reporter = reporters.XunitReporter(options)
|
|
|
|
mkdir(options.logsdir)
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-14 17:07:46 +00:00
|
|
|
self.options = options
|
2013-12-31 10:45:07 +00:00
|
|
|
wanted_testers = None
|
|
|
|
for tester in self.testers:
|
|
|
|
if tester.name in args:
|
|
|
|
wanted_testers = tester.name
|
|
|
|
if wanted_testers:
|
|
|
|
testers = self.testers
|
|
|
|
self.testers = []
|
|
|
|
for tester in testers:
|
|
|
|
if tester.name in args:
|
|
|
|
self.testers.append(tester)
|
|
|
|
args.remove(tester.name)
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
for tester in self.testers:
|
|
|
|
tester.set_settings(options, args, self.reporter)
|
|
|
|
|
|
|
|
def list_tests(self):
|
|
|
|
for tester in self.testers:
|
|
|
|
tester.list_tests()
|
|
|
|
self.tests.extend(tester.tests)
|
2014-04-02 17:14:30 +00:00
|
|
|
return self.tests
|
2013-12-31 10:45:07 +00:00
|
|
|
|
2014-01-14 17:07:46 +00:00
|
|
|
def _run_tests(self):
|
2014-04-02 17:14:30 +00:00
|
|
|
cur_test_num = 0
|
|
|
|
total_num_tests = 0
|
|
|
|
for tester in self.testers:
|
|
|
|
total_num_tests += len(tester.list_tests())
|
|
|
|
|
2013-12-31 10:45:07 +00:00
|
|
|
for tester in self.testers:
|
2014-04-02 17:14:30 +00:00
|
|
|
res = tester.run_tests(cur_test_num, total_num_tests)
|
|
|
|
cur_test_num += len(tester.list_tests())
|
2014-01-24 15:38:12 +00:00
|
|
|
if res != Result.PASSED and (self.options.forever or
|
|
|
|
self.options.fatal_error):
|
2014-01-14 17:07:46 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2014-02-19 12:07:03 +00:00
|
|
|
def _clean_tests(self):
|
|
|
|
for tester in self.testers:
|
|
|
|
tester.clean_tests()
|
|
|
|
|
2014-01-14 17:07:46 +00:00
|
|
|
def run_tests(self):
|
|
|
|
if self.options.forever:
|
|
|
|
while self._run_tests():
|
2014-02-19 12:07:03 +00:00
|
|
|
self._clean_tests()
|
2014-01-14 17:07:46 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self._run_tests()
|
2013-12-31 10:45:07 +00:00
|
|
|
|
|
|
|
def final_report(self):
|
|
|
|
self.reporter.final_report()
|
2014-01-13 16:31:57 +00:00
|
|
|
|
|
|
|
def needs_http_server(self):
|
|
|
|
for tester in self.testers:
|
|
|
|
if tester.needs_http_server():
|
|
|
|
return True
|
2014-01-24 10:41:25 +00:00
|
|
|
|
2014-01-30 11:20:33 +00:00
|
|
|
def get_blacklisted(self):
|
|
|
|
res = []
|
|
|
|
for tester in self.testers:
|
|
|
|
for blacklisted in tester.get_blacklisted():
|
|
|
|
if isinstance(blacklisted, str):
|
|
|
|
res.append(blacklisted, "Unknown")
|
|
|
|
else:
|
|
|
|
res.append(blacklisted)
|
|
|
|
return res
|
|
|
|
|
2014-01-24 10:41:25 +00:00
|
|
|
|
|
|
|
class NamedDic(object):
|
|
|
|
|
|
|
|
def __init__(self, props):
|
|
|
|
if props:
|
|
|
|
for name, value in props.iteritems():
|
|
|
|
setattr(self, name, value)
|
|
|
|
|
2014-01-30 15:56:51 +00:00
|
|
|
class Scenario(object):
|
2014-04-30 09:06:09 +00:00
|
|
|
def __init__(self, name, props, path=None):
|
2014-01-24 10:41:25 +00:00
|
|
|
self.name = name
|
2014-04-30 09:06:09 +00:00
|
|
|
self.path = path
|
2014-02-12 10:18:14 +00:00
|
|
|
|
|
|
|
for prop, value in props:
|
2014-04-25 11:17:39 +00:00
|
|
|
setattr(self, prop.replace("-", "_"), value)
|
|
|
|
|
2014-04-30 09:06:09 +00:00
|
|
|
def get_execution_name(self):
|
|
|
|
if self.path is not None:
|
|
|
|
return self.path
|
|
|
|
else:
|
|
|
|
return self.name
|
|
|
|
|
2014-04-25 11:17:39 +00:00
|
|
|
def seeks(self):
|
|
|
|
if hasattr(self, "seek"):
|
|
|
|
return bool(self.seek)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def does_reverse_playback(self):
|
|
|
|
if hasattr(self, "reverse_playback"):
|
|
|
|
return bool(self.seek)
|
|
|
|
|
2014-04-29 17:04:46 +00:00
|
|
|
return False
|
|
|
|
|
2014-04-25 11:17:39 +00:00
|
|
|
|
2014-04-29 17:04:46 +00:00
|
|
|
def get_min_tracks(self, track_type):
|
|
|
|
try:
|
|
|
|
return int(getattr(self, "min_%s_track" % track_type))
|
|
|
|
except AttributeError:
|
|
|
|
return 0
|
2014-04-25 11:17:39 +00:00
|
|
|
|
2014-02-12 10:18:14 +00:00
|
|
|
|
2014-03-28 14:00:01 +00:00
|
|
|
class ScenarioManager(Loggable):
|
2014-02-12 10:18:14 +00:00
|
|
|
_instance = None
|
|
|
|
all_scenarios = []
|
2014-04-30 09:06:09 +00:00
|
|
|
|
|
|
|
FILE_EXTENDION = "scenario"
|
2014-02-12 10:18:14 +00:00
|
|
|
GST_VALIDATE_COMMAND = "gst-validate-1.0"
|
2014-03-28 14:00:01 +00:00
|
|
|
if "win32" in sys.platform:
|
|
|
|
GST_VALIDATE_COMMAND += ".exe"
|
2014-02-12 10:18:14 +00:00
|
|
|
|
|
|
|
def __new__(cls, *args, **kwargs):
|
|
|
|
if not cls._instance:
|
|
|
|
cls._instance = super(ScenarioManager, cls).__new__(
|
|
|
|
cls, *args, **kwargs)
|
|
|
|
cls._instance.config = None
|
2014-03-28 14:01:12 +00:00
|
|
|
cls._instance.discovered = False
|
|
|
|
Loggable.__init__(cls._instance)
|
2014-02-12 10:18:14 +00:00
|
|
|
|
2014-03-28 14:01:12 +00:00
|
|
|
return cls._instance
|
2014-04-25 11:19:19 +00:00
|
|
|
|
2014-04-30 09:06:09 +00:00
|
|
|
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 = []
|
2014-02-12 10:18:14 +00:00
|
|
|
scenario_defs = os.path.join(self.config.main_dir, "scenarios.def")
|
|
|
|
try:
|
2014-04-30 09:06:09 +00:00
|
|
|
command = [self.GST_VALIDATE_COMMAND, "--scenarios-defs-output-file", scenario_defs]
|
|
|
|
command.extend(scenario_paths)
|
|
|
|
subprocess.check_output(command)
|
2014-02-12 10:18:14 +00:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
config = ConfigParser.ConfigParser()
|
|
|
|
f = open(scenario_defs)
|
|
|
|
config.readfp(f)
|
|
|
|
|
|
|
|
for section in config.sections():
|
2014-04-30 09:06:09 +00:00
|
|
|
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)
|
2014-02-12 10:18:14 +00:00
|
|
|
|
2014-04-30 09:06:09 +00:00
|
|
|
return scenarios
|
2014-03-28 14:01:12 +00:00
|
|
|
|
|
|
|
def get_scenario(self, name):
|
|
|
|
if self.discovered is False:
|
2014-04-30 09:06:09 +00:00
|
|
|
self.discover_scenarios()
|
2014-03-28 14:01:12 +00:00
|
|
|
|
2014-04-25 09:32:04 +00:00
|
|
|
if name is None:
|
|
|
|
return self.all_scenarios
|
|
|
|
|
2014-03-28 14:01:12 +00:00
|
|
|
try:
|
|
|
|
return [scenario for scenario in self.all_scenarios if scenario.name == name][0]
|
|
|
|
except IndexError:
|
|
|
|
self.warning("Scenario: %s not found" % name)
|
|
|
|
return None
|