tests: Optimize wait_event()
Replace the fixed 100 ms waits with a select()-based wait and timeout for full wait based on monotonic time to optimize wait_event(). Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
606110e647
commit
36408936f8
2 changed files with 25 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Python class for controlling hostapd
|
||||
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
||||
# Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
|
||||
#
|
||||
# This software may be distributed under the terms of the BSD license.
|
||||
# See README for more details.
|
||||
|
@ -121,16 +121,20 @@ class Hostapd:
|
|||
logger.debug(self.ifname + ": " + ev)
|
||||
|
||||
def wait_event(self, events, timeout):
|
||||
count = 0
|
||||
while count < timeout * 10:
|
||||
count = count + 1
|
||||
time.sleep(0.1)
|
||||
start = os.times()[4]
|
||||
while True:
|
||||
while self.mon.pending():
|
||||
ev = self.mon.recv()
|
||||
logger.debug(self.ifname + ": " + ev)
|
||||
for event in events:
|
||||
if event in ev:
|
||||
return ev
|
||||
now = os.times()[4]
|
||||
remaining = start + timeout - now
|
||||
if remaining <= 0:
|
||||
break
|
||||
if not self.mon.pending(timeout=remaining):
|
||||
break
|
||||
return None
|
||||
|
||||
def get_status(self):
|
||||
|
|
|
@ -447,32 +447,40 @@ class WpaSupplicant:
|
|||
raise Exception("P2P_CONNECT failed")
|
||||
|
||||
def wait_event(self, events, timeout=10):
|
||||
count = 0
|
||||
while count < timeout * 10:
|
||||
count = count + 1
|
||||
time.sleep(0.1)
|
||||
start = os.times()[4]
|
||||
while True:
|
||||
while self.mon.pending():
|
||||
ev = self.mon.recv()
|
||||
logger.debug(self.ifname + ": " + ev)
|
||||
for event in events:
|
||||
if event in ev:
|
||||
return ev
|
||||
now = os.times()[4]
|
||||
remaining = start + timeout - now
|
||||
if remaining <= 0:
|
||||
break
|
||||
if not self.mon.pending(timeout=remaining):
|
||||
break
|
||||
return None
|
||||
|
||||
def wait_global_event(self, events, timeout):
|
||||
if self.global_iface is None:
|
||||
self.wait_event(events, timeout)
|
||||
else:
|
||||
count = 0
|
||||
while count < timeout * 10:
|
||||
count = count + 1
|
||||
time.sleep(0.1)
|
||||
start = os.times()[4]
|
||||
while True:
|
||||
while self.global_mon.pending():
|
||||
ev = self.global_mon.recv()
|
||||
logger.debug(self.ifname + "(global): " + ev)
|
||||
for event in events:
|
||||
if event in ev:
|
||||
return ev
|
||||
now = os.times()[4]
|
||||
remaining = start + timeout - now
|
||||
if remaining <= 0:
|
||||
break
|
||||
if not self.global_mon.pending(timeout=remaining):
|
||||
break
|
||||
return None
|
||||
|
||||
def wait_go_ending_session(self):
|
||||
|
|
Loading…
Reference in a new issue