Commit 1eb3b3e7 authored by Jan Kiene's avatar Jan Kiene
Browse files

run formatter on changed files

parent 8f6a2fcf
Loading
Loading
Loading
Loading
+82 −61
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,8 +28,7 @@ __copyright__ = \
    the United Nations Convention on Contracts on the International Sales of Goods.
    """

__doc__ = \
    """
__doc__ = """
    Test file to run C encoder and decoder code.
    The outputs are compared with C generated references.
    """
@@ -46,20 +44,36 @@ from tests.cmp_pcm import cmp_pcm

# 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']
output_mode_list = ['BINAURAL', 'EXT']
ivas_br_masa = [13200, 16400, 24400, 32000, 48000, 64000, 80000, 96000, 128000, 160000, 192000, 256000, 384000, 512000]
output_mode_list = ["BINAURAL", "EXT"]
ivas_br_masa = [
    13200,
    16400,
    24400,
    32000,
    48000,
    64000,
    80000,
    96000,
    128000,
    160000,
    192000,
    256000,
    384000,
    512000,
]

# Write file-based parameter sets here (metafile, pcm/wave, numDir, numTC, DTX_toggle)
masa_metadata_audio_ndir_ntransportch_dtx_list = [  # ('stv1MASA1TC48c.met', 'stv1MASA1TC48c.wav', 1, 1, False),
    # ('stv1MASA2TC48c.met', 'stv1MASA2TC48c.wav', 1, 2, False),
                                                  ('stv2MASA1TC48c.met', 'stv2MASA1TC48c.wav', 2, 1, False),
    ("stv2MASA1TC48c.met", "stv2MASA1TC48c.wav", 2, 1, False),
    # ('stv2MASA2TC48c.met', 'stv2MASA2TC48c.wav', 2, 2, False),
    # ('stv1MASA1TC48n.met', 'stv1MASA1TC48n.wav', 1, 1, True),
                                                  ('stv1MASA2TC48n.met', 'stv1MASA2TC48n.wav', 1, 2, True)]
    ("stv1MASA2TC48n.met", "stv1MASA2TC48n.wav", 1, 2, True),
]

# Used to not test every combination
test_split_br = [13200, 24400, 48000, 80000, 128000, 256000, 512000];
AbsTol = '0'
test_split_br = [13200, 24400, 48000, 80000, 128000, 256000, 512000]
AbsTol = "0"


def check_and_makedir(dir_path):
@@ -74,7 +88,10 @@ def check_and_makedir(dir_path):
@pytest.mark.create_ref
@pytest.mark.parametrize("output_mode", output_mode_list)
@pytest.mark.parametrize("ivas_br", ivas_br_masa)
@pytest.mark.parametrize("masa_metadata_audio_ndir_ntransportch_dtx", masa_metadata_audio_ndir_ntransportch_dtx_list)
@pytest.mark.parametrize(
    "masa_metadata_audio_ndir_ntransportch_dtx",
    masa_metadata_audio_ndir_ntransportch_dtx_list,
)
def test_masa_enc_dec(
    dut_encoder_frontend: EncoderFrontend,
    dut_decoder_frontend: DecoderFrontend,
@@ -102,9 +119,11 @@ def test_masa_enc_dec(

    # Apply test skipping here
    if dtx:
        if output_mode != 'EXT':
        if output_mode != "EXT":
            if ivas_br not in test_split_br:
                pytest.skip("Skipping some DTX bitrates for other than EXT output to save time")
                pytest.skip(
                    "Skipping some DTX bitrates for other than EXT output to save time"
                )

    # Set reference encoder and decoder

@@ -123,7 +142,7 @@ def test_masa_enc_dec(
    output_bitstream_dut = f"{out_dir_bs_dut}/masa{masa_channel_count}_ndirs{n_directions}_outputmode{output_mode}_ivasbr{ivas_br}k_DTX{dtx}.bts"
    dec_output_ref = f"{out_dir_dec_output_ref}/masa{masa_channel_count}_ndirs{n_directions}_outputmode{output_mode}_ivasbr{ivas_br}k_DTX{dtx}.wav"
    dec_output_dut = f"{out_dir_dec_output_dut}/masa{masa_channel_count}_ndirs{n_directions}_outputmode{output_mode}_ivasbr{ivas_br}k_DTX{dtx}.wav"
    if output_mode == 'EXT':
    if output_mode == "EXT":
        dec_met_output_ref = f"{dec_output_ref}.met"
        dec_met_output_dut = f"{dec_output_dut}.met"
    else:
@@ -175,12 +194,14 @@ def test_masa_enc_dec(
        )

        # Compare outputs. For EXT output, also compare metadata.
        if output_mode == 'EXT':
        if output_mode == "EXT":
            # Compare metadata as binary blob
            metacmp_res = cmp(dec_met_output_ref, dec_met_output_dut)

            # Compare audio outputs
            pcmcmp_res, reason = cmp_pcm(dec_output_dut, dec_output_ref, output_mode, int(out_fs*1000))
            pcmcmp_res, reason = cmp_pcm(
                dec_output_dut, dec_output_ref, output_mode, int(out_fs * 1000)
            )

            # Fail if compare fails compare result
            if metacmp_res == False and pcmcmp_res != 0:
@@ -196,7 +217,9 @@ def test_masa_enc_dec(
            # Compare audio outputs
            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))
                cmp_result, reason = cmp_pcm(
                    dec_output_dut, dec_output_ref, output_mode, int(out_fs * 1000)
                )
                # Report compare result
                assert cmp_result == 0, reason
            else:
@@ -225,9 +248,8 @@ def ivas_enc(
    output_bitstream,
    dtx: Optional[bool] = False,
):

    # ------------  run cmd  ------------
    options = ['-masa', f"{masa_channel_count}", f"{masa_path}"]
    options = ["-masa", f"{masa_channel_count}", f"{masa_path}"]

    # call encoder
    encoder_frontend.run(
@@ -247,7 +269,6 @@ def ivas_dec(
    input_bitstream,
    output_path,
):

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

    # call decoder
+0 −1
Original line number Diff line number Diff line
@@ -291,7 +291,6 @@ def test_param_file_tests(
        output_differs, reason = cmp_pcm(
            dut_output_file, ref_output_file, output_config, fs
        )

        md_out_files = get_expected_md_files(ref_output_file, enc_split, output_config)

        metadata_differs = False
+79 −61
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,8 +28,7 @@ __copyright__ = \
    the United Nations Convention on Contracts on the International Sales of Goods.
    """

__doc__ = \
    """
__doc__ = """
    Test file to run C encoder and decoder code.
    The outputs are compared with C generated references.
    """
@@ -43,28 +41,40 @@ from tests.cmp_pcm import cmp_pcm
from tests.cut_pcm import cut_samples
from tests.conftest import EncoderFrontend, DecoderFrontend
from cut_bs import cut_from_start
# params

tag_list = ['stvFOA']
tag_list_HOA2 = ['stv2OA']
tag_list_HOA3 = ['stv3OA']

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_FOA = ['13200','16400','32000','64000', '96000', '160000', '256000', '384000', '512000','sw_24k4_256k.bin']
ivas_br_HOA2 = ['256000', '384000', '512000']
ivas_br_HOA3 = ['256000', '384000', '512000']
# params

sample_rate_list = ['48', '32', '16']
tag_list = ["stvFOA"]
tag_list_HOA2 = ["stv2OA"]
tag_list_HOA3 = ["stv3OA"]

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_FOA = [
    "13200",
    "16400",
    "32000",
    "64000",
    "96000",
    "160000",
    "256000",
    "384000",
    "512000",
    "sw_24k4_256k.bin",
]
ivas_br_HOA2 = ["256000", "384000", "512000"]
ivas_br_HOA3 = ["256000", "384000", "512000"]

sample_rate_list = ["48", "32", "16"]
bypass_list = [1, 2]
gain_list = [0, 1]

sample_rate_bw_idx_list = [('48', 'SWB'), ('48', 'WB'), ('32', 'WB')]
sample_rate_bw_idx_list = [("48", "SWB"), ("48", "WB"), ("32", "WB")]

AbsTol = '0'
AbsTol = "0"


def check_and_makedir(dir_path):
@@ -97,9 +107,9 @@ def test_bypass_enc(
    if update_ref == 1 and bypass == 1:
        pytest.skip()

    tag = tag + fs + 'c'
    ivas_br = '256000'
    dtx = '0'
    tag = tag + fs + "c"
    ivas_br = "256000"
    dtx = "0"
    max_bw = "FB"
    gain_flag = -1
    sba_order = "+1"
@@ -123,7 +133,7 @@ def test_bypass_enc(
        sba_order,
        update_ref,
        gain_flag,
        cut_testv=True
        cut_testv=True,
    )

    # dec
@@ -170,26 +180,26 @@ def test_sba_enc_system(
    gain_flag,
):
    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 == 'sw_24k4_256k.bin' and gain_flag != 1:
    if ivas_br == "sw_24k4_256k.bin" and gain_flag != 1:
        pytest.skip()
    if ivas_br == '13200' or ivas_br == '16400':
        if dtx == '1' and gain_flag == 0 and fs != '16':
    if ivas_br == "13200" or ivas_br == "16400":
        if dtx == "1" and gain_flag == 0 and fs != "16":
            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"
    max_bw = "FB"
    bypass = -1
    sba_order = "+1"
    output_config = "FOA"
    if gain_flag == 1:
        cut_gain = "16.0"
    elif dtx == '1':
    elif dtx == "1":
        cut_gain = ".004"
    else:
        cut_gain = "1.0"
@@ -213,7 +223,7 @@ def test_sba_enc_system(
        gain_flag,
        cut_gain=cut_gain,
        create_dutenc=True,
        cut_testv=True
        cut_testv=True,
    )

    # dec
@@ -252,11 +262,11 @@ def test_spar_hoa2_enc_system(
    ivas_br,
    tag,
):
    fs = '48'
    dtx = '0'
    fs = "48"
    dtx = "0"
    gain_flag = -1

    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    max_bw = "FB"
    bypass = -1
    sba_order = "+2"
@@ -318,11 +328,11 @@ def test_spar_hoa3_enc_system(
    ivas_br,
    tag,
):
    fs = '48'
    dtx = '0'
    fs = "48"
    dtx = "0"
    gain_flag = -1

    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    max_bw = "FB"
    bypass = -1
    sba_order = "+3"
@@ -388,16 +398,16 @@ def test_sba_enc_BWforce_system(
    tag,
    sample_rate_bw_idx,
):
    if dtx == '1' and ivas_br not in ['32000','64000']:
    if dtx == "1" and ivas_br not in ["32000", "64000"]:
        # skip high bitrates for DTX until DTX issue is resolved
        pytest.skip()
    if ivas_br == '13200' or ivas_br == '16400':
    if ivas_br == "13200" or ivas_br == "16400":
        pytest.skip()
    if ivas_br == 'sw_24k4_256k.bin':
    if ivas_br == "sw_24k4_256k.bin":
        pytest.skip()
    fs = sample_rate_bw_idx[0]
    bw = sample_rate_bw_idx[1]
    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    bypass = -1
    gain_flag = -1
    sba_order = "+1"
@@ -421,7 +431,7 @@ def test_sba_enc_BWforce_system(
        sba_order,
        update_ref,
        gain_flag,
        cut_testv=True
        cut_testv=True,
    )

    # dec
@@ -463,11 +473,10 @@ def sba_enc(
    sba_order,
    update_ref,
    gain_flag,
    cut_gain='1.0',
    cut_gain="1.0",
    create_dutenc=False,
    cut_testv=False
    cut_testv=False,
):

    # ------------  run cmd  ------------
    dut_out_dir = f"{dut_base_path}/sba_bs/pkt"
    ref_out_dir = f"{reference_path}/sba_bs/pkt"
@@ -484,13 +493,13 @@ def sba_enc(
        tag = tag + dict_bw_tag[ivas_max_bw]

    tag_out = f"{tag}_ivasbr{ivas_br[:-3]}k_DTX{dtx}"
    if ivas_br == 'sw_24k4_256k.bin':
    if ivas_br == "sw_24k4_256k.bin":
        ivas_br = f"{br_switch_file_path}/sw_24k4_256k.bin"
    short_tag_ext = ""
    if gain_flag == 1:
        short_tag_ext += f'_Gain{gain_flag}'
        short_tag_ext += f"_Gain{gain_flag}"
    if SID == 1:
        short_tag_ext += f'_SID'
        short_tag_ext += f"_SID"
    # we update only bypass = 0/2 (bypass 1 is the same as the baseline)
    if bypass in [0, 2]:
        short_tag_ext += f"_pca{bypass}"
@@ -507,10 +516,12 @@ def sba_enc(
    if SID == 1:
        dut_pkt_file_cut = f"{dut_out_dir}/{tag_out}{long_tag_ext}_cut.pkt"
        ref_pkt_file_cut = f"{ref_out_dir}/{tag_out}{short_tag_ext}_cut.pkt"
        ref_pkt_file_dutenc_cut = f"{ref_out_dir}/{tag_out}{short_tag_ext}_dutenc_cut.pkt"
        ref_pkt_file_dutenc_cut = (
            f"{ref_out_dir}/{tag_out}{short_tag_ext}_dutenc_cut.pkt"
        )
    input_path = f"{test_vector_path}/{tag_in}{in_extension}"
    bypass_mode = bypass if bypass >= 0 else None
    dtx_mode = dtx == '1'
    dtx_mode = dtx == "1"

    if cut_testv:
        # use shortened and potentially gain adjusted input PCM file - create if not present
@@ -523,7 +534,15 @@ def sba_enc(
        else:
            cut_file = f"{test_vector_path}/{tag_in}_cut_{cut_gain}{in_extension}"
        if not os.path.exists(cut_file):
            cut_samples(input_path, cut_file, num_channels, sampling_rate + "000", cut_from, cut_len, cut_gain)
            cut_samples(
                input_path,
                cut_file,
                num_channels,
                sampling_rate + "000",
                cut_from,
                cut_len,
                cut_gain,
            )
        input_path = cut_file

    if ref_encoder_frontend:
@@ -598,7 +617,6 @@ def sba_dec(
    gain_flag,
    keep_files,
):

    # --------  run cmd  ------------
    # sampling rate to BW mapping
    bw_idx = dict_fsample_bw[sampling_rate]
@@ -609,12 +627,12 @@ def sba_dec(

    short_tag_ext = ""
    if gain_flag == 1:
        short_tag_ext += f'_Gain{gain_flag}'
        short_tag_ext += f"_Gain{gain_flag}"
    # we update only bypass = 0/2 (bypass 1 is the same as the baseline)
    if bypass in [0, 2]:
        short_tag_ext += f"_pca{bypass}"
    if SID == 1:
       short_tag_ext += f'_SID_cut'
        short_tag_ext += f"_SID_cut"
    # to avoid conflicting names in case of parallel test execution, differentiate all cases
    if gain_flag == 1:
        long_tag_ext = f"_Gain{gain_flag}"
+43 −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,8 +28,7 @@ accordance with the laws of the Federal Republic of Germany excluding its confli
the United Nations Convention on Contracts on the International Sales of Goods.
"""

__doc__ = \
"""
__doc__ = """
Pytest customization (configuration and fixtures) for the IVAS codec test suite.
"""

@@ -143,10 +141,15 @@ def pytest_addoption(parser):
    parser.addoption(
        "--selection_be_md5_file",
        type=Path,
        help="Path to file with md5 sums for the reference signals of the selection-BE test"
        help="Path to file with md5 sums for the reference signals of the selection-BE test",
    )

    parser.addoption("--testcase_timeout", type=int, default=None, help="Timeout in seconds for each individual testcase. Default is no timeout.")
    parser.addoption(
        "--testcase_timeout",
        type=int,
        default=None,
        help="Timeout in seconds for each individual testcase. Default is no timeout.",
    )


@pytest.fixture(scope="session", autouse=True)
@@ -167,6 +170,7 @@ def keep_files(request) -> bool:
    """
    return request.config.option.keep_files


@pytest.fixture(scope="session")
def compare_bitstream(request) -> bool:
    """
@@ -174,6 +178,7 @@ def compare_bitstream(request) -> bool:
    """
    return request.config.option.compare_bitstream


@pytest.fixture(scope="session")
def dut_encoder_path(request) -> str:
    """
@@ -269,12 +274,16 @@ class EncoderFrontend:
            stderr_str = textwrap.indent(self.stderr, prefix="\t")
            log_dbg_msg(f"{self._type} encoder stderr:\n{stderr_str}")
        if self.returncode:
            pytest.fail(f"{self._type} encoder terminated with a non-0 return code: {self.returncode}")
            pytest.fail(
                f"{self._type} encoder terminated with a non-0 return code: {self.returncode}"
            )

    def _check_run(self):
        if self.returncode is not None:
            if self.returncode:
                pytest.fail(f"{self._type} encoder terminated with a non-0 return code: {self.returncode}")
                pytest.fail(
                    f"{self._type} encoder terminated with a non-0 return code: {self.returncode}"
                )
        else:
            logger.warning("%s encoder was set-up, but not run", self._type)
        # next assert is not OK since stderr contains messages even when encoding was successful
@@ -423,12 +432,16 @@ class DecoderFrontend:
            stderr_str = textwrap.indent(self.stderr, prefix="\t")
            log_dbg_msg(f"{self._type} decoder stderr:\n{stderr_str}")
        if self.returncode:
            pytest.fail(f"{self._type} decoder terminated with a non-0 return code: {self.returncode}")
            pytest.fail(
                f"{self._type} decoder terminated with a non-0 return code: {self.returncode}"
            )

    def _check_run(self):
        if self.returncode is not None:
            if self.returncode:
                pytest.fail(f"{self._type} decoder terminated with a non-0 return code: {self.returncode}")
                pytest.fail(
                    f"{self._type} decoder terminated with a non-0 return code: {self.returncode}"
                )
        else:
            logger.warning("%s decoder was set-up, but not run", self._type)
        # next assert is not OK since stderr contains messages even when decoding was successful
@@ -440,7 +453,9 @@ def dut_decoder_frontend(dut_decoder_path, request) -> DecoderFrontend:
    """
    Return a :class:`conftest.DecoderFrontend` instance as DUT for the test session.
    """
    decoder = DecoderFrontend(dut_decoder_path, "DUT", timeout=request.config.getoption("--testcase_timeout"))
    decoder = DecoderFrontend(
        dut_decoder_path, "DUT", timeout=request.config.getoption("--testcase_timeout")
    )
    yield decoder

    # Fixture teardown
@@ -511,6 +526,7 @@ def test_vector_path(request) -> str:

    return path


@pytest.fixture(scope="session")
def br_switch_file_path(request) -> str:
    """
@@ -527,6 +543,7 @@ def br_switch_file_path(request) -> str:

    return path


@pytest.fixture(scope="session")
def reference_path(request) -> str:
    """
@@ -543,7 +560,9 @@ def reference_path(request) -> str:

    if request.config.option.update_ref == "0":
        if not os.path.isdir(path):
            raise FileNotFoundError(f"REF path {path} not found!\nPlease generate the references, first!\n!")
            raise FileNotFoundError(
                f"REF path {path} not found!\nPlease generate the references, first!\n!"
            )

    return path

@@ -566,20 +585,23 @@ def dut_base_path(request) -> str:


def pytest_configure(config):
    config.addinivalue_line(
        "markers", "serial: mark test to run only in serial"
    )
    config.addinivalue_line("markers", "serial: mark test to run only in serial")
    config.addinivalue_line(
        "markers", "create_ref: mark test capable of producing references"
    )
    config.addinivalue_line(
        "markers", "create_ref_part2: reference creation test that depends on create_ref references"
        "markers",
        "create_ref_part2: reference creation test that depends on create_ref references",
    )
    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")
            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()}
            testconfig.MD5_REF_DICT = {
                line.split()[0]: line.split()[1] for line in f.readlines()
            }