Commit 1f435707 authored by norvell's avatar norvell
Browse files

Change test_264444.py to recycle the logging and cmp_pcm tools

parent 78d0014c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ sys.path.append(os.path.join(os.path.dirname(THIS_PATH), "../scripts"))
import numpy as np
import pyaudio3dtools
import pyivastest
from .constants import ODG_PATTERN_PQEVALAUDIO
from constants import ODG_PATTERN_PQEVALAUDIO


def cmp_pcm(
@@ -167,6 +167,7 @@ if __name__ == "__main__":
    parser.add_argument("-s", "--sampling_rate", type=int, default=48000, dest="fs")
    parser.add_argument("--get_mld", action="store_true")
    parser.add_argument("--mld_lim", type=float, default=0, dest="mld_lim")
    parser.add_argument("--get_odg", action="store_true")
    args = parser.parse_args()

    result, msg = cmp_pcm(**vars(args))
+2 −8
Original line number Diff line number Diff line
@@ -451,9 +451,6 @@ def ref_encoder_path(request) -> str:
    if request.config.option.ref_encoder_path:
        return request.config.option.ref_encoder_path

    if request.config.option.update_ref == "0":
        return None

    # assume specifically named encoder when update_ref is selected, but no ref_encoder_path is specified
    here = Path(__file__).parent.resolve()
    system = platform.system()
@@ -474,7 +471,7 @@ def ref_encoder_path(request) -> str:


@pytest.fixture(scope="function")
def ref_encoder_frontend(ref_encoder_path, request) -> Union[None, EncoderFrontend]:
def ref_encoder_frontend(ref_encoder_path, request) -> EncoderFrontend:
    """
    Return a :class:`conftest.EncoderFrontend` instance as REF for the test session.
    """
@@ -700,9 +697,6 @@ def ref_decoder_path(request) -> str:
    if request.config.option.ref_decoder_path:
        return request.config.option.ref_decoder_path

    if request.config.option.update_ref == "0":
        return None

    # assume specifically named decoder when update_ref is selected, but no ref_decoder_path is specified
    here = Path(__file__).parent.resolve()
    system = platform.system()
@@ -723,7 +717,7 @@ def ref_decoder_path(request) -> str:


@pytest.fixture(scope="function")
def ref_decoder_frontend(ref_decoder_path, request) -> Union[None, DecoderFrontend]:
def ref_decoder_frontend(ref_decoder_path, request) -> DecoderFrontend:
    """
    Return a :class:`conftest.DecoderFrontend` instance as DUT for the test session.
    """
+96 −52
Original line number Diff line number Diff line
@@ -34,10 +34,13 @@ Execute tests specified via a parameter file.

import filecmp
import os
import subprocess

import re
import pytest

from tests.cmp_pcm import cmp_pcm
from tests.conftest import DecoderFrontend, EncoderFrontend, parse_properties


test_dict = {}
TEST_DIR = "evs_be_test"
scripts = [
@@ -47,6 +50,7 @@ scripts = [
    "Readme_EVS_enc.txt",
    "Readme_JBM_dec.txt",
]

for s in scripts:
    with open(os.path.join(TEST_DIR, s), "r", encoding="UTF-8") as fp:
        tag = ""
@@ -71,61 +75,101 @@ for s in scripts:
                diff_opts = ""

@pytest.mark.parametrize("test_tag", list(test_dict.keys()))
def test_evs_26444(runner_frontend, test_tag):
def test_evs_26444(
    record_property,
    props_to_record,
    dut_encoder_frontend: EncoderFrontend,
    dut_decoder_frontend: DecoderFrontend,
    ref_decoder_frontend: DecoderFrontend,
    test_tag,
    get_mld,
    get_mld_lim,
    abs_tol,
    get_ssnr,
    get_odg,    
):
    enc_opts, dec_opts, diff_opts = test_dict[test_tag]
    
    result = None
    if enc_opts:
        enc_opts = enc_opts.replace("./", TEST_DIR + "/")
        enc_opts = enc_opts.replace("-rf rf_config.cfg", "-rf " + TEST_DIR + "/rf_config.cfg") # Special handling of this arguments since the path is missing
        cmd = ["./IVAS_cod", "-q"] + enc_opts.split()[1:]
        print(" ".join(["Encoder command: "] + cmd))
        runner_frontend.run(cmd)
    if dec_opts:
        dec_opts = dec_opts.replace("./", TEST_DIR + "/")
        cmd = ["./IVAS_dec", "-q"] + dec_opts.split()[1:]
        print(" ".join(["Decoder command: "] + cmd))
        runner_frontend.run(cmd)

    result = runner_frontend.result
    diff_opts = diff_opts.replace("./", TEST_DIR + "/")

    if result != None and result.returncode:
        pytest.fail("Non-zero returncode for command: " + " ".join(cmd))
    if enc_opts:
        args = enc_opts.split()[1:]

    diff_opts = diff_opts.replace("./", TEST_DIR + "/")
    if ";" in diff_opts:
        cmd1, cmd2 = diff_opts.split(";")
        cmd1 = cmd1.split()
        cmd2 = cmd2.split()
        result1 = filecmp.cmp(cmd1[0], cmd1[1])
        result2 = filecmp.cmp(cmd2[2], cmd2[3])
    else:
        cmd1 = diff_opts.split()
        result1 = filecmp.cmp(cmd1[0], cmd1[1])
        result2 = True
    if not (result1 and result2):
        pytest.fail("Output differs")
        bitrate = args[-4]
        sampling_rate = args[-3]
        in_file = args[-2]
        out_file = args[-1]
        add_option_list = args[:-4]
        
        dut_encoder_frontend.run(
            bitrate,
            sampling_rate,
            in_file,
            out_file,
            add_option_list=add_option_list,
            run_dir=TEST_DIR,
        )

class Runner:
    def __init__(self) -> None:
        self.returncode = None
        self.result = None

    def run(self, cmd: str) -> None:
        result = subprocess.run(cmd, capture_output=True, check=False)
        self.result = result
        self.returncode = result.returncode
    if dec_opts:
        args = dec_opts.split()[1:]
        output_config = "" # Empty for EVS operation
        sampling_rate = args[-3]
        in_file = args[-2]
        out_file = args[-1]
        add_option_list = args[:-3]

        dut_decoder_frontend.run(
            output_config,
            sampling_rate,
            in_file,
            out_file,
            add_option_list=add_option_list,
            run_dir=TEST_DIR,
            )

    # Run comparison on encoder and decoder test cases
    equal = True
    for diff_opt in diff_opts.split(';'):
        pattern = r'(\$DIFF_BIN\s?-w\s?)?'
        diff_opt = re.sub(pattern, '', diff_opt).strip()
        [ref, test] = diff_opt.split()[:2]
        if enc_opts and (get_mld or get_ssnr or get_odg):
            for file in [ref, test]:
                output_config = "" # Empty for EVS operation
                in_file = file
                out_file = file + '.wav'
                add_option_list = []
                ref_decoder_frontend.run(
                    output_config,
                    sampling_rate,
                    in_file,
                    out_file,
                    add_option_list=add_option_list,
                )

            fs = int(sampling_rate) * 1000
            output_differs, reason = cmp_pcm(
                ref + ".wav",
                test + ".wav",
                output_config,
                fs,
                get_mld=get_mld,
                mld_lim=get_mld_lim,
                abs_tol=abs_tol,
                allow_differing_lengths=False,
                get_ssnr=get_ssnr,
                get_odg=get_odg,
            )

            props = parse_properties(reason, output_differs, props_to_record)
            for k, v in props.items():
                record_property(k, v)
            equal &= output_differs == False

    def _check_run(self):
        if self.returncode is not None:
            if self.returncode:
                pytest.fail( "Command terminated with a non-0 return code" )
        else:
            equal &= filecmp.cmp(ref, test)

@pytest.fixture(scope="function")
def runner_frontend() -> Runner:
    runner = Runner()
    yield runner
    if not equal:
        pytest.fail("Output differs")
    # Fixture teardown
    runner._check_run()