forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate suppress files automatically for source-code suppressions
- Loading branch information
1 parent
776ff71
commit cb7d4e5
Showing
11 changed files
with
192 additions
and
35 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"directory": ".", | ||
"command": "g++ suppress.cpp", | ||
"file": "suppress.cpp" | ||
} | ||
] |
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 @@ | ||
c417110e71a5cb8e8163d524076bb3ed||suppress.cpp||deliberate segfault! |
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 @@ | ||
int main() | ||
{ | ||
int *p = 0; | ||
|
||
// codechecker_suppress [all] deliberate segfault! | ||
return *p + 2; | ||
} |
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,74 @@ | ||
# ----------------------------------------------------------------------------- | ||
# The CodeChecker Infrastructure | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# ----------------------------------------------------------------------------- | ||
""" | ||
Test source-code level suppression data writing to suppress file. | ||
""" | ||
|
||
from subprocess import CalledProcessError | ||
import os | ||
import shlex | ||
import subprocess | ||
import unittest | ||
|
||
from libtest import env | ||
|
||
|
||
class TestSuppress(unittest.TestCase): | ||
""" | ||
Test source-code level suppression data writing to suppress file. | ||
""" | ||
|
||
def setUp(self): | ||
self.test_workspace = os.environ['TEST_WORKSPACE'] | ||
self.test_dir = os.path.join( | ||
os.path.dirname(__file__), "test_files") | ||
|
||
def test_source_suppress_export(self): | ||
""" | ||
Test exporting a source suppress comment automatically to file. | ||
""" | ||
|
||
def __call(command): | ||
try: | ||
print(' '.join(command)) | ||
proc = subprocess.Popen(shlex.split(' '.join(command)), | ||
cwd=self.test_dir, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
env=env.test_env()) | ||
out, err = proc.communicate() | ||
print(out) | ||
print(err) | ||
return 0 | ||
except CalledProcessError as cerr: | ||
print("Failed to call:\n" + ' '.join(cerr.cmd)) | ||
return cerr.returncode | ||
|
||
analyze_cmd = ['CodeChecker', 'analyze', | ||
os.path.join(self.test_dir, "build.json"), | ||
"--output", os.path.join(self.test_workspace, "reports") | ||
] | ||
ret = __call(analyze_cmd) | ||
self.assertEqual(ret, 0, "Couldn't create analysis of test project.") | ||
|
||
generated_file = os.path.join(self.test_workspace, | ||
"generated.suppress") | ||
|
||
extract_cmd = ['CodeChecker', 'parse', | ||
os.path.join(self.test_workspace, "reports"), | ||
"--suppress", generated_file, | ||
"--export-source-suppress" | ||
] | ||
__call(extract_cmd) | ||
self.assertEqual(ret, 0, "Failed to generate suppress file.") | ||
|
||
with open(generated_file, 'r') as generated: | ||
with open(os.path.join(self.test_dir, "expected.suppress"), | ||
'r') as expected: | ||
self.assertEqual(generated.read().strip(), | ||
expected.read().strip(), | ||
"The generated suppress file does not " | ||
"look like what was expected.") |