-
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/#12839 - added Python tests for known issues with whole p…
…rogram analysis (#6521) added Python tests showing inline suppressions not working with whole program analysis and -j2 as well as tests for missing whole program analysis execution for addons
- Loading branch information
Showing
3 changed files
with
93 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,88 @@ | ||
import os | ||
import pytest | ||
import json | ||
from testutils import cppcheck | ||
|
||
__script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# 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 | ||
} | ||
print(obj) | ||
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_addon_suppress_inline(extra_args): | ||
args = [ | ||
'-q', | ||
'--addon=misra', | ||
'--template=simple', | ||
'--enable=information,style', | ||
'--disable=missingInclude', # TODO: remove | ||
'--inline-suppr', | ||
'--error-exitcode=1', | ||
'whole-program/whole1.c', | ||
'whole-program/whole2.c' | ||
] | ||
args += extra_args | ||
ret, stdout, stderr = cppcheck(args, cwd=__script_dir) | ||
lines = stderr.splitlines() | ||
assert lines == [] | ||
assert stdout == '' | ||
assert ret == 0, stdout | ||
|
||
|
||
def test_addon_suppress_inline(): | ||
__test_addon_suppress_inline(['-j1']) | ||
|
||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_addon_suppress_inline_j(): | ||
__test_addon_suppress_inline(['-j2']) | ||
|
||
|
||
def __test_addon_suppress_inline_project(tmpdir, extra_args): | ||
compile_db = __create_compile_commands(tmpdir, [ | ||
os.path.join(__script_dir, 'whole-program', 'whole1.c'), | ||
os.path.join(__script_dir, 'whole-program', 'whole2.c') | ||
]) | ||
|
||
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 | ||
|
||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_addon_suppress_inline_project(tmpdir): | ||
__test_addon_suppress_inline_project(tmpdir, ['-j1']) | ||
|
||
|
||
@pytest.mark.xfail(strict=True) | ||
def test_addon_suppress_inline_project_j(tmpdir): | ||
__test_addon_suppress_inline_project(tmpdir, ['-j2']) |