-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3160 from jay24rajput/sparse_parser
[report-converter] Sparse parser
- Loading branch information
Showing
14 changed files
with
513 additions
and
3 deletions.
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.