[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/2] xen/cppcheck: add a way to exclude files from the scan


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Thu, 2 Mar 2023 10:59:35 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pxAIuiwrQCtAuLVxb0RF6pYc0I4QlhSkLghUhk+zzvc=; b=Lv4nWG0wR3bJRYu2EQhAFn7DLcTT64SHLYGS/3CnYGJn+tD3fBxXHQK/0WMWaPwMVAYSkEU1c5UMdnj5IIo0OtRX10UTMEuSt7i5odlxwCBdaPU4Rq5YD2znc+BDkwwkjl+we6hJsGThR839iRaUpk0WT2z6TUVlcmbIFUS822qHDp6vZY4WjwZ1QWd8BSzSmNmrrreJV9sDd2v/ptyKct0nU4uJSS+iXKfYTzAU7Gs1TPUZN5EN6s0Rab+XoyQBgGUOSTARDfIGAogU5VFMUVzX2MWabiUZVXub6ynJQVie3Cs5OtuXMby9SfQLxvn+mMuxYPeBqksciLsQQE7TsA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1Zgsj1ZvjeKDB3YbnbqFUaNMOFKIeo3lG73AYo+fOliTT0ZN600o3sP4INRBUhkC5mzC+kMk3eogS5VJadRXlYyGhHsqVkCz3vBE8MJHAxL8YojXDaLFvGI5T3iirAFftgiz+sAr1VKJLbuatYyDBgbYJNn947io6rHJFEMsjnJ5ROcTc6b7rjL2/ABfW9lIgo1wyAH99jTKCLYQ7pukwlgHoKMqa2/CAySXB5fmWNT31uIfMEpyhnR1fpN+iSAe0iBpgvMcEfm52+EA8VW635vrKXPmEcXlnnGc7trC8r0aNszezFCdXOlJVMmeFhXuDxFTlIWrt29X/XK/YN8Tg==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 02 Mar 2023 11:00:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHZTCPAFkIxBTdSO0yOTrnaP+pA8a7mnRSAgAC2voA=
  • Thread-topic: [PATCH v2 1/2] xen/cppcheck: add a way to exclude files from the scan

>> +Exclude file list for xen-analysis script
>> +=========================================
>> +
>> +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 because they are not owned by Xen and they must be 
>> kept
>> +in sync with their origin (completely or even partially), hence we can't 
>> easily
>> +fix findings or deviate from them.
> 
> I would stay more generic and say something like:
> 
> 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.).
> 
> But what you wrote is also OK.

I’m ok with that too, I can update with your wordings
>> 
>> +++ b/xen/scripts/xen_analysis/exclusion_file_list.py
>> @@ -0,0 +1,79 @@
>> +#!/usr/bin/env python3
>> +
>> +import os, glob, json
>> +from . import settings
>> +
>> +class ExclusionFileListError(Exception):
>> +    pass
>> +
>> +
>> +def __cppcheck_path_exclude_syntax(path):
>> +    # Prepending * to the relative path to match every path where the Xen
>> +    # codebase could be
>> +    path = "*" + path
>> +
>> +    # Check if the path is to a folder without the wildcard at the end
>> +    if not (path.endswith(".c") or path.endswith(".h") or 
>> path.endswith("*")):
> 
> Isn't there a python call to check that it is actually a folder? I think
> that would be more resilient because otherwise if someone passes a .S or
> .cpp file it would be detected as directory.
> 
> 
>> +        # The path is to a folder, if it doesn't have the final /, add it
>> +        if not path.endswith("/"):
>> +            path = path + "/"
>> +        # Since the path is a folder, add a wildcard to the end so that
>> +        # cppcheck will remove every issue related with this path
>> +        path = path + "*"
>> +
>> +    return path

Yes you are very right, here I wanted to accept the relative path to a folder 
with
or without the ending '/*’, but it carries on much more complexity because here 
the
relative path can contain wildcards in it, so we can’t use os.path.isdir() 
which would
fail.

At cost of being more strict on how folders shall be declared, I think it’s 
better to
enforce the ‘/*’ at the end of a path that is excluding a folder.

We have a previous check using glob() to ensure path with wildcards are real 
path
so we are safe that the passed relative path are OK.

Dropping the requirement of passing folder paths with or without the ‘/*’ 
simplifies
the code and this would be the final result:


diff --git a/docs/misra/exclude-list.rst b/docs/misra/exclude-list.rst
index 969539c46beb..c97431a86120 100644
--- a/docs/misra/exclude-list.rst
+++ b/docs/misra/exclude-list.rst
@@ -3,11 +3,11 @@
 Exclude file list for xen-analysis script
 =========================================
 
-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 because they are not owned by Xen and they must be 
kept
-in sync with their origin (completely or even partially), hence we can't easily
-fix findings or deviate from them.
+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.).
 
 For this reason the file docs/misra/exclude-list.json is used to exclude every
 entry listed in that file from the final report.
@@ -42,3 +42,5 @@ Here is an explanation of the fields inside an object of the 
"content" array:
 
 To ease the review and the modifications of the entries, they shall be listed 
in
 alphabetical order referring to the rel_path field.
+Excluded folder paths shall end with '/*' in order to match everything on that
+folder.
diff --git a/xen/scripts/xen_analysis/exclusion_file_list.py 
b/xen/scripts/xen_analysis/exclusion_file_list.py
index 4a47a90f5944..871e480586bb 100644
--- a/xen/scripts/xen_analysis/exclusion_file_list.py
+++ b/xen/scripts/xen_analysis/exclusion_file_list.py
@@ -12,15 +12,6 @@ def __cppcheck_path_exclude_syntax(path):
     # codebase could be
     path = "*" + path
 
-    # Check if the path is to a folder without the wildcard at the end
-    if not (path.endswith(".c") or path.endswith(".h") or path.endswith("*")):
-        # The path is to a folder, if it doesn't have the final /, add it
-        if not path.endswith("/"):
-            path = path + "/"
-        # Since the path is a folder, add a wildcard to the end so that
-        # cppcheck will remove every issue related with this path
-        path = path + "*"
-
     return path
 
 
I’ve included also your wording and I’ve specified in the docs how to exclude a 
folder.

Do you think it’s ok to proceed in this way?

Cheers,
Luca



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.