]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Optimize wait_event()
authorJouni Malinen <j@w1.fi>
Sun, 5 Jan 2014 06:02:06 +0000 (08:02 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 7 Jan 2014 08:45:10 +0000 (10:45 +0200)
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>

tests/hwsim/hostapd.py
tests/hwsim/wpasupplicant.py

index 94e95d04d82ae5aa6c63c212b7667807bd3bf5da..fa1d356126b51aeffa2b6722009d49293907f472 100644 (file)
@@ -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):
index 3823ad21ff6c029d0cd31425f4ea24bf12793f1d..0fc5c79fd7e81ca7e6f5be0fc39f93c4a2fc9389 100644 (file)
@@ -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):