Commit 8a6dfd5c authored by Jan Kiene's avatar Jan Kiene
Browse files

first version of jbm be test port to pytest

parent 39369f07
Loading
Loading
Loading
Loading
+35 −2
Original line number Diff line number Diff line
@@ -487,6 +487,7 @@ class DecoderFrontend:
        output_path: Path,
        quiet_mode: Optional[bool] = True,
        plc_file: Optional[Path] = None,
        netsim_profile: Optional[Path] = None,
        add_option_list: Optional[list] = None,
        run_dir: Optional[Path] = None,
    ) -> None:
@@ -525,11 +526,43 @@ class DecoderFrontend:
            try:
                if not os.path.exists(str(input_bitstream_path) + eid_output_suffix):
                    result = run(eid_command, check=True, cwd=run_dir)
            except Exception:
                pytest.fail("eid-xor operation failed!")
            except Exception as e:
                pytest.fail(f"eid-xor operation failed! - {e}")

            input_bitstream_path += eid_output_suffix

        if netsim_profile is not None:
            system = platform.system()

            # TODO: centralize this in a utils file
            if system == "Windows":
                netsim_path = "./scripts/tools/Win32/networkSimulator_g192.exe"
            elif system == "Linux":
                netsim_path = "./scripts/tools/Linux/networkSimulator_g192"
            elif system == "Darwin":
                netsim_path = "./scripts/tools/Darwin/networkSimulator_g192"
            else:
                raise ValueError(f'Wrong system "{system}"!')

            if not os.path.isfile(netsim_path):
                raise FileNotFoundError(f"network simulator binary {netsim_path} not found!\n")
            netsim_bitstream_path = input_bitstream_path.with_suffix(".netsimout")
            tracefile_path = input_bitstream_path.with_suffix(".netsimtrace")
            # TODO: need to check if the "1" works with every profile
            netsim_command = [netsim_path, netsim_profile, input_bitstream_path, netsim_bitstream_path, tracefile_path, "1"]
            print(netsim_command)
            try:
                run(netsim_command, check=True, cwd=run_dir)
            except Exception as e:
                pytest.fail(f"netsim operation failed! - {e}")

            input_bitstream_path = netsim_bitstream_path
            voip_opt = ["-voip"]
            if add_option_list is None:
                add_option_list = voip_opt
            elif "-voip" not in add_option_list:
                add_option_list.extend(voip_opt)

        if add_option_list is not None:
            command.extend(add_option_list)

+6 −0
Original line number Diff line number Diff line
import pathlib

HERE = pathlib.Path(__file__).parent.absolute()
SCRIPTS_DIR = HERE.parent.joinpath("scripts")
TESTV_DIR = SCRIPTS_DIR.joinpath("testv")

# regex patterns for parsing the output from cmp_pcm -> mainly for BASOP ci
MLD_PATTERN = r"MLD: ([\d\.]*)"
MAX_DIFF_PATTERN = r"MAXIMUM ABS DIFF: (\d*)"
+74 −0
Original line number Diff line number Diff line
import pytest
import pathlib
import sys
from tempfile import TemporaryDirectory

from .constants import TESTV_DIR, SCRIPTS_DIR

sys.path.append(SCRIPTS_DIR)
from pyaudio3dtools import audiofile, audioarray


TESTCASES = [
    ["stereo", 32000, "EXT"],
    ["stereo", 48000, "EXT"],
]
DLY_PROFILE = SCRIPTS_DIR.joinpath("dly_error_profiles/dly_error_profile_0.dat")


def get_options(in_format):
    options = list()
    if in_format == "stereo":
        options.append("-stereo")

    return options


@pytest.mark.parametrize("in_format,bitrate,out_format", TESTCASES)
def test_be_for_jbm_neutral_dly_profile(
    in_format, bitrate, out_format, dut_encoder_frontend, dut_decoder_frontend
):
    with TemporaryDirectory() as tmp_dir:
        tmp_dir = pathlib.Path(tmp_dir)

        # run encoder
        bitstream_file = tmp_dir.joinpath(f"{in_format}.192").absolute()
        sampling_rate_khz = 48
        inp_file = "stvST48c.wav"
        input_file = TESTV_DIR.joinpath(inp_file)
        options = get_options(in_format)
        dut_encoder_frontend.run(
            bitrate,
            sampling_rate_khz,
            input_file,
            bitstream_file,
            add_option_list=options,
            run_dir=tmp_dir,
        )

        # run decoder without network simulation
        output = tmp_dir.joinpath(f"{in_format}-{bitrate}-{out_format}.wav").absolute()
        dut_decoder_frontend.run(out_format, sampling_rate_khz, bitstream_file, output)

        # run decoder with network simulation
        output_jbm = output.with_suffix(".jbm-0.wav")
        dut_decoder_frontend.run(
            out_format,
            sampling_rate_khz,
            bitstream_file,
            output_jbm,
            netsim_profile=DLY_PROFILE,
        )

        # compare no-jbm and jbm output
        x, _ = audiofile.readfile(output)
        x_jbm, _ = audiofile.readfile(output_jbm)
        cmp_result = audioarray.compare(
            x,
            x_jbm,
            fs=sampling_rate_khz * 1000,
            per_frame=False,
            test_start_offset_ms=60,
        )
        if not cmp_result["bitexact"]:
            pytest.fail("Difference between no jbm and zero-delay jbm decoding!")