aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite_clopts.py
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-15 18:44:59 +0100
committerPeter Wu <peter@lekensteyn.nl>2018-11-16 13:55:28 +0000
commit3ab521118a0d068e0d5c795a5a57b13cd7790a75 (patch)
tree72900c817752260ab91945cc85302b78f8eaffe6 /test/suite_clopts.py
parentcb9be3850da46ca1f706a00b16cdb65a95ce66a0 (diff)
test: convert capture tests to use fixtures, fix tests without dumpcap
Add a new --capture-interface option to pytest, similar to test.py. It will grab some Ethernet interface on Windows. An empty value overrides this and disables capture tests. Remove the test.py --enable-capture option since that is implied by the --capture-interface option. Port the `test.py --program-path` option to pytest and additionally make the pytest look in the current working directory if neither WS_BIN_PATH nor --program-path are specified. Drop config.setProgramPath, this allows tests to be run even if not all binaries are available. With all capture tests converted to fixtures, it is now possible to run tests when Wireshark is not built with libpcap as tests that depend on cmd_dumpcap (or capture_interface) will be skipped. Bug: 14949 Change-Id: Ie802c07904936de4cd30a4c68b6a5139e6680fbd Reviewed-on: https://code.wireshark.org/review/30656 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test/suite_clopts.py')
-rw-r--r--test/suite_clopts.py40
1 files changed, 13 insertions, 27 deletions
diff --git a/test/suite_clopts.py b/test/suite_clopts.py
index 9be3e13079..722769b08d 100644
--- a/test/suite_clopts.py
+++ b/test/suite_clopts.py
@@ -9,10 +9,8 @@
#
'''Command line option tests'''
-import config
import subprocess
import subprocesstest
-import unittest
import fixtures
#glossaries = ('fields', 'protocols', 'values', 'decodes', 'defaultprefs', 'currentprefs')
@@ -44,36 +42,31 @@ class case_dumpcap_options(subprocesstest.SubprocessTestCase):
self.assertIn(process.returncode, valid_returns)
+@fixtures.mark_usefixtures('base_env')
@fixtures.uses_fixtures
class case_dumpcap_capture_clopts(subprocesstest.SubprocessTestCase):
- def test_dumpcap_invalid_capfilter(self, cmd_dumpcap, base_env):
+ def test_dumpcap_invalid_capfilter(self, cmd_dumpcap, capture_interface):
'''Invalid capture filter'''
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
invalid_filter = '__invalid_protocol'
# $DUMPCAP -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
testout_file = self.filename_from_id(testout_pcap)
- self.runProcess((cmd_dumpcap, '-f', invalid_filter, '-w', testout_file), env=base_env)
+ self.runProcess((cmd_dumpcap, '-f', invalid_filter, '-w', testout_file))
self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
- def test_dumpcap_invalid_interface_name(self, cmd_dumpcap, base_env):
+ def test_dumpcap_invalid_interface_name(self, cmd_dumpcap, capture_interface):
'''Invalid capture interface name'''
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
invalid_interface = '__invalid_interface'
# $DUMPCAP -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
testout_file = self.filename_from_id(testout_pcap)
- self.runProcess((cmd_dumpcap, '-i', invalid_interface, '-w', testout_file), env=base_env)
+ self.runProcess((cmd_dumpcap, '-i', invalid_interface, '-w', testout_file))
self.assertTrue(self.grepOutput('The capture session could not be initiated'))
- def test_dumpcap_invalid_interface_index(self, cmd_dumpcap, base_env):
+ def test_dumpcap_invalid_interface_index(self, cmd_dumpcap, capture_interface):
'''Invalid capture interface index'''
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
invalid_index = '0'
# $DUMPCAP -i 0 -w './testout.pcap' > ./testout.txt 2>&1
testout_file = self.filename_from_id(testout_pcap)
- self.runProcess((cmd_dumpcap, '-i', invalid_index, '-w', testout_file), env=base_env)
+ self.runProcess((cmd_dumpcap, '-i', invalid_index, '-w', testout_file))
self.assertTrue(self.grepOutput('There is no interface with that adapter index'))
@@ -106,8 +99,9 @@ class case_tshark_options(subprocesstest.SubprocessTestCase):
self.assertRun((cmd_tshark, '-' + char_arg))
# XXX Should we generate individual test functions instead of looping?
- def test_tshark_interface_chars(self, cmd_tshark):
+ def test_tshark_interface_chars(self, cmd_tshark, cmd_dumpcap):
'''Valid tshark parameters requiring capture permissions'''
+ # These options require dumpcap
valid_returns = [self.exit_ok, self.exit_error]
for char_arg in 'DL':
process = self.runProcess((cmd_tshark, '-' + char_arg))
@@ -117,30 +111,24 @@ class case_tshark_options(subprocesstest.SubprocessTestCase):
@fixtures.mark_usefixtures('test_env')
@fixtures.uses_fixtures
class case_tshark_capture_clopts(subprocesstest.SubprocessTestCase):
- def test_tshark_invalid_capfilter(self, cmd_tshark):
+ def test_tshark_invalid_capfilter(self, cmd_tshark, capture_interface):
'''Invalid capture filter'''
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
invalid_filter = '__invalid_protocol'
# $TSHARK -f 'jkghg' -w './testout.pcap' > ./testout.txt 2>&1
testout_file = self.filename_from_id(testout_pcap)
self.runProcess((cmd_tshark, '-f', invalid_filter, '-w', testout_file ))
self.assertTrue(self.grepOutput('Invalid capture filter "' + invalid_filter + '" for interface'))
- def test_tshark_invalid_interface_name(self, cmd_tshark):
+ def test_tshark_invalid_interface_name(self, cmd_tshark, capture_interface):
'''Invalid capture interface name'''
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
invalid_interface = '__invalid_interface'
# $TSHARK -i invalid_interface -w './testout.pcap' > ./testout.txt 2>&1
testout_file = self.filename_from_id(testout_pcap)
self.runProcess((cmd_tshark, '-i', invalid_interface, '-w', testout_file))
self.assertTrue(self.grepOutput('The capture session could not be initiated'))
- def test_tshark_invalid_interface_index(self, cmd_tshark):
+ def test_tshark_invalid_interface_index(self, cmd_tshark, capture_interface):
'''Invalid capture interface index'''
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
invalid_index = '0'
# $TSHARK -i 0 -w './testout.pcap' > ./testout.txt 2>&1
testout_file = self.filename_from_id(testout_pcap)
@@ -151,9 +139,7 @@ class case_tshark_capture_clopts(subprocesstest.SubprocessTestCase):
@fixtures.mark_usefixtures('test_env')
@fixtures.uses_fixtures
class case_tshark_name_resolution_clopts(subprocesstest.SubprocessTestCase):
- def test_tshark_valid_name_resolution(self, cmd_tshark):
- if not config.canCapture():
- self.skipTest('Test requires capture privileges and an interface.')
+ def test_tshark_valid_name_resolution(self, cmd_tshark, capture_interface):
# $TSHARK -N mnNtdv -a duration:1 > ./testout.txt 2>&1
self.assertRun((cmd_tshark, '-N', 'mnNtdv', '-a', 'duration: 1'))