mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 14:49:24 +01:00
test-runner: cleanup output files/others in Process
A cleanup parameter was added to __init__ which can be used by processes which create any additional files or require more a custom cleanup routine. Some additional house keeping was done to make Process cleanup more robust.
This commit is contained in:
parent
697b4ce82f
commit
5e79cda7c6
@ -160,7 +160,7 @@ class Process:
|
|||||||
case.
|
case.
|
||||||
'''
|
'''
|
||||||
def __init__(self, args, wait=False, env=None, ctx=None, check=False,
|
def __init__(self, args, wait=False, env=None, ctx=None, check=False,
|
||||||
outfile=None, namespace=None, need_out=False):
|
outfile=None, namespace=None, need_out=False, cleanup=None):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.wait = wait
|
self.wait = wait
|
||||||
self.name = args[0]
|
self.name = args[0]
|
||||||
@ -168,6 +168,7 @@ class Process:
|
|||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.write_fds = []
|
self.write_fds = []
|
||||||
self.io_watch = None
|
self.io_watch = None
|
||||||
|
self.cleanup = cleanup
|
||||||
|
|
||||||
if not namespace:
|
if not namespace:
|
||||||
self.output_name = '/tmp/%s-out' % self.name
|
self.output_name = '/tmp/%s-out' % self.name
|
||||||
@ -250,6 +251,9 @@ class Process:
|
|||||||
if len(self.write_fds) > 0:
|
if len(self.write_fds) > 0:
|
||||||
for fd in self.write_fds:
|
for fd in self.write_fds:
|
||||||
fd.write(self.out)
|
fd.write(self.out)
|
||||||
|
fd.close()
|
||||||
|
|
||||||
|
self.write_fds = []
|
||||||
|
|
||||||
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:
|
||||||
@ -283,11 +287,16 @@ class Process:
|
|||||||
if self.io_watch:
|
if self.io_watch:
|
||||||
GLib.source_remove(self.io_watch)
|
GLib.source_remove(self.io_watch)
|
||||||
|
|
||||||
if self.write_fds != []:
|
|
||||||
for f in self.write_fds:
|
for f in self.write_fds:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
try:
|
||||||
os.remove(self.output_name)
|
os.remove(self.output_name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if self.cleanup:
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
def kill(self, force=False):
|
def kill(self, force=False):
|
||||||
print("Killing process %s" % self.args)
|
print("Killing process %s" % self.args)
|
||||||
@ -298,6 +307,8 @@ class Process:
|
|||||||
self.pid.kill()
|
self.pid.kill()
|
||||||
|
|
||||||
self.pid.wait(timeout=15)
|
self.pid.wait(timeout=15)
|
||||||
|
self.pid = None
|
||||||
|
self.write_fds = []
|
||||||
|
|
||||||
def wait_for_socket(self, socket, wait):
|
def wait_for_socket(self, socket, wait):
|
||||||
waited = 0
|
waited = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user