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._starting_time = None
|
||||||
self.result = Result.NOT_RUN
|
self.result = Result.NOT_RUN
|
||||||
self.logfile = None
|
self.logfile = None
|
||||||
|
self.out = None
|
||||||
self.extra_logfiles = []
|
self.extra_logfiles = []
|
||||||
self._env_variable = ''
|
self._env_variable = ''
|
||||||
|
|
||||||
|
@ -102,16 +103,41 @@ class Test(Loggable):
|
||||||
self._env_variable += " "
|
self._env_variable += " "
|
||||||
self._env_variable += "%s=%s" % (variable, value)
|
self._env_variable += "%s=%s" % (variable, value)
|
||||||
|
|
||||||
def get_extra_log_content(self, extralog):
|
def open_logfile(self):
|
||||||
if extralog not in self.extra_logfiles:
|
path = os.path.join(self.options.logsdir,
|
||||||
return ""
|
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()
|
value = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
return value
|
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):
|
def get_classname(self):
|
||||||
name = self.classname.split('.')[-1]
|
name = self.classname.split('.')[-1]
|
||||||
classname = self.classname.replace('.%s' % name, '')
|
classname = self.classname.replace('.%s' % name, '')
|
||||||
|
@ -235,13 +261,15 @@ class Test(Loggable):
|
||||||
|
|
||||||
def thread_wrapper(self):
|
def thread_wrapper(self):
|
||||||
self.process = subprocess.Popen("exec " + self.command,
|
self.process = subprocess.Popen("exec " + self.command,
|
||||||
stderr=self.reporter.out,
|
stderr=self.out,
|
||||||
stdout=self.reporter.out,
|
stdout=self.out,
|
||||||
shell=True,
|
shell=True,
|
||||||
env=self.proc_env)
|
env=self.proc_env)
|
||||||
self.process.wait()
|
self.process.wait()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.open_logfile()
|
||||||
|
|
||||||
self.command = "%s " % (self.application)
|
self.command = "%s " % (self.application)
|
||||||
self._starting_time = time.time()
|
self._starting_time = time.time()
|
||||||
self.build_arguments()
|
self.build_arguments()
|
||||||
|
@ -256,12 +284,12 @@ class Test(Loggable):
|
||||||
for log in self.extra_logfiles:
|
for log in self.extra_logfiles:
|
||||||
message += "\n - %s" % log
|
message += "\n - %s" % log
|
||||||
|
|
||||||
self.reporter.out.write("=================\n"
|
self.out.write("=================\n"
|
||||||
"Test name: %s\n"
|
"Test name: %s\n"
|
||||||
"Command: '%s'\n"
|
"Command: '%s'\n"
|
||||||
"=================\n\n"
|
"=================\n\n"
|
||||||
% (self.classname, self.command))
|
% (self.classname, self.command))
|
||||||
self.reporter.out.flush()
|
self.out.flush()
|
||||||
|
|
||||||
printc(message, Colors.OKBLUE)
|
printc(message, Colors.OKBLUE)
|
||||||
|
|
||||||
|
@ -282,6 +310,8 @@ class Test(Loggable):
|
||||||
" (" + self.message + ")" if self.message else ""),
|
" (" + self.message + ")" if self.message else ""),
|
||||||
color=utils.get_color_for_result(self.result))
|
color=utils.get_color_for_result(self.result))
|
||||||
|
|
||||||
|
self.close_logfile()
|
||||||
|
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
|
|
||||||
|
@ -748,11 +778,9 @@ class TestsManager(Loggable):
|
||||||
i = cur_test_num
|
i = cur_test_num
|
||||||
for test in self.tests:
|
for test in self.tests:
|
||||||
sys.stdout.write("[%d / %d] " % (i + 1, total_num_tests))
|
sys.stdout.write("[%d / %d] " % (i + 1, total_num_tests))
|
||||||
self.reporter.open_logfile(test)
|
|
||||||
res = test.run()
|
res = test.run()
|
||||||
i += 1
|
i += 1
|
||||||
self.reporter.after_test(test)
|
self.reporter.after_test(test)
|
||||||
self.reporter.close_logfile()
|
|
||||||
if res != Result.PASSED and (self.options.forever or
|
if res != Result.PASSED and (self.options.forever or
|
||||||
self.options.fatal_error):
|
self.options.fatal_error):
|
||||||
return test.result
|
return test.result
|
||||||
|
|
|
@ -55,7 +55,6 @@ class Reporter(Loggable):
|
||||||
def __init__(self, options):
|
def __init__(self, options):
|
||||||
Loggable.__init__(self)
|
Loggable.__init__(self)
|
||||||
|
|
||||||
self.out = None
|
|
||||||
self.options = options
|
self.options = options
|
||||||
self._start_time = 0
|
self._start_time = 0
|
||||||
self.stats = {'timeout': 0,
|
self.stats = {'timeout': 0,
|
||||||
|
@ -69,19 +68,6 @@ class Reporter(Loggable):
|
||||||
"""Initialize a timer before starting tests."""
|
"""Initialize a timer before starting tests."""
|
||||||
self._start_time = time.time()
|
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):
|
def set_failed(self, test):
|
||||||
self.stats["failure"] += 1
|
self.stats["failure"] += 1
|
||||||
|
|
||||||
|
@ -104,12 +90,6 @@ class Reporter(Loggable):
|
||||||
|
|
||||||
self.add_results(test)
|
self.add_results(test)
|
||||||
|
|
||||||
def close_logfile(self):
|
|
||||||
if not self.options.redirect_logs:
|
|
||||||
self.out.close()
|
|
||||||
|
|
||||||
self.out = None
|
|
||||||
|
|
||||||
def final_report(self):
|
def final_report(self):
|
||||||
print "\n"
|
print "\n"
|
||||||
printc("Final Report:", title=True)
|
printc("Final Report:", title=True)
|
||||||
|
@ -160,8 +140,7 @@ class XunitReporter(Reporter):
|
||||||
def _get_captured(self, test):
|
def _get_captured(self, test):
|
||||||
captured = ""
|
captured = ""
|
||||||
if not self.options.redirect_logs:
|
if not self.options.redirect_logs:
|
||||||
self.out.seek(0)
|
value = test.get_log_content()
|
||||||
value = self.out.read()
|
|
||||||
if value:
|
if value:
|
||||||
captured += '<system-out><![CDATA[%s' % \
|
captured += '<system-out><![CDATA[%s' % \
|
||||||
escape_cdata(value)
|
escape_cdata(value)
|
||||||
|
|
Loading…
Reference in a new issue