From f73018eb0cdb3c32a8b695325946cc24c2006640 Mon Sep 17 00:00:00 2001 From: Dario Lombardo Date: Tue, 10 Dec 2019 23:47:17 +0100 Subject: test: add suite_extcaps. All the shipped extcaps will be tested against: --help --extcap-interfaces --extcap-interface --extcap-dtls --extcap-interface --extcap-config Bug: 16268 Change-Id: I7949103940c95c9c23fc5dd3743c15995d3a152d Reviewed-on: https://code.wireshark.org/review/35409 Petri-Dish: Dario Lombardo Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- test/fixtures_ws.py | 7 ++++ test/subprocesstest.py | 12 +++---- test/suite_extcaps.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 test/suite_extcaps.py (limited to 'test') 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 @@ -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.''' 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 +# +# Copyright (c) 2019 Dario Lombardo +# +# 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") -- cgit v1.2.3