tests: tshark: deal with "wlan_mgt" -> "wlan" rename

Recent versions of tshark/wireshark renamed these fields, deal
with that in the tshark wrapper code.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2017-10-24 17:11:31 +02:00 committed by Jouni Malinen
parent 13dc368aa9
commit 7d1ebdec18

View file

@ -12,10 +12,14 @@ import subprocess
import logging
logger = logging.getLogger()
class UnknownFieldsException(Exception):
def __init__(self, fields):
Exception.__init__(self, "unknown tshark fields %s" % ','.join(fields))
self.fields = fields
_tshark_filter_arg = '-Y'
def run_tshark(filename, filter, display=None, wait=True):
def _run_tshark(filename, filter, display=None, wait=True):
global _tshark_filter_arg
if wait:
@ -44,8 +48,21 @@ def run_tshark(filename, filter, display=None, wait=True):
out = output[0]
res = cmd.wait()
if res == 1:
if "Some fields aren't valid" in output[1]:
raise Exception("Unknown tshark field")
errmsg = "Some fields aren't valid"
if errmsg in output[1]:
errors = output[1].split('\n')
fields = []
collect = False
for f in errors:
if collect:
f = f.strip()
if f:
fields.append(f)
continue
if errmsg in f:
collect = True
continue
raise UnknownFieldsException(fields)
# remember this for efficiency
_tshark_filter_arg = '-R'
arg[3] = '-R'
@ -55,3 +72,19 @@ def run_tshark(filename, filter, display=None, wait=True):
cmd.wait()
return out
def run_tshark(filename, filter, display=None, wait=True):
if display is None: display = []
try:
return _run_tshark(filename, filter, display, wait)
except UnknownFieldsException, e:
all_wlan_mgt = True
for f in e.fields:
if not f.startswith('wlan_mgt.'):
all_wlan_mgt = False
break
if not all_wlan_mgt:
raise
return _run_tshark(filename, filter.replace('wlan_mgt', 'wlan'),
[x.replace('wlan_mgt', 'wlan') for x in display],
wait)