3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

auto-t: iwd.py: use non_block_wait

This commit is contained in:
James Prestwood 2021-08-13 09:24:38 -07:00 committed by Denis Kenzior
parent 80ee406e3e
commit 732871b601

View File

@ -109,9 +109,7 @@ class AsyncOpAbstract(object):
self._exception = _convert_dbus_ex(ex)
def _wait_for_async_op(self):
context = ctx.mainloop.get_context()
while not self._is_completed:
context.iteration(may_block=True)
ctx.non_block_wait(lambda s: s._is_completed, 30, self, exception=None)
self._is_completed = False
if self._exception is not None:
@ -1019,16 +1017,8 @@ class IWD(AsyncOpAbstract):
self._iwd_proc = self.namespace.start_iwd(iwd_config_dir,
iwd_storage_dir)
tries = 0
while not self._bus.name_has_owner(IWD_SERVICE):
if not ctx.args.gdb:
if tries > 200:
if start_iwd_daemon:
self.namespace.stop_process(self._iwd_proc)
self._iwd_proc = None
raise TimeoutError('IWD has failed to start')
tries += 1
time.sleep(0.1)
ctx.non_block_wait(self._bus.name_has_owner, 20, IWD_SERVICE,
exception=TimeoutError('IWD has failed to start'))
self._devices = DeviceList(self)
@ -1074,27 +1064,13 @@ class IWD(AsyncOpAbstract):
@staticmethod
def _wait_for_object_condition(obj, condition_str, max_wait = 50):
class TimeoutData:
_wait_timed_out = False
def _eval_wrap(obj, condition_str):
return eval(condition_str)
data = TimeoutData()
def wait_timeout_cb(data):
data._wait_timed_out = True
return False
try:
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb, data)
context = ctx.mainloop.get_context()
while not eval(condition_str):
context.iteration(may_block=True)
if data._wait_timed_out and ctx.args.gdb == None:
raise TimeoutError('[' + condition_str + ']'\
ctx.non_block_wait(_eval_wrap, max_wait, obj, condition_str,
exception=TimeoutError('[' + condition_str + ']'\
' condition was not met in '\
+ str(max_wait) + ' sec')
finally:
if not data._wait_timed_out:
GLib.source_remove(timeout)
+ str(max_wait) + ' sec'))
def wait_for_object_condition(self, *args, **kwargs):
self._wait_for_object_condition(*args, **kwargs)
@ -1108,22 +1084,7 @@ class IWD(AsyncOpAbstract):
This allows an object to be checked for a state transition without any
intermediate state changes.
'''
self._wait_timed_out = False
def wait_timeout_cb():
self._wait_timed_out = True
return False
# Does initial condition pass?
if not eval(from_str):
raise Exception("initial condition [%s] not met" % from_str)
try:
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
context = ctx.mainloop.get_context()
while True:
context.iteration(may_block=True)
def _eval_from_to(obj, from_str, to_str):
# If neither the initial or expected condition evaluate the
# object must be in another unexpected state.
if not eval(from_str) and not eval(to_str):
@ -1132,30 +1093,21 @@ class IWD(AsyncOpAbstract):
# Initial condition does not evaluate but expected does, pass
if not eval(from_str) and eval(to_str):
break
return True
if self._wait_timed_out and ctx.args.gdb == None:
raise TimeoutError('[' + to_str + ']'\
' condition was not met in '\
+ str(max_wait) + ' sec')
finally:
if not self._wait_timed_out:
GLib.source_remove(timeout)
def wait(self, time):
self._wait_timed_out = False
def wait_timeout_cb():
self._wait_timed_out = True
return False
try:
timeout = GLib.timeout_add(int(time * 1000), wait_timeout_cb)
context = ctx.mainloop.get_context()
while not self._wait_timed_out:
context.iteration(may_block=True)
finally:
if not self._wait_timed_out:
GLib.source_remove(timeout)
# Does initial condition pass?
if not eval(from_str):
raise Exception("initial condition [%s] not met" % from_str)
ctx.non_block_wait(_eval_from_to, max_wait, obj, from_str, to_str,
exception=TimeoutError('[' + to_str + ']'\
' condition was not met in '\
+ str(max_wait) + ' sec'))
def wait(self, time):
ctx.non_block_wait(lambda : False, time, exception=False)
@staticmethod
def clear_storage(storage_dir=IWD_STORAGE_DIR):
@ -1200,21 +1152,8 @@ class IWD(AsyncOpAbstract):
if not wait_to_appear:
return list(self._devices.values() if not p2p else self._devices.p2p_dict.values())
self._wait_timed_out = False
def wait_timeout_cb():
self._wait_timed_out = True
return False
try:
timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb)
context = ctx.mainloop.get_context()
while len(self._devices) < wait_to_appear:
context.iteration(may_block=True)
if self._wait_timed_out:
raise TimeoutError('IWD has no associated devices')
finally:
if not self._wait_timed_out:
GLib.source_remove(timeout)
ctx.non_block_wait(lambda s, n: len(s._devices) >= n, max_wait, self, wait_to_appear,
exception=TimeoutError('IWD has no associated devices'))
return list(self._devices.values() if not p2p else self._devices.p2p_dict.values())[:wait_to_appear]