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

Re: [PATCH 2/4] xen/scripts: add cppcheck tool to the xen-analysis.py script


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 29 Nov 2022 10:42:20 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=Dmgb0WJLW4ak4TGCs9NLhwpQvw06caLPzbln007chRo=; b=ar9C83iqwXTNyy1fDpiCxY30nAXcFSRPHXfhVZngTzj/VAgP3FKPYmGlU6UxL24sjCPzUjdMGwsjZ/u/PEtQAenKY6D6pxRJYFpNXW2w/de3CT+9TjzRmUNRwRfvBqbg7KeXOL3Wl0Kj5fv9bQeVHzvPB/rQEO/A7BniTYtFZZDkE160paDjVOFJaK3XJe1u6Gv8/njk2UkmAPzTIg26M0LlJ4NyuMdwrAi54mcAl6g7+oY+k6V+Gi/OwQRswVyHg/P879wA7Xwr3zNS1MTP036OHO6SAudauc+n3NbKkoA+sSDUB0/FTDbMbL6HhZvRaiu3bkic0v81dlHKGnWL6w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxlEmKA9m7mcyFP66DhBcyZNVUqIb5z+TSZGbSFO/e6Xm6dePzEwb/IVq7VXY1DKVBAGuWNOoslNRSLic7GTYzrdxu1/gw2jgnTrVC7liqd1WPhr+uMn7CTs53w18G95NOzJZyInahCT+KiUTE6N3RmJX3jYyytSfLiydzKNULcwmnGfjMGnbMBsdgQJvAp4l91QF8ACg6KHcrQNqb1uKhnY5kgofXeJI1gltvw5OM7OKmYwgYDyu7q4zGKlu3k6vepeJ8tcErQJt4mZ6pY98SLcggMa2GosIjBmJ2tdJM2J3GwUdAdF/15lqbdZZfN4V7PGuaSS4lPVISDzu83x0A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 29 Nov 2022 09:42:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 28.11.2022 16:37, Luca Fancellu wrote:
>> On 28 Nov 2022, at 15:19, Jan Beulich <jbeulich@xxxxxxxx> wrote:
>> On 28.11.2022 15:10, Luca Fancellu wrote:
>>> Change cppcheck invocation method by using the xen-analysis.py
>>> script using the arguments --run-cppcheck.
>>>
>>> Now cppcheck analysis will build Xen while the analysis is performed
>>> on the source files, it will produce a text report and an additional
>>> html output when the script is called with --cppcheck-html.
>>>
>>> With this patch cppcheck will benefit of platform configuration files
>>> that will help it to understand the target of the compilation and
>>> improve the analysis.
>>>
>>> To do so:
>>> - remove cppcheck rules from Makefile and move them to the script.
>>> - Update xen-analysis.py with the code to integrate cppcheck.
>>> - merge the script merge_cppcheck_reports.py into the xen-analysis
>>>   script package and rework the code to integrate it.
>>> - add platform configuration files for cppcheck..
>>> - add cppcheck-cc.sh script that is a wrapper for cppcheck and it's
>>>   used as Xen compiler, it will intercept all flags given from the
>>>   make build system and it will execute cppcheck on the compiled
>>>   file together with the file compilation.
>>> - guarded hypercall-defs.c with CPPCHECK define because cppcheck
>>>   gets confused as the file does not contain c code.
>>> - add false-positive-cppcheck.json file
>>> - update documentation.
>>> - update .gitignore
>>>
>>> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
>>
>> Just two and a half questions, not a full review:
>>
>>> ---
>>> .gitignore                                    |   8 +-
>>> docs/misra/cppcheck.txt                       |  27 +-
>>> docs/misra/documenting-violations.rst         |   7 +-
>>> docs/misra/false-positive-cppcheck.json       |  12 +
>>> docs/misra/xen-static-analysis.rst            |  42 ++-
>>> xen/Makefile                                  | 116 +-------
>>> xen/include/hypercall-defs.c                  |   9 +
>>> xen/scripts/xen-analysis.py                   |  18 +-
>>> xen/scripts/xen_analysis/cppcheck_analysis.py | 272 ++++++++++++++++++
>>> .../xen_analysis/cppcheck_report_utils.py     | 130 +++++++++
>>> xen/scripts/xen_analysis/generic_analysis.py  |  21 +-
>>> xen/scripts/xen_analysis/settings.py          |  77 ++++-
>>> xen/scripts/xen_analysis/utils.py             |  21 +-
>>> xen/tools/cppcheck-cc.sh                      | 223 ++++++++++++++
>>> xen/tools/cppcheck-plat/arm32-wchar_t4.xml    |  17 ++
>>> xen/tools/cppcheck-plat/arm64-wchar_t2.xml    |  17 ++
>>> xen/tools/cppcheck-plat/arm64-wchar_t4.xml    |  17 ++
>>> xen/tools/cppcheck-plat/x86_64-wchar_t2.xml   |  17 ++
>>> xen/tools/cppcheck-plat/x86_64-wchar_t4.xml   |  17 ++
>>
>> What are these last five files about? There's nothing about them in
>> the description afaics.
> 
> They are cppcheck platform configuration files, they help cppcheck to 
> understand
> the size of the types depending on the target of the compilation.
> 
> This section in the commit message is to introduce them:
> 
> With this patch cppcheck will benefit of platform configuration files
> that will help it to understand the target of the compilation and
> improve the analysis.
> 
> Do you think I should say it differently? Or maybe say that they reside in 
> xen/tools/cppcheck-plat/ ?

Perhaps (I didn't read that paragraph as relating to _anything_ in
tree), e.g.:

With this patch cppcheck will benefit from platform configuration files
that will help it to understand the target of the compilation and
improve the analysis. These are XML files placed in
xen/tools/cppcheck-plat/, describing ... (I don't know what to put here).

Please write the description here such that people not familiar with
cppcheck (or more generally with any external tool) can still follow
what you're talking about and what the patch is doing.

>>> --- /dev/null
>>> +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
>>> @@ -0,0 +1,272 @@
>>> +#!/usr/bin/env python3
>>> +
>>> +import os, re, shutil
>>> +from . import settings, utils, cppcheck_report_utils
>>> +
>>> +class GetMakeVarsPhaseError(Exception):
>>> +    pass
>>> +
>>> +class CppcheckDepsPhaseError(Exception):
>>> +    pass
>>> +
>>> +class CppcheckReportPhaseError(Exception):
>>> +    pass
>>> +
>>> +CPPCHECK_BUILD_DIR = "build-dir-cppcheck"
>>> +CPPCHECK_HTMLREPORT_OUTDIR = "cppcheck-htmlreport"
>>> +CPPCHECK_REPORT_OUTDIR = "cppcheck-report"
>>> +cppcheck_extra_make_args = ""
>>> +xen_cc = ""
>>> +
>>> +def get_make_vars():
>>> +    global xen_cc
>>> +    invoke_make = utils.invoke_command(
>>> +            "make -C {} {} export-variable-CC"
>>> +                .format(settings.xen_dir, settings.make_forward_args),
>>> +            True, GetMakeVarsPhaseError,
>>> +            "Error occured retrieving make vars:\n{}"
>>> +        )
>>> +
>>> +    cc_var_regex = re.search('^CC=(.*)$', invoke_make, flags=re.M)
>>> +    if cc_var_regex:
>>> +        xen_cc = cc_var_regex.group(1)
>>> +
>>> +    if xen_cc == "":
>>> +        raise GetMakeVarsPhaseError("CC variable not found in Xen make 
>>> output")
>>
>> What use is CC without CFLAGS? Once again the description could do
>> with containing some information on what's going on here, and why
>> you need to export any variables in the first place.
> 
> We don’t need CFLAGS here, we need only CC to generate 
> include/generated/compiler-def.h and
> to pass CC to the cppcheck-cc.sh --compiler argument.

Hmm, I see that include/generated/compiler-def.h is generated already
now without any use of CFLAGS. Which looks suspicious to me. Sadly
the uses in xen/Makefile are lacking any details on what this is for,
and Bertrand's commit introducing it doesn't explain its purpose
either. Maybe again something entirely obvious to people knowing
cppcheck sufficiently well ...

> Would a comment in the code be ok?

Not sure (yet).

Jan



 


Rackspace

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