Parcourir la source

tests: bgscan test cases

Signed-off-by: Jouni Malinen <j@w1.fi>
Jouni Malinen il y a 11 ans
Parent
commit
31ec9faf47
2 fichiers modifiés avec 117 ajouts et 1 suppressions
  1. 115 0
      tests/hwsim/test_bgscan.py
  2. 2 1
      tests/hwsim/wpasupplicant.py

+ 115 - 0
tests/hwsim/test_bgscan.py

@@ -0,0 +1,115 @@
+# bgscan tests
+# Copyright (c) 2014, Jouni Malinen <j@w1.fi>
+#
+# This software may be distributed under the terms of the BSD license.
+# See README for more details.
+
+import time
+import logging
+logger = logging.getLogger()
+import os
+
+import hostapd
+
+def test_bgscan_simple(dev, apdev):
+    """bgscan_simple"""
+    hostapd.add_ap(apdev[0]['ifname'], { "ssid": "bgscan" })
+    hostapd.add_ap(apdev[1]['ifname'], { "ssid": "bgscan" })
+
+    dev[0].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
+                   bgscan="simple:1:-20:2")
+    dev[1].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
+                   bgscan="simple:1:-45:2")
+
+    ev = dev[0].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
+    if ev is None:
+        raise Exception("dev0 did not indicate signal change event")
+    if "above=0" not in ev:
+        raise Exception("Unexpected signal change event contents from dev0: " + ev)
+
+    ev = dev[1].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
+    if ev is None:
+        raise Exception("dev1 did not indicate signal change event")
+    if "above=1" not in ev:
+        raise Exception("Unexpected signal change event contents from dev1: " + ev)
+
+    ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
+    if ev is None:
+        raise Exception("dev0 did not start a scan")
+
+    ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
+    if ev is None:
+        raise Exception("dev1 did not start a scan")
+
+    ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
+    if ev is None:
+        raise Exception("dev0 did not complete a scan")
+    ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
+    if ev is None:
+        raise Exception("dev1 did not complete a scan")
+
+def test_bgscan_learn(dev, apdev):
+    """bgscan_learn"""
+    hostapd.add_ap(apdev[0]['ifname'], { "ssid": "bgscan" })
+    hostapd.add_ap(apdev[1]['ifname'], { "ssid": "bgscan" })
+
+    try:
+        os.remove("/tmp/test_bgscan_learn.bgscan")
+    except:
+        pass
+
+    try:
+        dev[0].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
+                       bgscan="learn:1:-20:2")
+        dev[1].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
+                       bgscan="learn:1:-45:2:/tmp/test_bgscan_learn.bgscan")
+
+        ev = dev[0].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
+        if ev is None:
+            raise Exception("dev0 did not indicate signal change event")
+        if "above=0" not in ev:
+            raise Exception("Unexpected signal change event contents from dev0: " + ev)
+
+        ev = dev[1].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
+        if ev is None:
+            raise Exception("dev1 did not indicate signal change event")
+        if "above=1" not in ev:
+            raise Exception("Unexpected signal change event contents from dev1: " + ev)
+
+        ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
+        if ev is None:
+            raise Exception("dev0 did not start a scan")
+
+        ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
+        if ev is None:
+            raise Exception("dev1 did not start a scan")
+
+        ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
+        if ev is None:
+            raise Exception("dev0 did not complete a scan")
+        ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
+        if ev is None:
+            raise Exception("dev1 did not complete a scan")
+
+        dev[0].request("DISCONNECT")
+        dev[1].request("DISCONNECT")
+        dev[0].request("REMOVE_NETWORK all")
+        dev[1].request("REMOVE_NETWORK all")
+
+        with open("/tmp/test_bgscan_learn.bgscan", "r") as f:
+            lines = f.read().splitlines()
+        if lines[0] != "wpa_supplicant-bgscan-learn":
+            raise Exception("Unexpected bgscan header line")
+        if 'BSS 02:00:00:00:03:00 2412' not in lines:
+            raise Exception("Missing BSS1")
+        if 'BSS 02:00:00:00:04:00 2412' not in lines:
+            raise Exception("Missing BSS2")
+        if 'NEIGHBOR 02:00:00:00:03:00 02:00:00:00:04:00' not in lines:
+            raise Exception("Missing BSS1->BSS2 neighbor entry")
+        if 'NEIGHBOR 02:00:00:00:04:00 02:00:00:00:03:00' not in lines:
+            raise Exception("Missing BSS2->BSS1 neighbor entry")
+    finally:
+        try:
+            os.remove("/tmp/test_bgscan_learn.bgscan")
+        except:
+            pass

+ 2 - 1
tests/hwsim/wpasupplicant.py

@@ -639,7 +639,8 @@ class WpaSupplicant:
                    "ca_cert", "client_cert", "private_key",
                    "ca_cert", "client_cert", "private_key",
                    "private_key_passwd", "ca_cert2", "client_cert2",
                    "private_key_passwd", "ca_cert2", "client_cert2",
                    "private_key2", "phase1", "phase2", "domain_suffix_match",
                    "private_key2", "phase1", "phase2", "domain_suffix_match",
-                   "altsubject_match", "subject_match", "pac_file", "dh_file" ]
+                   "altsubject_match", "subject_match", "pac_file", "dh_file",
+                   "bgscan" ]
         for field in quoted:
         for field in quoted:
             if field in kwargs and kwargs[field]:
             if field in kwargs and kwargs[field]:
                 self.set_network_quoted(id, field, kwargs[field])
                 self.set_network_quoted(id, field, kwargs[field])