-
Notifications
You must be signed in to change notification settings - Fork 385
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
[report-converter] Sparse parser #3160
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tools/report-converter/codechecker_report_converter/sparse/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- |
36 changes: 36 additions & 0 deletions
36
tools/report-converter/codechecker_report_converter/sparse/analyzer_result.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
|
||
from codechecker_report_converter.analyzer_result import AnalyzerResult | ||
|
||
from .output_parser import SparseParser | ||
from ..plist_converter import PlistConverter | ||
|
||
|
||
class SparseAnalyzerResult(AnalyzerResult): | ||
""" Transform analyzer result of Sparse. """ | ||
|
||
TOOL_NAME = 'sparse' | ||
NAME = 'Sparse' | ||
URL = 'https://git.kernel.org/pub/scm/devel/sparse/sparse.git' | ||
|
||
def parse(self, analyzer_result): | ||
""" Creates plist files from the given analyzer result to the given | ||
output directory. | ||
""" | ||
parser = SparseParser(analyzer_result) | ||
|
||
content = self._get_analyzer_result_file_content(analyzer_result) | ||
if not content: | ||
return | ||
|
||
messages = parser.parse_messages(content) | ||
|
||
plist_converter = PlistConverter(self.TOOL_NAME) | ||
plist_converter.add_messages(messages) | ||
return plist_converter.get_plist_results() |
88 changes: 88 additions & 0 deletions
88
tools/report-converter/codechecker_report_converter/sparse/output_parser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# Part of the CodeChecker project, under the Apache License v2.0 with | ||
# LLVM Exceptions. See LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ------------------------------------------------------------------------- | ||
|
||
import logging | ||
import os | ||
import re | ||
|
||
from ..output_parser import BaseParser, Message, Event | ||
LOG = logging.getLogger('ReportConverter') | ||
|
||
|
||
class SparseParser(BaseParser): | ||
""" | ||
Parser for Sparse Output | ||
""" | ||
|
||
def __init__(self, analyzer_result): | ||
super(SparseParser, self).__init__() | ||
|
||
self.analyzer_result = analyzer_result | ||
|
||
self.message_line_re = re.compile( | ||
# File path followed by a ':'. | ||
r'^(?P<path>[\S ]+?):' | ||
# Line number followed by a ':'. | ||
r'(?P<line>\d+?):' | ||
# Column number followed by a ':'. | ||
r'(?P<column>\d+?):' | ||
# Message. | ||
r'(?P<message>[\S \t]+)\s*') | ||
|
||
self.note_line_re = re.compile( | ||
# File path followed by a ':'. | ||
r'^(?P<path>\.[\S ]+?):' | ||
# Line number followed by a ':'. | ||
r'(?P<line>\d+?):' | ||
# Column number followed by a ':'. | ||
r'(?P<column>\d+?):' | ||
# Message. | ||
r'(?P<message>[\S \t]+)\s*' | ||
) | ||
|
||
def parse_message(self, it, line): | ||
""" | ||
Actual Parsing function for the given line | ||
It is expected that each line contains a seperate report | ||
""" | ||
match = self.message_line_re.match(line) | ||
|
||
if (match is None): | ||
return None, next(it) | ||
|
||
checker_name = None | ||
|
||
file_path = os.path.normpath( | ||
os.path.join(os.path.dirname(self.analyzer_result), | ||
match.group('path'))) | ||
message = Message( | ||
file_path, | ||
int(match.group('line')), | ||
int(match.group('column')), | ||
match.group('message').strip(), | ||
checker_name) | ||
|
||
try: | ||
line = next(it) | ||
note_match = self.note_line_re.match(line) | ||
while note_match: | ||
file_path = os.path.normpath( | ||
os.path.join(os.path.dirname(self.analyzer_result), | ||
note_match.group('path'))) | ||
message.events.append(Event(file_path, | ||
int(note_match.group('line')), | ||
int(note_match | ||
.group('column')), | ||
note_match.group('message') | ||
.strip())) | ||
line = next(it) | ||
note_match = self.note_line_re.match(line) | ||
return message, line | ||
|
||
except StopIteration: | ||
return message, '' |
4 changes: 4 additions & 0 deletions
4
tools/report-converter/tests/unit/sparse_output_test_files/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
all: | ||
# Due to difference in format on kernel and command below, and to | ||
# test all the cases of output, the output is different in sample.out file | ||
sparse -Wsparse-all files/sample.c > ./sample.out 2>&1 || exit 0; |
9 changes: 9 additions & 0 deletions
9
tools/report-converter/tests/unit/sparse_output_test_files/files/sample.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
#include "sample.h" | ||
|
||
unsigned int machine_id; | ||
|
||
void main() | ||
{ | ||
printf("Inside main function"); | ||
} |
10 changes: 10 additions & 0 deletions
10
tools/report-converter/tests/unit/sparse_output_test_files/files/sample.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
static inline struct task_struct *get_task_struct(struct task_struct *t1, struct task_struct *t2) | ||
{ | ||
refcount_inc(t1, t2); | ||
return t2; | ||
} | ||
|
||
void refcount_inc(struct task_struct *t1, struct task_struct *t2) | ||
{ | ||
return; | ||
} |
69 changes: 69 additions & 0 deletions
69
tools/report-converter/tests/unit/sparse_output_test_files/sample.c.expected.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>diagnostics</key> | ||
<array> | ||
<dict> | ||
<key>category</key> | ||
<string>unknown</string> | ||
<key>check_name</key> | ||
<string>sparse</string> | ||
<key>description</key> | ||
<string>warning: symbol 'machine_id' was not declared. Should it be static?</string> | ||
<key>issue_hash_content_of_line_in_context</key> | ||
<string>474283465f76d26a290e0ce2e5dd3502</string> | ||
<key>location</key> | ||
<dict> | ||
<key>col</key> | ||
<integer>1</integer> | ||
<key>file</key> | ||
<integer>0</integer> | ||
<key>line</key> | ||
<integer>4</integer> | ||
</dict> | ||
<key>path</key> | ||
<array> | ||
<dict> | ||
<key>depth</key> | ||
<integer>0</integer> | ||
<key>kind</key> | ||
<string>event</string> | ||
<key>location</key> | ||
<dict> | ||
<key>col</key> | ||
<integer>1</integer> | ||
<key>file</key> | ||
<integer>0</integer> | ||
<key>line</key> | ||
<integer>4</integer> | ||
</dict> | ||
<key>message</key> | ||
<string>warning: symbol 'machine_id' was not declared. Should it be static?</string> | ||
</dict> | ||
</array> | ||
<key>type</key> | ||
<string>sparse</string> | ||
</dict> | ||
</array> | ||
<key>files</key> | ||
<array> | ||
<string>files/sample.c</string> | ||
</array> | ||
<key>metadata</key> | ||
<dict> | ||
<key>analyzer</key> | ||
<dict> | ||
<key>name</key> | ||
<string>sparse</string> | ||
</dict> | ||
<key>generated_by</key> | ||
<dict> | ||
<key>name</key> | ||
<string>report-converter</string> | ||
<key>version</key> | ||
<string>x.y.z</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 tried to convert what the sample.out with the report-converter tool and then store the results to a running server. Now there is only one report with a lot of bug steps:
I don't think this is what you want.
In my previous comment (#3160 (comment)) my recommendation was the following:
./files/sample.h:3:40: warning: incorrect type in argument 2 (different address spaces)
(thewarning
keyword identifies that we have a new report)../files/sample.h:3:40: expected struct task_struct *p1
. (So it doesn't contain the warning keyword like in the previous case).files/sample.c: note: in included file:
.So in case of the following output:
I want to see 3 reports:
files/sample.h:3:40: expected struct task_struct *p1
files/sample.h:3:40: got struct spinlock [noderef] __rcu *
In the third case the report will have multiple bug steps.
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.
Well Actually I thought that is what we wanted, a single report for all the files and hence changed the code to include it in the single report. 😢
This logic won't always stand true as some lines also start with
error
. Do you recommend modifying the regex as well now?Alright so in the tests, we will also have two
sample.c.expected.plist
andsample.h.expected.plist
, this is after the assumption that second line in thesample.out
file is removed. Correct me if I am wrong