]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Improve tshark boolean output support
authorBenjamin Berg <benjamin.berg@intel.com>
Wed, 11 Jun 2025 08:47:26 +0000 (10:47 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 21 Jun 2025 08:39:49 +0000 (11:39 +0300)
Newer tshark versions are exporting some values as boolean with a
False/True string value. Add a helper that accepts an integer of any
base and also a "True"/"False" string.

Update various places to use the new helper.

Fixes: bf67d09e587a ("tests: Handle newer tshark version returning boolean values")
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
tests/hwsim/test_ap_open.py
tests/hwsim/test_ap_vlan.py
tests/hwsim/utils.py

index ceba146a03268e58e463c3410e242aaa5a119e50..8e90683b4f0c324b78eff8e1bff2fc6aa802a0c4 100644 (file)
@@ -539,7 +539,7 @@ def test_ap_open_ps_mc_buf(dev, apdev, params):
                    bg_scan_period="0")
     hapd.wait_sta()
 
-    buffered_mcast = 0
+    buffered_mcast = False
     try:
         dev[0].cmd_execute(['iw', 'dev', dev[0].ifname,
                             'set', 'power_save', 'on'])
@@ -555,21 +555,16 @@ def test_ap_open_ps_mc_buf(dev, apdev, params):
                              "wlan.fc.type_subtype == 0x0008",
                              ["wlan.tim.bmapctl.multicast"])
             for line in out.splitlines():
-                if line == "True":
-                    buffered_mcast = 1
-                elif line == "False":
-                    buffered_mcast = 0
-                else:
-                    buffered_mcast = int(line)
-                if buffered_mcast == 1:
+                buffered_mcast = parse_bool(line)
+                if buffered_mcast:
                     break
-            if buffered_mcast == 1:
+            if buffered_mcast:
                 break
     finally:
         dev[0].cmd_execute(['iw', 'dev', dev[0].ifname,
                             'set', 'power_save', 'off'])
 
-    if buffered_mcast != 1:
+    if not buffered_mcast:
         raise Exception("AP did not buffer multicast frames")
 
 @remote_compatible
index f4001bbefa95cc58246178f2cb8ca22df4f26f95..029b978591c42d0ba25b208d4fac14e571d93817 100644 (file)
@@ -626,8 +626,8 @@ def test_ap_vlan_without_station(dev, apdev, p):
                 logger.info("first frame not observed")
             state = 1
             for l in lines:
-                is_protected = int(l, 16)
-                if is_protected != 1:
+                is_protected = parse_bool(l)
+                if not is_protected:
                     state = 0
             if state != 1:
                 raise Exception("Broadcast packets were not encrypted when no station was connected")
@@ -644,13 +644,8 @@ def test_ap_vlan_without_station(dev, apdev, p):
                 raise Exception("second frame not observed")
             state = 1
             for l in lines:
-                if l == "True":
-                    is_protected = 1
-                elif l == "False":
-                    is_protected = 0
-                else:
-                    is_protected = int(l, 16)
-                if is_protected != 1:
+                is_protected = parse_bool(l)
+                if not is_protected:
                     state = 0
             if state != 1:
                 raise Exception("Broadcast packets were not encrypted when station was connected")
index 62371b0d77308db8f771ce8acc867b1a0764508d..5c2af56352c698eb295f5173a66ef9b6a8ee4538 100644 (file)
@@ -344,3 +344,17 @@ def disable_ipv6(fn):
             sysctl_write('net.ipv6.conf.all.disable_ipv6=0')
             sysctl_write('net.ipv6.conf.default.disable_ipv6=0')
     return cloned_wrapper(wrapper, fn)
+
+def parse_bool(s):
+    # Try parsing as integer of any base (expected 10 or 16),
+    # if that fails, try "True"/"False" literals
+    s = s.strip()
+    try:
+        return bool(int(s, 0))
+    except ValueError as e:
+        if s == 'True':
+            return True
+        elif s == 'False':
+            return False
+        else:
+            raise e