Browse Source

tests: Scan and only_new=1 multiple times

Signed-off-by: Jouni Malinen <j@w1.fi>
Jouni Malinen 8 years ago
parent
commit
79124c7ba1
2 changed files with 38 additions and 0 deletions
  1. 34 0
      tests/hwsim/test_scan.py
  2. 4 0
      tests/hwsim/wpasupplicant.py

+ 34 - 0
tests/hwsim/test_scan.py

@@ -1228,3 +1228,37 @@ def test_scan_chan_switch(dev, apdev):
     dev[0].dump_monitor()
     run_scan(dev[0], bssid, 2412)
     dev[0].dump_monitor()
+
+def test_scan_new_only(dev, apdev):
+    """Scan and only_new=1 multiple times"""
+    try:
+        _test_scan_new_only(dev, apdev)
+    finally:
+        dev[0].set("ignore_old_scan_res", "0")
+def _test_scan_new_only(dev, apdev):
+    dev[0].flush_scan_cache()
+    hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
+    dev[0].set("ignore_old_scan_res", "1")
+    # Get the BSS added to cfg80211 BSS list
+    bssid = hapd.own_addr()
+    dev[0].scan_for_bss(bssid, freq=2412)
+    bss = dev[0].get_bss(bssid)
+    idx1 = bss['update_idx']
+    dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
+    dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
+    bss = dev[0].get_bss(bssid)
+    idx2 = bss['update_idx']
+    if int(idx2) <= int(idx1):
+        raise Exception("Scan result update_idx did not increase")
+    # Disable AP to ensure there are no new scan results after this.
+    hapd.disable()
+
+    # Try to scan multiple times to verify that old scan results do not get
+    # accepted as new.
+    for i in range(10):
+        dev[0].scan(freq=2412)
+        bss = dev[0].get_bss(bssid)
+        if bss:
+            idx = bss['update_idx']
+            if int(idx) > int(idx2):
+                raise Exception("Unexpected update_idx increase")

+ 4 - 0
tests/hwsim/wpasupplicant.py

@@ -250,6 +250,10 @@ class WpaSupplicant:
         if not self.ping():
             logger.info("No PING response from " + self.ifname + " after reset")
 
+    def set(self, field, value):
+        if not "OK" in self.request("SET " + field + " " + value):
+            raise Exception("Failed to set wpa_supplicant parameter " + field)
+
     def add_network(self):
         id = self.request("ADD_NETWORK")
         if "FAIL" in id: