[PATCH 4/7] tests: improve tshark boolean output support
Benjamin Berg
benjamin at sipsolutions.net
Wed Jun 11 01:47:26 PDT 2025
From: Benjamin Berg <benjamin.berg at intel.com>
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 at intel.com>
---
tests/hwsim/test_ap_open.py | 15 +++++----------
tests/hwsim/test_ap_vlan.py | 13 ++++---------
tests/hwsim/utils.py | 14 ++++++++++++++
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/tests/hwsim/test_ap_open.py b/tests/hwsim/test_ap_open.py
index ceba146a03..8e90683b4f 100644
--- a/tests/hwsim/test_ap_open.py
+++ b/tests/hwsim/test_ap_open.py
@@ -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
diff --git a/tests/hwsim/test_ap_vlan.py b/tests/hwsim/test_ap_vlan.py
index f4001bbefa..029b978591 100644
--- a/tests/hwsim/test_ap_vlan.py
+++ b/tests/hwsim/test_ap_vlan.py
@@ -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")
diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py
index 62371b0d77..5c2af56352 100644
--- a/tests/hwsim/utils.py
+++ b/tests/hwsim/utils.py
@@ -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
--
2.49.0
More information about the Hostap
mailing list