Commit 46980480 authored by BOHMRR's avatar BOHMRR
Browse files

pytest: removed test_spar_foa_dec_BWforce_system since this test is covered by...

pytest: removed test_spar_foa_dec_BWforce_system since this test is covered by test_spar_foa_enc_BWforce_system
parent e68f0fd5
Loading
Loading
Loading
Loading
+0 −164
Original line number Diff line number Diff line
"""
   (C) 2022 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,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of 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,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.
"""

"""
Test file to run C decoder code.
The outputs are compared with C generated references.
"""

import os
import pytest
import errno
import shutil
import sys

sys.path.append('scripts/ivas_pytests/')
sys.path.append('scripts/ivas_pytests/tests/')
from il2mm import il2mm
from cmp_custom import cmp_custom 
from conftest import DecoderFrontend

#params
tag_list_bw_force = ['stvFOA']
dtx_set = ['0', '1']
dict_fsample_bw = {'48':'3', '32':'2', '16':'1'}
dict_bw_idx = {'FB':'3', 'SWB':'2', 'WB':'1'}
dict_bw_tag = {'SWB':'_ForceSWB', 'WB':'_ForceWB'}
ivas_br_list = ['32000', '64000', '96000', '160000', '256000']
sample_rate_bw_idx_list = [('48', 'SWB'), ('48', 'WB'), ('32', 'WB')]
AbsTol = '3'

ch_count_foa = 4


def check_and_makedir(dir_path):
    if not os.path.exists(dir_path):
        try:
            os.makedirs(dir_path)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise  # raises the error again


@pytest.mark.parametrize("ivas_br", ivas_br_list)
@pytest.mark.parametrize("dtx", dtx_set)
@pytest.mark.parametrize("tag", tag_list_bw_force)
@pytest.mark.parametrize("sample_rate_bw_idx", sample_rate_bw_idx_list)
def test_spar_foa_dec_BWforce_system(
    dut_decoder_frontend: DecoderFrontend,
    reference_path,
    dut_base_path,
    ivas_br,
    dtx,
    tag,
    sample_rate_bw_idx
):

    fs = sample_rate_bw_idx[0]
    bw = sample_rate_bw_idx[1]
    tag = tag + fs + 'c'

    #dec
    spar_foa_dec(dut_decoder_frontend, reference_path, dut_base_path, tag, ch_count_foa, fs, ivas_br, dtx, bw)


#########################################################
############ test function ##############################

def spar_foa_dec(
    decoder_frontend,
    reference_path,
    dut_base_path,
    tag,
    ch_count,
    sampling_rate,
    ivas_br,
    dtx,
    ivas_max_bw
):

    #########  run cmd   #####################################
    #sampling rate to BW mapping
    bw_idx = dict_fsample_bw[sampling_rate]
    if int(dict_bw_idx[ivas_max_bw]) < int(bw_idx):
        bw_tag = dict_bw_tag[ivas_max_bw]
        tag = tag + bw_tag

    tag_out = f"{tag}_ivasbr{ivas_br[:-3]}k_DTX{dtx}"

    dut_out_dir = f"{dut_base_path}/spar_foa_bs/raw/{tag_out}"
    ref_out_dir = f"{reference_path}/spar_foa_bs/raw/{tag_out}"
    check_and_makedir(dut_out_dir)

    ref_in_pkt = f"{reference_path}/spar_foa_bs/pkt/{tag_out}.pkt"

    decoder_frontend.run(
        "FOA",
        sampling_rate,
        ref_in_pkt,
        f"{dut_out_dir}/out.raw",
    )

    il2mm(f"{dut_out_dir}/out.raw", ch_count)

    #########  compare cmd   #####################################

    end_skip_samples = '0'

    test_fail = False
    for count in range(ch_count):
        ch_id = str(count + 1)

        if cmp_custom(
            f"{dut_out_dir}/out{ch_id}ch.raw",
            f"{ref_out_dir}/out{ch_id}ch.raw",
            "2",
            AbsTol,
            end_skip_samples
        ) != 0:
            test_fail = True

    ##File removal##
    # Unclear whether this clean-up is still needed
    # TODO: check temp file generation
    for count in range(ch_count, 16):
        ch_id = str(count + 1)
        temp_raw_file = f"{dut_out_dir}/out{ch_id}ch.raw"
        if os.path.isfile(temp_raw_file):
            os.remove(temp_raw_file)

    temp_md_file = f"{dut_out_dir}/MD_OUT_DUMMY.BIN"
    if os.path.isfile(temp_md_file):
        os.remove(temp_md_file)

    shutil.rmtree(dut_out_dir, ignore_errors=True)

    ##report failure
    assert not test_fail