Commit ec5c0f8d authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[format] isort --profile black ./tests && black ./tests

parent 366c01c8
Loading
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
#!/usr/bin/env python3

import argparse
import os
import sys
import argparse

THIS_PATH = os.path.join(os.getcwd(), __file__)
sys.path.append(os.path.join(os.path.dirname(THIS_PATH), "../scripts"))

import numpy as np
import pyaudio3dtools
import pyivastest
import numpy as np


def cmp_pcm(file1, file2, out_config, fs, get_mld=False, mld_lim=0) -> (int, str):
@@ -34,7 +34,9 @@ def cmp_pcm(file1, file2, out_config, fs, get_mld = False, mld_lim = 0) -> (int,
    s1, _ = pyaudio3dtools.audiofile.readfile(file1, nchannels, fs, outdtype=np.int16)
    s2, _ = pyaudio3dtools.audiofile.readfile(file2, nchannels, fs, outdtype=np.int16)

    nchannels = s1.shape[1] # In case of wav input, override the nchannels with the one from the wav header
    nchannels = s1.shape[
        1
    ]  # In case of wav input, override the nchannels with the one from the wav header

    if s1.shape != s2.shape:
        print(
@@ -43,7 +45,9 @@ def cmp_pcm(file1, file2, out_config, fs, get_mld = False, mld_lim = 0) -> (int,
        )
        return 1, "FAIL: File lengths differ"

    cmp_result = pyaudio3dtools.audioarray.compare(s1, s2, fs, per_frame=False, get_mld=get_mld)
    cmp_result = pyaudio3dtools.audioarray.compare(
        s1, s2, fs, per_frame=False, get_mld=get_mld
    )

    if cmp_result["bitexact"]:
        return 0, "SUCCESS: Files are bitexact"
@@ -55,7 +59,7 @@ def cmp_pcm(file1, file2, out_config, fs, get_mld = False, mld_lim = 0) -> (int,
        if get_mld:
            mld_msg = f"MLD: {cmp_result['MLD']}"
            print(mld_msg)
            if cmp_result['MLD'] <= mld_lim:
            if cmp_result["MLD"] <= mld_lim:
                return 0, f"MLD: {cmp_result['MLD']} <= {mld_lim}"
            else:
                return 1, f"MLD: {cmp_result['MLD']} > {mld_lim}"
+24 −13
Original line number Diff line number Diff line
@@ -33,14 +33,15 @@ __doc__ = """
    The outputs are compared with C generated references.
    """

import os
import errno
import pytest
from typing import Optional
import os
from filecmp import cmp
from typing import Optional

import pytest

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

# params
# output_mode_list = ['MONO', 'STEREO', '5_1', '7_1', '5_1_2', '5_1_4', '7_1_4', 'FOA', 'HOA2', 'HOA3', 'BINAURAL', 'BINAURAL_ROOM', 'EXT']
@@ -203,12 +204,17 @@ def test_masa_enc_dec(

            # Compare audio outputs
            pcmcmp_res, reason = cmp_pcm(
                dec_output_dut, dec_output_ref, output_mode, int(out_fs * 1000), get_mld=get_mld, mld_lim=get_mld_lim
                dec_output_dut,
                dec_output_ref,
                output_mode,
                int(out_fs * 1000),
                get_mld=get_mld,
                mld_lim=get_mld_lim,
            )
            if get_mld:
                mld = 0
                if "MLD" in reason:
                    mld = float(reason.split(':')[1].split()[0])
                    mld = float(reason.split(":")[1].split()[0])
                record_property("MLD", mld)

            if get_mld and get_mld_lim > 0:
@@ -230,12 +236,17 @@ def test_masa_enc_dec(
            filecmp_res = cmp(dec_output_ref, dec_output_dut)
            if filecmp_res == False:
                cmp_result, reason = cmp_pcm(
                    dec_output_dut, dec_output_ref, output_mode, int(out_fs * 1000), get_mld=get_mld, mld_lim=get_mld_lim
                    dec_output_dut,
                    dec_output_ref,
                    output_mode,
                    int(out_fs * 1000),
                    get_mld=get_mld,
                    mld_lim=get_mld_lim,
                )
                if get_mld:
                    mld = 0
                    if "MLD" in reason:
                        mld = float(reason.split(':')[1].split()[0])
                        mld = float(reason.split(":")[1].split()[0])
                    record_property("MLD", mld)
                # Report compare result
                if cmp_result != 0:
+26 −27
Original line number Diff line number Diff line
@@ -32,19 +32,20 @@ __doc__ = """
Execute tests specified via a parameter file.
"""

import os
from pathlib import Path
import errno
import platform
import filecmp
import os
import platform
from pathlib import Path
from subprocess import run

import pytest

from tests.cmp_pcm import cmp_pcm
from tests.conftest import DecoderFrontend, EncoderFrontend
from tests.cut_pcm import cut_samples
from tests.conftest import EncoderFrontend, DecoderFrontend
from tests.testconfig import PARAM_FILE


VALID_DEC_OUTPUT_CONF = [
    "MONO",
    "STEREO",
@@ -303,7 +304,6 @@ def test_param_file_tests(
        # in the parameter file, only "bit" is used as bitstream file name
        # -> re-use bitstream filename from encoder call


    # the output file is not the real output filename
    # -> construct output filename
    output_file = f"{testv_base}_{tag_str}.dec.wav"
@@ -327,14 +327,19 @@ def test_param_file_tests(
        ref_output_file = f"{reference_path}/param_file/dec/{output_file}"
        fs = int(sampling_rate) * 1000
        output_differs, reason = cmp_pcm(
            dut_output_file, ref_output_file, output_config, fs, get_mld=get_mld, mld_lim=get_mld_lim
            dut_output_file,
            ref_output_file,
            output_config,
            fs,
            get_mld=get_mld,
            mld_lim=get_mld_lim,
        )
        md_out_files = get_expected_md_files(ref_output_file, enc_split, output_config)

        if get_mld:
            mld = 0
            if "MLD" in reason:
                mld = float(reason.split(':')[1].split()[0])
                mld = float(reason.split(":")[1].split()[0])
            record_property("MLD", mld)

        metadata_differs = False
@@ -378,7 +383,6 @@ def test_param_file_tests(
                os.remove(f"{dut_base_path}/param_file/enc/{testv_base}_{tag_str}.192")



def encode(
    dut_encoder_frontend,
    ref_encoder_frontend,
@@ -491,6 +495,7 @@ def simulate(
        cmd_opts[3] = f"{dut_out_dir}/{netsim_tracefile}"
        run(netsim + cmd_opts, check=False)


def error_insertion(
    reference_path,
    dut_base_path,
@@ -511,21 +516,14 @@ def error_insertion(
    ref_out_file = f"{ref_out_dir}/{eid_xor_outfile}"

    if platform.system() == "Windows":
        eid_xor = [
            os.path.join(
                rootdir, "scripts", "tools", "Win32", "eid-xor.exe"
            )
        ]
        eid_xor = [os.path.join(rootdir, "scripts", "tools", "Win32", "eid-xor.exe")]
    elif platform.system() in ["Linux", "Darwin"]:
        eid_xor = [
            os.path.join(
                rootdir, "scripts", "tools", platform.system(), "eid-xor"
            )
            os.path.join(rootdir, "scripts", "tools", platform.system(), "eid-xor")
        ]
    else:
        assert False, f"eid-xor not available for {platform.system()}"


    if update_ref == 1 or update_ref == 2 and not os.path.exists(ref_out_file):
        # call eid-xor on REF encoder output
        cmd_opts = eid_opts_list
@@ -540,6 +538,7 @@ def error_insertion(
        cmd_opts[-1] = f"{dut_out_dir}/{eid_xor_outfile}"  # ref_out_file
        run(eid_xor + cmd_opts, check=False)


def decode(
    decoder_frontend,
    ref_decoder_frontend,
+31 −21
Original line number Diff line number Diff line
__copyright__ = \
    """
__copyright__ = """
    (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
@@ -29,27 +28,27 @@ __copyright__ = \
    the United Nations Convention on Contracts on the International Sales of Goods.
    """

__doc__ = \
    """
__doc__ = """
    Execute SBA decoder tests using different PLC patterns.
    """

import os
import errno
import os

import pytest

from tests.cmp_pcm import cmp_pcm
from tests.conftest import DecoderFrontend

# params
tag_list = ['stvFOA']
plc_patterns = ['PLperc12mblen5', 'PLperc40mblen50', 'PLperc42mblen2']
dtx_set = ['0', '1']
ivas_br_list = ['13200','16400','32000', '64000', '96000', '256000']
sampling_rate_list = ['48', '32', '16']
tag_list = ["stvFOA"]
plc_patterns = ["PLperc12mblen5", "PLperc40mblen50", "PLperc42mblen2"]
dtx_set = ["0", "1"]
ivas_br_list = ["13200", "16400", "32000", "64000", "96000", "256000"]
sampling_rate_list = ["48", "32", "16"]
gain_list = [0, 1]

AbsTol = '0'
AbsTol = "0"


def check_and_makedir(dir_path):
@@ -93,17 +92,22 @@ def test_sba_plc_system(
    get_mld_lim,
):
    SID = 0
    if dtx == '1' and ivas_br not in ['13200','16400','24400','32000', '64000']:
    if dtx == "1" and ivas_br not in ["13200", "16400", "24400", "32000", "64000"]:
        # skip high bitrates for DTX until DTX issue is resolved
        pytest.skip()
    if ivas_br == '13200' or ivas_br == '16400':
        if dtx == '1' and gain_flag == 0 and fs != '16' and plc_pattern == 'PLperc12mblen5':
    if ivas_br == "13200" or ivas_br == "16400":
        if (
            dtx == "1"
            and gain_flag == 0
            and fs != "16"
            and plc_pattern == "PLperc12mblen5"
        ):
            SID = 1
        else:
            pytest.skip()
    if gain_flag == 1 and ivas_br not in ['13200','16400','24400','32000']:
    if gain_flag == 1 and ivas_br not in ["13200", "16400", "24400", "32000"]:
        pytest.skip()
    tag = tag + fs + 'c'
    tag = tag + fs + "c"

    # dec
    sba_dec_plc(
@@ -148,12 +152,11 @@ def sba_dec_plc(
    get_mld=False,
    get_mld_lim=0,
):

    # ------------  run cmd  ------------

    tag_out = f"{tag}_ivasbr{ivas_br[:-3]}k_DTX{dtx}"
    if gain_flag != -1:
        tag_out += f'_Gain{gain_flag}'
        tag_out += f"_Gain{gain_flag}"
    plc_tag_out = f"{tag_out}_{plc_pattern}"

    dut_out_dir = f"{dut_base_path}/sba_bs/raw"
@@ -197,11 +200,18 @@ def sba_dec_plc(

        # --------------  compare cmd  --------------
        fs = int(sampling_rate) * 1000
        cmp_result, reason = cmp_pcm(dut_out_raw, ref_out_raw, output_config, fs, get_mld=get_mld, mld_lim=get_mld_lim)
        cmp_result, reason = cmp_pcm(
            dut_out_raw,
            ref_out_raw,
            output_config,
            fs,
            get_mld=get_mld,
            mld_lim=get_mld_lim,
        )
        if get_mld:
            mld = 0
            if "MLD" in reason:
                mld = float(reason.split(':')[1].split()[0])
                mld = float(reason.split(":")[1].split()[0])
            record_property("MLD", mld)

        # report compare result
+22 −10
Original line number Diff line number Diff line
@@ -33,14 +33,15 @@ __doc__ = """
    The outputs are compared with C generated references.
    """

import os
import errno
import os

import pytest
from cut_bs import cut_from_start

from tests.cmp_pcm import cmp_pcm
from tests.conftest import DecoderFrontend, EncoderFrontend
from tests.cut_pcm import cut_samples
from tests.conftest import EncoderFrontend, DecoderFrontend
from cut_bs import cut_from_start

# params

@@ -185,12 +186,16 @@ def test_sba_enc_system(
    get_mld,
    get_mld_lim,
):

    if dtx == "1" and ivas_br not in ["13200", "16400", "24400", "32000", "64000"]:
        # skip high bitrates for DTX until DTX issue is resolved
        pytest.skip()
    if SID == 1:
        if ivas_br not in ["13200", "16400", "64000"] or fs == "16" or gain_flag == 1 or dtx == "0":
        if (
            ivas_br not in ["13200", "16400", "64000"]
            or fs == "16"
            or gain_flag == 1
            or dtx == "0"
        ):
            pytest.skip()
    else:
        if ivas_br in ["13200", "16400"]:
@@ -249,7 +254,7 @@ def test_sba_enc_system(
        gain_flag,
        keep_files,
        get_mld=get_mld,
        get_mld_lim=get_mld_lim
        get_mld_lim=get_mld_lim,
    )


@@ -685,11 +690,18 @@ def sba_dec(
        )

        fs = int(sampling_rate) * 1000
        cmp_result, reason = cmp_pcm(dut_out_raw, ref_out_raw, output_config, fs, get_mld=get_mld, mld_lim=get_mld_lim )
        cmp_result, reason = cmp_pcm(
            dut_out_raw,
            ref_out_raw,
            output_config,
            fs,
            get_mld=get_mld,
            mld_lim=get_mld_lim,
        )
        if get_mld:
            mld = 0
            if "MLD" in reason:
                mld = float(reason.split(':')[1].split()[0])
                mld = float(reason.split(":")[1].split()[0])
            record_property("MLD", mld)

        # report compare result
Loading