Test: Integrate ftsanity directly into our tests.
Move tools/ftsanity.py to test/suite_unittests.py. Change-Id: I8582b19c0544d032eb0566bc1e82be385e904c11 Reviewed-on: https://code.wireshark.org/review/27341 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
15cfc41e94
commit
230d7d4e90
|
@ -1,7 +1,9 @@
|
|||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
# Wireshark tests
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# By
|
||||
# Gerald Combs <gerald@wireshark.org>
|
||||
# Gilbert Ramirez <gram [AT] alumni.rice.edu>
|
||||
#
|
||||
# Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
|
||||
#
|
||||
|
@ -12,7 +14,6 @@
|
|||
import config
|
||||
import os.path
|
||||
import subprocesstest
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
class case_unittests(subprocesstest.SubprocessTestCase):
|
||||
|
@ -44,16 +45,51 @@ class case_unittests(subprocesstest.SubprocessTestCase):
|
|||
'--verbose'
|
||||
))
|
||||
|
||||
def test_unit_ftsanity(self):
|
||||
'''ftsanity.py'''
|
||||
fts_cmd = [
|
||||
os.path.join(config.tools_dir, 'ftsanity.py'),
|
||||
config.cmd_tshark
|
||||
]
|
||||
if sys.executable:
|
||||
fts_cmd.insert(0, sys.executable)
|
||||
self.assertRun(fts_cmd)
|
||||
|
||||
def test_unit_fieldcount(self):
|
||||
'''fieldcount'''
|
||||
self.assertRun((config.cmd_tshark, '-G', 'fieldcount'))
|
||||
|
||||
class Proto:
|
||||
"""Data for a protocol."""
|
||||
def __init__(self, line):
|
||||
data = line.split("\t")
|
||||
assert len(data) == 3, "expected 3 columns in %s" % data
|
||||
assert data[0] == "P"
|
||||
self.name = data[1]
|
||||
self.abbrev = data[2]
|
||||
|
||||
class Field:
|
||||
"""Data for a field."""
|
||||
def __init__(self, line):
|
||||
data = line.split("\t")
|
||||
assert len(data) == 8, "expected 8 columns in %s" % data
|
||||
assert data[0] == "F"
|
||||
self.name = data[1]
|
||||
self.abbrev = data[2]
|
||||
self.ftype = data[3]
|
||||
self.parent = data[4]
|
||||
self.base = data[5]
|
||||
self.bitmask = int(data[6],0)
|
||||
self.blurb = data[7]
|
||||
|
||||
class case_unit_ftsanity(subprocesstest.SubprocessTestCase):
|
||||
def test_unit_ftsanity(self):
|
||||
"""Looks for problems in field type definitions."""
|
||||
tshark_proc = self.assertRun((config.cmd_tshark, "-G", "fields"))
|
||||
|
||||
lines = tshark_proc.stdout_str.splitlines()
|
||||
# XXX We don't currently check protos.
|
||||
protos = [Proto(x) for x in lines if x[0] == "P"]
|
||||
fields = [Field(x) for x in lines if x[0] == "F"]
|
||||
|
||||
err_list = []
|
||||
for field in fields:
|
||||
if field.bitmask != 0:
|
||||
if field.ftype.find("FT_UINT") != 0 and \
|
||||
field.ftype.find("FT_INT") != 0 and \
|
||||
field.ftype != "FT_BOOLEAN" and \
|
||||
field.ftype != "FT_CHAR":
|
||||
err_list.append("%s has a bitmask 0x%x but is type %s" % \
|
||||
(field.abbrev, field.bitmask, field.ftype))
|
||||
|
||||
self.assertEqual(len(err_list), 0, 'Found field type errors: \n' + '\n'.join(err_list))
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
Check the sanity of field definitions in Wireshark.
|
||||
"""
|
||||
#
|
||||
# Gilbert Ramirez <gram [AT] alumni.rice.edu>
|
||||
#
|
||||
# Wireshark - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Copyright 1998 Gerald Combs
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import sys
|
||||
|
||||
from optparse import OptionParser
|
||||
import subprocess
|
||||
|
||||
|
||||
errors = 0
|
||||
|
||||
class Proto:
|
||||
"""Data for a protocol."""
|
||||
def __init__(self, line):
|
||||
data = line.split("\t")
|
||||
assert len(data) == 3, "expected 3 columns in %s" % data
|
||||
assert data[0] == "P"
|
||||
self.name = data[1]
|
||||
self.abbrev = data[2]
|
||||
|
||||
class Field:
|
||||
"""Data for a field."""
|
||||
def __init__(self, line):
|
||||
data = line.split("\t")
|
||||
assert len(data) == 8, "expected 8 columns in %s" % data
|
||||
assert data[0] == "F"
|
||||
self.name = data[1]
|
||||
self.abbrev = data[2]
|
||||
self.ftype = data[3]
|
||||
self.parent = data[4]
|
||||
self.base = data[5]
|
||||
self.bitmask = int(data[6],0)
|
||||
self.blurb = data[7]
|
||||
|
||||
|
||||
def gather_data(tshark):
|
||||
"""Calls tshark and gathers data."""
|
||||
proc = subprocess.Popen([tshark, "-G", "fields"],
|
||||
stdout=subprocess.PIPE)
|
||||
output, error = proc.communicate()
|
||||
|
||||
if proc.returncode != 0:
|
||||
sys.exit("Failed: tshark -G fields")
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
output = output.decode('utf-8')
|
||||
|
||||
lines = output.splitlines()
|
||||
protos = [Proto(x) for x in lines if x[0] == "P"]
|
||||
fields = [Field(x) for x in lines if x[0] == "F"]
|
||||
|
||||
return protos, fields
|
||||
|
||||
|
||||
def check_fields(fields):
|
||||
"""Looks for problems in field definitions."""
|
||||
global errors
|
||||
for field in fields:
|
||||
if field.bitmask != 0:
|
||||
if field.ftype.find("FT_UINT") != 0 and \
|
||||
field.ftype.find("FT_INT") != 0 and \
|
||||
field.ftype != "FT_BOOLEAN" and \
|
||||
field.ftype != "FT_CHAR":
|
||||
print("%s has a bitmask 0x%x but is type %s" % \
|
||||
(field.abbrev, field.bitmask, field.ftype))
|
||||
errors += 1
|
||||
|
||||
def run(tshark):
|
||||
"""Run the tests."""
|
||||
global errors
|
||||
protos, fields = gather_data(tshark)
|
||||
|
||||
check_fields(fields)
|
||||
|
||||
if errors > 0:
|
||||
sys.exit("%d errors found" % (errors,))
|
||||
else:
|
||||
print("Success.")
|
||||
|
||||
def main():
|
||||
"""Parse the command-line."""
|
||||
usage = "%prog tshark"
|
||||
parser = OptionParser(usage=usage)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
if len(args) != 1:
|
||||
parser.error("Need location of tshark.")
|
||||
|
||||
run(args[0])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue