From patchwork Fri May 19 09:30:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13247978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BBC0C77B7A for ; Fri, 19 May 2023 09:30:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.536849.835551 (Exim 4.92) (envelope-from ) id 1pzwRV-00038y-L9; Fri, 19 May 2023 09:30:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 536849.835551; Fri, 19 May 2023 09:30:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzwRV-00038n-Gt; Fri, 19 May 2023 09:30:33 +0000 Received: by outflank-mailman (input) for mailman id 536849; Fri, 19 May 2023 09:30:32 +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 1pzwRU-00038Z-ER for xen-devel@lists.xenproject.org; Fri, 19 May 2023 09:30:32 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id cc6e24ca-f627-11ed-b22d-6b7b168915f2; Fri, 19 May 2023 11:30:31 +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 AEEC62F4; Fri, 19 May 2023 02:31:15 -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 9D3123F73F; Fri, 19 May 2023 02:30:29 -0700 (PDT) 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: cc6e24ca-f627-11ed-b22d-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 1/3] xen/misra: xen-analysis.py: Improve the cppcheck version check Date: Fri, 19 May 2023 10:30:17 +0100 Message-Id: <20230519093019.2131896-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230519093019.2131896-1-luca.fancellu@arm.com> References: <20230519093019.2131896-1-luca.fancellu@arm.com> MIME-Version: 1.0 Use tuple comparison to check the cppcheck version. Take the occasion to harden the regex, escaping the dots so that we check for them instead of generic characters. Suggested-by: Andrew Cooper Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini --- xen/scripts/xen_analysis/cppcheck_analysis.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py index c8abbe0fca79..8dc45e653b79 100644 --- a/xen/scripts/xen_analysis/cppcheck_analysis.py +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py @@ -157,7 +157,7 @@ def generate_cppcheck_deps(): "Error occured retrieving cppcheck version:\n{}\n\n{}" ) - version_regex = re.search('^Cppcheck (\d+).(\d+)(?:.\d+)?$', + version_regex = re.search('^Cppcheck (\d+)\.(\d+)(?:\.\d+)?$', invoke_cppcheck, flags=re.M) # Currently, only cppcheck version >= 2.7 is supported, but version 2.8 is # known to be broken, please refer to docs/misra/cppcheck.txt @@ -166,15 +166,10 @@ def generate_cppcheck_deps(): "Can't find cppcheck version or version not identified: " "{}".format(invoke_cppcheck) ) - major = int(version_regex.group(1)) - minor = int(version_regex.group(2)) - if major < 2 or (major == 2 and minor < 7): + version = (int(version_regex.group(1)), int(version_regex.group(2))) + if version < (2, 7) or version == (2, 8): raise CppcheckDepsPhaseError( - "Cppcheck version < 2.7 is not supported" - ) - if major == 2 and minor == 8: - raise CppcheckDepsPhaseError( - "Cppcheck version 2.8 is known to be broken, see the documentation" + "Cppcheck version < 2.7 or 2.8 are not supported" ) # If misra option is selected, append misra addon and generate cppcheck From patchwork Fri May 19 09:30:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13247979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9B31C7EE29 for ; Fri, 19 May 2023 09:30:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.536851.835571 (Exim 4.92) (envelope-from ) id 1pzwRX-0003dn-5S; Fri, 19 May 2023 09:30:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 536851.835571; Fri, 19 May 2023 09:30:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzwRX-0003dg-1t; Fri, 19 May 2023 09:30:35 +0000 Received: by outflank-mailman (input) for mailman id 536851; Fri, 19 May 2023 09:30:33 +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 1pzwRV-00038Z-G5 for xen-devel@lists.xenproject.org; Fri, 19 May 2023 09:30:33 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id cd4ebcb5-f627-11ed-b22d-6b7b168915f2; Fri, 19 May 2023 11:30:32 +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 2864015BF; Fri, 19 May 2023 02:31:17 -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 16E1C3F73F; Fri, 19 May 2023 02:30:30 -0700 (PDT) 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: cd4ebcb5-f627-11ed-b22d-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: Fix latent bug Date: Fri, 19 May 2023 10:30:18 +0100 Message-Id: <20230519093019.2131896-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230519093019.2131896-1-luca.fancellu@arm.com> References: <20230519093019.2131896-1-luca.fancellu@arm.com> MIME-Version: 1.0 Currenly there is a latent bug that is not triggered because the function cppcheck_merge_txt_fragments is called with the parameter strip_paths having a list of only one element. The bug is that the split function should not be in the loop for strip_paths, but one level before, fix it. Fixes: 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script") Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini --- xen/scripts/xen_analysis/cppcheck_report_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/scripts/xen_analysis/cppcheck_report_utils.py index c5f466aff141..fdc299c7e029 100644 --- a/xen/scripts/xen_analysis/cppcheck_report_utils.py +++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py @@ -104,8 +104,8 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): for path in strip_paths: text_report_content[i] = text_report_content[i].replace( path + "/", "") - # Split by : separator - text_report_content[i] = text_report_content[i].split(":") + # Split by : separator + text_report_content[i] = text_report_content[i].split(":") # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name) From patchwork Fri May 19 09:30:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13247980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED930C77B7A for ; Fri, 19 May 2023 09:30:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.536852.835581 (Exim 4.92) (envelope-from ) id 1pzwRY-0003uy-JO; Fri, 19 May 2023 09:30:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 536852.835581; Fri, 19 May 2023 09:30:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pzwRY-0003uo-GL; Fri, 19 May 2023 09:30:36 +0000 Received: by outflank-mailman (input) for mailman id 536852; Fri, 19 May 2023 09:30:35 +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 1pzwRX-00038Z-3N for xen-devel@lists.xenproject.org; Fri, 19 May 2023 09:30:35 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id ce3f963c-f627-11ed-b22d-6b7b168915f2; Fri, 19 May 2023 11:30:34 +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 B1CD615DB; Fri, 19 May 2023 02:31:18 -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 84D9D3F73F; Fri, 19 May 2023 02:30:32 -0700 (PDT) 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: ce3f963c-f627-11ed-b22d-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 , Michal Orzel Subject: [PATCH 3/3] xen/misra: xen-analysis.py: Fix cppcheck report relative paths Date: Fri, 19 May 2023 10:30:19 +0100 Message-Id: <20230519093019.2131896-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230519093019.2131896-1-luca.fancellu@arm.com> References: <20230519093019.2131896-1-luca.fancellu@arm.com> MIME-Version: 1.0 Fix the generation of the relative path from the repo, for cppcheck reports, when the script is launching make with in-tree build. Fixes: b046f7e37489 ("xen/misra: xen-analysis.py: use the relative path from the ...") Reported-by: Michal Orzel Signed-off-by: Luca Fancellu Acked-by: Stefano Stabellini Tested-by: Stefano Stabellini --- .../xen_analysis/cppcheck_report_utils.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/scripts/xen_analysis/cppcheck_report_utils.py index fdc299c7e029..10100f6c6a57 100644 --- a/xen/scripts/xen_analysis/cppcheck_report_utils.py +++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os +import os, re +from . import settings from xml.etree import ElementTree class CppcheckHTMLReportError(Exception): @@ -101,12 +102,28 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): text_report_content = list(text_report_content) # Strip path from report lines for i in list(range(0, len(text_report_content))): - for path in strip_paths: - text_report_content[i] = text_report_content[i].replace( - path + "/", "") # Split by : separator text_report_content[i] = text_report_content[i].split(":") + for path in strip_paths: + text_report_content[i][0] = \ + text_report_content[i][0].replace(path + "/", "") + + # When the compilation is in-tree, the makefile places + # the directory in /xen/xen, making cppcheck produce + # relative path from there, so check if "xen/" is a prefix + # of the path and if it's not, check if it can be added to + # have a relative path from the repository instead of from + # /xen/xen + if not text_report_content[i][0].startswith("xen/"): + # cppcheck first entry is in this format: + # path/to/file(line,cols), remove (line,cols) + cppcheck_file = re.sub(r'\(.*\)', '', + text_report_content[i][0]) + if os.path.isfile(settings.xen_dir + "/" + cppcheck_file): + text_report_content[i][0] = \ + "xen/" + text_report_content[i][0] + # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name) text_report_content.sort(key = lambda x: (x[1], x[0]))