On 24.03.2022 14:06, Andrew Cooper wrote:
> On 24/03/2022 11:04, Bertrand Marquis wrote:
>> cppcheck can be used to check Xen code quality.
>>
>> To create a report do "make cppcheck" on a built tree adding any options
>> you added during the process you used to build xen (like CROSS_COMPILE
>> or XEN_TARGET_ARCH). This will generate an xml report xen-cppcheck.xml.
>>
>> To create a html report do "make cppcheck-html" in the same way and a
>> full report to be seen in a browser will be generated in
>> cppcheck-htmlreport/index.html.
>>
>> For better results it is recommended to build your own cppcheck from the
>> latest sources that you can find at [1].
>> Development and result analysis has been done with cppcheck 2.7.
>>
>> The Makefile rule is searching for all C files which have been compiled
>> (ie which have a generated .o file) and is running cppcheck on all of
>> them using the current configuration of xen so only the code actually
>> compiled is checked.
>>
>> A new tool is introduced to merge all cppcheck reports into one global
>> report including all findings and removing duplicates.
>>
>> Some extra variables can be used to customize the report:
>> - CPPCHECK can be used to give the full path to the cppcheck binary to
>> use (default is to use the one from the standard path).
>> - CPPCHECK_HTMLREPORT can be used to give the full path to
>> cppcheck-htmlreport (default is to use the one from the standard path).
>>
>> This has been tested on several arm configurations (x86 should work but
>> has not been tested).
>>
>> [1] https://cppcheck.sourceforge.io/
>>
>> Signed-off-by: Bertrand Marquis <bertrand.marq...@arm.com>
>> Signed-off-by: Michal Orzel <michal.or...@arm.com>
>
> Does CPPCheck have configurable errors vs warnings? Should we wire this
> into CI so we can fail builds which introduce errors that we've already
> managed to purge from the codebase?
>
For cppcheck, every finding is an error as it is placed within <errors> section
in XML.
cppcheck differentiates different types of findings by using "severity" element
which can be e.g. error, style, warning, etc.
cppcheck-html uses this field to group findings into categories and present it
in a nice format to be seen on a web browser.
However there is currently no way to tell cppcheck to find only errors.
Cheers,
Michal