Skip to content

Commit 83f890a

Browse files
authored
refs #12835/#12839 - added Python tests for known issues with whole program 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
1 parent 6527912 commit 83f890a

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

test/cli/whole-program/whole1.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// cppcheck-suppress misra-c2012-8.4
2+
// cppcheck-suppress misra-c2012-5.8
3+
int misra_5_8_var1;

test/cli/whole-program/whole2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// cppcheck-suppress misra-c2012-5.8
2+
static int misra_5_8_var1;

test/cli/whole-program_test.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import os
2+
import pytest
3+
import json
4+
from testutils import cppcheck
5+
6+
__script_dir = os.path.dirname(os.path.abspath(__file__))
7+
8+
# TODO: use dedicated addon
9+
10+
11+
def __create_compile_commands(dir, entries):
12+
j = []
13+
for e in entries:
14+
f = os.path.basename(e)
15+
obj = {
16+
'directory': os.path.dirname(os.path.abspath(e)),
17+
'command': 'gcc -c {}'.format(f),
18+
'file': f
19+
}
20+
print(obj)
21+
j.append(obj)
22+
compile_commands = os.path.join(dir, 'compile_commmands.json')
23+
with open(compile_commands, 'wt') as f:
24+
f.write(json.dumps(j))
25+
return compile_commands
26+
27+
28+
def __test_addon_suppress_inline(extra_args):
29+
args = [
30+
'-q',
31+
'--addon=misra',
32+
'--template=simple',
33+
'--enable=information,style',
34+
'--disable=missingInclude', # TODO: remove
35+
'--inline-suppr',
36+
'--error-exitcode=1',
37+
'whole-program/whole1.c',
38+
'whole-program/whole2.c'
39+
]
40+
args += extra_args
41+
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
42+
lines = stderr.splitlines()
43+
assert lines == []
44+
assert stdout == ''
45+
assert ret == 0, stdout
46+
47+
48+
def test_addon_suppress_inline():
49+
__test_addon_suppress_inline(['-j1'])
50+
51+
52+
@pytest.mark.xfail(strict=True)
53+
def test_addon_suppress_inline_j():
54+
__test_addon_suppress_inline(['-j2'])
55+
56+
57+
def __test_addon_suppress_inline_project(tmpdir, extra_args):
58+
compile_db = __create_compile_commands(tmpdir, [
59+
os.path.join(__script_dir, 'whole-program', 'whole1.c'),
60+
os.path.join(__script_dir, 'whole-program', 'whole2.c')
61+
])
62+
63+
args = [
64+
'-q',
65+
'--addon=misra',
66+
'--template=simple',
67+
'--enable=information,style',
68+
'--disable=missingInclude', # TODO: remove
69+
'--inline-suppr',
70+
'--error-exitcode=1',
71+
'--project={}'.format(compile_db)
72+
]
73+
args += extra_args
74+
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
75+
lines = stderr.splitlines()
76+
assert lines == []
77+
assert stdout == ''
78+
assert ret == 0, stdout
79+
80+
81+
@pytest.mark.xfail(strict=True)
82+
def test_addon_suppress_inline_project(tmpdir):
83+
__test_addon_suppress_inline_project(tmpdir, ['-j1'])
84+
85+
86+
@pytest.mark.xfail(strict=True)
87+
def test_addon_suppress_inline_project_j(tmpdir):
88+
__test_addon_suppress_inline_project(tmpdir, ['-j2'])

0 commit comments

Comments
 (0)