selfcheck : cleaned up some suppressions, fixed warnings and some cleanups (#4436)

* cleaned up triage.pro and pass all triage files to selfcheck

* CI-unixish.yml: factored out redundant selfcheck flags

* CI-unixish.yml: cleaned up selfcheck suppressions and fixed warnings

* added explicit `missingInclude` checks to selfcheck to work around current issues/limitations / fixed selfcheck includes / added some unit tests for `missingInclude`

* applied the selfcheck changes to the sanitizer jobs

* only fail TSAN CI build in case of TSAN error / updated sanitizer CI build TODOs
This commit is contained in:
Oliver Stöneberg 2022-09-06 23:11:39 +02:00 committed by GitHub
parent 6960332f8a
commit 54771306c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 122 additions and 46 deletions

View File

@ -451,17 +451,36 @@ jobs:
qmake CONFIG+=debug HAVE_QCHART=yes
make -j$(nproc) compiler_uic_make_all mocables
- name: Generate triage UI files
run: |
pushd tools/triage
qmake CONFIG+=debug
make -j$(nproc) compiler_uic_make_all mocables
- name: Self check
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
# work around missingInclude not being reported with -j and the --check-config requirement for detailed warnings
./cppcheck $selfcheck_options cli lib --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
./cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
# early exit
if [ $ec -eq 1 ]; then
exit $ec
fi
# self check lib/cli
mkdir b1
./cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 --cppcheck-build-dir=b1 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings cli lib || ec=1
./cppcheck $selfcheck_options --cppcheck-build-dir=b1 --addon=naming.json cli lib || ec=1
# check gui with qt settings
mkdir b2
./cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 --cppcheck-build-dir=b2 -D__CPPCHECK__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --library=qt --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings gui/*.cpp gui/temp/*.cpp || ec=1
./cppcheck $selfcheck_options --cppcheck-build-dir=b2 -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1
# self check test and tools
./cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli -Igui --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings test/*.cpp tools/*.cpp || ec=1
./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
# triage
./cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --library=qt -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Igui --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings tools/triage || ec=1
./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
exit $ec

View File

@ -175,6 +175,7 @@ jobs:
python -m pytest test-helloworld.py || exit /b !errorlevel!
python -m pytest test-inline-suppress.py || exit /b !errorlevel!
python -m pytest test-more-projects.py || exit /b !errorlevel!
python -m pytest test-other.py || exit /b !errorlevel!
python -m pytest test-proj2.py || exit /b !errorlevel!
python -m pytest test-suppress-syntaxError.py || exit /b !errorlevel!

View File

@ -52,14 +52,15 @@ jobs:
- name: Run tests
run: ./cmake.output/bin/testrunner
# TODO: re-enable - was being killed because of incresaed memory usage
# TODO: no gui/temp/*.cpp files available
# TODO: re-enable - was being killed because of increased memory usage
# TODO: only fail the step on sanitizer issues
- name: Self check
if: false
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli --inconclusive --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings cli lib || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=qt --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli -Igui --inconclusive --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --library=qt -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Igui --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings tools/triage || ec=1
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
exit $ec

View File

@ -53,13 +53,14 @@ jobs:
run: ./cmake.output/bin/testrunner
# TODO: disabled for now as it takes around 40 minutes to finish
# TODO: no gui/temp/*.cpp files available
# set --error-exitcode=0 so we only fail on sanitizer issues - since it uses threads for execution it will exit the whole process on the first issue
- name: Self check
if: false
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=0 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli --inconclusive --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings cli lib || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=qt --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli -Igui --inconclusive --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --library=qt -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Igui --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings tools/triage || ec=1
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
exit $ec

View File

@ -52,12 +52,13 @@ jobs:
- name: Run tests
run: ./cmake.output/bin/testrunner
# TODO: no gui/temp/*.cpp files available
# TODO: only fail the step on sanitizer issues
- name: Self check
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli --inconclusive --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings cli lib || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=qt --addon=naming.json -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Icli -Igui --inconclusive --enable=style,performance,portability,warning,internal --exception-handling --debug-warnings test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck -q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ -DQ_MOC_OUTPUT_REVISION=67 --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib --library=qt -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ -Igui --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings tools/triage || ec=1
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
exit $ec

1
.gitignore vendored
View File

@ -55,6 +55,7 @@ build/
/gui/debug/
/gui/release/
/gui/temp/
/triage/temp
# Other (generated) GUI files
/gui/*.qm

View File

@ -1,15 +1,18 @@
unusedPrivateFunction:test/testbufferoverrun.cpp
unusedPrivateFunction:test/testcmdlineparser.cpp
shadowFunction
bitwiseOnBoolean
# temporary suppressions - fix the warnings!
unusedPrivateFunction:test/test*.cpp
useStlAlgorithm
simplifyUsing:lib/valueptr.h
varid0:gui/projectfile.cpp
# warnings in Qt generated code we cannot fix
symbolDatabaseWarning:gui/temp/moc_*.cpp
simplifyUsing:gui/temp/moc_*.cpp
symbolDatabaseWarning:tools/triage/moc_*.cpp
funcArgNamesDifferent:gui/temp/moc_*.cpp
symbolDatabaseWarning:tools/triage/temp/moc_*.cpp
naming-varname:gui/temp/ui_*.h
functionStatic:gui/temp/ui_fileview.h
# --debug-warnings suppressions
valueFlowBailout
@ -17,7 +20,4 @@ valueFlowBailoutIncompleteVar
autoNoType
bailoutUninitVar
*:gui/test/*
*:test/test.cxx
*:test/cfg/*
*:externals/*/*

View File

@ -4,6 +4,8 @@
import os
import re
import tempfile
import pytest
from testutils import create_gui_project_file, cppcheck
# Run Cppcheck from project path
@ -189,6 +191,17 @@ def test_build_dir_dump_output():
dump = f.read()
assert '</dump>' in dump, 'invalid dump data: ...' + dump[-100:]
def __test_missing_include_system(use_j):
args = '--enable=missingInclude --suppress=zerodiv helloworld'
if use_j:
args = '-j2 ' + args
_, _, stderr = cppcheck(args.split())
assert stderr == 'nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingIncludeSystem]\n\n'
def test_missing_include_system():
__test_missing_include_system(False)
@pytest.mark.xfail
def test_missing_include_system_j(): #11283
__test_missing_include_system(True)

49
test/cli/test-other.py Normal file
View File

@ -0,0 +1,49 @@
# python -m pytest test-other.py
import os
import pytest
from testutils import cppcheck
def __test_missing_include(tmpdir, use_j):
test_file = os.path.join(tmpdir, 'test.c')
with open(test_file, 'wt') as f:
f.write("""
#include "test.h"
""")
args = '--enable=missingInclude {}'.format(test_file)
if use_j:
args = '-j2 ' + args
_, _, stderr = cppcheck(args.split())
assert stderr == 'nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude]\n\n'
def test_missing_include(tmpdir):
__test_missing_include(tmpdir, False)
@pytest.mark.xfail
def test_missing_include_j(tmpdir): #11283
__test_missing_include(tmpdir, True)
def __test_missing_include_check_config(tmpdir, use_j):
test_file = os.path.join(tmpdir, 'test.c')
with open(test_file, 'wt') as f:
f.write("""
#include "test.h"
""")
# TODO: -rp is not working requiring the full path in the assert
args = '--check-config -rp={} {}'.format(tmpdir, test_file)
if use_j:
args = '-j2 ' + args
_, _, stderr = cppcheck(args.split())
assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n\n^\n'.format(test_file)
def test_missing_include_check_config(tmpdir):
__test_missing_include_check_config(tmpdir, False)
def test_missing_include_check_config_j(tmpdir):
__test_missing_include_check_config(tmpdir, True)

View File

@ -57,6 +57,7 @@ private:
TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true)
TEST_CASE(comparisonOfBoolWithInt8); // #9165
TEST_CASE(comparisonOfBoolWithInt9); // #9304
TEST_CASE(comparisonOfBoolWithInt10); // #10935
TEST_CASE(checkComparisonOfFuncReturningBool1);
TEST_CASE(checkComparisonOfFuncReturningBool2);

View File

@ -1677,6 +1677,7 @@ private:
}
}
// cppcheck-suppress unusedPrivateFunction
void simplifyKnownVariables29() { // ticket #1811
{
const char code[] = "int foo(int u, int v)\n"

View File

@ -366,6 +366,7 @@ private:
// a = b = 0;
TEST_CASE(multipleAssignment);
TEST_CASE(platformWin);
TEST_CASE(platformWin32A);
TEST_CASE(platformWin32W);
TEST_CASE(platformWin32AStringCat); // ticket #5015

View File

@ -165,6 +165,7 @@ private:
return !val.isTokValue();
}
// cppcheck-suppress unusedPrivateFunction
static bool isNotLifetimeValue(const ValueFlow::Value& val) {
return !val.isLifetimeValue();
}

View File

@ -1,12 +1,6 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-12-31T22:22:56
#
#-------------------------------------------------
lessThan(QT_MAJOR_VERSION, 5): error(requires >= Qt 5 (You used: $$QT_VERSION))
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += core gui widgets
TARGET = triage
TEMPLATE = app
@ -14,17 +8,9 @@ TEMPLATE = app
QMAKE_CXXFLAGS += -std=c++11
INCLUDEPATH += ../../gui
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
MOC_DIR = temp
OBJECTS_DIR = temp
UI_DIR = temp
SOURCES += main.cpp\
mainwindow.cpp \