Commit 9db4588a authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

improve printout messages

parent 8f9b5f8d
Loading
Loading
Loading
Loading
Loading
+31 −19
Original line number Diff line number Diff line
@@ -27,18 +27,26 @@ def cmp_bin_files(ref_file, cut_file, dtype=np.int16, nsamples_per_frame=960, le
    with open(cut_file, "r") as f:
        cut = np.fromfile(f, dtype=dtype)
        
    # remove the duplicates of each value
    # remove the duplicates of each value per frame
    if nsamples_per_frame > 1:
        ref = ref[::nsamples_per_frame]
        cut = cut[::nsamples_per_frame]

    # check the lengths
    N = ref.shape[0] + cut.shape[0]
    reason = f"File {os.path.basename(ref_file)}"
    
    # check file lengths
    result_len_check = 0
    if len_check and ref.shape != cut.shape:
        print( f"files have different length, ref: {ref.shape[0]}, cut: {cut.shape[0]}" )
        result = 1
        reason = f"files have different length!"
        return result, reason
        print(f"files have different length: Ref {ref.shape[0]}, DuT {cut.shape[0]}, ", end="")
        reason += f" has different length between Ref ({ref.shape[0]}) and DuT ({cut.shape[0]}), "
        
        # check if threshold has been exceeded
        if abs(ref.shape[0] - cut.shape[0]) / max(ref.shape[0], cut.shape[0]) > min_diff_thr:
            result_len_check = 1
        else:
            result_len_check = 0
    else:
        reason += ": "

    # calculate histograms from data
    unique_values = np.sort(np.unique(np.concatenate([ref, cut])))
@@ -50,22 +58,26 @@ def cmp_bin_files(ref_file, cut_file, dtype=np.int16, nsamples_per_frame=960, le
    diff = {unique_values[i]: diff_hist[i] for i in range(len(unique_values))}      
    diff = dict(sorted(diff.items(), key=lambda k: abs(k[1]), reverse=True))
    
    # calcualte the total number of differences
    # calculate the total number of differences
    total_num_diff = sum(np.abs(list(diff.values())))
    total_num_diff_ratio = total_num_diff / N
    total_num_diff_ratio = total_num_diff / max(ref.shape[0], cut.shape[0])
    
    if total_num_diff_ratio > min_diff_thr:
        print( f"files are different, total number of differences is {total_num_diff} ({(total_num_diff_ratio*100):.2f}%), exceeding the threshold of {(min_diff_thr*100):.2f}%!" )
        result = 1
        reason = f"files are different, total number of differences is {total_num_diff} ({(total_num_diff_ratio*100):.2f}%), exceeding the threshold of {(min_diff_thr*100):.2f}%!"
    elif total_num_diff_ratio > 0 and total_num_diff_ratio < min_diff_thr:
        print( f"files are different, total number of differences is {total_num_diff} ({(total_num_diff_ratio*100):.2f}%)." )
        result = 0
        reason = f"files are different, total number of differences is {total_num_diff} ({(total_num_diff_ratio*100):.2f}%)."
        msg = f"the total number of differences is {total_num_diff} ({(total_num_diff_ratio*100):.2f}%), exceeding the threshold of {(min_diff_thr*100):.2f}%!"
        reason += msg
        print(msg, end="")
        result_diff_check = 1
    else:
        print( f"files are bit-exact." )
        msg = f"the total number of differences is {total_num_diff} ({(total_num_diff_ratio*100):.2f}%)."
        reason += msg
        print( msg, end="" )
        result_diff_check = 0
        
    print("")
        
    result = 0
        reason = f"files are bit-exact."
    if result_len_check or result_diff_check:
        result = 1
        
    return result, reason

+17 −18
Original line number Diff line number Diff line
@@ -215,7 +215,8 @@ def test_param_file_tests(
            print ("=================================\n")
            
            msg = ""
            max_diff = 0
            max_enc_diff = 0
            enc_test_result = 0
            for f in ENC_AUX_FILES:
                filename = f[0]
                dtype = f[1]
@@ -242,29 +243,22 @@ def test_param_file_tests(
                        min_diff_thr=0.1,
                    )
                    
                    # check if the maximum difference has been exceeded
                    if output_differs:
                        enc_test_result = 1
                        if msg:
                            msg += ", "
                        msg += reason
                        search_result = re.search(MAX_ENC_DIFF_PATTERN, reason)
                        
                    # check if the maximum difference has been exceeded
                    search_result = re.search(MAX_ENC_DIFF_PATTERN, reason)
                    if search_result:
                        diff = search_result.groups(1)[0]
                            diff = np.float(diff)
                            if diff > max_diff:
                                max_diff = diff
                        else:
                            msg = "Error " + MAX_ENC_DIFF_PATTERN + " not found"
                            print(msg)
                            pytest.fail(msg)
                        diff = float(diff)
                        if diff > max_enc_diff:
                            max_enc_diff = diff

            print ("")

            if max_diff > 0:
                record_property("MAXIMUM ENC DIFF", max_diff)
                
            if msg:
                pytest.fail(reason)

            # remove encoder output files to save disk space
            if ref_enc_dbg_dir:
                shutil.rmtree(ref_enc_dbg_dir.name)
@@ -272,6 +266,11 @@ def test_param_file_tests(
            if dut_enc_dbg_dir:
                shutil.rmtree(dut_enc_dbg_dir.name)

            if enc_test_result:
                record_property("MAXIMUM ENC DIFF", max_enc_diff)
                pytest.fail(msg)
                

    # check for networkSimulator_g192 command line
    if sim_opts != "":
        sim_split = sim_opts.split()
+2 −1
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@ import numpy as np
# regex patterns for parsing the output from cmp_pcm -> mainly for BASOP ci
MLD_PATTERN = r"MLD: ([\d\.]*)"
MAX_DIFF_PATTERN = r"MAXIMUM ABS DIFF: (\d*)"
MAX_ENC_DIFF_PATTERN = r"The total number of differences is \d (\d+\.\d+)%"
MAX_ENC_DIFF_PATTERN = r"total number of differences is \d+ \((\d+\.\d+)%\)"


# list of encoder filename patterns with their data type and number of samples per frame
# note: instead of specifying the number of samples per frame, you can use a formula incl. 'fs', e.g. 'fs/50'