* [PATCH 0/2] Cppcheck MISRA analysis improvements
@ 2023-01-06 10:41 Luca Fancellu
2023-01-06 10:41 ` [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries Luca Fancellu
2023-01-06 10:41 ` [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules Luca Fancellu
0 siblings, 2 replies; 8+ messages in thread
From: Luca Fancellu @ 2023-01-06 10:41 UTC (permalink / raw)
To: xen-devel
Cc: wei.chen, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall, Stefano Stabellini, Wei Liu
This serie is adding a way to skip the check for some rules that the Xen project
has agreed to follow, this is because cppcheck reports too many false-positive
on some rules and it would be easier in a first phase to skip the check on them
and allow the tool to be mature enough before using it on the specific rules.
The serie includes also an improvement for the cppcheck report.
Luca Fancellu (2):
xen/cppcheck: sort alphabetically cppcheck report entries
xen/cppcheck: add parameter to skip given MISRA rules
xen/scripts/xen_analysis/cppcheck_analysis.py | 8 +++--
.../xen_analysis/cppcheck_report_utils.py | 2 ++
xen/scripts/xen_analysis/settings.py | 35 +++++++++++--------
xen/tools/convert_misra_doc.py | 28 ++++++++++-----
4 files changed, 48 insertions(+), 25 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries
2023-01-06 10:41 [PATCH 0/2] Cppcheck MISRA analysis improvements Luca Fancellu
@ 2023-01-06 10:41 ` Luca Fancellu
2023-01-09 11:15 ` Michal Orzel
2023-01-06 10:41 ` [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules Luca Fancellu
1 sibling, 1 reply; 8+ messages in thread
From: Luca Fancellu @ 2023-01-06 10:41 UTC (permalink / raw)
To: xen-devel
Cc: wei.chen, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall, Stefano Stabellini, Wei Liu
Sort alphabetically cppcheck report entries when producing the text
report, this will help comparing different reports and will group
together findings from the same file.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
xen/scripts/xen_analysis/cppcheck_report_utils.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/scripts/xen_analysis/cppcheck_report_utils.py
index 02440aefdfec..f02166ed9d19 100644
--- a/xen/scripts/xen_analysis/cppcheck_report_utils.py
+++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py
@@ -104,6 +104,8 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths):
for path in strip_paths:
text_report_content[i] = text_report_content[i].replace(
path + "/", "")
+ # sort alphabetically the entries
+ text_report_content.sort()
# Write the final text report
outfile.writelines(text_report_content)
except OSError as e:
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules
2023-01-06 10:41 [PATCH 0/2] Cppcheck MISRA analysis improvements Luca Fancellu
2023-01-06 10:41 ` [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries Luca Fancellu
@ 2023-01-06 10:41 ` Luca Fancellu
2023-01-18 8:35 ` Luca Fancellu
2023-01-21 0:39 ` Stefano Stabellini
1 sibling, 2 replies; 8+ messages in thread
From: Luca Fancellu @ 2023-01-06 10:41 UTC (permalink / raw)
To: xen-devel
Cc: wei.chen, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall, Stefano Stabellini, Wei Liu
Add parameter to skip the passed MISRA rules during the cppcheck
analysis, the rules are specified as a list of comma separated
rules with the MISRA number notation (e.g. 1.1,1.3,...).
Modify convert_misra_doc.py script to take an extra parameter
giving a list of MISRA rule to be skipped, comma separated.
While there, fix some typos in the help and print functions.
Modify settings.py and cppcheck_analysis.py to have a new
parameter (--cppcheck-skip-rules) used to specify a list of
MISRA rule to be skipped during the cppcheck analysis.
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
xen/scripts/xen_analysis/cppcheck_analysis.py | 8 +++--
xen/scripts/xen_analysis/settings.py | 35 +++++++++++--------
xen/tools/convert_misra_doc.py | 28 ++++++++++-----
3 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
index 0e952a169641..cc1f403d315e 100644
--- a/xen/scripts/xen_analysis/cppcheck_analysis.py
+++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
@@ -153,11 +153,15 @@ def generate_cppcheck_deps():
if settings.cppcheck_misra:
cppcheck_flags = cppcheck_flags + " --addon=cppcheck-misra.json"
+ skip_rules_arg = ""
+ if settings.cppcheck_skip_rules != "":
+ skip_rules_arg = "-s {}".format(settings.cppcheck_skip_rules)
+
utils.invoke_command(
"{}/convert_misra_doc.py -i {}/docs/misra/rules.rst"
- " -o {}/cppcheck-misra.txt -j {}/cppcheck-misra.json"
+ " -o {}/cppcheck-misra.txt -j {}/cppcheck-misra.json {}"
.format(settings.tools_dir, settings.repo_dir,
- settings.outdir, settings.outdir),
+ settings.outdir, settings.outdir, skip_rules_arg),
False, CppcheckDepsPhaseError,
"An error occured when running:\n{}"
)
diff --git a/xen/scripts/xen_analysis/settings.py b/xen/scripts/xen_analysis/settings.py
index a8502e554e95..8c0d357fe0dc 100644
--- a/xen/scripts/xen_analysis/settings.py
+++ b/xen/scripts/xen_analysis/settings.py
@@ -24,6 +24,7 @@ cppcheck_binpath = "cppcheck"
cppcheck_html = False
cppcheck_htmlreport_binpath = "cppcheck-htmlreport"
cppcheck_misra = False
+cppcheck_skip_rules = ""
make_forward_args = ""
outdir = xen_dir
@@ -53,20 +54,22 @@ Cppcheck report creation phase runs only when --run-cppcheck is passed to the
script.
Options:
- --build-only Run only the commands to build Xen with the optional
- make arguments passed to the script
- --clean-only Run only the commands to clean the analysis artifacts
- --cppcheck-bin= Path to the cppcheck binary (Default: {})
- --cppcheck-html Produce an additional HTML output report for Cppcheck
- --cppcheck-html-bin= Path to the cppcheck-html binary (Default: {})
- --cppcheck-misra Activate the Cppcheck MISRA analysis
- --distclean Clean analysis artifacts and reports
- -h, --help Print this help
- --no-build Skip the build Xen phase
- --no-clean Don\'t clean the analysis artifacts on exit
- --run-coverity Run the analysis for the Coverity tool
- --run-cppcheck Run the Cppcheck analysis tool on Xen
- --run-eclair Run the analysis for the Eclair tool
+ --build-only Run only the commands to build Xen with the optional
+ make arguments passed to the script
+ --clean-only Run only the commands to clean the analysis artifacts
+ --cppcheck-bin= Path to the cppcheck binary (Default: {})
+ --cppcheck-html Produce an additional HTML output report for Cppcheck
+ --cppcheck-html-bin= Path to the cppcheck-html binary (Default: {})
+ --cppcheck-misra Activate the Cppcheck MISRA analysis
+ --cppcheck-skip-rules= List of MISRA rules to be skipped, comma separated.
+ (e.g. --cppcheck-skip-rules=1.1,20.7,8.4)
+ --distclean Clean analysis artifacts and reports
+ -h, --help Print this help
+ --no-build Skip the build Xen phase
+ --no-clean Don\'t clean the analysis artifacts on exit
+ --run-coverity Run the analysis for the Coverity tool
+ --run-cppcheck Run the Cppcheck analysis tool on Xen
+ --run-eclair Run the analysis for the Eclair tool
"""
print(msg.format(sys.argv[0], cppcheck_binpath,
cppcheck_htmlreport_binpath))
@@ -78,6 +81,7 @@ def parse_commandline(argv):
global cppcheck_html
global cppcheck_htmlreport_binpath
global cppcheck_misra
+ global cppcheck_skip_rules
global make_forward_args
global outdir
global step_get_make_vars
@@ -115,6 +119,9 @@ def parse_commandline(argv):
cppcheck_htmlreport_binpath = args_with_content_regex.group(2)
elif option == "--cppcheck-misra":
cppcheck_misra = True
+ elif args_with_content_regex and \
+ args_with_content_regex.group(1) == "--cppcheck-skip-rules":
+ cppcheck_skip_rules = args_with_content_regex.group(2)
elif option == "--distclean":
target_distclean = True
elif (option == "--help") or (option == "-h"):
diff --git a/xen/tools/convert_misra_doc.py b/xen/tools/convert_misra_doc.py
index 13074d8a2e91..8984ec625fa7 100755
--- a/xen/tools/convert_misra_doc.py
+++ b/xen/tools/convert_misra_doc.py
@@ -4,12 +4,14 @@
This script is converting the misra documentation RST file into a text file
that can be used as text-rules for cppcheck.
Usage:
- convert_misr_doc.py -i INPUT [-o OUTPUT] [-j JSON]
+ convert_misra_doc.py -i INPUT [-o OUTPUT] [-j JSON] [-s RULES,[...,RULES]]
INPUT - RST file containing the list of misra rules.
OUTPUT - file to store the text output to be used by cppcheck.
If not specified, the result will be printed to stdout.
JSON - cppcheck json file to be created (optional).
+ RULES - list of rules to skip during the analysis, comma separated
+ (e.g. 1.1,1.2,1.3,...)
"""
import sys, getopt, re
@@ -47,21 +49,25 @@ def main(argv):
outfile = ''
outstr = sys.stdout
jsonfile = ''
+ force_skip = ''
try:
- opts, args = getopt.getopt(argv,"hi:o:j:",["input=","output=","json="])
+ opts, args = getopt.getopt(argv,"hi:o:j:s:",
+ ["input=","output=","json=","skip="])
except getopt.GetoptError:
- print('convert-misra.py -i <input> [-o <output>] [-j <json>')
+ print('convert-misra.py -i <input> [-o <output>] [-j <json>] [-s <rules>]')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
- print('convert-misra.py -i <input> [-o <output>] [-j <json>')
+ print('convert-misra.py -i <input> [-o <output>] [-j <json>] [-s <rules>]')
print(' If output is not specified, print to stdout')
sys.exit(1)
elif opt in ("-i", "--input"):
infile = arg
elif opt in ("-o", "--output"):
outfile = arg
+ elif opt in ("-s", "--skip"):
+ force_skip = arg
elif opt in ("-j", "--json"):
jsonfile = arg
@@ -169,14 +175,18 @@ def main(argv):
skip_list = []
+ # Add rules to be skipped anyway
+ for r in force_skip.split(','):
+ skip_list.append(r)
+
# Search for missing rules and add a dummy text with the rule number
for i in misra_c2012_rules:
for j in list(range(1,misra_c2012_rules[i]+1)):
- if str(i) + '.' + str(j) not in rule_list:
- outstr.write('Rule ' + str(i) + '.' + str(j) + '\n')
- outstr.write('No description for rule ' + str(i) + '.' + str(j)
- + '\n')
- skip_list.append(str(i) + '.' + str(j))
+ rule_str = str(i) + '.' + str(j)
+ if (rule_str not in rule_list) and (rule_str not in skip_list):
+ outstr.write('Rule ' + rule_str + '\n')
+ outstr.write('No description for rule ' + rule_str + '\n')
+ skip_list.append(rule_str)
# Make cppcheck happy by starting the appendix
outstr.write('Appendix B\n')
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries
2023-01-06 10:41 ` [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries Luca Fancellu
@ 2023-01-09 11:15 ` Michal Orzel
2023-01-09 11:41 ` Jan Beulich
0 siblings, 1 reply; 8+ messages in thread
From: Michal Orzel @ 2023-01-09 11:15 UTC (permalink / raw)
To: Luca Fancellu, xen-devel
Cc: wei.chen, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall, Stefano Stabellini, Wei Liu
Hi Luca,
On 06/01/2023 11:41, Luca Fancellu wrote:
>
>
> Sort alphabetically cppcheck report entries when producing the text
> report, this will help comparing different reports and will group
> together findings from the same file.
>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
> xen/scripts/xen_analysis/cppcheck_report_utils.py | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/scripts/xen_analysis/cppcheck_report_utils.py
> index 02440aefdfec..f02166ed9d19 100644
> --- a/xen/scripts/xen_analysis/cppcheck_report_utils.py
> +++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py
> @@ -104,6 +104,8 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths):
> for path in strip_paths:
> text_report_content[i] = text_report_content[i].replace(
> path + "/", "")
> + # sort alphabetically the entries
> + text_report_content.sort()
> # Write the final text report
> outfile.writelines(text_report_content)
> except OSError as e:
> --
> 2.17.1
>
>
Having the report sorted is certainly a good idea. I am just thinking whether it should be done
per file or per finding (e.g. rule). When fixing MISRA issues, best approach is to try to fix all
the issues for a given rule (i.e. a series fixing one rule) rather than all the issues in a file
from different rules. Having a report sorted per finding would make this process easier. We could
add a custom key to sort function to take the second element (after splitting with ':' separator)
which is the name of the finding to achieve this goal. Let me know your thoughts.
~Michal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries
2023-01-09 11:15 ` Michal Orzel
@ 2023-01-09 11:41 ` Jan Beulich
2023-01-09 14:26 ` Luca Fancellu
0 siblings, 1 reply; 8+ messages in thread
From: Jan Beulich @ 2023-01-09 11:41 UTC (permalink / raw)
To: Michal Orzel, Luca Fancellu
Cc: wei.chen, Andrew Cooper, xen-devel, George Dunlap, Julien Grall,
Stefano Stabellini, Wei Liu
On 09.01.2023 12:15, Michal Orzel wrote:
> On 06/01/2023 11:41, Luca Fancellu wrote:
>> Sort alphabetically cppcheck report entries when producing the text
>> report, this will help comparing different reports and will group
>> together findings from the same file.
>>
>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>> ---
>> xen/scripts/xen_analysis/cppcheck_report_utils.py | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/scripts/xen_analysis/cppcheck_report_utils.py
>> index 02440aefdfec..f02166ed9d19 100644
>> --- a/xen/scripts/xen_analysis/cppcheck_report_utils.py
>> +++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py
>> @@ -104,6 +104,8 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths):
>> for path in strip_paths:
>> text_report_content[i] = text_report_content[i].replace(
>> path + "/", "")
>> + # sort alphabetically the entries
>> + text_report_content.sort()
>> # Write the final text report
>> outfile.writelines(text_report_content)
>> except OSError as e:
>> --
>> 2.17.1
>>
>>
>
> Having the report sorted is certainly a good idea. I am just thinking whether it should be done
> per file or per finding (e.g. rule). When fixing MISRA issues, best approach is to try to fix all
> the issues for a given rule (i.e. a series fixing one rule) rather than all the issues in a file
> from different rules. Having a report sorted per finding would make this process easier. We could
> add a custom key to sort function to take the second element (after splitting with ':' separator)
> which is the name of the finding to achieve this goal. Let me know your thoughts.
+1 - sorting by file name wants to be the 2nd sorting criteria, i.e. only among
all instances of the same finding.
Jan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries
2023-01-09 11:41 ` Jan Beulich
@ 2023-01-09 14:26 ` Luca Fancellu
0 siblings, 0 replies; 8+ messages in thread
From: Luca Fancellu @ 2023-01-09 14:26 UTC (permalink / raw)
To: Jan Beulich, Michal Orzel
Cc: Wei Chen, Andrew Cooper, Xen-devel, George Dunlap, Julien Grall,
Stefano Stabellini, Wei Liu
> On 9 Jan 2023, at 11:41, Jan Beulich <jbeulich@suse.com> wrote:
>
> On 09.01.2023 12:15, Michal Orzel wrote:
>> On 06/01/2023 11:41, Luca Fancellu wrote:
>>> Sort alphabetically cppcheck report entries when producing the text
>>> report, this will help comparing different reports and will group
>>> together findings from the same file.
>>>
>>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>>> ---
>>> xen/scripts/xen_analysis/cppcheck_report_utils.py | 2 ++
>>> 1 file changed, 2 insertions(+)
>>>
>>> diff --git a/xen/scripts/xen_analysis/cppcheck_report_utils.py b/xen/scripts/xen_analysis/cppcheck_report_utils.py
>>> index 02440aefdfec..f02166ed9d19 100644
>>> --- a/xen/scripts/xen_analysis/cppcheck_report_utils.py
>>> +++ b/xen/scripts/xen_analysis/cppcheck_report_utils.py
>>> @@ -104,6 +104,8 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths):
>>> for path in strip_paths:
>>> text_report_content[i] = text_report_content[i].replace(
>>> path + "/", "")
>>> + # sort alphabetically the entries
>>> + text_report_content.sort()
>>> # Write the final text report
>>> outfile.writelines(text_report_content)
>>> except OSError as e:
>>> --
>>> 2.17.1
>>>
>>>
>>
Hi Michal, Jan,
>> Having the report sorted is certainly a good idea. I am just thinking whether it should be done
>> per file or per finding (e.g. rule). When fixing MISRA issues, best approach is to try to fix all
>> the issues for a given rule (i.e. a series fixing one rule) rather than all the issues in a file
>> from different rules. Having a report sorted per finding would make this process easier. We could
>> add a custom key to sort function to take the second element (after splitting with ':' separator)
>> which is the name of the finding to achieve this goal. Let me know your thoughts.
>
> +1 - sorting by file name wants to be the 2nd sorting criteria, i.e. only among
> all instances of the same finding.
Yes both suggestions make sense to me.
>
> Jan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules
2023-01-06 10:41 ` [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules Luca Fancellu
@ 2023-01-18 8:35 ` Luca Fancellu
2023-01-21 0:39 ` Stefano Stabellini
1 sibling, 0 replies; 8+ messages in thread
From: Luca Fancellu @ 2023-01-18 8:35 UTC (permalink / raw)
To: Xen-devel
Cc: Wei Chen, George Dunlap, Jan Beulich, Julien Grall,
Stefano Stabellini, Michal Orzel, Xenia Ragiadakou
> On 6 Jan 2023, at 10:41, Luca Fancellu <Luca.Fancellu@arm.com> wrote:
>
> Add parameter to skip the passed MISRA rules during the cppcheck
> analysis, the rules are specified as a list of comma separated
> rules with the MISRA number notation (e.g. 1.1,1.3,...).
>
> Modify convert_misra_doc.py script to take an extra parameter
> giving a list of MISRA rule to be skipped, comma separated.
> While there, fix some typos in the help and print functions.
>
> Modify settings.py and cppcheck_analysis.py to have a new
> parameter (--cppcheck-skip-rules) used to specify a list of
> MISRA rule to be skipped during the cppcheck analysis.
>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
Gentle ping on this one, I’ve done the modifications for the suggestions received on the first patch,
I’m going to respin the serie so I would like to see if I need to change something also on this one.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules
2023-01-06 10:41 ` [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules Luca Fancellu
2023-01-18 8:35 ` Luca Fancellu
@ 2023-01-21 0:39 ` Stefano Stabellini
1 sibling, 0 replies; 8+ messages in thread
From: Stefano Stabellini @ 2023-01-21 0:39 UTC (permalink / raw)
To: Luca Fancellu
Cc: xen-devel, wei.chen, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall, Stefano Stabellini, Wei Liu
On Fri, 6 Jan 2023, Luca Fancellu wrote:
> Add parameter to skip the passed MISRA rules during the cppcheck
> analysis, the rules are specified as a list of comma separated
> rules with the MISRA number notation (e.g. 1.1,1.3,...).
>
> Modify convert_misra_doc.py script to take an extra parameter
> giving a list of MISRA rule to be skipped, comma separated.
> While there, fix some typos in the help and print functions.
>
> Modify settings.py and cppcheck_analysis.py to have a new
> parameter (--cppcheck-skip-rules) used to specify a list of
> MISRA rule to be skipped during the cppcheck analysis.
>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> xen/scripts/xen_analysis/cppcheck_analysis.py | 8 +++--
> xen/scripts/xen_analysis/settings.py | 35 +++++++++++--------
> xen/tools/convert_misra_doc.py | 28 ++++++++++-----
> 3 files changed, 46 insertions(+), 25 deletions(-)
>
> diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
> index 0e952a169641..cc1f403d315e 100644
> --- a/xen/scripts/xen_analysis/cppcheck_analysis.py
> +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
> @@ -153,11 +153,15 @@ def generate_cppcheck_deps():
> if settings.cppcheck_misra:
> cppcheck_flags = cppcheck_flags + " --addon=cppcheck-misra.json"
>
> + skip_rules_arg = ""
> + if settings.cppcheck_skip_rules != "":
> + skip_rules_arg = "-s {}".format(settings.cppcheck_skip_rules)
> +
> utils.invoke_command(
> "{}/convert_misra_doc.py -i {}/docs/misra/rules.rst"
> - " -o {}/cppcheck-misra.txt -j {}/cppcheck-misra.json"
> + " -o {}/cppcheck-misra.txt -j {}/cppcheck-misra.json {}"
> .format(settings.tools_dir, settings.repo_dir,
> - settings.outdir, settings.outdir),
> + settings.outdir, settings.outdir, skip_rules_arg),
> False, CppcheckDepsPhaseError,
> "An error occured when running:\n{}"
> )
> diff --git a/xen/scripts/xen_analysis/settings.py b/xen/scripts/xen_analysis/settings.py
> index a8502e554e95..8c0d357fe0dc 100644
> --- a/xen/scripts/xen_analysis/settings.py
> +++ b/xen/scripts/xen_analysis/settings.py
> @@ -24,6 +24,7 @@ cppcheck_binpath = "cppcheck"
> cppcheck_html = False
> cppcheck_htmlreport_binpath = "cppcheck-htmlreport"
> cppcheck_misra = False
> +cppcheck_skip_rules = ""
> make_forward_args = ""
> outdir = xen_dir
>
> @@ -53,20 +54,22 @@ Cppcheck report creation phase runs only when --run-cppcheck is passed to the
> script.
>
> Options:
> - --build-only Run only the commands to build Xen with the optional
> - make arguments passed to the script
> - --clean-only Run only the commands to clean the analysis artifacts
> - --cppcheck-bin= Path to the cppcheck binary (Default: {})
> - --cppcheck-html Produce an additional HTML output report for Cppcheck
> - --cppcheck-html-bin= Path to the cppcheck-html binary (Default: {})
> - --cppcheck-misra Activate the Cppcheck MISRA analysis
> - --distclean Clean analysis artifacts and reports
> - -h, --help Print this help
> - --no-build Skip the build Xen phase
> - --no-clean Don\'t clean the analysis artifacts on exit
> - --run-coverity Run the analysis for the Coverity tool
> - --run-cppcheck Run the Cppcheck analysis tool on Xen
> - --run-eclair Run the analysis for the Eclair tool
> + --build-only Run only the commands to build Xen with the optional
> + make arguments passed to the script
> + --clean-only Run only the commands to clean the analysis artifacts
> + --cppcheck-bin= Path to the cppcheck binary (Default: {})
> + --cppcheck-html Produce an additional HTML output report for Cppcheck
> + --cppcheck-html-bin= Path to the cppcheck-html binary (Default: {})
> + --cppcheck-misra Activate the Cppcheck MISRA analysis
> + --cppcheck-skip-rules= List of MISRA rules to be skipped, comma separated.
> + (e.g. --cppcheck-skip-rules=1.1,20.7,8.4)
> + --distclean Clean analysis artifacts and reports
> + -h, --help Print this help
> + --no-build Skip the build Xen phase
> + --no-clean Don\'t clean the analysis artifacts on exit
> + --run-coverity Run the analysis for the Coverity tool
> + --run-cppcheck Run the Cppcheck analysis tool on Xen
> + --run-eclair Run the analysis for the Eclair tool
> """
> print(msg.format(sys.argv[0], cppcheck_binpath,
> cppcheck_htmlreport_binpath))
> @@ -78,6 +81,7 @@ def parse_commandline(argv):
> global cppcheck_html
> global cppcheck_htmlreport_binpath
> global cppcheck_misra
> + global cppcheck_skip_rules
> global make_forward_args
> global outdir
> global step_get_make_vars
> @@ -115,6 +119,9 @@ def parse_commandline(argv):
> cppcheck_htmlreport_binpath = args_with_content_regex.group(2)
> elif option == "--cppcheck-misra":
> cppcheck_misra = True
> + elif args_with_content_regex and \
> + args_with_content_regex.group(1) == "--cppcheck-skip-rules":
> + cppcheck_skip_rules = args_with_content_regex.group(2)
> elif option == "--distclean":
> target_distclean = True
> elif (option == "--help") or (option == "-h"):
> diff --git a/xen/tools/convert_misra_doc.py b/xen/tools/convert_misra_doc.py
> index 13074d8a2e91..8984ec625fa7 100755
> --- a/xen/tools/convert_misra_doc.py
> +++ b/xen/tools/convert_misra_doc.py
> @@ -4,12 +4,14 @@
> This script is converting the misra documentation RST file into a text file
> that can be used as text-rules for cppcheck.
> Usage:
> - convert_misr_doc.py -i INPUT [-o OUTPUT] [-j JSON]
> + convert_misra_doc.py -i INPUT [-o OUTPUT] [-j JSON] [-s RULES,[...,RULES]]
>
> INPUT - RST file containing the list of misra rules.
> OUTPUT - file to store the text output to be used by cppcheck.
> If not specified, the result will be printed to stdout.
> JSON - cppcheck json file to be created (optional).
> + RULES - list of rules to skip during the analysis, comma separated
> + (e.g. 1.1,1.2,1.3,...)
> """
>
> import sys, getopt, re
> @@ -47,21 +49,25 @@ def main(argv):
> outfile = ''
> outstr = sys.stdout
> jsonfile = ''
> + force_skip = ''
>
> try:
> - opts, args = getopt.getopt(argv,"hi:o:j:",["input=","output=","json="])
> + opts, args = getopt.getopt(argv,"hi:o:j:s:",
> + ["input=","output=","json=","skip="])
> except getopt.GetoptError:
> - print('convert-misra.py -i <input> [-o <output>] [-j <json>')
> + print('convert-misra.py -i <input> [-o <output>] [-j <json>] [-s <rules>]')
> sys.exit(2)
> for opt, arg in opts:
> if opt == '-h':
> - print('convert-misra.py -i <input> [-o <output>] [-j <json>')
> + print('convert-misra.py -i <input> [-o <output>] [-j <json>] [-s <rules>]')
> print(' If output is not specified, print to stdout')
> sys.exit(1)
> elif opt in ("-i", "--input"):
> infile = arg
> elif opt in ("-o", "--output"):
> outfile = arg
> + elif opt in ("-s", "--skip"):
> + force_skip = arg
> elif opt in ("-j", "--json"):
> jsonfile = arg
>
> @@ -169,14 +175,18 @@ def main(argv):
>
> skip_list = []
>
> + # Add rules to be skipped anyway
> + for r in force_skip.split(','):
> + skip_list.append(r)
> +
> # Search for missing rules and add a dummy text with the rule number
> for i in misra_c2012_rules:
> for j in list(range(1,misra_c2012_rules[i]+1)):
> - if str(i) + '.' + str(j) not in rule_list:
> - outstr.write('Rule ' + str(i) + '.' + str(j) + '\n')
> - outstr.write('No description for rule ' + str(i) + '.' + str(j)
> - + '\n')
> - skip_list.append(str(i) + '.' + str(j))
> + rule_str = str(i) + '.' + str(j)
> + if (rule_str not in rule_list) and (rule_str not in skip_list):
> + outstr.write('Rule ' + rule_str + '\n')
> + outstr.write('No description for rule ' + rule_str + '\n')
> + skip_list.append(rule_str)
>
> # Make cppcheck happy by starting the appendix
> outstr.write('Appendix B\n')
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-01-21 0:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 10:41 [PATCH 0/2] Cppcheck MISRA analysis improvements Luca Fancellu
2023-01-06 10:41 ` [PATCH 1/2] xen/cppcheck: sort alphabetically cppcheck report entries Luca Fancellu
2023-01-09 11:15 ` Michal Orzel
2023-01-09 11:41 ` Jan Beulich
2023-01-09 14:26 ` Luca Fancellu
2023-01-06 10:41 ` [PATCH 2/2] xen/cppcheck: add parameter to skip given MISRA rules Luca Fancellu
2023-01-18 8:35 ` Luca Fancellu
2023-01-21 0:39 ` Stefano Stabellini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.