Commit eaeb6331 authored by Jan Kiene's avatar Jan Kiene
Browse files

add --selection_be_md5_file parameter

parent 649241d1
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -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(
@@ -147,9 +160,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 +180,10 @@ 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")
        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")
+11 −0
Original line number Diff line number Diff line
@@ -133,6 +133,13 @@ def pytest_addoption(parser):
        " Use --keep_files to prevent these deletions.",
    )

    parser.addoption(
        "--selection_be_md5_file",
        type=Path,
        default=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 +520,7 @@ 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
        with open(md5_file_path) as f:
            testconfig.MD5_REF_DICT = {line.split()[0]: line.split()[1] for line in f.readlines()}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -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