mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
validate:launcher: factor out TTY check and enhance iteration output
This commit is contained in:
parent
48fa4b6c4b
commit
ddb81f29e8
2 changed files with 22 additions and 19 deletions
|
@ -55,7 +55,7 @@ from .vfb_server import get_virual_frame_buffer_server
|
||||||
from .httpserver import HTTPServer
|
from .httpserver import HTTPServer
|
||||||
from .utils import mkdir, Result, Colors, printc, DEFAULT_TIMEOUT, GST_SECOND, \
|
from .utils import mkdir, Result, Colors, printc, DEFAULT_TIMEOUT, GST_SECOND, \
|
||||||
Protocols, look_for_file_in_source_dir, get_data_file, BackTraceGenerator, \
|
Protocols, look_for_file_in_source_dir, get_data_file, BackTraceGenerator, \
|
||||||
check_bugs_resolution
|
check_bugs_resolution, is_tty
|
||||||
|
|
||||||
# The factor by which we increase the hard timeout when running inside
|
# The factor by which we increase the hard timeout when running inside
|
||||||
# Valgrind
|
# Valgrind
|
||||||
|
@ -622,11 +622,7 @@ class Test(Loggable):
|
||||||
message = "%s %s: %s%s" % (self.number, self.classname, self.result,
|
message = "%s %s: %s%s" % (self.number, self.classname, self.result,
|
||||||
" (" + self.message + ")" if self.message else "")
|
" (" + self.message + ")" if self.message else "")
|
||||||
end = "\r"
|
end = "\r"
|
||||||
if sys.stdout.isatty():
|
if not is_tty():
|
||||||
term_width = shutil.get_terminal_size((80, 20))[0]
|
|
||||||
if len(message) > term_width:
|
|
||||||
message = message[0:term_width - 2] + '…'
|
|
||||||
else:
|
|
||||||
message = None
|
message = None
|
||||||
|
|
||||||
if message is not None:
|
if message is not None:
|
||||||
|
@ -1869,7 +1865,7 @@ class _TestsLauncher(Loggable):
|
||||||
if not self.all_tests:
|
if not self.all_tests:
|
||||||
self.all_tests = self.list_tests()
|
self.all_tests = self.list_tests()
|
||||||
self.total_num_tests = len(self.all_tests)
|
self.total_num_tests = len(self.all_tests)
|
||||||
if not sys.stdout.isatty():
|
if not is_tty():
|
||||||
printc("\nRunning %d tests..." % self.total_num_tests, color=Colors.HEADER)
|
printc("\nRunning %d tests..." % self.total_num_tests, color=Colors.HEADER)
|
||||||
|
|
||||||
self.reporter.init_timer()
|
self.reporter.init_timer()
|
||||||
|
@ -1925,24 +1921,25 @@ class _TestsLauncher(Loggable):
|
||||||
if self.options.forever:
|
if self.options.forever:
|
||||||
r = 1
|
r = 1
|
||||||
while True:
|
while True:
|
||||||
printc("-> Iteration %d" % r, end='')
|
printc("-> Iteration %d" % r, end='\r')
|
||||||
|
|
||||||
if not self._run_tests():
|
if not self._run_tests():
|
||||||
break
|
break
|
||||||
r += 1
|
r += 1
|
||||||
self.clean_tests()
|
self.clean_tests()
|
||||||
printc("OK", Colors.OKGREEN)
|
msg = "-> Iteration %d... %sOK%s" % (r, Colors.OKGREEN, Colors.ENDC)
|
||||||
|
printc(msg, end="\r")
|
||||||
|
|
||||||
return False
|
return False
|
||||||
elif self.options.n_runs:
|
elif self.options.n_runs:
|
||||||
res = True
|
res = True
|
||||||
for r in range(self.options.n_runs):
|
for r in range(self.options.n_runs):
|
||||||
printc("-> Iteration %d" % r)
|
printc("-> Iteration %d" % r, end='\r')
|
||||||
if not self._run_tests():
|
if not self._run_tests():
|
||||||
res = False
|
res = False
|
||||||
printc("ERROR", Colors.FAIL)
|
printc("ERROR", Colors.FAIL, end="\r")
|
||||||
else:
|
else:
|
||||||
printc("OK", Colors.OKGREEN)
|
printc("OK", Colors.OKGREEN, end="\r")
|
||||||
self.clean_tests()
|
self.clean_tests()
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -88,14 +88,14 @@ class Protocols(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_tty():
|
||||||
|
return hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
|
||||||
|
|
||||||
|
|
||||||
def supports_ansi_colors():
|
def supports_ansi_colors():
|
||||||
if 'GST_VALIDATE_LAUNCHER_FORCE_COLORS' in os.environ:
|
|
||||||
return True
|
|
||||||
platform = sys.platform
|
platform = sys.platform
|
||||||
supported_platform = platform != 'win32' or 'ANSICON' in os.environ
|
supported_platform = platform != 'win32' or 'ANSICON' in os.environ
|
||||||
# isatty is not always implemented, #6223.
|
if not supported_platform or not is_tty():
|
||||||
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
|
|
||||||
if not supported_platform or not is_a_tty:
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -185,12 +185,18 @@ def printc(message, color="", title=False, title_char='', end="\n"):
|
||||||
if hasattr(message, "result") and color == '':
|
if hasattr(message, "result") and color == '':
|
||||||
color = get_color_for_result(message.result)
|
color = get_color_for_result(message.result)
|
||||||
|
|
||||||
if not sys.stdout.isatty():
|
if not is_tty():
|
||||||
end = "\n"
|
end = "\n"
|
||||||
|
|
||||||
message = str(message)
|
message = str(message)
|
||||||
message += ' ' * max(0, last_carriage_return_len - len(message))
|
message += ' ' * max(0, last_carriage_return_len - len(message))
|
||||||
last_carriage_return_len = len(message) if end == "\r" else 0
|
if end == '\r':
|
||||||
|
term_width = shutil.get_terminal_size((80, 20))[0]
|
||||||
|
if len(message) > term_width:
|
||||||
|
message = message[0:term_width - 2] + '…'
|
||||||
|
last_carriage_return_len = len(message)
|
||||||
|
else:
|
||||||
|
last_carriage_return_len = 0
|
||||||
sys.stdout.write(color + str(message) + Colors.ENDC + end)
|
sys.stdout.write(color + str(message) + Colors.ENDC + end)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue