Review at https://gerrit.osmocom.org/2780
ofono_client: Fix race condition when checking for required features I got a backtrace in which the modem was lacking feature 'net'. That happens for 2 reasons: 1- net feature is not shown unless the modem is Online (at least for sierra modems) 2- Even after it has been set online, a lapse of time can pass before the feature gets shown. To fix both cases, we move the requirement check after we know the modem is online and we add extra code to wait for 3 seconds for the features to appear before raising an exception. Change-Id: Ibbfbbd2be6ecd3cebae83becf1cc34e15dc8e579 --- M src/osmo_gsm_tester/ofono_client.py 1 file changed, 13 insertions(+), 6 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/80/2780/1 diff --git a/src/osmo_gsm_tester/ofono_client.py b/src/osmo_gsm_tester/ofono_client.py index dfa33c4..6b93bd9 100644 --- a/src/osmo_gsm_tester/ofono_client.py +++ b/src/osmo_gsm_tester/ofono_client.py @@ -231,6 +231,11 @@ self.dbg(name, '==', is_val) return is_val is not None and is_val == val + def property_list_contains(self, name, val, iface=I_MODEM): + current = set(self.properties(iface).get(name)) + expected = set(val) + return expected < current + def set_bool(self, name, bool_val, iface=I_MODEM): # to make sure any pending signals are received before we send out more DBus requests event_loop.poll() @@ -253,13 +258,15 @@ def is_online(self): return self.property_is('Online', True) - def require_features(self, *required): + def require_features(self, *required, timeout=3): '''Make sure the given feature strings are present in properties()['Features'], raise an exception otherwise.''' - features = set(self.properties().get('Features')) - r = set(required) - if not (r < features): - self.raise_exn('This modem lacks features:', r - features) + try: # wait for timeout seconds to see if the modem has required features + event_loop.wait(self, self.property_list_contains, 'Features', required, timeout=timeout) + except RuntimeError: + current = set(self.properties().get('Features')) + expected = set(val) + self.raise_exn('This modem lacks features:', expected < current) @@ -278,7 +285,6 @@ self.mcc = None self.sms_received_list = [] self.dbus = ModemDbusInteraction(self.path) - self.dbus.require_features('sms', 'net') self.dbus.required_signals = { I_SMS: ( ('IncomingMessage', self._on_incoming_message), ), I_NETREG: ( ('PropertyChanged', self._on_netreg_property_changed), ), @@ -420,6 +426,7 @@ self.log('connect to', mcc, mnc) self.mcc = mcc self.mnc = mnc + self.dbus.require_features('sms', 'net') if self.dbus.has_interface(I_NETREG): self.register_timeout(1) else: -- To view, visit https://gerrit.osmocom.org/2780 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibbfbbd2be6ecd3cebae83becf1cc34e15dc8e579 Gerrit-PatchSet: 1 Gerrit-Project: osmo-gsm-tester Gerrit-Branch: master Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de>