Loading tests/codec_be_on_mr_selection/__init__.py +25 −9 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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( Loading @@ -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] Loading Loading @@ -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: Loading @@ -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) tests/codec_be_on_mr_selection/test_experiments.py +6 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref, keep_files, ): run_check( experiment, Loading @@ -63,6 +64,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref == 1, keep_files=keep_files, ) Loading @@ -79,6 +81,7 @@ def test_bs1534_no_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, keep_files, ): category = "" run_check( Loading @@ -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, ) Loading @@ -111,6 +115,7 @@ def test_bs1534_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, keep_files, ): run_check( experiment, Loading @@ -123,4 +128,5 @@ def test_bs1534_masa( dut_decoder_frontend, update_ref == 1, input_file_num=input_file_num, keep_files=keep_files, ) tests/conftest.py +12 −0 Original line number Diff line number Diff line Loading @@ -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): Loading Loading @@ -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()} tests/testconfig.py +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
tests/codec_be_on_mr_selection/__init__.py +25 −9 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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( Loading @@ -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] Loading Loading @@ -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: Loading @@ -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)
tests/codec_be_on_mr_selection/test_experiments.py +6 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref, keep_files, ): run_check( experiment, Loading @@ -63,6 +64,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref == 1, keep_files=keep_files, ) Loading @@ -79,6 +81,7 @@ def test_bs1534_no_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, keep_files, ): category = "" run_check( Loading @@ -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, ) Loading @@ -111,6 +115,7 @@ def test_bs1534_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, keep_files, ): run_check( experiment, Loading @@ -123,4 +128,5 @@ def test_bs1534_masa( dut_decoder_frontend, update_ref == 1, input_file_num=input_file_num, keep_files=keep_files, )
tests/conftest.py +12 −0 Original line number Diff line number Diff line Loading @@ -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): Loading Loading @@ -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()}
tests/testconfig.py +2 −0 Original line number Diff line number Diff line Loading @@ -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