All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Fancellu <luca.fancellu@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [RFC PATCH v2 2/8] exclude-list: generalise exclude-list
Date: Tue, 31 Oct 2023 13:22:58 +0000	[thread overview]
Message-ID: <20231031132304.2573924-3-luca.fancellu@arm.com> (raw)
In-Reply-To: <20231031132304.2573924-1-luca.fancellu@arm.com>

Currently exclude-list.json is used by the xen-analysis tool to
remove from the report (cppcheck for now) violations from the
files listed in it, however that list can be used by different
users that might want to exclude some of the files from their
computation for many reason.

So add a new field that can be part of each entry to link
the tool supposed to consider that exclusion.

Update exclusion_file_list.py to implement the logic and update
the documentation to reflect this change.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
 docs/misra/exclude-list.rst                   | 31 ++++++++++++-------
 .../xen_analysis/exclusion_file_list.py       | 16 ++++++++--
 2 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/docs/misra/exclude-list.rst b/docs/misra/exclude-list.rst
index c97431a86120..42dbceb82523 100644
--- a/docs/misra/exclude-list.rst
+++ b/docs/misra/exclude-list.rst
@@ -1,17 +1,16 @@
 .. SPDX-License-Identifier: CC-BY-4.0
 
-Exclude file list for xen-analysis script
-=========================================
+Exclude file list for xen scripts
+=================================
 
-The code analysis is performed on the Xen codebase for both MISRA
-checkers and static analysis checkers, there are some files however that
-needs to be removed from the findings report for various reasons (e.g.
-they are imported from external sources, they generate too many false
-positive results, etc.).
+Different Xen scripts can perform operations on the codebase to check its
+compliance for a set of rules, however Xen contains some files that are taken
+from other projects (e.g. linux) and they can't be updated to ease backporting
+fixes from their source, for this reason the file docs/misra/exclude-list.json
+is kept as a source of all these files that are external to the Xen project.
 
-For this reason the file docs/misra/exclude-list.json is used to exclude every
-entry listed in that file from the final report.
-Currently only the cppcheck analysis will use this file.
+Every entry of the file can be linked to different checkers, so that this list
+can be used by multiple scripts selecting only the required entries.
 
 Here is an example of the exclude-list.json file::
 
@@ -20,11 +19,13 @@ Here is an example of the exclude-list.json file::
 |    "content": [
 |        {
 |            "rel_path": "relative/path/from/xen/file",
-|            "comment": "This file is originated from ..."
+|            "comment": "This file is originated from ...",
+|            "checkers": "xen-analysis"
 |        },
 |        {
 |            "rel_path": "relative/path/from/xen/folder/*",
-|            "comment": "This folder is a library"
+|            "comment": "This folder is a library",
+|            "checkers": "xen-analysis some-checker"
 |        },
 |        {
 |            "rel_path": "relative/path/from/xen/mem*.c",
@@ -39,6 +40,12 @@ Here is an explanation of the fields inside an object of the "content" array:
    match more than one file/folder at the time. This field is mandatory.
  - comment: an optional comment to explain why the file is removed from the
    analysis.
+ - checkers: an optional list of checkers that will exclude this entries from
+   their results. This field is optional and when not specified, it means every
+   checker will use that entry.
+   Current implemented values for this field are:
+    - xen-analysis: the xen-analysis.py script exclude this entry for both MISRA
+      and static analysis scan. (Implemented only for Cppcheck tool)
 
 To ease the review and the modifications of the entries, they shall be listed in
 alphabetical order referring to the rel_path field.
diff --git a/xen/scripts/xen_analysis/exclusion_file_list.py b/xen/scripts/xen_analysis/exclusion_file_list.py
index 79ebd34f55ec..8b10665a19e8 100644
--- a/xen/scripts/xen_analysis/exclusion_file_list.py
+++ b/xen/scripts/xen_analysis/exclusion_file_list.py
@@ -9,7 +9,7 @@ class ExclusionFileListError(Exception):
 
 def cppcheck_exclusion_file_list(input_file):
     ret = []
-    excl_list = load_exclusion_file_list(input_file)
+    excl_list = load_exclusion_file_list(input_file, "xen-analysis")
 
     for entry in excl_list:
         # Prepending * to the relative path to match every path where the Xen
@@ -25,7 +25,7 @@ def cppcheck_exclusion_file_list(input_file):
 # If the first entry contained a wildcard '*', the second entry will have an
 # array of the solved absolute path for that entry.
 # Returns [('path',[path,path,...]), ('path',[path,path,...]), ...]
-def load_exclusion_file_list(input_file):
+def load_exclusion_file_list(input_file, checker=""):
     ret = []
     try:
         with open(input_file, "rt") as handle:
@@ -51,6 +51,18 @@ def load_exclusion_file_list(input_file):
             raise ExclusionFileListError(
                 "Malformed JSON entry: rel_path field not found!"
             )
+        # Check the checker field
+        try:
+            entry_checkers = entry['checkers']
+        except KeyError:
+            # If the field doesn't exists, assume that this entry is for every
+            # checker
+            entry_checkers = checker
+
+        # Check if this entry is for the selected checker
+        if checker not in entry_checkers:
+            continue
+
         abs_path = settings.xen_dir + "/" + path
         check_path = [abs_path]
 
-- 
2.34.1



  parent reply	other threads:[~2023-10-31 13:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 13:22 [RFC PATCH v2 0/8] clang-format for Xen Luca Fancellu
2023-10-31 13:22 ` [RFC PATCH v2 1/8] cppcheck: rework exclusion_file_list.py code Luca Fancellu
2023-10-31 13:22 ` Luca Fancellu [this message]
2023-10-31 13:22 ` [RFC PATCH v2 3/8] [WIP]xen/scripts: add codestyle.py script Luca Fancellu
2023-10-31 13:23 ` [RFC PATCH v2 4/8] exclude-list: add entries to the excluded list for codestyle Luca Fancellu
2023-10-31 13:23 ` [RFC PATCH v2 5/8] [WIP]codestyle.py: Protect generic piece of code Luca Fancellu
2023-10-31 13:23 ` [RFC PATCH v2 6/8] [WIP]x86/exclude-list: protect mm_type_tbl in mtrr from being formatted Luca Fancellu
2023-10-31 13:23 ` [RFC PATCH v2 7/8] xen: Add clang-format configuration Luca Fancellu
2023-11-02  9:10   ` Jan Beulich
2023-11-02 11:41     ` Luca Fancellu
2023-11-02 11:53       ` Jan Beulich
2023-11-02 16:13         ` Luca Fancellu
2023-10-31 13:23 ` [RFC PATCH v2 8/8] feedback from the community Luca Fancellu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231031132304.2573924-3-luca.fancellu@arm.com \
    --to=luca.fancellu@arm.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.