Commit 89cb0afc authored by Sumeyra Demir Kanik's avatar Sumeyra Demir Kanik
Browse files

Merge branch 'main' into 488-waveform-and-md-desynchronized-in-external-renderer

parents 58f923d6 92b9bbcd
Loading
Loading
Loading
Loading
Loading
+25 −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(
@@ -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)
+6 −0
Original line number Diff line number Diff line
@@ -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,
    )
+12 −0
Original line number Diff line number Diff line
@@ -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()}
+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