forked from Archive/PX4-Autopilot
mavsdk_tests: make sure all log output is printed
This fixes the issue where the last lines of the log output was not printed in case of error or on the verbose setting. This meant that essentially the actual test error was not printed. The fix involves two parts: 1. Firstly collect the output again even if a process has exited. 2. Collect all lines at once and not one line per iteration.
This commit is contained in:
parent
dc29a994b7
commit
28f4dc10ae
|
@ -325,12 +325,13 @@ class Tester:
|
|||
test_timeout_s = test['timeout_min']*60
|
||||
while self.active_runners[-1].time_elapsed_s() < test_timeout_s:
|
||||
returncode = self.active_runners[-1].poll()
|
||||
|
||||
self.collect_runner_output()
|
||||
|
||||
if returncode is not None:
|
||||
is_success = (returncode == 0)
|
||||
break
|
||||
|
||||
self.collect_runner_output()
|
||||
|
||||
else:
|
||||
print(colorize(
|
||||
"Test timeout of {} mins triggered!".
|
||||
|
@ -439,14 +440,15 @@ class Tester:
|
|||
max_name = max(len(runner.name) for runner in self.active_runners)
|
||||
|
||||
for runner in self.active_runners:
|
||||
output = runner.get_output()
|
||||
if not output:
|
||||
continue
|
||||
while True:
|
||||
line = runner.get_output_line()
|
||||
if not line:
|
||||
break
|
||||
|
||||
output = self.add_name_prefix(max_name, runner.name, output)
|
||||
self.add_to_combined_log(output)
|
||||
if self.verbose:
|
||||
print(output, end="")
|
||||
line = self.add_name_prefix(max_name, runner.name, line)
|
||||
self.add_to_combined_log(line)
|
||||
if self.verbose:
|
||||
print(line, end="")
|
||||
|
||||
def start_combined_log(self, filename: str) -> None:
|
||||
self.log_fd = open(filename, 'w')
|
||||
|
|
|
@ -72,6 +72,8 @@ class Runner:
|
|||
line = self.process.stdout.readline()
|
||||
if line == "\n":
|
||||
continue
|
||||
if not line:
|
||||
continue
|
||||
self.output_queue.put(line)
|
||||
self.log_fd.write(line)
|
||||
self.log_fd.flush()
|
||||
|
@ -89,11 +91,12 @@ class Runner:
|
|||
print("stopped.")
|
||||
return errno.ETIMEDOUT
|
||||
|
||||
def get_output(self) -> Optional[str]:
|
||||
try:
|
||||
return self.output_queue.get(block=True, timeout=0.1)
|
||||
except queue.Empty:
|
||||
return None
|
||||
def get_output_line(self) -> Optional[str]:
|
||||
while True:
|
||||
try:
|
||||
return self.output_queue.get(block=True, timeout=0.1)
|
||||
except queue.Empty:
|
||||
return None
|
||||
|
||||
def stop(self) -> int:
|
||||
atexit.unregister(self.stop)
|
||||
|
|
Loading…
Reference in New Issue