Skip to content
Snippets Groups Projects
Commit 3656e8fa authored by Ostermayer, Markus's avatar Ostermayer, Markus
Browse files

reworked the follow-methode

parent cf044dc8
No related branches found
No related tags found
1 merge request!7reworked the follow-methode
Pipeline #199553 waiting for manual action
...@@ -67,20 +67,42 @@ def _print_testresult( ...@@ -67,20 +67,42 @@ def _print_testresult(
print(f'{testname}{result}') print(f'{testname}{result}')
def follow(file, sleep_sec=0.1) -> Iterator[str]: def follow(
""" Yield each line from a file as they are written. file,
`sleep_sec` is the time to sleep after empty reads. """ sleep_sec: float = 0.5,
timeout: int = 10,
use_color: bool = True,
) -> Iterator[str]:
# SRC: https://stackoverflow.com/a/54263201 # SRC: https://stackoverflow.com/a/54263201
line = '' line = ''
idle_time: float = 0.0
sys.stdout.write('Executing test ........... ')
sys.stdout.flush()
while True: while True:
tmp = file.readline() tmp = file.readline()
if tmp is not None:
if tmp != '':
line += tmp line += tmp
if line.endswith('\n'): if line.endswith('\n'):
yield line yield line
line = '' line = ''
elif sleep_sec: idle_time = 0
else:
time.sleep(sleep_sec) time.sleep(sleep_sec)
idle_time += sleep_sec
if idle_time > timeout:
if use_color:
sys.stdout.write(
(
f'{Colors.green.value}Executed!'
f'{Colors.normal.value}\n'
),
)
else:
sys.stdout.write('Executed!\n')
return
def execute_test( def execute_test(
...@@ -116,17 +138,12 @@ def execute_test( ...@@ -116,17 +138,12 @@ def execute_test(
with open( with open(
f'{build_path}/{testname.filename_without_ending}.log', f'{build_path}/{testname.filename_without_ending}.log',
) as logfile: ) as logfile:
for logline in follow(logfile): for logline in follow(logfile, use_color=True):
if 'Assertion failed' in logline: if 'Assertion failed' in logline:
test_result = Result.failed test_result = Result.failed
break
elif 'KERNEL PANIC' in logline: elif 'KERNEL PANIC' in logline:
test_result = Result.failed test_result = Result.failed
break
elif 'cleanupDeadThreads: done' in logline:
break
qemu_prozess.terminate() qemu_prozess.terminate()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment