]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: wpasupplicant: Refactor code duplication in wait_global_event()
authorJohannes Berg <johannes.berg@intel.com>
Fri, 1 Feb 2019 20:31:59 +0000 (21:31 +0100)
committerJouni Malinen <j@w1.fi>
Fri, 1 Feb 2019 21:02:43 +0000 (23:02 +0200)
This code is identical to the wait_event() code, except for the
mon/global_mon instance. Create a _wait_event() function that
encapsulates this, and use it for both.

While at it, fix the bug in wait_global_event() where in the case
of not having a global_mon it always returns None.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
tests/hwsim/wpasupplicant.py

index fed9a5eff398ee21dcee323ff8f66054d80ba114..0cc6ea8c946acdac7ae47a723586dbdcad5a3280 100644 (file)
@@ -764,12 +764,12 @@ class WpaSupplicant:
             return self.group_form_result(ev, expect_failure, go_neg_res)
         raise Exception("P2P_CONNECT failed")
 
-    def wait_event(self, events, timeout=10):
+    def _wait_event(self, mon, pfx, events, timeout):
         start = os.times()[4]
         while True:
-            while self.mon.pending():
-                ev = self.mon.recv()
-                logger.debug(self.dbg + ": " + ev)
+            while mon.pending():
+                ev = mon.recv()
+                logger.debug(self.dbg + pfx + ev)
                 for event in events:
                     if event in ev:
                         return ev
@@ -777,29 +777,18 @@ class WpaSupplicant:
             remaining = start + timeout - now
             if remaining <= 0:
                 break
-            if not self.mon.pending(timeout=remaining):
+            if not mon.pending(timeout=remaining):
                 break
         return None
 
+    def wait_event(self, events, timeout=10):
+        return self._wait_event(self.mon, ": ", events, timeout)
+
     def wait_global_event(self, events, timeout):
         if self.global_iface is None:
-            self.wait_event(events, timeout)
-        else:
-            start = os.times()[4]
-            while True:
-                while self.global_mon.pending():
-                    ev = self.global_mon.recv()
-                    logger.debug(self.global_dbg + 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
+            return self.wait_event(events, timeout)
+        return self._wait_event(self.global_mon, "(global): ",
+                                events, timeout)
 
     def wait_group_event(self, events, timeout=10):
         if self.group_ifname and self.group_ifname != self.ifname: