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

Re: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Tue, 8 Nov 2022 10:59:06 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • 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=2; 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=UvH8NTVnFj0ETGtNDCxJZEb7yA7H68vvL5CXJ9zlHY0=; b=bKM4+6LFSFvHKHdnRtw3Rav1oyS0aO/tNekPFsQ9WpfQRODa98hsimIgqzxi+TN5bbcB0qrgn3duuZaegFHSa+i8cf3IiQiK1Eihnc00rFlF/gfYhQYPHa82wOWhjRmp07p+LOboZfKGYnHCAUqwEStLSkODrU8hmoiBBZeyg6BEBvUxAeDRacsIPThpRr8rwaE0dl9a/gwnfT7Xm5MMv6Mit0psVR6kbsTRnL6QZwqFDv0j3jBb5bhAP8uUgWwXNsVz+6i1fWpd79XvPKJgwIPo05kDA5KgDp1heF0rI0nLYVWoLz5Bgdx7ge3Psx+kl5P6TGfmJhIxZL44TgdzuQ==
  • 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=UvH8NTVnFj0ETGtNDCxJZEb7yA7H68vvL5CXJ9zlHY0=; b=gyQr8npj9r7m1b7VSxofM3C6+vUFB7RbX+fHQTbpCaPcoCfYowtlJRL3QNAW6xaJf2Pj64GgpU78H4aoc5X9Dq8WxEj6oCMtD4oHJfSUfZL8XDBX2/SqNV5GHH0rcHtPx+1+wUuXhq4WSfTvasXCoC6W/3f2Y5mskJa7cyJPGD0LMBUaNLwARhNutpxRQvJvrLlfAHvvB+h6pfSsF0qKq/kyG8BMqG1YM0UEjvBbSmK30g9ojx2bmgeEGNTwebkbeJD4w0ALbikBOSWBW/vqTQZZSRp4gcYeQpfXXdQzj0v9F2Ul1Oa4ZGuZuKwU6TxfHUA/bwcICF/7m4e2teFYwQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=IirV/gm5SUJmbU2RdmJBAgxyjsnYAyOiAvKrqvXZw2r0v0wXZWf1RjFSYG9ICE1mVFsYIL2Bgywb/VeXhXgUR3XcCa0E8JXea00gA4VbH5Q5E5gBNQ/LXqaGb1g2dZfXEClD6/DAKIsuFRgjgS1ZoIDtOWH3imhiu2H2GJH6Rs+vrcPXKmaIIX/3+kBROu6HfYGtj1yoQoLgnMvCycPUF192ZVTCkeJAFGWXbWK3NY68otkguwlA8L9FmOcx4ZS0o/mGx4tNNnbwHVy51VD6pvFGUtLZhYujUNT9/3D3tYu0dA1u80XWriu86BKSoanKncuX3mTRUnca0Gkk6mnccQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TwPPj8zYLJiDygBN8Jim+OSB/xoo/htjteukxrDuonX4Xu8z2pq347e2W8avD4z/gIifhklRl94L2Ji/6Avlm51yrNv8nxbtAmeUDAzoNaHd30VKRJ3wpQ+XvP7ZpKSP/4cpX+iBF/qGr3yQx0BU/k/el+UD5a+CUWuMMBQ8Z8PMfjfOaZQnoNsmzmRubmU3M8GI6GYo6EqPyMBUEEVXfiMP1QOwluM9oZdD7ry10iKLxsEeGmQ/vtD6fI9oYJ4mTSd6mIJ55tolf1znm2nqGzqqBaL8hh4dLOzTDtbE7+o6me9n6enB+0uY0WRx8kVk1cjVzeuzvzjfmtEc5OUlOQ==
  • Authentication-results-original: 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, 08 Nov 2022 10:59:58 +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: AQHY8pZ008DS0BACDkyhs+OWN8Oan64zqLWAgAE0WoA=
  • Thread-topic: [RFC PATCH 1/4] xen/Makefile: add analysis-coverity and analysis-eclair

Hi Jan

> 
> On 07.11.2022 11:47, Luca Fancellu wrote:
>> +Here is an example to add a new justification in 
>> false-positive-<tool>.json::
> 
> With <tool> already present in the name, ...
> 
>> +|{
>> +|    "version": "1.0",
>> +|    "content": [
>> +|        {
>> +|            "id": "SAF-0-false-positive-<tool>",
>> +|            "analyser": {
>> +|                "<tool>": "<proprietary-id>"
> 
> ... can we avoid the redundancy here? Perhaps ...
> 
>> +|            },
>> +|            "tool-version": "<version>",
> 
> ... it could be
> 
>            "analyser": {
>                "<version>": "<proprietary-id>"
>            },

Yes it’s a bit redundant but it helps re-using the same tool we use for 
safe.json

> 
> ? It's not really clear to me though how a false positive would be
> correctly recorded which is present over a range of versions.

We could put a range in "tool-version”: “<verision-old> - <version-new>"

> 
>> --- a/xen/Makefile
>> +++ b/xen/Makefile
>> @@ -457,7 +457,8 @@ endif # need-config
>> 
>> __all: build
>> 
>> -main-targets := build install uninstall clean distclean MAP cppcheck 
>> cppcheck-html
>> +main-targets := build install uninstall clean distclean MAP cppcheck \
>> +    cppcheck-html analysis-coverity analysis-eclair
>> .PHONY: $(main-targets)
>> ifneq ($(XEN_TARGET_ARCH),x86_32)
>> $(main-targets): %: _% ;
>> @@ -572,7 +573,7 @@ _clean:
>>      rm -f $(TARGET).efi $(TARGET).efi.map $(TARGET).efi.stripped
>>      rm -f asm-offsets.s arch/*/include/asm/asm-offsets.h
>>      rm -f .banner .allconfig.tmp include/xen/compile.h
>> -    rm -f cppcheck-misra.* xen-cppcheck.xml
>> +    rm -f cppcheck-misra.* xen-cppcheck.xml *.sed
> 
> Is *.sed perhaps a little too wide? But yes, we can of course deal with that
> in case any *.sed file appears in the source tree.
> 
>> @@ -757,6 +758,51 @@ cppcheck-version:
>> $(objtree)/include/generated/compiler-def.h:
>>      $(Q)$(CC) -dM -E -o $@ - < /dev/null
>> 
>> +JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \
>> +                       $(XEN_ROOT)/docs/misra/false-positive-$$*.json
>> +
>> +# The following command is using grep to find all files that contains a 
>> comment
>> +# containing "SAF-<anything>" on a single line.
>> +# %.safparse will be the original files saved from the build system, these 
>> files
>> +# will be restored at the end of the analysis step
>> +PARSE_FILE_LIST := $(addsuffix .safparse,$(filter-out %.safparse,\
>> +$(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))
> 
> Please indent such line continuations. And then isn't this going to risk
> matching non-source files as well? Perhaps you want to restrict this to
> *.c and *.h?

Yes, how about this, it will filter out *.safparse files while keeping in only 
.h and .c:

PARSE_FILE_LIST := $(addsuffix .safparse,$(filter %.c %.h,\
    $(shell grep -ERl '^[[:blank:]]*\/\*[[:space:]]+SAF-.*\*\/$$' $(srctree))))


> 
>> +.PRECIOUS: $(PARSE_FILE_LIST) $(objtree)/%.sed
>> +
>> +.SECONDEXPANSION:
> 
> I have to admit that I'm a little worried of this living relatively early in
> the script.
> 
>> +$(objtree)/%.sed: $(JUSTIFICATION_FILES) 
>> $(srctree)/tools/xenfusa-gen-tags.py
>> +    $(PYTHON) $(srctree)/tools/xenfusa-gen-tags.py \
>> +            $(foreach file, $(filter %.json, $^), --input $(file)) --output 
>> $@ \
>> +            --tool $*
> 
> To reduce redundancy, how about
> 
> $(objtree)/%.sed: $(srctree)/tools/xenfusa-gen-tags.py $(JUSTIFICATION_FILES)
>       $(PYTHON) $< --output $@ --tool $* \
>               $(foreach file, $(filter %.json, $^), --input $(file))
> 
> ?

Yes it sounds better

> 
>> +%.safparse: %
> 
> For this to not be overly widely matching, maybe better
> 
> $(PARSE_FILE_LIST): %.safparse: %
> 
> ?

Yes very sensible

> 
>> +# Create a copy of the original file (-p preserves also timestamp)
>> +    $(Q)if [ -f "$@" ]; then \
>> +            echo "Found $@, please check the integrity of $*"; \
>> +            exit 1; \
>> +    fi
>> +    $(Q)cp -p "$*" "$@"
> 
> While you use the full source name as the stem, I still think $< would be
> more clear to use here.

Agree

> 
> To limit work done, could this me "mv" instead of "cp -p", and then ...
> 
>> +analysis-parse-tags-%: $(PARSE_FILE_LIST) $(objtree)/%.sed
>> +    $(Q)for file in $(patsubst %.safparse,%,$(PARSE_FILE_LIST)); do \
>> +            sed -i -f "$(objtree)/$*.sed" "$${file}"; \
> 
> ... with then using
> 
>               sed -f "$(objtree)/$*.sed" "$${file}.safparse" >"$${file}"
> 
> here? This would then also have source consistent between prereqs and
> rule.

We saw that mv is not preserving the timestamp of the file, instead we would 
like to preserve
it, for this reason we used cp -p

> 
>> +    done
>> +
>> +analysis-build-%: analysis-parse-tags-%
>> +    $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile build
> 
> This rule doesn't use the stem, so I'm struggling to understand what
> this is about.

Yes, here my aim was to catch analysis-build-{eclair,coverity}, here I see that 
if the user has a typo
the rule will run anyway, but it will be stopped by the dependency chain 
because at the end we have:

JUSTIFICATION_FILES := $(XEN_ROOT)/docs/misra/safe.json \
                       $(XEN_ROOT)/docs/misra/false-positive-$$*.json

That will give an error because 
$(XEN_ROOT)/docs/misra/false-positive-<typo>.json does not exists.

If you think it is not enough, what if I reduce the scope of the rule like this?

_analysis-coverity _analysis-eclair: _analysis-%: analysis-build-%

Or, if you are still worried about “analysis-build-%: analysis-parse-tags-%”, 
then I can do something
like this: 

analysis-supported-coverity analysis-supported-eclair:
    @echo > /dev/null

analysis-supported-%:
    @error Unsupported analysis tool @*

analysis-build-%: analysis-parse-tags-% | analysis-supported-%
    $(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile build

[…]

_analysis-%: analysis-build-% | analysis-supported-%
    $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-clean

> 
>> +analysis-clean:
>> +# Reverts the original file (-p preserves also timestamp)
>> +    $(Q)find $(srctree) -type f -name "*.safparse" -print | \
>> +    while IFS= read file; do \
>> +            cp -p "$${file}" "$${file%.safparse}"; \
>> +            rm -f "$${file}"; \
> 
> Why not "mv"?
> 
>> +    done
>> +
>> +_analysis-%: analysis-build-%
>> +    $(Q)$(MAKE) O=$(abs_objtree) -f $(srctree)/Makefile analysis-clean
> 
> Again no use of the stem, plus here I wonder if this may not lead to
> people invoking "analysis-clean" without having said anything about
> cleaning on their command line.

In any case, the cleaning process is very safe and does not clean anything that 
was not dirty before,
so in case of typos, it’s just like a nop.

> 
>> --- /dev/null
>> +++ b/xen/tools/xenfusa-gen-tags.py
>> @@ -0,0 +1,81 @@
>> +#!/usr/bin/env python
>> +
>> +import sys, getopt, json
>> +
>> +def help():
>> +    print('Usage: {} [OPTION] ...'.format(sys.argv[0]))
>> +    print('')
>> +    print('This script converts the justification file to a set of sed 
>> rules')
>> +    print('that will replace generic tags from Xen codebase in-code 
>> comments')
>> +    print('to in-code comments having the proprietary syntax for the 
>> selected')
>> +    print('tool.')
>> +    print('')
>> +    print('Options:')
>> +    print('  -i/--input   Json file containing the justifications, can be')
>> +    print('               passed multiple times for multiple files')
>> +    print('  -o/--output  Sed file containing the substitution rules')
>> +    print('  -t/--tool    Tool that will use the in-code comments')
>> +    print('')
>> +
>> +# This is the dictionary for the rules that translates to proprietary 
>> comments:
>> +#  - cppcheck: /* cppcheck-suppress[id] */
>> +#  - coverity: /* coverity[id] */
>> +#  - eclair:   /* -E> hide id 1 "" */
>> +# Add entries to support more analyzers
>> +tool_syntax = {
>> +    "cppcheck":"s,^.*/*[[:space:]]*TAG.*$,/* cppcheck-suppress[VID] */,g",
>> +    "coverity":"s,^.*/*[[:space:]]*TAG.*$,/* coverity[VID] */,g",
>> +    "eclair":"s,^.*/*[[:space:]]*TAG.*$,/* -E> hide VID 1 \"\" */,g"
>> +}
>> +
>> +def main(argv):
>> +    infiles = []
>> +    justifications = []
>> +    outfile = ''
>> +    tool = ''
>> +
>> +    try:
>> +        opts, args = 
>> getopt.getopt(argv,"hi:o:t:",["input=","output=","tool="])
>> +    except getopt.GetoptError:
>> +        help()
>> +        sys.exit(2)
>> +    for opt, arg in opts:
>> +        if opt == '-h':
>> +            help()
>> +            sys.exit(0)
>> +        elif opt in ("-i", "--input"):
>> +            infiles.append(arg)
>> +        elif opt in ("-o", "--output"):
>> +            outfile = arg
>> +        elif opt in ("-t", "--tool"):
>> +            tool = arg
>> +
>> +    # Open all input files
>> +    for file in infiles:
>> +        try:
>> +            handle = open(file, 'rt')
>> +            content = json.load(handle)
>> +            justifications = justifications + content['content']
>> +            handle.close()
>> +        except json.JSONDecodeError:
>> +            print('JSON decoding error in file: ' + file)
>> +        except:
>> +            print('Error opening ' + file)
>> +            sys.exit(1)
>> +
>> +    try:
>> +        outstr = open(outfile, "w")
>> +    except:
>> +        print('Error creating ' + outfile)
>> +        sys.exit(1)
>> +
>> +    for j in justifications:
>> +        if tool in j['analyser']:
>> +            comment=tool_syntax[tool].replace("TAG",j['id'])
>> +            comment=comment.replace("VID",j['analyser'][tool])
>> +            outstr.write('{}\n'.format(comment))
>> +
>> +    outstr.close()
>> +
>> +if __name__ == "__main__":
>> +   main(sys.argv[1:])
>> \ No newline at end of file
> 
> Nit: ^^^

Will fix

> 
> Jan


 


Rackspace

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