Browse Source

mavsdk_tests: collect buffered up stdout output

Somehow only subprocess.stdout.readline() works at a time. In order not
to miss out on some of the stdout output, we need to collect it all at
the end. Also, we can stop using readline() for processes that have quit
already.
sbg
Julian Oes 5 years ago
parent
commit
76750fc8a6
  1. 2
      test/mavsdk_tests/mavsdk_test_runner.py
  2. 15
      test/mavsdk_tests/process_helper.py

2
test/mavsdk_tests/mavsdk_test_runner.py

@ -341,6 +341,8 @@ class Tester: @@ -341,6 +341,8 @@ class Tester:
is_success = False
self.stop_runners()
# Collect what was left in output buffers.
self.collect_runner_output()
self.stop_combined_log()
result = {'success': is_success,

15
test/mavsdk_tests/process_helper.py

@ -53,7 +53,7 @@ class Runner: @@ -53,7 +53,7 @@ class Runner:
cwd=self.cwd,
env=self.env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stderr=subprocess.PIPE,
universal_newlines=True
)
@ -63,11 +63,12 @@ class Runner: @@ -63,11 +63,12 @@ class Runner:
def process_output(self) -> None:
assert self.process.stdout is not None
while not self.stop_thread.is_set():
while True:
line = self.process.stdout.readline()
if line == "\n":
continue
if not line:
if not line and \
(self.stop_thread.is_set() or self.poll is not None):
break
if not line or line == "\n":
continue
self.output_queue.put(line)
self.log_fd.write(line)
@ -99,8 +100,6 @@ class Runner: @@ -99,8 +100,6 @@ class Runner:
if not self.stop_thread:
return 0
self.stop_thread.set()
returncode = self.process.poll()
if returncode is None:
@ -123,8 +122,8 @@ class Runner: @@ -123,8 +122,8 @@ class Runner:
print("{} exited with {}".format(
self.cmd, self.process.returncode))
self.stop_thread.set()
self.thread.join()
self.log_fd.close()
return self.process.returncode

Loading…
Cancel
Save