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
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Python class for controlling hostapd
|
# 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.
|
# This software may be distributed under the terms of the BSD license.
|
||||||
# See README for more details.
|
# See README for more details.
|
||||||
|
@ -121,16 +121,20 @@ class Hostapd:
|
||||||
logger.debug(self.ifname + ": " + ev)
|
logger.debug(self.ifname + ": " + ev)
|
||||||
|
|
||||||
def wait_event(self, events, timeout):
|
def wait_event(self, events, timeout):
|
||||||
count = 0
|
start = os.times()[4]
|
||||||
while count < timeout * 10:
|
while True:
|
||||||
count = count + 1
|
|
||||||
time.sleep(0.1)
|
|
||||||
while self.mon.pending():
|
while self.mon.pending():
|
||||||
ev = self.mon.recv()
|
ev = self.mon.recv()
|
||||||
logger.debug(self.ifname + ": " + ev)
|
logger.debug(self.ifname + ": " + ev)
|
||||||
for event in events:
|
for event in events:
|
||||||
if event in ev:
|
if event in ev:
|
||||||
return 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
|
return None
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
|
|
|
@ -447,32 +447,40 @@ class WpaSupplicant:
|
||||||
raise Exception("P2P_CONNECT failed")
|
raise Exception("P2P_CONNECT failed")
|
||||||
|
|
||||||
def wait_event(self, events, timeout=10):
|
def wait_event(self, events, timeout=10):
|
||||||
count = 0
|
start = os.times()[4]
|
||||||
while count < timeout * 10:
|
while True:
|
||||||
count = count + 1
|
|
||||||
time.sleep(0.1)
|
|
||||||
while self.mon.pending():
|
while self.mon.pending():
|
||||||
ev = self.mon.recv()
|
ev = self.mon.recv()
|
||||||
logger.debug(self.ifname + ": " + ev)
|
logger.debug(self.ifname + ": " + ev)
|
||||||
for event in events:
|
for event in events:
|
||||||
if event in ev:
|
if event in ev:
|
||||||
return 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
|
return None
|
||||||
|
|
||||||
def wait_global_event(self, events, timeout):
|
def wait_global_event(self, events, timeout):
|
||||||
if self.global_iface is None:
|
if self.global_iface is None:
|
||||||
self.wait_event(events, timeout)
|
self.wait_event(events, timeout)
|
||||||
else:
|
else:
|
||||||
count = 0
|
start = os.times()[4]
|
||||||
while count < timeout * 10:
|
while True:
|
||||||
count = count + 1
|
|
||||||
time.sleep(0.1)
|
|
||||||
while self.global_mon.pending():
|
while self.global_mon.pending():
|
||||||
ev = self.global_mon.recv()
|
ev = self.global_mon.recv()
|
||||||
logger.debug(self.ifname + "(global): " + ev)
|
logger.debug(self.ifname + "(global): " + ev)
|
||||||
for event in events:
|
for event in events:
|
||||||
if event in ev:
|
if event in ev:
|
||||||
return 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
|
return None
|
||||||
|
|
||||||
def wait_go_ending_session(self):
|
def wait_go_ending_session(self):
|
||||||
|
|
Loading…
Reference in a new issue