test: add suite_extcaps.
authorDario Lombardo <lomato@gmail.com>
Tue, 10 Dec 2019 22:47:17 +0000 (23:47 +0100)
committerPeter Wu <peter@lekensteyn.nl>
Tue, 17 Dec 2019 13:59:17 +0000 (13:59 +0000)
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>
CMakeLists.txt
test/fixtures_ws.py
test/subprocesstest.py
test/suite_extcaps.py [new file with mode: 0644]

index c31eeb68e060a5fb5fc8d27feaf8c473b3c6a49f..3856a544f9d336789f05071b90c15eda1a27f3a0 100644 (file)
@@ -3291,6 +3291,7 @@ set(_test_group_list
        suite_dfilter.group_uint64
        suite_dissection
        suite_dissectors.group_asterix
+       suite_extcaps
        suite_fileformats
        suite_follow
        suite_io
index 161da3f3cea5230a275bbd2720b5cd7e5625afd3..79eb0c092ae26c8b5bc7deeb4d934707acd24816 100644 (file)
@@ -145,6 +145,13 @@ def wireshark_command(cmd_wireshark):
     return (cmd_wireshark, '-ogui.update.enabled:FALSE')
 
 
+@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.'''
index fafd77314469f5f358650933b4f2729afebd3df9..a2ad5adab169858c127d1de8d67642ded854f9e7 100644 (file)
@@ -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 (file)
index 0000000..64b0e83
--- /dev/null
@@ -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")