From nobody Sun May 5 13:00:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1675076558503179.5727750854212; Mon, 30 Jan 2023 03:02:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.486882.754282 (Exim 4.92) (envelope-from ) id 1pMRv5-00010c-1G; Mon, 30 Jan 2023 11:01:51 +0000 Received: by outflank-mailman (output) from mailman id 486882.754282; Mon, 30 Jan 2023 11:01:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMRv4-0000zr-TU; Mon, 30 Jan 2023 11:01:50 +0000 Received: by outflank-mailman (input) for mailman id 486882; Mon, 30 Jan 2023 11:01:50 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMRv4-0000xa-1D for xen-devel@lists.xenproject.org; Mon, 30 Jan 2023 11:01:50 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7d21635d-a08d-11ed-b8d1-410ff93cb8f0; Mon, 30 Jan 2023 12:01:47 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7B02D16F3; Mon, 30 Jan 2023 03:02:28 -0800 (PST) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 268BC3F71E; Mon, 30 Jan 2023 03:01:45 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7d21635d-a08d-11ed-b8d1-410ff93cb8f0 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, wei.chen@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Michal Orzel Subject: [PATCH v2 1/2] xen/cppcheck: sort alphabetically cppcheck report entries Date: Mon, 30 Jan 2023 11:01:31 +0000 Message-Id: <20230130110132.2774782-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230130110132.2774782-1-luca.fancellu@arm.com> References: <20230130110132.2774782-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1675076560369100003 Sort alphabetically cppcheck report entries when producing the text report, this will help comparing different reports and will group together findings from the same file. The sort operation is performed with two criteria, the first one is sorting by misra rule, the second one is sorting by file. Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Reviewed-by: Michal Orzel --- Changes in v2: - Sort with two criteria, first misra rule, second filename (Michal, Jan) --- --- xen/scripts/xen_analysis/cppcheck_report_utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/script= s/xen_analysis/cppcheck_report_utils.py index 02440aefdfec..0b6cc72b9ac1 100644 --- a/xen/scripts/xen_analysis/cppcheck_report_utils.py +++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py @@ -104,6 +104,13 @@ def cppcheck_merge_txt_fragments(fragments_list, out_t= xt_file, strip_paths): for path in strip_paths: text_report_content[i] =3D text_report_content[i].repl= ace( path + "/"= , "") + # Split by : separator + text_report_content[i] =3D text_report_content[i].spli= t(":") + # sort alphabetically for second field (misra rule) and as sec= ond + # criteria for the first field (file name) + text_report_content.sort(key =3D lambda x: (x[1], x[0])) + # merge back with : separator + text_report_content =3D [":".join(x) for x in text_report_cont= ent] #=C2=A0Write the final text report outfile.writelines(text_report_content) except OSError as e: --=20 2.25.1 From nobody Sun May 5 13:00:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1675076556379365.6228014690623; Mon, 30 Jan 2023 03:02:36 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.486883.754297 (Exim 4.92) (envelope-from ) id 1pMRv6-0001S1-82; Mon, 30 Jan 2023 11:01:52 +0000 Received: by outflank-mailman (output) from mailman id 486883.754297; Mon, 30 Jan 2023 11:01:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMRv6-0001Ru-5C; Mon, 30 Jan 2023 11:01:52 +0000 Received: by outflank-mailman (input) for mailman id 486883; Mon, 30 Jan 2023 11:01:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMRv4-0000xg-Ss for xen-devel@lists.xenproject.org; Mon, 30 Jan 2023 11:01:51 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7df2c5c9-a08d-11ed-9ec0-891035b88211; Mon, 30 Jan 2023 12:01:49 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E0DDF16F8; Mon, 30 Jan 2023 03:02:29 -0800 (PST) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A9FC63F71E; Mon, 30 Jan 2023 03:01:46 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7df2c5c9-a08d-11ed-9ec0-891035b88211 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, wei.chen@arm.com, Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v2 2/2] xen/cppcheck: add parameter to skip given MISRA rules Date: Mon, 30 Jan 2023 11:01:32 +0000 Message-Id: <20230130110132.2774782-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230130110132.2774782-1-luca.fancellu@arm.com> References: <20230130110132.2774782-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1675076558592100001 Content-Type: text/plain; charset="utf-8" Add parameter to skip the passed MISRA rules during the cppcheck analysis, the rules are specified as a list of comma separated rules with the MISRA number notation (e.g. 1.1,1.3,...). Modify convert_misra_doc.py script to take an extra parameter giving a list of MISRA rule to be skipped, comma separated. While there, fix some typos in the help and print functions. Modify settings.py and cppcheck_analysis.py to have a new parameter (--cppcheck-skip-rules) used to specify a list of MISRA rule to be skipped during the cppcheck analysis. Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini --- Changes in v2: - Add Ack-by (Stefano) --- --- xen/scripts/xen_analysis/cppcheck_analysis.py | 8 +++-- xen/scripts/xen_analysis/settings.py | 35 +++++++++++-------- xen/tools/convert_misra_doc.py | 28 ++++++++++----- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xe= n_analysis/cppcheck_analysis.py index 0e952a169641..cc1f403d315e 100644 --- a/xen/scripts/xen_analysis/cppcheck_analysis.py +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py @@ -153,11 +153,15 @@ def generate_cppcheck_deps(): if settings.cppcheck_misra: cppcheck_flags =3D cppcheck_flags + " --addon=3Dcppcheck-misra.jso= n" =20 + skip_rules_arg =3D "" + if settings.cppcheck_skip_rules !=3D "": + skip_rules_arg =3D "-s {}".format(settings.cppcheck_skip_rules) + utils.invoke_command( "{}/convert_misra_doc.py -i {}/docs/misra/rules.rst" - " -o {}/cppcheck-misra.txt -j {}/cppcheck-misra.json" + " -o {}/cppcheck-misra.txt -j {}/cppcheck-misra.json {}" .format(settings.tools_dir, settings.repo_dir, - settings.outdir, settings.outdir), + settings.outdir, settings.outdir, skip_rules_arg), False, CppcheckDepsPhaseError, "An error occured when running:\n{}" ) diff --git a/xen/scripts/xen_analysis/settings.py b/xen/scripts/xen_analysi= s/settings.py index a8502e554e95..8c0d357fe0dc 100644 --- a/xen/scripts/xen_analysis/settings.py +++ b/xen/scripts/xen_analysis/settings.py @@ -24,6 +24,7 @@ cppcheck_binpath =3D "cppcheck" cppcheck_html =3D False cppcheck_htmlreport_binpath =3D "cppcheck-htmlreport" cppcheck_misra =3D False +cppcheck_skip_rules =3D "" make_forward_args =3D "" outdir =3D xen_dir =20 @@ -53,20 +54,22 @@ Cppcheck report creation phase runs only when --run-cpp= check is passed to the script. =20 Options: - --build-only Run only the commands to build Xen with the option= al - make arguments passed to the script - --clean-only Run only the commands to clean the analysis artifa= cts - --cppcheck-bin=3D Path to the cppcheck binary (Default: {}) - --cppcheck-html Produce an additional HTML output report for Cppch= eck - --cppcheck-html-bin=3D Path to the cppcheck-html binary (Default: {}) - --cppcheck-misra Activate the Cppcheck MISRA analysis - --distclean Clean analysis artifacts and reports - -h, --help Print this help - --no-build Skip the build Xen phase - --no-clean Don\'t clean the analysis artifacts on exit - --run-coverity Run the analysis for the Coverity tool - --run-cppcheck Run the Cppcheck analysis tool on Xen - --run-eclair Run the analysis for the Eclair tool + --build-only Run only the commands to build Xen with the opti= onal + make arguments passed to the script + --clean-only Run only the commands to clean the analysis arti= facts + --cppcheck-bin=3D Path to the cppcheck binary (Default: {}) + --cppcheck-html Produce an additional HTML output report for Cpp= check + --cppcheck-html-bin=3D Path to the cppcheck-html binary (Default: {}) + --cppcheck-misra Activate the Cppcheck MISRA analysis + --cppcheck-skip-rules=3D List of MISRA rules to be skipped, comma separ= ated. + (e.g. --cppcheck-skip-rules=3D1.1,20.7,8.4) + --distclean Clean analysis artifacts and reports + -h, --help Print this help + --no-build Skip the build Xen phase + --no-clean Don\'t clean the analysis artifacts on exit + --run-coverity Run the analysis for the Coverity tool + --run-cppcheck Run the Cppcheck analysis tool on Xen + --run-eclair Run the analysis for the Eclair tool """ print(msg.format(sys.argv[0], cppcheck_binpath, cppcheck_htmlreport_binpath)) @@ -78,6 +81,7 @@ def parse_commandline(argv): global cppcheck_html global cppcheck_htmlreport_binpath global cppcheck_misra + global cppcheck_skip_rules global make_forward_args global outdir global step_get_make_vars @@ -115,6 +119,9 @@ def parse_commandline(argv): cppcheck_htmlreport_binpath =3D args_with_content_regex.group(= 2) elif option =3D=3D "--cppcheck-misra": cppcheck_misra =3D True + elif args_with_content_regex and \ + args_with_content_regex.group(1) =3D=3D "--cppcheck-skip-rule= s": + cppcheck_skip_rules =3D args_with_content_regex.group(2) elif option =3D=3D "--distclean": target_distclean =3D True elif (option =3D=3D "--help") or (option =3D=3D "-h"): diff --git a/xen/tools/convert_misra_doc.py b/xen/tools/convert_misra_doc.py index 13074d8a2e91..8984ec625fa7 100755 --- a/xen/tools/convert_misra_doc.py +++ b/xen/tools/convert_misra_doc.py @@ -4,12 +4,14 @@ This script is converting the misra documentation RST file into a text file that can be used as text-rules for cppcheck. Usage: - convert_misr_doc.py -i INPUT [-o OUTPUT] [-j JSON] + convert_misra_doc.py -i INPUT [-o OUTPUT] [-j JSON] [-s RULES,[...,RUL= ES]] =20 INPUT - RST file containing the list of misra rules. OUTPUT - file to store the text output to be used by cppcheck. If not specified, the result will be printed to stdout. JSON - cppcheck json file to be created (optional). + RULES - list of rules to skip during the analysis, comma separated + (e.g. 1.1,1.2,1.3,...) """ =20 import sys, getopt, re @@ -47,21 +49,25 @@ def main(argv): outfile =3D '' outstr =3D sys.stdout jsonfile =3D '' + force_skip =3D '' =20 try: - opts, args =3D getopt.getopt(argv,"hi:o:j:",["input=3D","output=3D= ","json=3D"]) + opts, args =3D getopt.getopt(argv,"hi:o:j:s:", + ["input=3D","output=3D","json=3D","skip= =3D"]) except getopt.GetoptError: - print('convert-misra.py -i [-o ] [-j ') + print('convert-misra.py -i [-o ] [-j ] [-s <= rules>]') sys.exit(2) for opt, arg in opts: if opt =3D=3D '-h': - print('convert-misra.py -i [-o ] [-j ') + print('convert-misra.py -i [-o ] [-j ] [= -s ]') print(' If output is not specified, print to stdout') sys.exit(1) elif opt in ("-i", "--input"): infile =3D arg elif opt in ("-o", "--output"): outfile =3D arg + elif opt in ("-s", "--skip"): + force_skip =3D arg elif opt in ("-j", "--json"): jsonfile =3D arg =20 @@ -169,14 +175,18 @@ def main(argv): =20 skip_list =3D [] =20 + # Add rules to be skipped anyway + for r in force_skip.split(','): + skip_list.append(r) + # Search for missing rules and add a dummy text with the rule number for i in misra_c2012_rules: for j in list(range(1,misra_c2012_rules[i]+1)): - if str(i) + '.' + str(j) not in rule_list: - outstr.write('Rule ' + str(i) + '.' + str(j) + '\n') - outstr.write('No description for rule ' + str(i) + '.' + s= tr(j) - + '\n') - skip_list.append(str(i) + '.' + str(j)) + rule_str =3D str(i) + '.' + str(j) + if (rule_str not in rule_list) and (rule_str not in skip_list): + outstr.write('Rule ' + rule_str + '\n') + outstr.write('No description for rule ' + rule_str + '\n') + skip_list.append(rule_str) =20 # Make cppcheck happy by starting the appendix outstr.write('Appendix B\n') --=20 2.25.1