Skip to content

Commit

Permalink
refs #12835/#12839 - added Python tests for known issues with whole p…
Browse files Browse the repository at this point in the history
…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
firewave authored Jun 14, 2024
1 parent 6527912 commit 83f890a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/cli/whole-program/whole1.c
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;
2 changes: 2 additions & 0 deletions test/cli/whole-program/whole2.c
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;
88 changes: 88 additions & 0 deletions test/cli/whole-program_test.py
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'])

0 comments on commit 83f890a

Please sign in to comment.