launcher: Add --dump-on-failure switch

When the test fails, it can be useful to have the log files dumped
to stdout.

https://bugzilla.gnome.org/show_bug.cgi?id=741092
This commit is contained in:
Mathieu Duponchelle 2016-09-01 03:39:18 +02:00
parent 40d803271c
commit ec1d8d7d8c
2 changed files with 20 additions and 0 deletions

View file

@ -410,6 +410,19 @@ class Test(Loggable):
self.last_change_ts = time.time()
self.start_ts = time.time()
def _dump_log_file(self, logfile):
message = "Dumping contents of %s\n" % logfile
printc(message, Colors.FAIL)
with open(logfile, 'r') as fin:
print fin.read()
def _dump_log_files(self):
printc("Dumping log files on failure\n", Colors.FAIL)
self._dump_log_file(self.logfile)
for logfile in self.extra_logfiles:
self._dump_log_file(logfile)
def test_end(self):
self.kill_subprocess()
self.thread.join()
@ -421,6 +434,10 @@ class Test(Loggable):
self.close_logfile()
if self.options.dump_on_failure:
if self.result is not Result.PASSED:
self._dump_log_files()
return self.result

View file

@ -422,6 +422,9 @@ Note that all testsuite should be inside python modules, so the directory should
action='store',
help="Defines the limit for which a test is considered as long (in seconds)."
" Note that 0 will enable all tests", type=int),
parser.add_argument("--dump-on-failure", dest="dump_on_failure",
action="store_true", default=False,
help="Dump logs to stdout when a test fails")
parser.add_argument("-c", "--config", dest="config",
help="This is DEPRECATED, prefer using the testsuite format"
" to configure testsuites")