Re: [PATCH 1/2] xen/misra: add diff-report.py tool
On Fri, 19 May 2023, Luca Fancellu wrote: > Add a new tool, diff-report.py that can be used to make diff between > reports generated by xen-analysis.py tool. > Currently this tool supports the Xen cppcheck text report format in > its operations. > > The tool prints every finding that is in the report passed with -r > (check report) which is not in the report passed with -b (baseline). > > Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini > --- > Changes from v1: > - removed 2 method from class ReportEntry that landed there by a >mistake on rebase. > - Made the script compatible also with python2 (Stefano) > --- > xen/scripts/diff-report.py| 80 ++ > .../xen_analysis/diff_tool/__init__.py| 0 > .../xen_analysis/diff_tool/cppcheck_report.py | 44 > xen/scripts/xen_analysis/diff_tool/debug.py | 40 +++ > xen/scripts/xen_analysis/diff_tool/report.py | 100 ++ > 5 files changed, 264 insertions(+) > create mode 100755 xen/scripts/diff-report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py > > diff --git a/xen/scripts/diff-report.py b/xen/scripts/diff-report.py > new file mode 100755 > index ..f97cb2355cc3 > --- /dev/null > +++ b/xen/scripts/diff-report.py > @@ -0,0 +1,80 @@ > +#!/usr/bin/env python3 > + > +from __future__ import print_function > +import os > +import sys > +from argparse import ArgumentParser > +from xen_analysis.diff_tool.cppcheck_report import CppcheckReport > +from xen_analysis.diff_tool.debug import Debug > +from xen_analysis.diff_tool.report import ReportError > + > + > +def log_info(text, end='\n'): > +# type: (str, str) -> None > +global args > +global file_out > + > +if (args.verbose): > +print(text, end=end, file=file_out) > + > + > +def main(argv): > +# type: (list) -> None > +global args > +global file_out > + > +parser = ArgumentParser(prog="diff-report.py") > +parser.add_argument("-b", "--baseline", required=True, type=str, > +help="Path to the baseline report.") > +parser.add_argument("--debug", action='store_true', > +help="Produce intermediate reports during > operations.") > +parser.add_argument("-o", "--out", default="stdout", type=str, > +help="Where to print the tool output. Default is " > + "stdout") > +parser.add_argument("-r", "--report", required=True, type=str, > +help="Path to the 'check report', the one checked " > + "against the baseline.") > +parser.add_argument("-v", "--verbose", action='store_true', > +help="Print more informations during the run.") > + > +args = parser.parse_args() > + > +if args.out == "stdout": > +file_out = sys.stdout > +else: > +try: > +file_out = open(args.out, "wt") > +except OSError as e: > +print("ERROR: Issue opening file {}: {}".format(args.out, e)) > +sys.exit(1) > + > +debug = Debug(args) > + > +try: > +baseline_path = os.path.realpath(args.baseline) > +log_info("Loading baseline report {}".format(baseline_path), "") > +baseline = CppcheckReport(baseline_path) > +baseline.parse() > +debug.debug_print_parsed_report(baseline) > +log_info(" [OK]") > +new_rep_path = os.path.realpath(args.report) > +log_info("Loading check report {}".format(new_rep_path), "") > +new_rep = CppcheckReport(new_rep_path) > +new_rep.parse() > +debug.debug_print_parsed_report(new_rep) > +log_info(" [OK]") > +except ReportError as e: > +print("ERROR: {}".format(e)) > +sys.exit(1) > + > +output = new_rep - baseline > +print(output, end="", file=file_out) > + > +if len(output) > 0: > +sys.exit(1) > + > +sys.exit(0) > + > + > +if __name__ == "__main__": > +main(sys.argv[1:]) > diff --git a/xen/scripts/xen_analysis/diff_tool/__init__.py > b/xen/scripts/xen_analysis/diff_tool/__init__.py > new file mode 100644 > index ..e69de29bb2d1 > diff --git a/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > new file mode 100644 > index ..e7e80a9dde84 > --- /dev/null > +++ b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > @@ -0,0 +1,44 @@ > +#!/usr/bin/env python3 > + > +import re > +from .report import Report, ReportError > + > + > +class CppcheckReport(Report): > +def __init__(self, report_path): > +# type: (str) -> None > +super(CppcheckRepo
Re: [PATCH 1/2] xen/misra: add diff-report.py tool
On 19.05.2023 13:10, Luca Fancellu wrote: > > >> On 19 May 2023, at 11:53, Jan Beulich wrote: >> >> On 19.05.2023 11:46, Luca Fancellu wrote: >>> Add a new tool, diff-report.py that can be used to make diff between >>> reports generated by xen-analysis.py tool. >>> Currently this tool supports the Xen cppcheck text report format in >>> its operations. >>> >>> The tool prints every finding that is in the report passed with -r >>> (check report) which is not in the report passed with -b (baseline). >>> >>> Signed-off-by: Luca Fancellu >>> --- >>> Changes from v1: >>> - removed 2 method from class ReportEntry that landed there by a >>> mistake on rebase. >>> - Made the script compatible also with python2 (Stefano) >>> --- >>> xen/scripts/diff-report.py| 80 ++ >>> .../xen_analysis/diff_tool/__init__.py| 0 >>> .../xen_analysis/diff_tool/cppcheck_report.py | 44 >>> xen/scripts/xen_analysis/diff_tool/debug.py | 40 +++ >>> xen/scripts/xen_analysis/diff_tool/report.py | 100 ++ >>> 5 files changed, 264 insertions(+) >>> create mode 100755 xen/scripts/diff-report.py >>> create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py >>> create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py >>> create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py >>> create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py >> >> If I'm not mistaken Python has no issue with dashes in path names. >> Hence it would once again be better if the underscores were avoided >> in the new directory names. > > From what I know python can’t use import for module with dashes in the name, > unless > using some tricks, but if anyone knows more about that please correct me if > I’m wrong. > > The style guide for python > (https://peps.python.org/pep-0008/#package-and-module-names) > Says: > > Modules should have short, all-lowercase names. Underscores can be used in > the module > name if it improves readability. Python packages should also have short, > all-lowercase names, > although the use of underscores is discouraged. Hmm, I was initially thinking there might be such a restriction, but the I checked a pretty old installation and found plat-linux2/ there with several .py / .pyo / .pyc files underneath. Which suggested to me that, for them to be of any use, such a path name must be permitted. But well, if underscores are required to be used if any separator is wanted, so be it. Albeit ... > So, yes, the use is discouraged, but here I think it improves the > readability. Unless we want > to use “difftool” instead of “diff_tool” and “cppcheckreport” instead of > “cppcheck_report”. ... personally I'd like both shorter variants better, plus perhaps xen_ dropped from xen_analysis, or some different name used there altogether (to me this name doesn't really tell me what to expect there, but maybe that's indeed just me). > Can I ask the reason why we need to avoid underscores in file names? First of all they're odd, a space or dash is simply more natural to use. From my pov they ought to be used only when a visual separator is wanted, but neither space nor dash fit the purpose (e.g. for lexical reasons in programming languages). Plus typing them requires, on all keyboards I'm aware of, to be used when dash doesn't. Jan
Re: [PATCH 1/2] xen/misra: add diff-report.py tool
> On 19 May 2023, at 11:53, Jan Beulich wrote: > > On 19.05.2023 11:46, Luca Fancellu wrote: >> Add a new tool, diff-report.py that can be used to make diff between >> reports generated by xen-analysis.py tool. >> Currently this tool supports the Xen cppcheck text report format in >> its operations. >> >> The tool prints every finding that is in the report passed with -r >> (check report) which is not in the report passed with -b (baseline). >> >> Signed-off-by: Luca Fancellu >> --- >> Changes from v1: >> - removed 2 method from class ReportEntry that landed there by a >> mistake on rebase. >> - Made the script compatible also with python2 (Stefano) >> --- >> xen/scripts/diff-report.py| 80 ++ >> .../xen_analysis/diff_tool/__init__.py| 0 >> .../xen_analysis/diff_tool/cppcheck_report.py | 44 >> xen/scripts/xen_analysis/diff_tool/debug.py | 40 +++ >> xen/scripts/xen_analysis/diff_tool/report.py | 100 ++ >> 5 files changed, 264 insertions(+) >> create mode 100755 xen/scripts/diff-report.py >> create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py >> create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py >> create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py >> create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py > > If I'm not mistaken Python has no issue with dashes in path names. > Hence it would once again be better if the underscores were avoided > in the new directory names. Hi Jan, From what I know python can’t use import for module with dashes in the name, unless using some tricks, but if anyone knows more about that please correct me if I’m wrong. The style guide for python (https://peps.python.org/pep-0008/#package-and-module-names) Says: Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. So, yes, the use is discouraged, but here I think it improves the readability. Unless we want to use “difftool” instead of “diff_tool” and “cppcheckreport” instead of “cppcheck_report”. Can I ask the reason why we need to avoid underscores in file names? > > Jan
Re: [PATCH 1/2] xen/misra: add diff-report.py tool
On 19.05.2023 11:46, Luca Fancellu wrote: > Add a new tool, diff-report.py that can be used to make diff between > reports generated by xen-analysis.py tool. > Currently this tool supports the Xen cppcheck text report format in > its operations. > > The tool prints every finding that is in the report passed with -r > (check report) which is not in the report passed with -b (baseline). > > Signed-off-by: Luca Fancellu > --- > Changes from v1: > - removed 2 method from class ReportEntry that landed there by a >mistake on rebase. > - Made the script compatible also with python2 (Stefano) > --- > xen/scripts/diff-report.py| 80 ++ > .../xen_analysis/diff_tool/__init__.py| 0 > .../xen_analysis/diff_tool/cppcheck_report.py | 44 > xen/scripts/xen_analysis/diff_tool/debug.py | 40 +++ > xen/scripts/xen_analysis/diff_tool/report.py | 100 ++ > 5 files changed, 264 insertions(+) > create mode 100755 xen/scripts/diff-report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py If I'm not mistaken Python has no issue with dashes in path names. Hence it would once again be better if the underscores were avoided in the new directory names. Jan
[PATCH 1/2] xen/misra: add diff-report.py tool
Add a new tool, diff-report.py that can be used to make diff between reports generated by xen-analysis.py tool. Currently this tool supports the Xen cppcheck text report format in its operations. The tool prints every finding that is in the report passed with -r (check report) which is not in the report passed with -b (baseline). Signed-off-by: Luca Fancellu --- Changes from v1: - removed 2 method from class ReportEntry that landed there by a mistake on rebase. - Made the script compatible also with python2 (Stefano) --- xen/scripts/diff-report.py| 80 ++ .../xen_analysis/diff_tool/__init__.py| 0 .../xen_analysis/diff_tool/cppcheck_report.py | 44 xen/scripts/xen_analysis/diff_tool/debug.py | 40 +++ xen/scripts/xen_analysis/diff_tool/report.py | 100 ++ 5 files changed, 264 insertions(+) create mode 100755 xen/scripts/diff-report.py create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py diff --git a/xen/scripts/diff-report.py b/xen/scripts/diff-report.py new file mode 100755 index ..f97cb2355cc3 --- /dev/null +++ b/xen/scripts/diff-report.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +from __future__ import print_function +import os +import sys +from argparse import ArgumentParser +from xen_analysis.diff_tool.cppcheck_report import CppcheckReport +from xen_analysis.diff_tool.debug import Debug +from xen_analysis.diff_tool.report import ReportError + + +def log_info(text, end='\n'): +# type: (str, str) -> None +global args +global file_out + +if (args.verbose): +print(text, end=end, file=file_out) + + +def main(argv): +# type: (list) -> None +global args +global file_out + +parser = ArgumentParser(prog="diff-report.py") +parser.add_argument("-b", "--baseline", required=True, type=str, +help="Path to the baseline report.") +parser.add_argument("--debug", action='store_true', +help="Produce intermediate reports during operations.") +parser.add_argument("-o", "--out", default="stdout", type=str, +help="Where to print the tool output. Default is " + "stdout") +parser.add_argument("-r", "--report", required=True, type=str, +help="Path to the 'check report', the one checked " + "against the baseline.") +parser.add_argument("-v", "--verbose", action='store_true', +help="Print more informations during the run.") + +args = parser.parse_args() + +if args.out == "stdout": +file_out = sys.stdout +else: +try: +file_out = open(args.out, "wt") +except OSError as e: +print("ERROR: Issue opening file {}: {}".format(args.out, e)) +sys.exit(1) + +debug = Debug(args) + +try: +baseline_path = os.path.realpath(args.baseline) +log_info("Loading baseline report {}".format(baseline_path), "") +baseline = CppcheckReport(baseline_path) +baseline.parse() +debug.debug_print_parsed_report(baseline) +log_info(" [OK]") +new_rep_path = os.path.realpath(args.report) +log_info("Loading check report {}".format(new_rep_path), "") +new_rep = CppcheckReport(new_rep_path) +new_rep.parse() +debug.debug_print_parsed_report(new_rep) +log_info(" [OK]") +except ReportError as e: +print("ERROR: {}".format(e)) +sys.exit(1) + +output = new_rep - baseline +print(output, end="", file=file_out) + +if len(output) > 0: +sys.exit(1) + +sys.exit(0) + + +if __name__ == "__main__": +main(sys.argv[1:]) diff --git a/xen/scripts/xen_analysis/diff_tool/__init__.py b/xen/scripts/xen_analysis/diff_tool/__init__.py new file mode 100644 index ..e69de29bb2d1 diff --git a/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py new file mode 100644 index ..e7e80a9dde84 --- /dev/null +++ b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import re +from .report import Report, ReportError + + +class CppcheckReport(Report): +def __init__(self, report_path): +# type: (str) -> None +super(CppcheckReport, self).__init__(report_path) +# This matches a string like: +# path/to/file.c(,): +# and captures file name path and line number +# the last capture group is used for text substitution in __str__ +self.__report_entry_regex = re.compile(r'^(.*)\((\d+)(,\d+\):.*)$') + +def parse(self): +# type: () -> None +report_p
Re: [PATCH 1/2] xen/misra: add diff-report.py tool
> On 17 May 2023, at 02:26, Stefano Stabellini wrote: > > On Thu, 4 May 2023, Luca Fancellu wrote: >> Add a new tool, diff-report.py that can be used to make diff between >> reports generated by xen-analysis.py tool. >> Currently this tool supports the Xen cppcheck text report format in >> its operations. >> >> The tool prints every finding that is in the report passed with -r >> (check report) which is not in the report passed with -b (baseline). >> >> Signed-off-by: Luca Fancellu > > Acked-by: Stefano Stabellini > Tested-by: Stefano Stabellini Thank you Stefano for taking the time to review and test it, I will push the new version of the serie with the stale functions removed and I will add your A-by and T-by. Cheers, Luca
Re: [PATCH 1/2] xen/misra: add diff-report.py tool
On Thu, 4 May 2023, Luca Fancellu wrote: > Add a new tool, diff-report.py that can be used to make diff between > reports generated by xen-analysis.py tool. > Currently this tool supports the Xen cppcheck text report format in > its operations. > > The tool prints every finding that is in the report passed with -r > (check report) which is not in the report passed with -b (baseline). > > Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini > --- > xen/scripts/diff-report.py| 76 > .../xen_analysis/diff_tool/__init__.py| 0 > .../xen_analysis/diff_tool/cppcheck_report.py | 41 +++ > xen/scripts/xen_analysis/diff_tool/debug.py | 36 ++ > xen/scripts/xen_analysis/diff_tool/report.py | 114 ++ > 5 files changed, 267 insertions(+) > create mode 100755 xen/scripts/diff-report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py > > diff --git a/xen/scripts/diff-report.py b/xen/scripts/diff-report.py > new file mode 100755 > index ..4913fb43a8f9 > --- /dev/null > +++ b/xen/scripts/diff-report.py > @@ -0,0 +1,76 @@ > +#!/usr/bin/env python3 > + > +import os, sys > +from argparse import ArgumentParser > +from xen_analysis.diff_tool.debug import Debug > +from xen_analysis.diff_tool.report import ReportError > +from xen_analysis.diff_tool.cppcheck_report import CppcheckReport > + > + > +def log_info(text, end='\n'): > +global args > +global file_out > + > +if (args.verbose): > +print(text, end=end, file=file_out) > + > + > +def main(argv): > +global args > +global file_out > + > +parser = ArgumentParser(prog="diff-report.py") > +parser.add_argument("-b", "--baseline", required=True, type=str, > +help="Path to the baseline report.") > +parser.add_argument("--debug", action='store_true', > +help="Produce intermediate reports during > operations.") > +parser.add_argument("-o", "--out", default="stdout", type=str, > +help="Where to print the tool output. Default is " > + "stdout") > +parser.add_argument("-r", "--report", required=True, type=str, > +help="Path to the 'check report', the one checked " > + "against the baseline.") > +parser.add_argument("-v", "--verbose", action='store_true', > +help="Print more informations during the run.") > + > +args = parser.parse_args() > + > +if args.out == "stdout": > +file_out = sys.stdout > +else: > +try: > +file_out = open(args.out, "wt") > +except OSError as e: > +print("ERROR: Issue opening file {}: {}".format(args.out, e)) > +sys.exit(1) > + > +debug = Debug(args) > + > +try: > +baseline_path = os.path.realpath(args.baseline) > +log_info("Loading baseline report {}".format(baseline_path), "") > +baseline = CppcheckReport(baseline_path) > +baseline.parse() > +debug.debug_print_parsed_report(baseline) > +log_info(" [OK]") > +new_rep_path = os.path.realpath(args.report) > +log_info("Loading check report {}".format(new_rep_path), "") > +new_rep = CppcheckReport(new_rep_path) > +new_rep.parse() > +debug.debug_print_parsed_report(new_rep) > +log_info(" [OK]") > +except ReportError as e: > +print("ERROR: {}".format(e)) > +sys.exit(1) > + > +output = new_rep - baseline > +print(output, end="", file=file_out) > + > +if len(output) > 0: > +sys.exit(1) > + > +sys.exit(0) > + > + > +if __name__ == "__main__": > +main(sys.argv[1:]) > diff --git a/xen/scripts/xen_analysis/diff_tool/__init__.py > b/xen/scripts/xen_analysis/diff_tool/__init__.py > new file mode 100644 > index ..e69de29bb2d1 > diff --git a/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > new file mode 100644 > index ..787a51aca583 > --- /dev/null > +++ b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > @@ -0,0 +1,41 @@ > +#!/usr/bin/env python3 > + > +import re > +from .report import Report, ReportError > + > + > +class CppcheckReport(Report): > +def __init__(self, report_path: str) -> None: > +super().__init__(report_path) > +# This matches a string like: > +# path/to/file.c(,): > +# and captures file name path and line number > +# the last capture group is used for text substitution in __str__ > +self.__report_entry_regex = re.compile(r'^(.*)\((\d+)(,\d+\):.*)$') > + > +def par
Re: [PATCH 1/2] xen/misra: add diff-report.py tool
> On 4 May 2023, at 15:25, Luca Fancellu wrote: > > Add a new tool, diff-report.py that can be used to make diff between > reports generated by xen-analysis.py tool. > Currently this tool supports the Xen cppcheck text report format in > its operations. > > The tool prints every finding that is in the report passed with -r > (check report) which is not in the report passed with -b (baseline). > > Signed-off-by: Luca Fancellu > --- > xen/scripts/diff-report.py| 76 > .../xen_analysis/diff_tool/__init__.py| 0 > .../xen_analysis/diff_tool/cppcheck_report.py | 41 +++ > xen/scripts/xen_analysis/diff_tool/debug.py | 36 ++ > xen/scripts/xen_analysis/diff_tool/report.py | 114 ++ > 5 files changed, 267 insertions(+) > create mode 100755 xen/scripts/diff-report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py > create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py > > diff --git a/xen/scripts/diff-report.py b/xen/scripts/diff-report.py > new file mode 100755 > index ..4913fb43a8f9 > --- /dev/null > +++ b/xen/scripts/diff-report.py > @@ -0,0 +1,76 @@ > +#!/usr/bin/env python3 > + > +import os, sys > +from argparse import ArgumentParser > +from xen_analysis.diff_tool.debug import Debug > +from xen_analysis.diff_tool.report import ReportError > +from xen_analysis.diff_tool.cppcheck_report import CppcheckReport > + > + > +def log_info(text, end='\n'): > +global args > +global file_out > + > +if (args.verbose): > +print(text, end=end, file=file_out) > + > + > +def main(argv): > +global args > +global file_out > + > +parser = ArgumentParser(prog="diff-report.py") > +parser.add_argument("-b", "--baseline", required=True, type=str, > +help="Path to the baseline report.") > +parser.add_argument("--debug", action='store_true', > +help="Produce intermediate reports during > operations.") > +parser.add_argument("-o", "--out", default="stdout", type=str, > +help="Where to print the tool output. Default is " > + "stdout") > +parser.add_argument("-r", "--report", required=True, type=str, > +help="Path to the 'check report', the one checked " > + "against the baseline.") > +parser.add_argument("-v", "--verbose", action='store_true', > +help="Print more informations during the run.") > + > +args = parser.parse_args() > + > +if args.out == "stdout": > +file_out = sys.stdout > +else: > +try: > +file_out = open(args.out, "wt") > +except OSError as e: > +print("ERROR: Issue opening file {}: {}".format(args.out, e)) > +sys.exit(1) > + > +debug = Debug(args) > + > +try: > +baseline_path = os.path.realpath(args.baseline) > +log_info("Loading baseline report {}".format(baseline_path), "") > +baseline = CppcheckReport(baseline_path) > +baseline.parse() > +debug.debug_print_parsed_report(baseline) > +log_info(" [OK]") > +new_rep_path = os.path.realpath(args.report) > +log_info("Loading check report {}".format(new_rep_path), "") > +new_rep = CppcheckReport(new_rep_path) > +new_rep.parse() > +debug.debug_print_parsed_report(new_rep) > +log_info(" [OK]") > +except ReportError as e: > +print("ERROR: {}".format(e)) > +sys.exit(1) > + > +output = new_rep - baseline > +print(output, end="", file=file_out) > + > +if len(output) > 0: > +sys.exit(1) > + > +sys.exit(0) > + > + > +if __name__ == "__main__": > +main(sys.argv[1:]) > diff --git a/xen/scripts/xen_analysis/diff_tool/__init__.py > b/xen/scripts/xen_analysis/diff_tool/__init__.py > new file mode 100644 > index ..e69de29bb2d1 > diff --git a/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > new file mode 100644 > index ..787a51aca583 > --- /dev/null > +++ b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py > @@ -0,0 +1,41 @@ > +#!/usr/bin/env python3 > + > +import re > +from .report import Report, ReportError > + > + > +class CppcheckReport(Report): > +def __init__(self, report_path: str) -> None: > +super().__init__(report_path) > +# This matches a string like: > +# path/to/file.c(,): > +# and captures file name path and line number > +# the last capture group is used for text substitution in __str__ > +self.__report_entry_regex = re.compile(r'^(.*)\((\d+)(,\d+\):.*)$') > + > +def parse(self) -> None: > +report_path = self.get_report_pat
[PATCH 1/2] xen/misra: add diff-report.py tool
Add a new tool, diff-report.py that can be used to make diff between reports generated by xen-analysis.py tool. Currently this tool supports the Xen cppcheck text report format in its operations. The tool prints every finding that is in the report passed with -r (check report) which is not in the report passed with -b (baseline). Signed-off-by: Luca Fancellu --- xen/scripts/diff-report.py| 76 .../xen_analysis/diff_tool/__init__.py| 0 .../xen_analysis/diff_tool/cppcheck_report.py | 41 +++ xen/scripts/xen_analysis/diff_tool/debug.py | 36 ++ xen/scripts/xen_analysis/diff_tool/report.py | 114 ++ 5 files changed, 267 insertions(+) create mode 100755 xen/scripts/diff-report.py create mode 100644 xen/scripts/xen_analysis/diff_tool/__init__.py create mode 100644 xen/scripts/xen_analysis/diff_tool/cppcheck_report.py create mode 100644 xen/scripts/xen_analysis/diff_tool/debug.py create mode 100644 xen/scripts/xen_analysis/diff_tool/report.py diff --git a/xen/scripts/diff-report.py b/xen/scripts/diff-report.py new file mode 100755 index ..4913fb43a8f9 --- /dev/null +++ b/xen/scripts/diff-report.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import os, sys +from argparse import ArgumentParser +from xen_analysis.diff_tool.debug import Debug +from xen_analysis.diff_tool.report import ReportError +from xen_analysis.diff_tool.cppcheck_report import CppcheckReport + + +def log_info(text, end='\n'): +global args +global file_out + +if (args.verbose): +print(text, end=end, file=file_out) + + +def main(argv): +global args +global file_out + +parser = ArgumentParser(prog="diff-report.py") +parser.add_argument("-b", "--baseline", required=True, type=str, +help="Path to the baseline report.") +parser.add_argument("--debug", action='store_true', +help="Produce intermediate reports during operations.") +parser.add_argument("-o", "--out", default="stdout", type=str, +help="Where to print the tool output. Default is " + "stdout") +parser.add_argument("-r", "--report", required=True, type=str, +help="Path to the 'check report', the one checked " + "against the baseline.") +parser.add_argument("-v", "--verbose", action='store_true', +help="Print more informations during the run.") + +args = parser.parse_args() + +if args.out == "stdout": +file_out = sys.stdout +else: +try: +file_out = open(args.out, "wt") +except OSError as e: +print("ERROR: Issue opening file {}: {}".format(args.out, e)) +sys.exit(1) + +debug = Debug(args) + +try: +baseline_path = os.path.realpath(args.baseline) +log_info("Loading baseline report {}".format(baseline_path), "") +baseline = CppcheckReport(baseline_path) +baseline.parse() +debug.debug_print_parsed_report(baseline) +log_info(" [OK]") +new_rep_path = os.path.realpath(args.report) +log_info("Loading check report {}".format(new_rep_path), "") +new_rep = CppcheckReport(new_rep_path) +new_rep.parse() +debug.debug_print_parsed_report(new_rep) +log_info(" [OK]") +except ReportError as e: +print("ERROR: {}".format(e)) +sys.exit(1) + +output = new_rep - baseline +print(output, end="", file=file_out) + +if len(output) > 0: +sys.exit(1) + +sys.exit(0) + + +if __name__ == "__main__": +main(sys.argv[1:]) diff --git a/xen/scripts/xen_analysis/diff_tool/__init__.py b/xen/scripts/xen_analysis/diff_tool/__init__.py new file mode 100644 index ..e69de29bb2d1 diff --git a/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py new file mode 100644 index ..787a51aca583 --- /dev/null +++ b/xen/scripts/xen_analysis/diff_tool/cppcheck_report.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import re +from .report import Report, ReportError + + +class CppcheckReport(Report): +def __init__(self, report_path: str) -> None: +super().__init__(report_path) +# This matches a string like: +# path/to/file.c(,): +# and captures file name path and line number +# the last capture group is used for text substitution in __str__ +self.__report_entry_regex = re.compile(r'^(.*)\((\d+)(,\d+\):.*)$') + +def parse(self) -> None: +report_path = self.get_report_path() +try: +with open(report_path, "rt") as infile: +report_lines = infile.readlines() +except OSError as e: +raise ReportError("Issue with reading file {}: {}" + .format(report_path, e)) +for line in report_lines: +