-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PVS-Studio Static Code Analyzer support #4356
Conversation
Was added support for PVS-Studio JSON report format in CodeChecker report converter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @feeelin,
Thanks for the contribution!
Please add tests for your newly implemented report converter.
Look for already existing converter tests under: codechecker/tools/report-converter/tests/unit/analyzers
.
You should create a separate pvs_studio_output_test_files
in this folder, containing the sample outputs of your analyzer, the expected .plist
(CodeChecker) output, and the source that's the basis of the analyzer output.
You can write your test implementation by using these sample files in test_pvs_studio_parser.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added tests for the PVS-Studio report converter by analogy with other tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I see a few linter errors in the parser source and the test source..
https://github.com/Ericsson/codechecker/actions/runs/11106888906/job/30856471518?pr=4356
pycodestyle codechecker_report_converter tests --exclude tests/unit/analyzers/pyflakes_output_test_files/files
codechecker_report_converter/analyzers/pvs_studio/analyzer_result.py:12:80: E501 line too long (80 > 79 characters)
codechecker_report_converter/analyzers/pvs_studio/analyzer_result.py:39:80: E501 line too long (88 > 79 characters)
codechecker_report_converter/analyzers/pvs_studio/analyzer_result.py:53:80: E501 line too long (81 > 79 characters)
codechecker_report_converter/analyzers/pvs_studio/analyzer_result.py:57:80: E501 line too long (86 > 79 characters)
tests/unit/analyzers/test_pvs_studio_parser.py:10:1: E302 expected 2 blank lines, found 1
tests/unit/analyzers/test_pvs_studio_parser.py:28:80: E501 line too long (116 > 79 characters)
tests/unit/analyzers/test_pvs_studio_parser.py:37:80: E501 line too long (85 > 79 characters)
tests/unit/analyzers/test_pvs_studio_parser.py:38:1: W293 blank line contains whitespace
make: *** [tests/Makefile:29: pycodestyle] Error 1
Okay, I'll fix that in the near future! There is one question: will the severity field in the Report class be used when displaying the report in the future? If it is, I would add the transformation of our diagnostics' levels into CodeChecker's severity format so that in the future we could determine the level of PVS-Studio diagnostics more precisely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the crashing test. Our analyzer records the full path to the file in the report, so I made a method that will make the path to the nearby sample.cpp file up to date, don't be scared by this change :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the specifics of the tests, now only the analyzer's warning will be checked instead of the whole report, because unittest caches the unupdated path to the file in .plist
files.
Also added PVS-Studio to the list of supported analyzers and report-converter documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your patch!!
I have some minor remarks for the test cases.
Could you please take a look at them?
|
||
with open(plist_file, mode='rb') as pfile: | ||
res = plistlib.load(pfile) | ||
res['files'][0] = os.path.join('files', 'sample.cpp') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you modifying transformation result plist after calling the transform()?
Shouldn't we have there an absolute path to sample.cpp? This should be compared to the location of sample.cpp in the sample.plist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably forgot to remove that line when I added the method to set absolute paths in the json report. Fixed it.
self.assertEqual( | ||
res["diagnostics"][0]["location"]["line"], | ||
exp["diagnostics"][0]["location"]["line"] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please add an assertion about the generated HASH? That would prove that the transform() generates the correct hash for the report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, I added this.
) | ||
|
||
@staticmethod | ||
def make_report_valid() -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a docstring comment to this function explaining what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, I added this.
report_path = os.path.join(samples_path, "sample.json") | ||
with open(report_path, 'r') as file: | ||
data = json.loads(file.read()) | ||
data["warnings"][0]["positions"][0]["file"] = path_to_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does PVS studio support relative path to the source files?
If it does, I think we could test the transform() function for .json files with relative paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, PVS-Studio uses absolute paths to source files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add the license header to __init__.py
Sorry for the slow review process. After after fixing these minor things, we can merge it. Thanks for your work!
tools/report-converter/codechecker_report_converter/analyzers/pvs_studio/analyzer_result.py
Outdated
Show resolved
Hide resolved
Committed the latest edits. Thanks for your help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks a lot!
Hi, @feeelin, we plan our next feature release for early December, CodeChecker 6.25.0. This change will be included in that release. |
Hi, |
Hello! We added support for JSON report of PVS-Studio static analyzer in report-converter so that you could view the analyzer's report in CodeChecker!
Usage:
report-converter -t pvs-studio -o <path to converted reports> <path to PVS-Studio's report.json>