mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 17:59:25 +01:00
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.
This commit is contained in:
parent
d11974c717
commit
8aac527e29
@ -244,31 +244,22 @@ class Process:
|
|||||||
|
|
||||||
self.pid.wait(timeout=5)
|
self.pid.wait(timeout=5)
|
||||||
self.killed = True
|
self.killed = True
|
||||||
|
self.ret = self.pid.returncode
|
||||||
|
|
||||||
self.stdout.seek(self.io_position)
|
self.stdout.seek(self.io_position)
|
||||||
self.out = self.stdout.read()
|
self.out = self.stdout.read()
|
||||||
self.stdout.seek(0, 2)
|
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:
|
if len(self.write_fds) > 0:
|
||||||
for fd in self.write_fds:
|
self.process_io(self.stdout)
|
||||||
fd.write(self.out)
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
self.write_fds = []
|
self.write_fds = []
|
||||||
|
|
||||||
if self.verbose:
|
|
||||||
sys.__stdout__.write(self.out)
|
|
||||||
|
|
||||||
print("%s returned %d" % (args[0], self.ret))
|
print("%s returned %d" % (args[0], self.ret))
|
||||||
if check and self.ret != 0:
|
if check and self.ret != 0:
|
||||||
raise subprocess.CalledProcessError(returncode=self.ret, cmd=self.args)
|
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
|
# The file will have already been written to, meaning the seek
|
||||||
# position points to EOF. This is why the position is saved so
|
# position points to EOF. This is why the position is saved so
|
||||||
@ -286,20 +277,27 @@ class Process:
|
|||||||
|
|
||||||
for f in self.write_fds:
|
for f in self.write_fds:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
f.flush()
|
||||||
|
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
sys.__stdout__.write(data)
|
sys.__stdout__.write(data)
|
||||||
|
sys.__stdout__.flush()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def io_callback(self, source, cb_condition):
|
||||||
|
return self.process_io(source)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
print("Del process %s" % self.args)
|
print("Del process %s" % self.args)
|
||||||
|
|
||||||
|
os.remove(self.output_name)
|
||||||
|
|
||||||
|
self.stdout.close()
|
||||||
|
|
||||||
if not self.killed:
|
if not self.killed:
|
||||||
self.kill()
|
self.kill()
|
||||||
|
|
||||||
os.remove(self.output_name)
|
|
||||||
|
|
||||||
def kill(self, force=False):
|
def kill(self, force=False):
|
||||||
print("Killing process %s" % self.args)
|
print("Killing process %s" % self.args)
|
||||||
|
|
||||||
@ -319,8 +317,10 @@ class Process:
|
|||||||
|
|
||||||
self.ctx = None
|
self.ctx = None
|
||||||
|
|
||||||
for f in self.write_fds:
|
self.process_io(self.stdout)
|
||||||
f.close()
|
|
||||||
|
if self.cleanup:
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
self.write_fds = []
|
self.write_fds = []
|
||||||
|
|
||||||
@ -328,13 +328,7 @@ class Process:
|
|||||||
GLib.source_remove(self.io_watch)
|
GLib.source_remove(self.io_watch)
|
||||||
self.io_watch = None
|
self.io_watch = None
|
||||||
|
|
||||||
if self.cleanup:
|
|
||||||
self.cleanup()
|
|
||||||
|
|
||||||
self.cleanup = None
|
self.cleanup = None
|
||||||
|
|
||||||
self.stdout.close()
|
|
||||||
|
|
||||||
self.killed = True
|
self.killed = True
|
||||||
|
|
||||||
def wait_for_socket(self, socket, wait):
|
def wait_for_socket(self, socket, wait):
|
||||||
|
Loading…
Reference in New Issue
Block a user