Tests: Remove unittest dependency (asterix)
This commit is contained in:
parent
aa1b94055d
commit
742740b2bb
|
@ -4,13 +4,10 @@
|
|||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# Standard modules
|
||||
import inspect
|
||||
import json
|
||||
|
||||
# Wireshark modules
|
||||
import fixtures
|
||||
import subprocesstest
|
||||
import subprocess
|
||||
import pytest
|
||||
|
||||
|
||||
class _dissection_validator_real:
|
||||
|
@ -26,13 +23,14 @@ class _dissection_validator_real:
|
|||
unacceptable overhead during execution of the unittests.
|
||||
'''
|
||||
|
||||
def __init__(self, protocol, request, cmd_tshark, cmd_text2pcap, result_file):
|
||||
def __init__(self, protocol, request, cmd_tshark, cmd_text2pcap, result_file, env):
|
||||
self.dissection_list = []
|
||||
self.protocol = protocol
|
||||
self.cmd_tshark = cmd_tshark
|
||||
self.cmd_text2pcap = cmd_text2pcap
|
||||
self.test_case = request.instance
|
||||
self.result_file = result_file
|
||||
self.env = env
|
||||
|
||||
def add_dissection(self, byte_list, expected_result, line_no=None):
|
||||
'''Adds a byte bundle and an expected result to the set of byte
|
||||
|
@ -71,41 +69,39 @@ class _dissection_validator_real:
|
|||
f.write("0 {}\n".format(hex_string))
|
||||
|
||||
# generate our pcap file by feeding the messages to text2pcap
|
||||
self.test_case.assertRun((
|
||||
subprocess.check_call((
|
||||
self.cmd_text2pcap,
|
||||
'-u', '1234,1234',
|
||||
text_file, pcap_file
|
||||
))
|
||||
), env=self.env)
|
||||
|
||||
# generate our dissection from our pcap file
|
||||
tshark_proc = self.test_case.assertRun((
|
||||
tshark_stdout = subprocess.check_output((
|
||||
self.cmd_tshark,
|
||||
'-r', pcap_file,
|
||||
'-T', 'json',
|
||||
'-d', 'udp.port==1234,{}'.format(self.protocol),
|
||||
'-J', self.protocol
|
||||
))
|
||||
), encoding='utf-8', env=self.env)
|
||||
|
||||
dissections = json.loads(tshark_proc.stdout_str)
|
||||
dissections = json.loads(tshark_stdout)
|
||||
for (line_no, hex_string, expected_result), dissection in zip(self.dissection_list, dissections):
|
||||
|
||||
# strip away everything except the protocol
|
||||
result = dissection['_source']['layers']
|
||||
self.test_case.assertIn(self.protocol, result)
|
||||
assert self.protocol in result
|
||||
result = result[self.protocol]
|
||||
|
||||
# verify that the dissection is as expected
|
||||
self.test_case.assertEqual(
|
||||
expected_result,
|
||||
result,
|
||||
"expected != result, while dissecting [{}] from line {}.".format(hex_string, line_no))
|
||||
assert expected_result == result, \
|
||||
"expected != result, while dissecting [{}] from line {}.".format(hex_string, line_no)
|
||||
|
||||
# cleanup for next test
|
||||
self.dissection_list = []
|
||||
|
||||
|
||||
@fixtures.fixture
|
||||
def dissection_validator(request, cmd_tshark, cmd_text2pcap, result_file):
|
||||
@pytest.fixture
|
||||
def dissection_validator(request, cmd_tshark, cmd_text2pcap, result_file, test_env):
|
||||
|
||||
def generate_validator(protocol):
|
||||
retval = _dissection_validator_real(
|
||||
|
@ -113,7 +109,8 @@ def dissection_validator(request, cmd_tshark, cmd_text2pcap, result_file):
|
|||
request,
|
||||
cmd_tshark,
|
||||
cmd_text2pcap,
|
||||
result_file)
|
||||
result_file,
|
||||
test_env)
|
||||
return retval
|
||||
|
||||
return generate_validator
|
||||
|
|
|
@ -6,18 +6,14 @@
|
|||
#
|
||||
'''ASTERIX dissector tests'''
|
||||
|
||||
# Standard modules
|
||||
import inspect
|
||||
import pytest
|
||||
|
||||
# Wireshark modules
|
||||
import fixtures
|
||||
import subprocesstest
|
||||
from suite_dissectors.dissectorstest import *
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_asterix(subprocesstest.SubprocessTestCase):
|
||||
class TestAsterix:
|
||||
|
||||
def test_for_asterix(self, dissection_validator):
|
||||
'''Verifies that the asterix dissector is installed and accessible'''
|
||||
|
@ -66,7 +62,7 @@ class _asterix_validator_real:
|
|||
self.validator.check_dissections()
|
||||
|
||||
|
||||
@fixtures.fixture
|
||||
@pytest.fixture
|
||||
def asterix_validator(dissection_validator):
|
||||
|
||||
def generate_asterix_validator(category):
|
||||
|
@ -101,7 +97,7 @@ class _asterix_re_validator_real(_asterix_validator_real):
|
|||
self.category), expected_result, line_no)
|
||||
|
||||
|
||||
@fixtures.fixture
|
||||
@pytest.fixture
|
||||
def asterix_re_validator(dissection_validator):
|
||||
|
||||
def generate_re_asterix_validator(category, re_byte_list):
|
||||
|
@ -174,9 +170,7 @@ def counter_local(vmap, counter, key, idx, value):
|
|||
return result
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_category_019(subprocesstest.SubprocessTestCase):
|
||||
class TestCategory019:
|
||||
'''
|
||||
Unittest case for ASTERIX Category 019
|
||||
|
||||
|
@ -208,8 +202,6 @@ class case_category_019(subprocesstest.SubprocessTestCase):
|
|||
FX - Field Extension Indicator -
|
||||
'''
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def test_for_fields(self, asterix_validator):
|
||||
'''verifies existence of all fields and their maximum value'''
|
||||
|
||||
|
@ -783,9 +775,7 @@ class case_category_019(subprocesstest.SubprocessTestCase):
|
|||
validator.check_dissections()
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_category_034(subprocesstest.SubprocessTestCase):
|
||||
class TestCategory034:
|
||||
'''
|
||||
Unittest case for ASTERIX Category 034
|
||||
|
||||
|
@ -816,8 +806,6 @@ class case_category_034(subprocesstest.SubprocessTestCase):
|
|||
FX N/A. Field Extension Indicator n.a.
|
||||
'''
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def test_for_fields(self, asterix_validator):
|
||||
'''verifies existence of all fields and their maximum value'''
|
||||
|
||||
|
@ -1373,9 +1361,7 @@ class case_category_034(subprocesstest.SubprocessTestCase):
|
|||
validator.check_dissections()
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_category_048(subprocesstest.SubprocessTestCase):
|
||||
class TestCategory048:
|
||||
'''
|
||||
Unittest case for ASTERIX Category 048
|
||||
|
||||
|
@ -1423,8 +1409,6 @@ class case_category_048(subprocesstest.SubprocessTestCase):
|
|||
FX n.a. Field Extension Indicator n.a.
|
||||
'''
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def test_for_fields(self, asterix_re_validator):
|
||||
'''verifies existence of all fields and their maximum value'''
|
||||
|
||||
|
@ -3091,9 +3075,7 @@ class case_category_048(subprocesstest.SubprocessTestCase):
|
|||
validator.check_dissections()
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_category_063(subprocesstest.SubprocessTestCase):
|
||||
class TestCategory063:
|
||||
'''
|
||||
Unittest case for ASTERIX Category 063
|
||||
|
||||
|
@ -3124,8 +3106,6 @@ class case_category_063(subprocesstest.SubprocessTestCase):
|
|||
FX - Field extension indicator -
|
||||
'''
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def test_for_fields(self, asterix_validator):
|
||||
'''verifies existence of all fields and their maximum value'''
|
||||
|
||||
|
@ -3530,9 +3510,7 @@ class case_category_063(subprocesstest.SubprocessTestCase):
|
|||
validator.check_dissections()
|
||||
|
||||
|
||||
@fixtures.mark_usefixtures('test_env')
|
||||
@fixtures.uses_fixtures
|
||||
class case_category_065(subprocesstest.SubprocessTestCase):
|
||||
class TestCategory065:
|
||||
'''
|
||||
Unittest case for ASTERIX Category 065
|
||||
|
||||
|
@ -3564,8 +3542,6 @@ class case_category_065(subprocesstest.SubprocessTestCase):
|
|||
FX - Field extension indicator -
|
||||
'''
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def test_for_fields(self, asterix_validator):
|
||||
'''verifies existence of all fields and their maximum value'''
|
||||
|
||||
|
|
Loading…
Reference in New Issue