Commit fefdc04b authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

run eid-xor in pytest

parent cb64d738
Loading
Loading
Loading
Loading
Loading
+86 −3
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ with open(PARAM_FILE, "r", encoding="UTF-8") as fp:
        enc_opts = ""
        dec_opts = ""
        sim_opts = ""
        eid_opts = ""
        for line in block.split("\n"):
            if line.startswith("// "):
                tag = line[3:]
@@ -80,13 +81,15 @@ with open(PARAM_FILE, "r", encoding="UTF-8") as fp:
                dec_opts = line[12:]
            if line.startswith("networkSimulator_g192 "):
                sim_opts = line[22:]
            if line.startswith("eid-xor "):
                eid_opts = line[8:]
        if tag == "" or enc_opts == "" or dec_opts == "":
            # no complete parameter set
            continue
        if tag in param_file_test_dict:
            print("non-unique tag found - ignoring new entry")
            continue
        param_file_test_dict[tag] = (enc_opts, dec_opts, sim_opts)
        param_file_test_dict[tag] = (enc_opts, dec_opts, sim_opts, eid_opts)


def check_and_makedir(dir_path):
@@ -134,7 +137,7 @@ def test_param_file_tests(
    keep_files,
    test_tag,
):
    enc_opts, dec_opts, sim_opts = param_file_test_dict[test_tag]
    enc_opts, dec_opts, sim_opts, eid_opts = param_file_test_dict[test_tag]

    tag_str = convert_test_string_to_tag(test_tag)

@@ -194,10 +197,11 @@ def test_param_file_tests(
        is_exist = os.path.exists(cut_file)
        if is_exist:
            os.remove(cut_file)
         
    # check for networkSimulator_g192 command line
    if sim_opts != "":
        sim_split = sim_opts.split()
        assert len(sim_split) == 6, "networkSimulator_g192 binary expects 6 parameters"
        assert len(sim_split) == 6, "networkSimulator_g192 expects 6 parameters"
        # [sim_profile, sim_input, sim_output, sim_trace, sim_nFPP, sim_offset] = sim_split
        if sim_split[0].startswith(("../")):
            # remove leading "../"
@@ -224,6 +228,31 @@ def test_param_file_tests(
            rootdir,
        )
              
    # check for eid-xor command line
    if eid_opts != "":
        eid_split = eid_opts.split()
        assert len(eid_split) >= 3, "eid-xor expects at least 3 parameters"
        # [..., in_bs, err_pat_bs, out_bs] = eid_split
        if eid_split[-2].startswith(("../")):
            # remove leading "../"
            eid_split[-2] = eid_split[-2][3:]
        assert eid_split[-3] == "bit"
        # in the parameter file, only "bit" is used as the input bitstream file name
        # -> re-use bitstream filename from encoder call
        eid_split[-3] = bitstream_file
        assert eid_split[-1] == "bit_error"
        # in the parameter file, only "bit_error" is used as the output bitstream file name
        # -> construct netsim output file name
        eid_xor_outfile = f"{testv_base}_{tag_str}.fer.192"
        eid_split[-1] = eid_xor_outfile
        error_insertion(
            reference_path,
            dut_base_path,
            eid_split,
            update_ref,
            rootdir,
        )

    # evaluate decoder options
    dec_split = dec_opts.split()
    assert len(dec_split) >= 3
@@ -261,11 +290,17 @@ def test_param_file_tests(
        # -> re-use netsim_outfile
        bitstream_file = netsim_outfile
        tracefile_dec = f"{testv_base}_{tag_str}.dectrace"
    elif eid_opts != "":
        assert bitstream_file_dec == "bit_error"
        # in the parameter file, only "bit_error" is used as bitstream input file name
        # -> re-use eid_xor_outfile
        bitstream_file = eid_xor_outfile
    else:
        assert bitstream_file_dec == "bit"
        # 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"
@@ -441,6 +476,54 @@ 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,
    eid_opts_list,
    update_ref,
    rootdir,
):
    """
    Call eid-xor to insert frame erasure on REF and/or DUT encoder output.
    """
    
    # directories
    dut_out_dir = f"{dut_base_path}/param_file/enc"
    ref_out_dir = f"{reference_path}/param_file/enc"

    eid_xor_infile = eid_opts_list[-3]
    eid_xor_outfile = eid_opts_list[-1]
    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"
            )
        ]
    elif platform.system() in ["Linux", "Darwin"]:
        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
        cmd_opts[-3] = f"{ref_out_dir}/{eid_xor_infile}"
        cmd_opts[-1] = f"{ref_out_dir}/{eid_xor_outfile}"  # ref_out_file
        run(eid_xor + cmd_opts, check=False)
        
    if update_ref in [0, 2]:
        # call eid-xor on DUT encoder output
        cmd_opts = eid_opts_list
        cmd_opts[-3] = f"{dut_out_dir}/{eid_xor_infile}"
        cmd_opts[-1] = f"{dut_out_dir}/{eid_xor_outfile}"  # ref_out_file
        run(eid_xor + cmd_opts, check=False)

def decode(
    decoder_frontend,