From 28f4dc10ae1afafca98379f55aa468f109f27fbc Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Fri, 3 Apr 2020 08:47:41 +0200 Subject: [PATCH] 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. --- test/mavsdk_tests/mavsdk_test_runner.py | 20 +++++++++++--------- test/mavsdk_tests/process_helper.py | 13 ++++++++----- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/test/mavsdk_tests/mavsdk_test_runner.py b/test/mavsdk_tests/mavsdk_test_runner.py index 9f0a5be8b7..3562c60b9d 100755 --- a/test/mavsdk_tests/mavsdk_test_runner.py +++ b/test/mavsdk_tests/mavsdk_test_runner.py @@ -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') diff --git a/test/mavsdk_tests/process_helper.py b/test/mavsdk_tests/process_helper.py index 71e2f94663..26c8b94542 100644 --- a/test/mavsdk_tests/process_helper.py +++ b/test/mavsdk_tests/process_helper.py @@ -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)