]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Make pmksa_cache_expiration more robust
authorJouni Malinen <j@w1.fi>
Fri, 27 Dec 2019 13:58:32 +0000 (15:58 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 27 Dec 2019 14:03:50 +0000 (16:03 +0200)
Wait for hostapd to enter the PTKINITDONE state before checking
connectivity. This is needed to avoid a race condition with UML
time-travel.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/hostapd.py
tests/hwsim/test_pmksa_cache.py

index 4430d8055356be0ca6f9400f4533cc73ebdd4466..e555f75ed866f3bc9aa80b4f703d9389d4195f7e 100644 (file)
@@ -271,6 +271,18 @@ class Hostapd:
         if addr and addr not in ev:
             raise Exception("Unexpected STA address in connection event: " + ev)
 
+    def wait_ptkinitdone(self, addr, timeout=2):
+        while timeout > 0:
+            sta = self.get_sta(addr)
+            if 'hostapdWPAPTKState' not in sta:
+                raise Exception("GET_STA did not return hostapdWPAPTKState")
+            state = sta['hostapdWPAPTKState']
+            if state == "11":
+                return
+            os.sleep(0.1)
+            timeout -= 0.1
+        raise Exception("Timeout while waiting for PTKINITDONE")
+
     def get_status(self):
         res = self.request("STATUS")
         lines = res.splitlines()
index d309ebbca56d95b5b7e03585dd8f8575c392ab6a..11daaaa67ef5b27a2a3f16ed1d878a643685f769 100644 (file)
@@ -353,6 +353,7 @@ def test_pmksa_cache_expiration(dev, apdev):
     pmksa2 = dev[0].get_pmksa(bssid)
     if pmksa['pmkid'] == pmksa2['pmkid']:
         raise Exception("PMKID did not change")
+    hapd.wait_ptkinitdone(dev[0].own_addr())
     hwsim_utils.test_connectivity(dev[0], hapd)
 
 def test_pmksa_cache_expiration_disconnect(dev, apdev):