diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-03-22 15:46:33 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-03-25 07:15:36 +0000 |
commit | dbef80f5c723d63d174f645284dcd06cbddb3a48 (patch) | |
tree | 0415481755cae3419ede58559d655bf06be926e7 /tools | |
parent | 1ba4191c70784698a2fac085c508343d85c56486 (diff) |
dfilter-test.py: add OOT support and Python 3 compat
Support WS_BIN_PATH and SOURCE_DIR (modelled after test/config.sh) to
support out-of-tree builds (including cmake). Add Python 3 support and
mention this in the documentation.
Tested with Python 2.7.9, 3.2.6, 3.4.3:
WS_BIN_PATH=/tmp/wsbuild/run SOURCE_DIR=/tmp/wireshark \
tools/dfilter-test.py testBytesIPv6
(2.7.9 and 3.4.3 were also tested fully, but some cases seem to fail
even before this patch. 2.5.6 and 2.6.6 do not work because the unittest
module is outdated.)
Change-Id: I13074579f6f74206edb5cd7be8e7a8406de49c56
Reviewed-on: https://code.wireshark.org/review/7793
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/dftestlib/dftest.py | 10 | ||||
-rwxr-xr-x | tools/dftestlib/util.py | 12 |
2 files changed, 12 insertions, 10 deletions
diff --git a/tools/dftestlib/dftest.py b/tools/dftestlib/dftest.py index d6d32c497c..31086c3412 100755 --- a/tools/dftestlib/dftest.py +++ b/tools/dftestlib/dftest.py @@ -23,7 +23,7 @@ from dftestlib import util # The binaries to use. We assume we are running # from the top of the wireshark distro -TSHARK = os.path.join(".", "tshark") +TSHARK = os.path.join(os.getenv("WS_BIN_PATH", "."), "tshark") class DFTest(unittest.TestCase): """Base class for all tests in this dfilter-test collection.""" @@ -40,8 +40,8 @@ class DFTest(unittest.TestCase): # names the trace file to use for the tests. It *should* # reside in dftestfiles assert not os.path.isabs(cls.trace_file) - cls.trace_file = os.path.join(".", "tools", "dftestfiles", - cls.trace_file) + cls.trace_file = os.path.join(os.getenv("SOURCE_DIR", "."), "tools", + "dftestfiles", cls.trace_file) @classmethod def tearDownClass(cls): @@ -69,12 +69,12 @@ class DFTest(unittest.TestCase): def assertDFilterCount(self, dfilter, expected_count): """Run a display filter and expect a certain number of packets.""" - + (status, output) = self.runDFilter(dfilter) # tshark must succeed self.assertEqual(status, util.SUCCESS, output) - + # Split the output (one big string) into lines, removing # empty lines (extra newline at end of output) lines = [L for L in output.split("\n") if L != ""] diff --git a/tools/dftestlib/util.py b/tools/dftestlib/util.py index cb301eb0f6..6a0ae94581 100755 --- a/tools/dftestlib/util.py +++ b/tools/dftestlib/util.py @@ -15,7 +15,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import subprocess +import subprocess, sys SUCCESS = 0 def exec_cmdv(cmdv, cwd=None, stdin=None): @@ -31,14 +31,16 @@ def exec_cmdv(cmdv, cwd=None, stdin=None): retval = SUCCESS # If file isn't executable - except OSError, e: - output = str(e) - retval = None + except OSError as e: + return (None, str(e)) # If process returns non-zero - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError as e: output = e.output retval = e.returncode + if sys.version_info[0] >= 3: + output = output.decode('utf-8') + return (retval, output) |