From nobody Sun May 19 02:06:39 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 1683206002928224.67196391781818; Thu, 4 May 2023 06:13:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.529727.824440 (Exim 4.92) (envelope-from ) id 1puYlY-0004Q1-O1; Thu, 04 May 2023 13:13:00 +0000 Received: by outflank-mailman (output) from mailman id 529727.824440; Thu, 04 May 2023 13:13:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puYlY-0004Pu-Ku; Thu, 04 May 2023 13:13:00 +0000 Received: by outflank-mailman (input) for mailman id 529727; Thu, 04 May 2023 13:12:59 +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 1puYlX-00049n-Kx for xen-devel@lists.xenproject.org; Thu, 04 May 2023 13:12:59 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 626d8b4b-ea7d-11ed-8611-37d641c3527e; Thu, 04 May 2023 15:12:56 +0200 (CEST) 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 F0003C14; Thu, 4 May 2023 06:13:39 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5F9C63F67D; Thu, 4 May 2023 06:12:54 -0700 (PDT) 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: 626d8b4b-ea7d-11ed-8611-37d641c3527e 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 1/3] xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors Date: Thu, 4 May 2023 14:12:43 +0100 Message-Id: <20230504131245.2985400-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230504131245.2985400-1-luca.fancellu@arm.com> References: <20230504131245.2985400-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1683206003573100003 Content-Type: text/plain; charset="utf-8" Currently Cppcheck has a limitation that prevents to use make with parallel build and have a parallel Cppcheck invocation on each translation unit (the .c files), because of spurious internal errors. The issue comes from the fact that when using the build directory, Cppcheck saves temporary files as .c., but this doesn't work well when files with the same name are being analysed at the same time, leading to race conditions. Fix the issue creating, under the build directory, the same directory structure of the file being analysed to avoid any clash. Fixes: 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py= script") Signed-off-by: Luca Fancellu Reviewed-by: Stefano Stabellini --- xen/scripts/xen_analysis/cppcheck_analysis.py | 8 +++----- xen/tools/cppcheck-cc.sh | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xe= n_analysis/cppcheck_analysis.py index ab52ce38d502..658795bb9f5b 100644 --- a/xen/scripts/xen_analysis/cppcheck_analysis.py +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py @@ -139,7 +139,6 @@ def generate_cppcheck_deps(): # Compiler defines are in compiler-def.h which is included in config.h # cppcheck_flags=3D""" ---cppcheck-build-dir=3D{}/{} --max-ctu-depth=3D10 --enable=3Dstyle,information,missingInclude --template=3D\'{{file}}({{line}},{{column}}):{{id}}:{{severity}}:{{messag= e}}\' @@ -150,8 +149,7 @@ def generate_cppcheck_deps(): --suppress=3D'unusedStructMember:*' --include=3D{}/include/xen/config.h -DCPPCHECK -""".format(settings.outdir, CPPCHECK_BUILD_DIR, settings.xen_dir, - settings.outdir, settings.xen_dir) +""".format(settings.xen_dir, settings.outdir, settings.xen_dir) =20 invoke_cppcheck =3D utils.invoke_command( "{} --version".format(settings.cppcheck_binpath), @@ -204,9 +202,9 @@ def generate_cppcheck_deps(): =20 cppcheck_cc_flags =3D """--compiler=3D{} --cppcheck-cmd=3D{} {} --cppcheck-plat=3D{}/cppcheck-plat --ignore-path=3Dtools/ - --ignore-path=3Darch/x86/efi/check.c + --ignore-path=3Darch/x86/efi/check.c --build-dir=3D{}/{} """.format(xen_cc, settings.cppcheck_binpath, cppcheck_flags, - settings.tools_dir) + settings.tools_dir, settings.outdir, CPPCHECK_BUILD_DIR) =20 if settings.cppcheck_html: cppcheck_cc_flags =3D cppcheck_cc_flags + " --cppcheck-html" diff --git a/xen/tools/cppcheck-cc.sh b/xen/tools/cppcheck-cc.sh index f6728e4c1084..16a965edb7ec 100755 --- a/xen/tools/cppcheck-cc.sh +++ b/xen/tools/cppcheck-cc.sh @@ -24,6 +24,7 @@ Options: EOF } =20 +BUILD_DIR=3D"" CC_FILE=3D"" COMPILER=3D"" CPPCHECK_HTML=3D"n" @@ -66,6 +67,10 @@ do help exit 0 ;; + --build-dir=3D*) + BUILD_DIR=3D"${OPTION#*=3D}" + sm_tool_args=3D"n" + ;; --compiler=3D*) COMPILER=3D"${OPTION#*=3D}" sm_tool_args=3D"n" @@ -107,6 +112,12 @@ then exit 1 fi =20 +if [ "${BUILD_DIR}" =3D "" ] +then + echo "--build-dir arg is mandatory." + exit 1 +fi + function create_jcd() { local line=3D"${1}" local arg_num=3D0 @@ -199,13 +210,18 @@ then exit 1 fi =20 + # Generate build directory for the analysed file + cppcheck_build_dir=3D"${BUILD_DIR}/${OBJTREE_PATH}" + mkdir -p "${cppcheck_build_dir}" + # Shellcheck complains about missing quotes on CPPCHECK_TOOL_ARGS,= but # they can't be used here # shellcheck disable=3DSC2086 ${CPPCHECK_TOOL} ${CPPCHECK_TOOL_ARGS} \ --project=3D"${JDB_FILE}" \ --output-file=3D"${out_file}" \ - --platform=3D"${platform}" + --platform=3D"${platform}" \ + --cppcheck-build-dir=3D${cppcheck_build_dir} =20 if [ "${CPPCHECK_HTML}" =3D "y" ] then @@ -216,6 +232,7 @@ then --project=3D"${JDB_FILE}" \ --output-file=3D"${out_file%.txt}.xml" \ --platform=3D"${platform}" \ + --cppcheck-build-dir=3D${cppcheck_build_dir} \ -q \ --xml fi --=20 2.34.1 From nobody Sun May 19 02:06:39 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 1683205997188351.4634672194611; Thu, 4 May 2023 06:13:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.529726.824430 (Exim 4.92) (envelope-from ) id 1puYlX-00049z-Gr; Thu, 04 May 2023 13:12:59 +0000 Received: by outflank-mailman (output) from mailman id 529726.824430; Thu, 04 May 2023 13:12:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puYlX-00049q-E4; Thu, 04 May 2023 13:12:59 +0000 Received: by outflank-mailman (input) for mailman id 529726; Thu, 04 May 2023 13:12:58 +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 1puYlW-0003tK-9n for xen-devel@lists.xenproject.org; Thu, 04 May 2023 13:12:58 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 633d48c4-ea7d-11ed-b226-6b7b168915f2; Thu, 04 May 2023 15:12:57 +0200 (CEST) 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 6418112FC; Thu, 4 May 2023 06:13:41 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E283A3F67D; Thu, 4 May 2023 06:12:55 -0700 (PDT) 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: 633d48c4-ea7d-11ed-b226-6b7b168915f2 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 2/3] xen/misra: xen-analysis.py: allow cppcheck version above 2.7 Date: Thu, 4 May 2023 14:12:44 +0100 Message-Id: <20230504131245.2985400-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230504131245.2985400-1-luca.fancellu@arm.com> References: <20230504131245.2985400-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1683205998583100001 Content-Type: text/plain; charset="utf-8" Allow the use of Cppcheck version above 2.7, exception for 2.8 which is known and documented do be broken. Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini --- xen/scripts/xen_analysis/cppcheck_analysis.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xe= n_analysis/cppcheck_analysis.py index 658795bb9f5b..c3783e8df343 100644 --- a/xen/scripts/xen_analysis/cppcheck_analysis.py +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py @@ -157,13 +157,25 @@ def generate_cppcheck_deps(): "Error occured retrieving cppcheck version:\n{}\n\n{}" ) =20 - version_regex =3D re.search('^Cppcheck (.*)$', invoke_cppcheck, flags= =3Dre.M) + version_regex =3D re.search('^Cppcheck (\d+).(\d+)(?:.\d+)?$', + invoke_cppcheck, flags=3Dre.M) # Currently, only cppcheck version >=3D 2.7 is supported, but version = 2.8 is # known to be broken, please refer to docs/misra/cppcheck.txt - if (not version_regex) or (not version_regex.group(1).startswith("2.7"= )): + if (not version_regex) or len(version_regex.groups()) < 2: raise CppcheckDepsPhaseError( - "Can't find cppcheck version or version is not 2.7" - ) + "Can't find cppcheck version or version not identified: " + "{}".format(invoke_cppcheck) + ) + major =3D int(version_regex.group(1)) + minor =3D int(version_regex.group(2)) + if major < 2 or (major =3D=3D 2 and minor < 7): + raise CppcheckDepsPhaseError( + "Cppcheck version < 2.7 is not supported" + ) + if major =3D=3D 2 and minor =3D=3D 8: + raise CppcheckDepsPhaseError( + "Cppcheck version 2.8 is known to be broken, see the documenta= tion" + ) =20 # If misra option is selected, append misra addon and generate cppcheck # files for misra analysis --=20 2.34.1 From nobody Sun May 19 02:06:39 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 1683206002821364.8041373073852; Thu, 4 May 2023 06:13:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.529728.824446 (Exim 4.92) (envelope-from ) id 1puYlZ-0004Tv-67; Thu, 04 May 2023 13:13:01 +0000 Received: by outflank-mailman (output) from mailman id 529728.824446; Thu, 04 May 2023 13:13:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1puYlY-0004SZ-UU; Thu, 04 May 2023 13:13:00 +0000 Received: by outflank-mailman (input) for mailman id 529728; Thu, 04 May 2023 13:12:59 +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 1puYlX-0003tK-OS for xen-devel@lists.xenproject.org; Thu, 04 May 2023 13:12:59 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 64104f88-ea7d-11ed-b226-6b7b168915f2; Thu, 04 May 2023 15:12:59 +0200 (CEST) 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 CC979139F; Thu, 4 May 2023 06:13:42 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 56C753F67D; Thu, 4 May 2023 06:12:57 -0700 (PDT) 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: 64104f88-ea7d-11ed-b226-6b7b168915f2 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 3/3] xen/misra: xen-analysis.py: use the relative path from the ... Date: Thu, 4 May 2023 14:12:45 +0100 Message-Id: <20230504131245.2985400-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230504131245.2985400-1-luca.fancellu@arm.com> References: <20230504131245.2985400-1-luca.fancellu@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1683206003278100001 Content-Type: text/plain; charset="utf-8" repository in the reports Currently the cppcheck report entries shows the relative file path from the /xen folder of the repository instead of the base folder. In order to ease the checks, for example, when looking a git diff output and the report, use the repository folder as base. Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini --- xen/scripts/xen_analysis/cppcheck_analysis.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xe= n_analysis/cppcheck_analysis.py index c3783e8df343..c8abbe0fca79 100644 --- a/xen/scripts/xen_analysis/cppcheck_analysis.py +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py @@ -149,7 +149,7 @@ def generate_cppcheck_deps(): --suppress=3D'unusedStructMember:*' --include=3D{}/include/xen/config.h -DCPPCHECK -""".format(settings.xen_dir, settings.outdir, settings.xen_dir) +""".format(settings.repo_dir, settings.outdir, settings.xen_dir) =20 invoke_cppcheck =3D utils.invoke_command( "{} --version".format(settings.cppcheck_binpath), @@ -240,7 +240,7 @@ def generate_cppcheck_report(): try: cppcheck_report_utils.cppcheck_merge_txt_fragments(fragments, report_filename, - [settings.xen_d= ir]) + [settings.repo_= dir]) except cppcheck_report_utils.CppcheckTXTReportError as e: raise CppcheckReportPhaseError(e) =20 @@ -257,7 +257,7 @@ def generate_cppcheck_report(): try: cppcheck_report_utils.cppcheck_merge_xml_fragments(fragments, xml_filenam= e, - settings.xe= n_dir, + settings.re= po_dir, settings.ou= tdir) except cppcheck_report_utils.CppcheckHTMLReportError as e: raise CppcheckReportPhaseError(e) @@ -265,7 +265,7 @@ def generate_cppcheck_report(): utils.invoke_command( "{} --file=3D{} --source-dir=3D{} --report-dir=3D{}/html --tit= le=3DXen" .format(settings.cppcheck_htmlreport_binpath, xml_filename, - settings.xen_dir, html_report_dir), + settings.repo_dir, html_report_dir), False, CppcheckReportPhaseError, "Error occured generating Cppcheck HTML report:\n{}" ) @@ -273,7 +273,7 @@ def generate_cppcheck_report(): html_files =3D utils.recursive_find_file(html_report_dir, r'.*\.ht= ml$') try: cppcheck_report_utils.cppcheck_strip_path_html(html_files, - (settings.xen_d= ir, + (settings.repo_= dir, settings.outdi= r)) except cppcheck_report_utils.CppcheckHTMLReportError as e: raise CppcheckReportPhaseError(e) --=20 2.34.1