[PATCH 3/6] tests: reset country code after exception in wpas_config_file

Thomas Pedersen <[email protected]>
Newsgroups gmane.linux.drivers.hostap
Message-ID <[email protected]>
At some point during wpas_config_file we remove the
interface then check the config. If an exception occurs
there we'll hit an exception later when wpas.dump_monitor()
expects self.mon or self.ifname. wpas.request() and
wpas.wait_event() also expect an interface to be present.

Work around these and correctly reset the country code
when wpas_config_file fails by introducing a helper to
reset the regdomain globally.

TODO: this doesn't actually work as the
self.global_mon stops receiving events after
wpas.interface_remove("wlan5"), specifically
self.global_request("INTERFACE_REMOVE " + ifname), so
waiting for regdomain change will always fail, but at
least the regulatory domain does get reset.

Signed-off-by: Thomas Pedersen <[email protected]>
---
 tests/hwsim/test_wpas_config.py | 7 +++++--
 tests/hwsim/utils.py            | 9 +++++++++
 tests/hwsim/wpasupplicant.py    | 5 +++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/tests/hwsim/test_wpas_config.py b/tests/hwsim/test_wpas_config.py
index 6bf62d0b7a22..97b92700e2f0 100644
--- a/tests/hwsim/test_wpas_config.py
+++ b/tests/hwsim/test_wpas_config.py
@@ -285,8 +285,11 @@ def test_wpas_config_file(dev, apdev, params):
         except:
             pass
         wpas.dump_monitor()
-        wpas.request("SET country 00")
-        wpas.wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
+        try:
+            # FIXME: this doesn't work after wpas.interface_remove()!
+            clear_regdom_global(wpas)
+        except:
+            pass
 
 def test_wpas_config_file_wps(dev, apdev):
     """wpa_supplicant config file parsing/writing with WPS"""
diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py
index c259a766c0f0..066d1a629e7c 100644
--- a/tests/hwsim/utils.py
+++ b/tests/hwsim/utils.py
@@ -209,6 +209,15 @@ def clear_regdom_dev(dev, count=1):
     for i in range(count):
         dev[i].flush_scan_cache()
 
+def clear_regdom_global(dev):
+    dev.cmd_execute(['iw', 'reg', 'set', '00'])
+    for j in range(5):
+        ev = dev.wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
+        if ev is None:
+            raise Exception("No regdom change event")
+        if "type=WORLD" in ev:
+            break
+
 def radiotap_build():
     radiotap_payload = struct.pack('BB', 0x08, 0)
     radiotap_payload += struct.pack('BB', 0, 0)
diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py
index e273084acf5a..2d2266c3ca3c 100644
--- a/tests/hwsim/wpasupplicant.py
+++ b/tests/hwsim/wpasupplicant.py
@@ -912,13 +912,14 @@ class WpaSupplicant:
     def dump_monitor(self, mon=True, global_mon=True):
         count_iface = 0
         count_global = 0
-        while mon and self.monitor and self.mon.pending():
+        ifname = self.ifname or self.global_iface
+        while mon and self.monitor and self.mon and self.mon.pending():
             ev = self.mon.recv()
             logger.debug(self.dbg + ": " + ev)
             count_iface += 1
         while global_mon and self.monitor and self.global_mon and self.global_mon.pending():
             ev = self.global_mon.recv()
-            logger.debug(self.global_dbg + self.ifname + "(global): " + ev)
+            logger.debug(self.global_dbg + ifname + "(global): " + ev)
             count_global += 1
         return (count_iface, count_global)
 
-- 
2.20.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.