Fix and improvements to xen-analysis.py - Pt.2
cover Fix and improvements to xen-analysis.py - Pt.2
This serie includes one improvement suggested by Andrew Cooper, and two bug fix for the xen-analysis.py tool.
Luca Fancellu (3):
xen/misra: xen-analysis.py: Improve the cppcheck version check xen/misra: xen-analysis.py: Fix latent bug xen/misra: xen-analysis.py: Fix cppcheck report relative paths
xen/scripts/xen_analysis/cppcheck_analysis.py | 13 +++------ .../xen_analysis/cppcheck_report_utils.py | 27 +++++++++++++++---- 2 files changed, 26 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 xen/misra: xen-analysis.py: Improve the cppcheck version check
Use tuple comparison to check the cppcheck version.
Take the occasion to harden the regex, escaping the dots so that we check for them instead of generic characters.
--- xen/scripts/xen_analysis/cppcheck_analysis.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
xen/scripts/xen_analysis/cppcheck_analysis.py +4 -9
@@ -157,7 +157,7 @@ def generate_cppcheck_deps(): "Error occured retrieving cppcheck version:\n{}\n\n{}" ) - version_regex = re.search('^Cppcheck (\d+).(\d+)(?:.\d+)?$', + version_regex = re.search('^Cppcheck (\d+)\.(\d+)(?:\.\d+)?$', invoke_cppcheck, flags=re.M) # Currently, only cppcheck version >= 2.7 is supported, but version 2.8 is # known to be broken, please refer to docs/misra/cppcheck.txt
@@ -166,15 +166,10 @@ def generate_cppcheck_deps(): "Can't find cppcheck version or version not identified: " "{}".format(invoke_cppcheck) ) - major = int(version_regex.group(1)) - minor = int(version_regex.group(2)) - if major < 2 or (major == 2 and minor < 7): + version = (int(version_regex.group(1)), int(version_regex.group(2))) + if version < (2, 7) or version == (2, 8): raise CppcheckDepsPhaseError( - "Cppcheck version < 2.7 is not supported" - ) - if major == 2 and minor == 8: - raise CppcheckDepsPhaseError( - "Cppcheck version 2.8 is known to be broken, see the documentation" + "Cppcheck version < 2.7 or 2.8 are not supported" ) # If misra option is selected, append misra addon and generate cppcheck
Signature · 1 line
2.34.1
Re: [PATCH 1/3] xen/misra: xen-analysis.py: Improve the cppcheck version check
Quoted 7 lines · Luca Fancellu
Use tuple comparison to check the cppcheck version.
Take the occasion to harden the regex, escaping the dots so that we check for them instead of generic characters.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Luca Fancellu <[email protected]>
Quoted 39 lines
--- xen/scripts/xen_analysis/cppcheck_analysis.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)xen/scripts/xen_analysis/cppcheck_analysis.py +4
-9@@ -157,7 +157,7 @@ def generate_cppcheck_deps(): "Error occured retrieving cppcheck version:\n{}\n\n{}" ) - version_regex = re.search('^Cppcheck (\d+).(\d+)(?:.\d+)?$', + version_regex = re.search('^Cppcheck (\d+)\.(\d+)(?:\.\d+)?$', invoke_cppcheck, flags=re.M) # Currently, only cppcheck version >= 2.7 is supported, but version 2.8 is # known to be broken, please refer to docs/misra/cppcheck.txt@@ -166,15 +166,10 @@ def generate_cppcheck_deps(): "Can't find cppcheck version or version not identified: " "{}".format(invoke_cppcheck) ) - major = int(version_regex.group(1)) - minor = int(version_regex.group(2)) - if major < 2 or (major == 2 and minor < 7): + version = (int(version_regex.group(1)), int(version_regex.group(2))) + if version < (2, 7) or version == (2, 8): raise CppcheckDepsPhaseError( - "Cppcheck version < 2.7 is not supported" - ) - if major == 2 and minor == 8: - raise CppcheckDepsPhaseError( - "Cppcheck version 2.8 is known to be broken, see the documentation" + "Cppcheck version < 2.7 or 2.8 are not supported" ) # If misra option is selected, append misra addon and generate cppcheckSignature · 1 line
2.34.1
PATCH 2/3 xen/misra: xen-analysis.py: Fix latent bug
In reply to Luca FancelluCurrenly there is a latent bug that is not triggered because the function cppcheck_merge_txt_fragments is called with the parameter strip_paths having a list of only one element.
The bug is that the split function should not be in the loop for strip_paths, but one level before, fix it.
--- xen/scripts/xen_analysis/cppcheck_report_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/scripts/xen_analysis/cppcheck_report_utils.py +2 -2
@@ -104,8 +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 + "/", "") - # Split by : separator - text_report_content[i] = text_report_content[i].split(":") + # Split by : separator + text_report_content[i] = text_report_content[i].split(":") # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name)
Signature · 1 line
2.34.1
Re: [PATCH 2/3] xen/misra: xen-analysis.py: Fix latent bug
Quoted 9 lines · Luca Fancellu
Currenly there is a latent bug that is not triggered because the function
cppcheck_merge_txt_fragmentsis called with the parameterstrip_pathshaving a list of only one element.The bug is that the split function should not be in the loop for
strip_paths, but one level before, fix it.Fixes 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")Signed-off-by Luca Fancellu <[email protected]>
Quoted 22 lines
--- xen/scripts/xen_analysis/cppcheck_report_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/scripts/xen_analysis/cppcheck_report_utils.py +2
-2@@ -104,8 +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 + "/", "") - # Split by : separator - text_report_content[i] = text_report_content[i].split(":") + # Split by : separator + text_report_content[i] = text_report_content[i].split(":") # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name)Signature · 1 line
2.34.1
Re: [PATCH 2/3] xen/misra: xen-analysis.py: Fix latent bug
In reply to Luca FancelluQuoted 9 lines · Luca Fancellu
Currenly there is a latent bug that is not triggered because the function
cppcheck_merge_txt_fragmentsis called with the parameterstrip_pathshaving a list of only one element.The bug is that the split function should not be in the loop for
strip_paths, but one level before, fix it.Fixes 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")Signed-off-by Luca Fancellu <[email protected]>
Just wanted to mention it: I've committed the patch as is, but in the future could you please try to find slightly more specific a title for such a change? The way it is now, someone going over just the titles in the log will have no clue at all what kind of bug was addressed here.
Jan
Re: [PATCH 2/3] xen/misra: xen-analysis.py: Fix latent bug
Quoted 12 lines · Jan Beulich
Quoted 7 lines · Luca Fancellu
Currenly there is a latent bug that is not triggered because the function
cppcheck_merge_txt_fragmentsis called with the parameterstrip_pathshaving a list of only one element.The bug is that the split function should not be in the loop for
strip_paths, but one level before, fix it.
Quoted 8 lines
Quoted 2 lines
Fixes 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")Signed-off-by Luca Fancellu <[email protected]>Just wanted to mention it: I've committed the patch as is, but in the future could you please try to find slightly more specific a title for such a change? The way it is now, someone going over just the titles in the log will have no clue at all what kind of bug was addressed here.
Sure, I will be more specific in the future, thank you
Quoted 2 lines
Jan
PATCH 3/3 xen/misra: xen-analysis.py: Fix cppcheck report relative paths
In reply to Luca FancelluFix the generation of the relative path from the repo, for cppcheck reports, when the script is launching make with in-tree build.
--- .../xen_analysis/cppcheck_report_utils.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-)
xen/scripts/xen_analysis/cppcheck_report_utils.py +21 -4
@@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os +import os, re +from . import settings from xml.etree import ElementTree class CppcheckHTMLReportError(Exception):
@@ -101,12 +102,28 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): text_report_content = list(text_report_content) # Strip path from report lines for i in list(range(0, len(text_report_content))): - for path in strip_paths: - text_report_content[i] = text_report_content[i].replace( - path + "/", "") # Split by : separator text_report_content[i] = text_report_content[i].split(":") + for path in strip_paths: + text_report_content[i][0] = \ + text_report_content[i][0].replace(path + "/", "") + + # When the compilation is in-tree, the makefile places + # the directory in /xen/xen, making cppcheck produce + # relative path from there, so check if "xen/" is a prefix + # of the path and if it's not, check if it can be added to + # have a relative path from the repository instead of from + # /xen/xen + if not text_report_content[i][0].startswith("xen/"): + # cppcheck first entry is in this format: + # path/to/file(line,cols), remove (line,cols) + cppcheck_file = re.sub(r'\(.*\)', '', + text_report_content[i][0]) + if os.path.isfile(settings.xen_dir + "/" + cppcheck_file): + text_report_content[i][0] = \ + "xen/" + text_report_content[i][0] + # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name) text_report_content.sort(key = lambda x: (x[1], x[0]))
Signature · 1 line
2.34.1
Re: [PATCH 3/3] xen/misra: xen-analysis.py: Fix cppcheck report relative paths
Quoted 26 lines · Luca Fancellu
Fix the generation of the relative path from the repo, for cppcheck reports, when the script is launching make with in-tree build.
Fixes b046f7e37489 ("xen/misra: xen-analysis.py: use the relative path from the ...")Reported-by Michal Orzel <[email protected]>Signed-off-by Luca Fancellu <[email protected]>--- .../xen_analysis/cppcheck_report_utils.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-)xen/scripts/xen_analysis/cppcheck_report_utils.py +2
-1@@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os +import os, re +from . import settings from xml.etree import ElementTree class CppcheckHTMLReportError(Exception):@@ -101,12 +102,28 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): text_report_content = list(text_report_content) # Strip path from report lines
xen/scripts/xen_analysis/cppcheck_report_utils.py def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): · line 110
Quoted 10 lines
xen/scripts/xen_analysis/cppcheck_report_utils.py +3
-3for i in list(range(0, len(text_report_content))): - for path in strip_paths: - text_report_content[i] = text_report_content[i].replace( - path + "/", "") # Split by : separator text_report_content[i] = text_report_content[i].split(":") + for path in strip_paths: + text_report_content[i][0] = \ + text_report_content[i][0].replace(path + "/", "")
Why moving this for loop after "Split by : separator"? If it is necessary, would it make sense to do it in the previous patch?
Quoted 21 lines
xen/scripts/xen_analysis/cppcheck_report_utils.py +15
-0+ # When the compilation is in-tree, the makefile places + # the directory in /xen/xen, making cppcheck produce + # relative path from there, so check if "xen/" is a prefix + # of the path and if it's not, check if it can be added to + # have a relative path from the repository instead of from + # /xen/xen + if not text_report_content[i][0].startswith("xen/"): + # cppcheck first entry is in this format: + # path/to/file(line,cols), remove (line,cols) + cppcheck_file = re.sub(r'\(.*\)', '', + text_report_content[i][0]) + if os.path.isfile(settings.xen_dir + "/" + cppcheck_file): + text_report_content[i][0] = \ + "xen/" + text_report_content[i][0] + # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name) text_report_content.sort(key = lambda x: (x[1], x[0]))Signature · 1 line
2.34.1
Re: [PATCH 3/3] xen/misra: xen-analysis.py: Fix cppcheck report relative paths
Quoted 38 lines · Stefano Stabellini
Quoted 33 lines · Luca Fancellu
Fix the generation of the relative path from the repo, for cppcheck reports, when the script is launching make with in-tree build.
Fixes b046f7e37489 ("xen/misra: xen-analysis.py: use the relative path from the ...")Reported-by Michal Orzel <[email protected]>Signed-off-by Luca Fancellu <[email protected]>---
.../xen_analysis/cppcheck_report_utils.py| 25 ++++++++++++++++---1 file changed, 21 insertions(+), 4 deletions(-)xen/scripts/xen_analysis/cppcheck_report_utils.py +2
-1@@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os +import os, re +from . import settingsfrom xml.etree import ElementTree
class CppcheckHTMLReportError(Exception):
xen/scripts/xen_analysis/cppcheck_report_utils.py +0
-3@@ -101,12 +102,28 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): text_report_content = list(text_report_content) # Strip path from report lines for i in list(range(0, len(text_report_content))): - for path in strip_paths: - text_report_content[i] = text_report_content[i].replace( - path + "/", "") # Split by : separator text_report_content[i] = text_report_content[i].split(":")
Quoted 6 lines
xen/scripts/xen_analysis/cppcheck_report_utils.py def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): · line 110
Quoted 3 lines
xen/scripts/xen_analysis/cppcheck_report_utils.py +3
-0+ for path in strip_paths: + text_report_content[i][0] = \ + text_report_content[i][0].replace(path + "/", "")Why moving this for loop after "Split by : separator"? If it is necessary, would it make sense to do it in the previous patch?
Hi Stefano,
In the patch before I was fixing the bug, so I thought it was better to don’t introduce other changes, here I moved the loop after the split because in this way we take into account only the first element of the ‘:’ separated string, that is the path + “(line,col)”.
Before this path it was ok to do the replace on the full string because we were going just to remove the path, now instead we use that path to check if it actually exists.
Quoted 22 lines
Quoted 22 lines
xen/scripts/xen_analysis/cppcheck_report_utils.py +15
-0+ # When the compilation is in-tree, the makefile places + # the directory in /xen/xen, making cppcheck produce + # relative path from there, so check if "xen/" is a prefix + # of the path and if it's not, check if it can be added to + # have a relative path from the repository instead of from + # /xen/xen + if not text_report_content[i][0].startswith("xen/"): + # cppcheck first entry is in this format: + # path/to/file(line,cols), remove (line,cols) + cppcheck_file = re.sub(r'\(.*\)', '', + text_report_content[i][0]) + if os.path.isfile(settings.xen_dir + "/" + cppcheck_file): + text_report_content[i][0] = \ + "xen/" + text_report_content[i][0] + # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name) text_report_content.sort(key = lambda x: (x[1], x[0]))Signature · 1 line
2.34.1
Re: [PATCH 3/3] xen/misra: xen-analysis.py: Fix cppcheck report relative paths
In reply to Luca FancelluQuoted 6 lines · Luca Fancellu
Fix the generation of the relative path from the repo, for cppcheck reports, when the script is launching make with in-tree build.
Fixes b046f7e37489 ("xen/misra: xen-analysis.py: use the relative path from the ...")Reported-by Michal Orzel <[email protected]>Signed-off-by Luca Fancellu <[email protected]>
Quoted 52 lines
--- .../xen_analysis/cppcheck_report_utils.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-)xen/scripts/xen_analysis/cppcheck_report_utils.py +21
-4@@ -1,6 +1,7 @@ #!/usr/bin/env python3 -import os +import os, re +from . import settings from xml.etree import ElementTree class CppcheckHTMLReportError(Exception):@@ -101,12 +102,28 @@ def cppcheck_merge_txt_fragments(fragments_list, out_txt_file, strip_paths): text_report_content = list(text_report_content) # Strip path from report lines for i in list(range(0, len(text_report_content))): - for path in strip_paths: - text_report_content[i] = text_report_content[i].replace( - path + "/", "") # Split by : separator text_report_content[i] = text_report_content[i].split(":") + for path in strip_paths: + text_report_content[i][0] = \ + text_report_content[i][0].replace(path + "/", "") + + # When the compilation is in-tree, the makefile places + # the directory in /xen/xen, making cppcheck produce + # relative path from there, so check if "xen/" is a prefix + # of the path and if it's not, check if it can be added to + # have a relative path from the repository instead of from + # /xen/xen + if not text_report_content[i][0].startswith("xen/"): + # cppcheck first entry is in this format: + # path/to/file(line,cols), remove (line,cols) + cppcheck_file = re.sub(r'\(.*\)', '', + text_report_content[i][0]) + if os.path.isfile(settings.xen_dir + "/" + cppcheck_file): + text_report_content[i][0] = \ + "xen/" + text_report_content[i][0] + # sort alphabetically for second field (misra rule) and as second # criteria for the first field (file name) text_report_content.sort(key = lambda x: (x[1], x[0]))Signature · 1 line
2.34.1