fix multi-suite runs: implement modem cleanup

After a suite was done, the modem object would linger. If two suites were run
consecutively, the first suite's modem objects would still log incoming SMS.

Add an object cleanup mechanism in the SuiteRun class. Start by adding a
cleanup() to the Modem object and subscribing created modems there.

Move the modem_obj() function into SuiteRun, there is no use of it being
separate, and it makes for better logging.

Change-Id: I0048d33e661d683a263c98128cd5c38b8d897dab
This commit is contained in:
Neels Hofmeyr 2017-05-29 04:13:58 +02:00
parent 896f08f6ab
commit 4d688c2faf
2 changed files with 25 additions and 6 deletions

View File

@ -98,11 +98,14 @@ class ModemDbusInteraction(log.Origin):
# { I_SMS: ( token1, token2, ... ), }
self.connected_signals = util.listdict()
def __del__(self):
def cleanup(self):
self.unwatch_interfaces()
for interface_name in list(self.connected_signals.keys()):
self.remove_signals(interface_name)
def __del__(self):
self.cleanup()
def get_new_dbus_obj(self):
return systembus_get(self.modem_path)
@ -268,6 +271,10 @@ class Modem(log.Origin):
}
self.dbus.watch_interfaces()
def cleanup(self):
self.dbus.cleanup()
self.dbus = None
def properties(self, *args, **kwargs):
'''Return a dict of properties on this modem. For the actual arguments,
see ModemDbusInteraction.properties(), which this function calls. The

View File

@ -174,6 +174,7 @@ class SuiteRun(log.Origin):
trial = None
resources_pool = None
reserved_resources = None
objects_to_clean_up = None
_resource_requirements = None
_config = None
_processes = None
@ -186,6 +187,16 @@ class SuiteRun(log.Origin):
self.set_log_category(log.C_TST)
self.resources_pool = resource.ResourcesPool()
def register_for_cleanup(self, *obj):
assert all([hasattr(o, 'cleanup') for o in obj])
self.objects_to_clean_up = self.objects_to_clean_up or []
self.objects_to_clean_up.extend(obj)
def objects_cleanup(self):
while self.objects_to_clean_up:
obj = self.objects_to_clean_up.pop()
obj.cleanup()
def mark_start(self):
self.tests = []
self.start_timestamp = time.time()
@ -248,6 +259,7 @@ class SuiteRun(log.Origin):
# base exception is raised. Make sure to stop processes in this
# finally section. Resources are automatically freed with 'atexit'.
self.stop_processes()
self.objects_cleanup()
self.free_resources()
event_loop.unregister_poll_func(self.poll)
self.duration = time.time() - self.start_timestamp
@ -306,7 +318,11 @@ class SuiteRun(log.Origin):
return bts_obj(self, self.reserved_resources.get(resource.R_BTS))
def modem(self):
return modem_obj(self.reserved_resources.get(resource.R_MODEM))
conf = self.reserved_resources.get(resource.R_MODEM)
self.dbg('create Modem object', conf=conf)
modem = ofono_client.Modem(conf)
self.register_for_cleanup(modem)
return modem
def modems(self, count):
l = []
@ -398,8 +414,4 @@ def bts_obj(suite_run, conf):
raise RuntimeError('No such BTS type is defined: %r' % bts_type)
return bts_class(suite_run, conf)
def modem_obj(conf):
log.dbg(None, None, 'create Modem object', conf=conf)
return ofono_client.Modem(conf)
# vim: expandtab tabstop=4 shiftwidth=4