From 8aac527e293711e8277eff3a072844e2c5734c34 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 22 Apr 2021 10:37:42 -0700 Subject: [PATCH] test-runner: fix process output truncation There was a bug with process output where the last bit of data would never make it into stdout or log files. This was due to the IO watch being cleaned up when the process was killed and never allowing it to finish writing any pending data. Now the IO watch implementation has been moved out into its own function (io_process) which is now used to write the final bits of data out on process exit. --- tools/test-runner | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/tools/test-runner b/tools/test-runner index c3a5ff89..799953de 100755 --- a/tools/test-runner +++ b/tools/test-runner @@ -244,31 +244,22 @@ class Process: self.pid.wait(timeout=5) self.killed = True + self.ret = self.pid.returncode self.stdout.seek(self.io_position) self.out = self.stdout.read() self.stdout.seek(0, 2) - self.ret = self.pid.returncode - # - # No IO callback for wait/check=True processes so write out - # the data to any FD's now. - # if len(self.write_fds) > 0: - for fd in self.write_fds: - fd.write(self.out) - fd.close() + self.process_io(self.stdout) - self.write_fds = [] - - if self.verbose: - sys.__stdout__.write(self.out) + self.write_fds = [] print("%s returned %d" % (args[0], self.ret)) if check and self.ret != 0: raise subprocess.CalledProcessError(returncode=self.ret, cmd=self.args) - def io_callback(self, source, cb_condition): + def process_io(self, source): # # The file will have already been written to, meaning the seek # position points to EOF. This is why the position is saved so @@ -286,20 +277,27 @@ class Process: for f in self.write_fds: f.write(data) + f.flush() if self.verbose: sys.__stdout__.write(data) + sys.__stdout__.flush() return True + def io_callback(self, source, cb_condition): + return self.process_io(source) + def __del__(self): print("Del process %s" % self.args) + os.remove(self.output_name) + + self.stdout.close() + if not self.killed: self.kill() - os.remove(self.output_name) - def kill(self, force=False): print("Killing process %s" % self.args) @@ -319,8 +317,10 @@ class Process: self.ctx = None - for f in self.write_fds: - f.close() + self.process_io(self.stdout) + + if self.cleanup: + self.cleanup() self.write_fds = [] @@ -328,13 +328,7 @@ class Process: GLib.source_remove(self.io_watch) self.io_watch = None - if self.cleanup: - self.cleanup() - self.cleanup = None - - self.stdout.close() - self.killed = True def wait_for_socket(self, socket, wait):