mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-20 06:08:14 +00:00
validate: launcher: Move logfile handling out of Reporter and into Test
This makes each Test handle its own logfile, allowing the Reporter to work on multiple tests at the same time. Patch 5/5 to move logfile handling out of Reporter and into Test.
This commit is contained in:
parent
500206d3ad
commit
d12f55daf4
2 changed files with 43 additions and 36 deletions
|
@ -73,6 +73,7 @@ class Test(Loggable):
|
|||
self._starting_time = None
|
||||
self.result = Result.NOT_RUN
|
||||
self.logfile = None
|
||||
self.out = None
|
||||
self.extra_logfiles = []
|
||||
self._env_variable = ''
|
||||
|
||||
|
@ -102,16 +103,41 @@ class Test(Loggable):
|
|||
self._env_variable += " "
|
||||
self._env_variable += "%s=%s" % (variable, value)
|
||||
|
||||
def get_extra_log_content(self, extralog):
|
||||
if extralog not in self.extra_logfiles:
|
||||
return ""
|
||||
def open_logfile(self):
|
||||
path = os.path.join(self.options.logsdir,
|
||||
self.classname.replace(".", os.sep))
|
||||
mkdir(os.path.dirname(path))
|
||||
self.logfile = path
|
||||
|
||||
f = open(extralog, 'r+')
|
||||
if self.options.redirect_logs == 'stdout':
|
||||
self.out = sys.stdout
|
||||
elif self.options.redirect_logs == 'stderr':
|
||||
self.out = sys.stderr
|
||||
else:
|
||||
self.out = open(path, 'w+')
|
||||
|
||||
def close_logfile(self):
|
||||
if not self.options.redirect_logs:
|
||||
self.out.close()
|
||||
|
||||
self.out = None
|
||||
|
||||
def _get_file_content(self, file_name):
|
||||
f = open(file_name, 'r+')
|
||||
value = f.read()
|
||||
f.close()
|
||||
|
||||
return value
|
||||
|
||||
def get_log_content(self):
|
||||
return self._get_file_content(self.logfile)
|
||||
|
||||
def get_extra_log_content(self, extralog):
|
||||
if extralog not in self.extra_logfiles:
|
||||
return ""
|
||||
|
||||
return self._get_file_content(extralog)
|
||||
|
||||
def get_classname(self):
|
||||
name = self.classname.split('.')[-1]
|
||||
classname = self.classname.replace('.%s' % name, '')
|
||||
|
@ -235,13 +261,15 @@ class Test(Loggable):
|
|||
|
||||
def thread_wrapper(self):
|
||||
self.process = subprocess.Popen("exec " + self.command,
|
||||
stderr=self.reporter.out,
|
||||
stdout=self.reporter.out,
|
||||
stderr=self.out,
|
||||
stdout=self.out,
|
||||
shell=True,
|
||||
env=self.proc_env)
|
||||
self.process.wait()
|
||||
|
||||
def run(self):
|
||||
self.open_logfile()
|
||||
|
||||
self.command = "%s " % (self.application)
|
||||
self._starting_time = time.time()
|
||||
self.build_arguments()
|
||||
|
@ -256,12 +284,12 @@ class Test(Loggable):
|
|||
for log in self.extra_logfiles:
|
||||
message += "\n - %s" % log
|
||||
|
||||
self.reporter.out.write("=================\n"
|
||||
"Test name: %s\n"
|
||||
"Command: '%s'\n"
|
||||
"=================\n\n"
|
||||
% (self.classname, self.command))
|
||||
self.reporter.out.flush()
|
||||
self.out.write("=================\n"
|
||||
"Test name: %s\n"
|
||||
"Command: '%s'\n"
|
||||
"=================\n\n"
|
||||
% (self.classname, self.command))
|
||||
self.out.flush()
|
||||
|
||||
printc(message, Colors.OKBLUE)
|
||||
|
||||
|
@ -282,6 +310,8 @@ class Test(Loggable):
|
|||
" (" + self.message + ")" if self.message else ""),
|
||||
color=utils.get_color_for_result(self.result))
|
||||
|
||||
self.close_logfile()
|
||||
|
||||
return self.result
|
||||
|
||||
|
||||
|
@ -748,11 +778,9 @@ class TestsManager(Loggable):
|
|||
i = cur_test_num
|
||||
for test in self.tests:
|
||||
sys.stdout.write("[%d / %d] " % (i + 1, total_num_tests))
|
||||
self.reporter.open_logfile(test)
|
||||
res = test.run()
|
||||
i += 1
|
||||
self.reporter.after_test(test)
|
||||
self.reporter.close_logfile()
|
||||
if res != Result.PASSED and (self.options.forever or
|
||||
self.options.fatal_error):
|
||||
return test.result
|
||||
|
|
|
@ -55,7 +55,6 @@ class Reporter(Loggable):
|
|||
def __init__(self, options):
|
||||
Loggable.__init__(self)
|
||||
|
||||
self.out = None
|
||||
self.options = options
|
||||
self._start_time = 0
|
||||
self.stats = {'timeout': 0,
|
||||
|
@ -69,19 +68,6 @@ class Reporter(Loggable):
|
|||
"""Initialize a timer before starting tests."""
|
||||
self._start_time = time.time()
|
||||
|
||||
def open_logfile(self, test):
|
||||
path = os.path.join(self.options.logsdir,
|
||||
test.classname.replace(".", os.sep))
|
||||
mkdir(os.path.dirname(path))
|
||||
test.logfile = path
|
||||
|
||||
if self.options.redirect_logs == 'stdout':
|
||||
self.out = sys.stdout
|
||||
elif self.options.redirect_logs == 'stderr':
|
||||
self.out = sys.stderr
|
||||
else:
|
||||
self.out = open(path, 'w+')
|
||||
|
||||
def set_failed(self, test):
|
||||
self.stats["failure"] += 1
|
||||
|
||||
|
@ -104,12 +90,6 @@ class Reporter(Loggable):
|
|||
|
||||
self.add_results(test)
|
||||
|
||||
def close_logfile(self):
|
||||
if not self.options.redirect_logs:
|
||||
self.out.close()
|
||||
|
||||
self.out = None
|
||||
|
||||
def final_report(self):
|
||||
print "\n"
|
||||
printc("Final Report:", title=True)
|
||||
|
@ -160,8 +140,7 @@ class XunitReporter(Reporter):
|
|||
def _get_captured(self, test):
|
||||
captured = ""
|
||||
if not self.options.redirect_logs:
|
||||
self.out.seek(0)
|
||||
value = self.out.read()
|
||||
value = test.get_log_content()
|
||||
if value:
|
||||
captured += '<system-out><![CDATA[%s' % \
|
||||
escape_cdata(value)
|
||||
|
|
Loading…
Reference in a new issue