diff --git a/tests/codec_be_on_mr_selection/__init__.py b/tests/codec_be_on_mr_selection/__init__.py index 34a307a7393396bbb6aa614f4d496e25c2757bc2..b7f4cd8efeffaff30d451bb9d0eb49945f68a47d 100644 --- a/tests/codec_be_on_mr_selection/__init__.py +++ b/tests/codec_be_on_mr_selection/__init__.py @@ -35,6 +35,7 @@ import filecmp from pathlib import Path import subprocess from .constants import OUTPUT_MODES_AND_OPTIONS_FOR_EXPERIMENT, DTX_ON, FER_5PERC +from ..testconfig import MD5_REF_DICT HERE = Path(__file__).parent # set environment variables in CI job @@ -98,8 +99,20 @@ def apply_error_pattern_on_bitstream( subprocess.run(cmd) -def files_equal(dut_file, ref_file): - return filecmp.cmp(dut_file, ref_file) +def is_be_to_ref(dut_file): + """ + Check bitexactness either by comparing files directly or by comparing MD5 sums + """ + if MD5_REF_DICT == dict(): + ref_file = REF_PATH.joinpath(dut_file.name) + is_be = filecmp.cmp(dut_file, ref_file) + else: + md5_ref = MD5_REF_DICT[dut_file.name] + cmd = f"powershell.exe (Get-FileHash {str(dut_file)} -Algorithm MD5).Hash" + md5_dut = subprocess.check_output(cmd, shell=True).decode().splitlines()[-1] + is_be = md5_ref == md5_dut + + return is_be def run_check( @@ -113,6 +126,7 @@ def run_check( decoder_frontend, is_ref_creation, input_file_num=None, + keep_files=True, ): sampling_rate = 48 output_mode, options = OUTPUT_MODES_AND_OPTIONS_FOR_EXPERIMENT[experiment] @@ -147,9 +161,8 @@ def run_check( add_option_list=options + [str(f) for f in metadata], ) - ref_bitstream = REF_PATH.joinpath(dut_bitstream.name) - if not is_ref_creation and not files_equal(dut_bitstream, ref_bitstream): - pytest.fail("Bitstream file differs from reference") + if not is_be_to_ref(dut_bitstream): + pytest.fail(f"Bitstream file differs from reference") dut_bitstream_to_decoder = dut_bitstream if error_pattern is not None: @@ -168,12 +181,15 @@ def run_check( # this should not be a problem as both the reference and the tdut output was generated by the codec, so # diverging headers should also indicate a problem - still, keep in mind if something bogus happens if not is_ref_creation: - ref_output = REF_PATH.joinpath(dut_output.name) - if not files_equal(dut_output, ref_output): + if not is_be_to_ref(dut_output): pytest.fail("Decoder output differs from reference") + elif not keep_files: + os.remove(dut_output) + os.remove(dut_bitstream) for md in metadata: md_suffix = "".join(md.suffixes) dut_md = DUT_PATH.joinpath(dut_output.with_suffix(md_suffix).name) - ref_md = REF_PATH.joinpath(dut_output.with_suffix(md_suffix).name) - if not files_equal(dut_md, ref_md): + if not is_be_to_ref(dut_md): pytest.fail("Metadata file {md.name} differs from reference") + elif not keep_files: + os.remove(dut_md) diff --git a/tests/codec_be_on_mr_selection/test_experiments.py b/tests/codec_be_on_mr_selection/test_experiments.py index a0a4aa780a757cf887e6b80e72a8a48eed00899d..5b2f51689342117c2e543442a974bce6714ff6fc 100644 --- a/tests/codec_be_on_mr_selection/test_experiments.py +++ b/tests/codec_be_on_mr_selection/test_experiments.py @@ -52,6 +52,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref, + keep_files, ): run_check( experiment, @@ -63,6 +64,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref == 1, + keep_files=keep_files, ) @@ -79,6 +81,7 @@ def test_bs1534_no_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, + keep_files, ): category = "" run_check( @@ -92,6 +95,7 @@ def test_bs1534_no_masa( dut_decoder_frontend, update_ref == 1, input_file_num=input_file_num, + keep_files=keep_files, ) @@ -111,6 +115,7 @@ def test_bs1534_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, + keep_files, ): run_check( experiment, @@ -123,4 +128,5 @@ def test_bs1534_masa( dut_decoder_frontend, update_ref == 1, input_file_num=input_file_num, + keep_files=keep_files, ) diff --git a/tests/conftest.py b/tests/conftest.py index 12b62caccd9d49cd003b204cfe8ce7e307674a24..e4de453b0ea6698f9600076ded65a53a1a2b7d51 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -133,6 +133,12 @@ def pytest_addoption(parser): " Use --keep_files to prevent these deletions.", ) + parser.addoption( + "--selection_be_md5_file", + type=Path, + help="Path to file with md5 sums for the reference signals of the selection-BE test" + ) + @pytest.fixture(scope="session", autouse=True) def update_ref(request): @@ -513,3 +519,9 @@ def pytest_configure(config): ) if config.option.param_file: testconfig.PARAM_FILE = config.option.param_file + if config.option.selection_be_md5_file: + md5_file_path = config.option.selection_be_md5_file + if not platform.system() == "Windows": + raise NotImplementedError("MD5 comparison is currently hardcoded for windows") + with open(md5_file_path) as f: + testconfig.MD5_REF_DICT = {line.split()[0]: line.split()[1] for line in f.readlines()} diff --git a/tests/testconfig.py b/tests/testconfig.py index 12d170ba8db49171e16add1f827a590ffcb09bd3..1dbfbb840343801460f1548b4e8b662d9ce96e6e 100644 --- a/tests/testconfig.py +++ b/tests/testconfig.py @@ -35,3 +35,5 @@ To configure test modules. """ PARAM_FILE = "scripts/config/self_test.prm" + +MD5_REF_DICT = dict() \ No newline at end of file