Commit 36824cde authored by Jan Kiene's avatar Jan Kiene
Browse files

normalize paths in command lines

parent 65c6d892
Loading
Loading
Loading
Loading
Loading
+40 −8
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ def main(args):

        if xml_report is not None:
            cmdlines_crashes_introduced = get_command_lines_for_testcases(
                df_crashes_introduced["testcase"], xml_report
                df_crashes_introduced["testcase"], xml_report, args.inject_cwd
            )
            df_crashes_introduced = pd.merge(
                df_crashes_introduced, cmdlines_crashes_introduced, on="testcase"
@@ -110,7 +110,7 @@ def main(args):

        if xml_report is not None:
            cmdlines_crashes_fixed = get_command_lines_for_testcases(
                df_crashes_fixed["testcase"], xml_report
                df_crashes_fixed["testcase"], xml_report, args.inject_cwd
            )
            df_crashes_fixed = pd.merge(
                df_crashes_fixed, cmdlines_crashes_fixed, on="testcase"
@@ -148,7 +148,7 @@ def main(args):

            if xml_report is not None:
                cmdlines_worse = get_command_lines_for_testcases(
                    df_worse["testcase"], xml_report
                    df_worse["testcase"], xml_report, args.inject_cwd
                )
                df_worse = pd.merge(df_worse, cmdlines_worse, on="testcase")
        df_worse.to_csv(outfile, sep=";")
@@ -163,7 +163,7 @@ def main(args):

            if xml_report is not None:
                cmdlines_better = get_command_lines_for_testcases(
                    df_better["testcase"], xml_report
                    df_better["testcase"], xml_report, args.inject_cwd
                )
                df_better = pd.merge(df_better, cmdlines_better, on="testcase")
            df_better.to_csv(outfile, mode="a", sep=";")
@@ -172,7 +172,7 @@ def main(args):


def get_command_lines_for_testcases(
    testcases: pd.Series, xml_report: pathlib.Path
    testcases: pd.Series, xml_report: pathlib.Path, cwd: pathlib.Path
) -> pd.DataFrame:
    testcase_elems = [
        e
@@ -186,7 +186,7 @@ def get_command_lines_for_testcases(
        enc_cmd = ""
        dec_cmd = ""
        if (system_out := elem.find("system-out")) is not None:
            enc_cmd, dec_cmd = extract_cmdlines(system_out.text)
            enc_cmd, dec_cmd = extract_cmdlines(system_out.text, cwd)

        cmdlines["testcase"].append(testcase_name)
        cmdlines["enc_cmd"].append(enc_cmd)
@@ -195,7 +195,7 @@ def get_command_lines_for_testcases(
    return pd.DataFrame(cmdlines)


def extract_cmdlines(text: str) -> Tuple[str, str]:
def extract_cmdlines(text: str, cwd: pathlib.Path) -> Tuple[str, str]:
    enc_cmdline = "<not found>"
    dec_cmdline = "<not found>"

@@ -205,11 +205,37 @@ def extract_cmdlines(text: str) -> Tuple[str, str]:
        enc_cmdline = match_enc.group(1)
        dec_cmdline = match_dec.group(1)

        # TODO: post-process paths
        enc_cmdline = postprocess_cmdline(enc_cmdline, cwd)
        dec_cmdline = postprocess_cmdline(dec_cmdline, cwd)

    return enc_cmdline, dec_cmdline


def postprocess_cmdline(cmdline: str, cwd: pathlib.Path) -> str:
    cmdline_split = cmdline.split()
    cmdline_proc = []

    # change absolute paths into relative ones
    # remove the "quite" flag
    # for output and bitstream files only keep the filename
    for elem in cmdline_split:
        print(elem)
        if elem == "-q":
            continue
        elif (elem_as_path := pathlib.Path(elem)).is_absolute():
            if elem_as_path.suffix == ".192" or (
                elem_as_path.suffix == ".wav"
                and cmdline_split.index(elem) == len(cmdline_split) - 1
            ):
                cmdline_proc.append(elem_as_path.name)
            else:
                cmdline_proc.append(str(elem_as_path.relative_to(cwd)))
        else:
            cmdline_proc.append(elem)

    return " ".join(cmdline_proc)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("csv_current")
@@ -226,6 +252,12 @@ if __name__ == "__main__":
        help="XMLxml_report report file from pytest run. Pass to add command lines to the output files.",
        default=None,
    )
    parser.add_argument(
        "--inject_cwd",
        help="Use this as cwd when pruning the long paths in the command lines. Debug option for testing.",
        default=pathlib.Path(__file__).parent.absolute(),
        type=pathlib.Path,
    )

    args = parser.parse_args()
    sys.exit(main(args))