[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: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Tue, 29 Nov 2022 09:49:02 +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=LY1A6ky9m0QgZs2sJRFR1OL0cmd8JIFgOo9/CEqG/ns=; b=AG9ahIyf/N0IcKxQPrFmTjpB3y+K+t9dE7MsZdhJSEL6lqS4thKdm8j0CTTnhhsQBkD1luAJygFvyRgAnX3qYQbDvD2PMvirfa5bLQN3OpvsyicXxxgzWztHkqwwZwE/bXDK/k74NTUbB3k6IR+NfAJEq0TMmGyYuSWnsrpsu30RNhWGR++GCuMqM6LTxZgR5IR4mGHCBGJhRr3gpnSd3rQyXArm4DfDRrqvZ37wzQNG+gyXR3SHfJh8Im2l7SGHzWgNzpGLJnKCJWhCy2nJX+ObTs//LmktA73IFIy/fLASxcd6WBm6BEF4+RjlugsXl5x3WdhbjEcZP5CbGXlwDw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eUsa4A6CkfFEOuaVMIUJQaz1N7HC2lZFsqzbpAzXBSnEuLgXCm1hRpnVeDSrEyYe/l+N4pwqHpE+VwBY7bp6PNpNKq7vPRPluP7/YdEjRuSpdatgM4TfMxo7TvRe1ox4ebijansPcHSXktAclajWySimxji453mZlfwvsJmG+X4cVOma+08uO8IzqiGcQLKrPSeyLA/3kE3vqeCnThx+iiIswix9LGCND8hYW1Rh/oNxc93TJKiEZJJI2WXF4CfczW1S+E3/7hrpQoBi+prnlMZTuc7vwFDIJjj1g55nm6ogvWlKGmeZwC1eyt6IQebbONbVYujXNHG57oux9aoZCQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.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:49:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHZAzNLrQ+cdSzeJ02hq/RTLwHjha5Ucy2AgAAFEACAAS8cAIAAAd6A
  • Thread-topic: [PATCH 2/4] xen/scripts: add cppcheck tool to the xen-analysis.py script


> On 29 Nov 2022, at 09:42, Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 
> 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.

Ok I can modify the description to add more details

> 
>>>> --- /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®.