Skip to content
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

Merged
merged 11 commits into from
Oct 30, 2024
Merged

Conversation

feeelin
Copy link
Contributor

@feeelin feeelin commented Sep 30, 2024

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>

Was added support for PVS-Studio JSON report format in CodeChecker report converter
Copy link
Contributor

@vodorok vodorok left a 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.

Copy link
Contributor Author

@feeelin feeelin left a 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.

Copy link
Contributor

@vodorok vodorok left a 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

@feeelin
Copy link
Contributor Author

feeelin commented Oct 1, 2024

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.

Copy link
Contributor Author

@feeelin feeelin left a 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 :)

@feeelin feeelin requested a review from dkrupp as a code owner October 3, 2024 11:53
Copy link
Contributor Author

@feeelin feeelin left a 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.

@feeelin
Copy link
Contributor Author

feeelin commented Oct 9, 2024

Hello @vodorok, @bruntib, @dkrupp!
Still waiting for your response to merge the changes

@feeelin feeelin requested a review from vodorok October 9, 2024 11:07
@feeelin
Copy link
Contributor Author

feeelin commented Oct 14, 2024

Hello @vodorok, @bruntib, @dkrupp!
All tests is passed, still waiting for your review :)

Copy link
Member

@dkrupp dkrupp left a 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')
Copy link
Member

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.

Copy link
Contributor Author

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"]
)
Copy link
Member

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.

Copy link
Contributor Author

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:
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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.

@feeelin feeelin requested a review from dkrupp October 25, 2024 06:30
@feeelin
Copy link
Contributor Author

feeelin commented Oct 30, 2024

Hello @vodorok, @bruntib, @dkrupp!
The tests worked properly (except for the GUI, but I didn't make any changes to the interface and I suspect that the problem is not in my patch). Do any other changes need to be made, or we can end this branch?

Copy link
Member

@dkrupp dkrupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@bruntib bruntib left a 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!

@feeelin
Copy link
Contributor Author

feeelin commented Oct 30, 2024

Committed the latest edits. Thanks for your help!

Copy link
Contributor

@vodorok vodorok left a 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!

@bruntib bruntib merged commit 3320e9a into Ericsson:master Oct 30, 2024
7 of 8 checks passed
@feeelin
Copy link
Contributor Author

feeelin commented Nov 11, 2024

Hi, @bruntib, @dkrupp !
When will the changes from this branch make it into the release (pypi and github)?

@vodorok
Copy link
Contributor

vodorok commented Nov 11, 2024

Hi, @feeelin, we plan our next feature release for early December, CodeChecker 6.25.0. This change will be included in that release.

@feeelin
Copy link
Contributor Author

feeelin commented Dec 4, 2024

Hi, @bruntib, @dkrupp!
Have the plans for the 6.25.0 release changed? And will it be released before the end of this week?

@bruntib
Copy link
Contributor

bruntib commented Dec 4, 2024

Hi,
We're planning to deploy a release candidate this year. The main release will come in January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants