-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #12835 - added Python tests showing inline suppressions not work…
…ing with whole program analysis and -j2
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// cppcheck-suppress misra-c2012-8.4 | ||
// cppcheck-suppress misra-c2012-5.8 | ||
int misra_5_8_var1; |
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,2 @@ | ||
// cppcheck-suppress misra-c2012-5.8 | ||
static int misra_5_8_var1; |
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,87 @@ | ||
import os | ||
import pytest | ||
import json | ||
from testutils import cppcheck | ||
|
||
__script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
__proj_inline_suppres_path = 'whole-program' + os.path.sep | ||
|
||
# TODO: use dedicated addon | ||
|
||
|
||
def __create_compile_commands(dir, entries): | ||
j = [] | ||
for e in entries: | ||
f = os.path.basename(e) | ||
obj = { | ||
'directory': os.path.dirname(os.path.abspath(e)), | ||
'command': 'gcc -c {}'.format(f), | ||
'file': f | ||
} | ||
j.append(obj) | ||
compile_commands = os.path.join(dir, 'compile_commmands.json') | ||
with open(compile_commands, 'wt') as f: | ||
f.write(json.dumps(j)) | ||
return compile_commands | ||
|
||
|
||
def __test_suppress_inline(extra_args): | ||
args = [ | ||
'-q', | ||
'--addon=misra', | ||
'--template=simple', | ||
'--enable=information,style', | ||
'--disable=missingInclude', # TODO: remove | ||
'--inline-suppr', | ||
'--error-exitcode=1', | ||
'{}whole1.c'.format(__proj_inline_suppres_path), | ||
'{}whole2.c'.format(__proj_inline_suppres_path) | ||
] | ||
args += extra_args | ||
ret, stdout, stderr = cppcheck(args, cwd=__script_dir) | ||
lines = stderr.splitlines() | ||
assert lines == [] | ||
assert stdout == '' | ||
assert ret == 0, stdout | ||
|
||
|
||
def test_suppress_inline(): | ||
__test_suppress_inline(['-j1']) | ||
|
||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_suppress_inline_j(): | ||
__test_suppress_inline(['-j2']) | ||
|
||
|
||
def __test_suppress_inline_project(tmpdir, extra_args): | ||
compile_db = __create_compile_commands(tmpdir, [ | ||
'{}whole1.c'.format(__proj_inline_suppres_path), | ||
'{}whole2.c'.format(__proj_inline_suppres_path) | ||
]) | ||
|
||
args = [ | ||
'-q', | ||
'--addon=misra', | ||
'--template=simple', | ||
'--enable=information,style', | ||
'--disable=missingInclude', # TODO: remove | ||
'--inline-suppr', | ||
'--error-exitcode=1', | ||
'--project='.format(compile_db) | ||
] | ||
args += extra_args | ||
ret, stdout, stderr = cppcheck(args, cwd=__script_dir) | ||
lines = stderr.splitlines() | ||
assert lines == [] | ||
assert stdout == '' | ||
assert ret == 0, stdout | ||
|
||
|
||
def test_suppress_inline_project(): | ||
__test_suppress_inline(['-j1']) | ||
|
||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_suppress_inline_project_j(): | ||
__test_suppress_inline(['-j2']) |