launcher: Clean up outpout

Make our stdout output simpler to follow by:
  - Not printing the tests we launch (it is not really useful in the end)
  - Using `\r` when printing the passed tests
  - Not reprinting all the test in a now useless summary
This commit is contained in:
Thibault Saunier 2018-03-23 17:44:06 -03:00
parent 3f66772fa1
commit 2b40c6c306
3 changed files with 40 additions and 33 deletions

View file

@ -109,6 +109,8 @@ class Test(Loggable):
self.optional = False
self.is_parallel = is_parallel
self.generator = None
# String representation of the test number in the testsuite
self.number = ""
self.clean()
@ -134,6 +136,9 @@ class Test(Loggable):
" You can reproduce with: %s\n" \
% (self.message, self.get_command_repr())
if not self.options.redirect_logs and \
self.result == Result.PASSED or \
not self.options.dump_on_failure:
string += self.get_logfile_repr()
return string
@ -434,7 +439,7 @@ class Test(Loggable):
logfiles.insert(0, self.logfile)
for log in logfiles:
message += "\n - %s" % log
message += " - %s\n" % log
return message
@ -465,20 +470,17 @@ class Test(Loggable):
if self.options.valgrind:
self.command = self.use_valgrind(self.command, self.proc_env)
message = "Launching: %s%s\n" \
" Command: %s\n" % (Colors.ENDC, self.classname,
self.get_command_repr())
if not self.options.redirect_logs:
message += self.get_logfile_repr()
self.out.write("=================\n"
"Test name: %s\n"
"Command: '%s'\n"
"=================\n\n"
% (self.classname, ' '.join(self.command)))
self.out.flush()
else:
message = "Launching: %s%s\n" \
" Command: %s\n" % (Colors.ENDC, self.classname,
self.get_command_repr())
printc(message, Colors.OKBLUE)
self.thread = threading.Thread(target=self.thread_wrapper)
@ -506,13 +508,15 @@ class Test(Loggable):
self.thread.join()
self.time_taken = time.time() - self._starting_time
message = "%s: %s%s\n" % (self.classname, self.result,
if self.result != Result.PASSED:
message = str(self)
end = "\n"
else:
message = "%s %s: %s%s" % (self.number, self.classname, self.result,
" (" + self.message + ")" if self.message else "")
if not self.options.redirect_logs:
message += self.get_logfile_repr()
printc(message, color=utils.get_color_for_result(self.result))
end = "\r"
printc(message, color=utils.get_color_for_result(self.result), end=end)
self.close_logfile()
if self.options.dump_on_failure:
@ -1548,12 +1552,13 @@ class _TestsLauncher(Loggable):
return True
return False
def print_test_num(self, test):
def get_test_num(self, test):
cur_test_num = self.tests.index(test) + 1
sys.stdout.write("[%d / %d] " % (cur_test_num, self.total_num_tests))
return "[%d / %d] " % (cur_test_num, self.total_num_tests)
def server_wrapper(self, ready):
self.server = GstValidateTCPServer(('localhost', 0), GstValidateListener)
self.server = GstValidateTCPServer(
('localhost', 0), GstValidateListener)
self.server.socket.settimeout(None)
self.server.launcher = self
self.serverport = self.server.socket.getsockname()[1]
@ -1608,7 +1613,6 @@ class _TestsLauncher(Loggable):
except IndexError:
return False
self.print_test_num(test)
test.test_start(self.queue)
self.jobs.append(test)
@ -1653,7 +1657,7 @@ class _TestsLauncher(Loggable):
while jobs_running != 0:
test = self.tests_wait()
jobs_running -= 1
self.print_test_num(test)
test.number = self.get_test_num(test)
res = test.test_end()
self.reporter.after_test(test)
if res != Result.PASSED and (self.options.forever or

View file

@ -95,14 +95,6 @@ class Reporter(Loggable):
self.add_results(test)
def final_report(self):
print("\n")
printc("Final Report:", title=True)
sortedresults = sorted(self.results, key=lambda test: test.classname)
for test in sorted(sortedresults, key=lambda test: test.result):
printc(test)
if test.result != Result.PASSED:
print("\n")
print("\n")
lenstat = (len("Statistics") + 1)
printc("Statistics:\n%s" % (lenstat * "-"), Colors.OKBLUE)

View file

@ -145,7 +145,8 @@ def get_color_for_result(result):
return color
def printc(message, color="", title=False, title_char=''):
last_cariage_return_len = 0
def printc(message, color="", title=False, title_char='', end="\n"):
if title or title_char:
length = 0
for l in message.split("\n"):
@ -162,7 +163,17 @@ def printc(message, color="", title=False, title_char=''):
if hasattr(message, "result") and color == '':
color = get_color_for_result(message.result)
sys.stdout.write(color + str(message) + Colors.ENDC + "\n")
if not sys.stdout.isatty():
end = "\n"
global last_carriage_return_len
if end == "\r":
message += ' ' * max(0, last_carriage_return_len - len(message))
last_carriage_return_len = len(message)
else:
last_carriage_return_len = 0
sys.stdout.write(color + str(message) + Colors.ENDC + end)
sys.stdout.flush()