From 0075df74df28dbb4985d1285182815efc766a82b Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 27 Dec 2019 15:58:32 +0200 Subject: [PATCH] tests: Make pmksa_cache_expiration more robust 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 --- tests/hwsim/hostapd.py | 12 ++++++++++++ tests/hwsim/test_pmksa_cache.py | 1 + 2 files changed, 13 insertions(+) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 4430d8055..e555f75ed 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -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() diff --git a/tests/hwsim/test_pmksa_cache.py b/tests/hwsim/test_pmksa_cache.py index d309ebbca..11daaaa67 100644 --- a/tests/hwsim/test_pmksa_cache.py +++ b/tests/hwsim/test_pmksa_cache.py @@ -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):