aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2019-12-10 23:47:17 +0100
committerPeter Wu <peter@lekensteyn.nl>2019-12-17 13:59:17 +0000
commitf73018eb0cdb3c32a8b695325946cc24c2006640 (patch)
treee9639be6d87a243dfcf76eef19cb6067df21f42c /test
parentcc451ab6aa29b426cdfbb24ab06dbc183fde6f46 (diff)
test: add suite_extcaps.
All the shipped extcaps will be tested against: --help --extcap-interfaces --extcap-interface <IFACE> --extcap-dtls --extcap-interface <IFACE> --extcap-config Bug: 16268 Change-Id: I7949103940c95c9c23fc5dd3743c15995d3a152d Reviewed-on: https://code.wireshark.org/review/35409 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures_ws.py7
-rw-r--r--test/subprocesstest.py12
-rw-r--r--test/suite_extcaps.py88
3 files changed, 101 insertions, 6 deletions
diff --git a/test/fixtures_ws.py b/test/fixtures_ws.py
index 161da3f3ce..79eb0c092a 100644
--- a/test/fixtures_ws.py
+++ b/test/fixtures_ws.py
@@ -146,6 +146,13 @@ def wireshark_command(cmd_wireshark):
@fixtures.fixture(scope='session')
+def cmd_extcap(program):
+ def extcap_name(name):
+ return program(os.path.join('extcap', name))
+ return extcap_name
+
+
+@fixtures.fixture(scope='session')
def features(cmd_tshark, make_env):
'''Returns an object describing available features in tshark.'''
try:
diff --git a/test/subprocesstest.py b/test/subprocesstest.py
index fafd773144..a2ad5adab1 100644
--- a/test/subprocesstest.py
+++ b/test/subprocesstest.py
@@ -248,7 +248,7 @@ class SubprocessTestCase(unittest.TestCase):
return False
return True
- def startProcess(self, proc_args, stdin=None, env=None, shell=False):
+ def startProcess(self, proc_args, stdin=None, env=None, shell=False, cwd=None):
'''Start a process in the background. Returns a subprocess.Popen object.
You typically wait for it using waitProcess() or assertWaitProcess().'''
@@ -260,7 +260,7 @@ class SubprocessTestCase(unittest.TestCase):
# fixture (via a test method parameter or class decorator).
assert not (env is None and hasattr(self, '_fixture_request')), \
"Decorate class with @fixtures.mark_usefixtures('test_env')"
- proc = LoggingPopen(proc_args, stdin=stdin, env=env, shell=shell, log_fd=self.log_fd)
+ proc = LoggingPopen(proc_args, stdin=stdin, env=env, shell=shell, log_fd=self.log_fd, cwd=cwd)
self.processes.append(proc)
return proc
@@ -277,14 +277,14 @@ class SubprocessTestCase(unittest.TestCase):
process.wait_and_log()
self.assertEqual(process.returncode, expected_return)
- def runProcess(self, args, env=None, shell=False):
+ def runProcess(self, args, env=None, shell=False, cwd=None):
'''Start a process and wait for it to finish.'''
- process = self.startProcess(args, env=env, shell=shell)
+ process = self.startProcess(args, env=env, shell=shell, cwd=cwd)
process.wait_and_log()
return process
- def assertRun(self, args, env=None, shell=False, expected_return=0):
+ def assertRun(self, args, env=None, shell=False, expected_return=0, cwd=None):
'''Start a process and wait for it to finish. Check its return code.'''
- process = self.runProcess(args, env=env, shell=shell)
+ process = self.runProcess(args, env=env, shell=shell, cwd=cwd)
self.assertEqual(process.returncode, expected_return)
return process
diff --git a/test/suite_extcaps.py b/test/suite_extcaps.py
new file mode 100644
index 0000000000..64b0e833c5
--- /dev/null
+++ b/test/suite_extcaps.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+# Wireshark tests
+# By Gerald Combs <gerald@wireshark.org>
+#
+# Copyright (c) 2019 Dario Lombardo <lomato@gmail.com>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+'''extcap tests'''
+
+import subprocesstest
+import fixtures
+import re
+import os
+import sys
+
+
+@fixtures.fixture
+def check_extcap_execution(cmd_extcap, program_path, request):
+ def check_extcap_interface_execution(extcap_name, interface):
+ ''' Check if an extcap runs flawlessly for interface configuration. '''
+ self = request.instance
+ self.assertRun([cmd_extcap(extcap_name), '--extcap-interface',
+ interface, '--extcap-dlts'], cwd=program_path)
+ self.assertRun([cmd_extcap(extcap_name), '--extcap-interface',
+ interface, '--extcap-config'], cwd=program_path)
+
+ def extcap_get_interfaces(extcap_output):
+ ''' Extract the interface name from extcap. '''
+ parser = re.compile("{value=(.*?)}")
+ interfaces = []
+ for line in extcap_output.splitlines():
+ if line.startswith('interface '):
+ interfaces.append(parser.findall(line)[0])
+ return interfaces
+
+ def check_extcap_execution_real(extcap_name, always_present=True):
+ '''
+ Check if an extcap runs flawlessly.
+ always_present: at least one interface is always offered by the extcap.
+ '''
+ self = request.instance
+ self.assertRun([cmd_extcap(extcap_name), '--help'], cwd=program_path)
+ extcap_proc = self.assertRun(
+ [cmd_extcap(extcap_name), '--extcap-interfaces'], cwd=program_path)
+ interfaces = extcap_get_interfaces(extcap_proc.stdout_str)
+ if always_present:
+ self.assertGreaterEqual(len(interfaces), 1)
+ for interface in interfaces:
+ check_extcap_interface_execution(extcap_name, interface)
+
+ return check_extcap_execution_real
+
+
+@fixtures.mark_usefixtures('base_env')
+@fixtures.uses_fixtures
+class case_extcaps(subprocesstest.SubprocessTestCase):
+ def test_androiddump(self, check_extcap_execution):
+ ''' extcap interface tests for androiddump '''
+ check_extcap_execution("androiddump", always_present=False)
+
+ def test_ciscodump(self, check_extcap_execution):
+ ''' extcap interface tests for ciscodump '''
+ check_extcap_execution("ciscodump")
+
+ def test_dpauxmon(self, check_extcap_execution):
+ ''' extcap interface tests for dpauxmon '''
+ if sys.platform == 'win32':
+ fixtures.skip('dpauxmon not available on Windows')
+ check_extcap_execution("dpauxmon")
+
+ def test_randpktdump(self, check_extcap_execution):
+ ''' extcap interface tests for randpktdump '''
+ check_extcap_execution("randpktdump")
+
+ def test_sdjournal(self, check_extcap_execution):
+ ''' extcap interface tests for sdjournal '''
+ if sys.platform == 'win32':
+ fixtures.skip('sdjournal not available on Windows')
+ check_extcap_execution("sdjournal")
+
+ def test_sshdump(self, check_extcap_execution):
+ ''' extcap interface tests for sshdump '''
+ check_extcap_execution("sshdump")
+
+ def test_udpdump(self, check_extcap_execution):
+ ''' extcap interface tests for udpdump '''
+ check_extcap_execution("udpdump")