mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 17:59:25 +01:00
test-runner: move process tracking out of Namespace
Since Process.processes is a weak reference dictionary any process put in this dict will disappear if all references are lost. This is much better than keeping a list in the Namespace which will hold the references forever until test-runner manually kills them all at the end of the test. This does still need to be done for daemon processes but everything else can just go away when it is no longer needed.
This commit is contained in:
parent
92a3d8f498
commit
11271cd967
@ -57,12 +57,9 @@ def dbg(*s, **kwargs):
|
|||||||
|
|
||||||
def exit_vm():
|
def exit_vm():
|
||||||
if config:
|
if config:
|
||||||
for p in config.ctx.processes:
|
for p in Process.get_all():
|
||||||
print("Process %s still running!" % p.args[0])
|
print("Process %s still running!" % p.args[0])
|
||||||
p.kill()
|
p.kill()
|
||||||
p = None
|
|
||||||
|
|
||||||
config.ctx.processes = []
|
|
||||||
|
|
||||||
if config.ctx and config.ctx.results:
|
if config.ctx and config.ctx.results:
|
||||||
print_results(config.ctx.results)
|
print_results(config.ctx.results)
|
||||||
@ -178,6 +175,7 @@ class Process(subprocess.Popen):
|
|||||||
self.out = ''
|
self.out = ''
|
||||||
self.hup = False
|
self.hup = False
|
||||||
self.killed = False
|
self.killed = False
|
||||||
|
self.namespace = namespace
|
||||||
|
|
||||||
if not self.ctx:
|
if not self.ctx:
|
||||||
global config
|
global config
|
||||||
@ -219,6 +217,15 @@ class Process(subprocess.Popen):
|
|||||||
raise subprocess.CalledProcessError(returncode=self.returncode,
|
raise subprocess.CalledProcessError(returncode=self.returncode,
|
||||||
cmd=args)
|
cmd=args)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all(cls):
|
||||||
|
return cls.processes.values()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def kill_all(cls):
|
||||||
|
for p in cls.processes.values():
|
||||||
|
p.kill()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _write_io(instance, data, stdout=True):
|
def _write_io(instance, data, stdout=True):
|
||||||
for f in instance.write_fds:
|
for f in instance.write_fds:
|
||||||
@ -321,8 +328,6 @@ class Process(subprocess.Popen):
|
|||||||
self.cleanup = None
|
self.cleanup = None
|
||||||
self.killed = True
|
self.killed = True
|
||||||
|
|
||||||
if self in self.ctx.processes:
|
|
||||||
self.ctx.processes.remove(self)
|
|
||||||
# Override kill()
|
# Override kill()
|
||||||
def kill(self, force=False):
|
def kill(self, force=False):
|
||||||
if self.killed:
|
if self.killed:
|
||||||
@ -588,7 +593,6 @@ dbus_count = 0
|
|||||||
class Namespace:
|
class Namespace:
|
||||||
def __init__(self, args, name, radios):
|
def __init__(self, args, name, radios):
|
||||||
self.dbus_address = None
|
self.dbus_address = None
|
||||||
self.processes = []
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.radios = radios
|
self.radios = radios
|
||||||
self.args = args
|
self.args = args
|
||||||
@ -607,10 +611,7 @@ class Namespace:
|
|||||||
|
|
||||||
self.radios = []
|
self.radios = []
|
||||||
|
|
||||||
for p in list(self.processes):
|
Process.kill_all()
|
||||||
p.kill()
|
|
||||||
|
|
||||||
self.processes = []
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
print("Removing namespace %s" % self.name)
|
print("Removing namespace %s" % self.name)
|
||||||
@ -628,19 +629,14 @@ class Namespace:
|
|||||||
# In case this process needs DBus...
|
# In case this process needs DBus...
|
||||||
env['DBUS_SYSTEM_BUS_ADDRESS'] = self.dbus_address
|
env['DBUS_SYSTEM_BUS_ADDRESS'] = self.dbus_address
|
||||||
|
|
||||||
p = Process(args, namespace=self.name, env=env, **kwargs)
|
return Process(args, namespace=self.name, env=env, **kwargs)
|
||||||
|
|
||||||
if not kwargs.get('wait', False):
|
|
||||||
self.processes.append(p)
|
|
||||||
|
|
||||||
return p
|
|
||||||
|
|
||||||
def stop_process(self, p, force=False):
|
def stop_process(self, p, force=False):
|
||||||
p.kill(force)
|
p.kill(force)
|
||||||
|
|
||||||
def is_process_running(self, process):
|
def is_process_running(self, process):
|
||||||
for p in self.processes:
|
for p in Process.get_all():
|
||||||
if p.args[0] == process:
|
if p.namespace == self.name and p.args[0] == process:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -698,8 +694,7 @@ class Namespace:
|
|||||||
if self.is_verbose('iwd-acd'):
|
if self.is_verbose('iwd-acd'):
|
||||||
env['IWD_ACD_DEBUG'] = '1'
|
env['IWD_ACD_DEBUG'] = '1'
|
||||||
|
|
||||||
pid = self.start_process(args, env=env)
|
return self.start_process(args, env=env)
|
||||||
return pid
|
|
||||||
|
|
||||||
def is_verbose(self, process, log=True):
|
def is_verbose(self, process, log=True):
|
||||||
process = os.path.basename(process)
|
process = os.path.basename(process)
|
||||||
@ -786,7 +781,7 @@ class Namespace:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
ret = 'Namespace: %s\n' % self.name
|
ret = 'Namespace: %s\n' % self.name
|
||||||
ret += 'Processes:\n'
|
ret += 'Processes:\n'
|
||||||
for p in self.processes:
|
for p in Process.get_all():
|
||||||
ret += '\t%s' % str(p)
|
ret += '\t%s' % str(p)
|
||||||
|
|
||||||
ret += 'Radios:\n'
|
ret += 'Radios:\n'
|
||||||
@ -808,7 +803,6 @@ class TestContext(Namespace):
|
|||||||
'''
|
'''
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
self.name = None
|
self.name = None
|
||||||
self.processes = []
|
|
||||||
self.args = args
|
self.args = args
|
||||||
self.hw_config = None
|
self.hw_config = None
|
||||||
self.hostapd = None
|
self.hostapd = None
|
||||||
|
Loading…
Reference in New Issue
Block a user