From: Benjamin Berg Date: Wed, 11 Jun 2025 08:47:26 +0000 (+0200) Subject: tests: Improve tshark boolean output support X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5033955923ac00d56d597edf98c54a66851392cb;p=thirdparty%2Fhostap.git tests: Improve tshark boolean output support 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 --- diff --git a/tests/hwsim/test_ap_open.py b/tests/hwsim/test_ap_open.py index ceba146a0..8e90683b4 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 f4001bbef..029b97859 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 62371b0d7..5c2af5635 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