added validateCFG and checkcfg targets to CMake / some refactorings (#2687)

This commit is contained in:
Oliver Stöneberg 2020-11-02 20:16:15 +01:00 committed by GitHub
parent 4a2082e3c5
commit 488813d00f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 150 additions and 120 deletions

View File

@ -19,6 +19,16 @@ file(GLOB addons "addons/*.py")
file(GLOB cfgs "cfg/*.cfg")
file(GLOB platforms "platforms/*.xml")
find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
if (LIBXML2_XMLLINT_EXECUTABLE)
add_custom_target(validateCFG ${LIBXML2_XMLLINT_EXECUTABLE} --noout ${CMAKE_SOURCE_DIR}/cfg/cppcheck-cfg.rng)
foreach(cfg ${cfgs})
get_filename_component(cfgname ${cfg} NAME_WE)
add_custom_target(validateCFG-${cfgname} ${LIBXML2_XMLLINT_EXECUTABLE} --noout --relaxng ${CMAKE_SOURCE_DIR}/cfg/cppcheck-cfg.rng ${cfg})
add_dependencies(validateCFG validateCFG-${cfgname})
endforeach()
endif()
if (BUILD_TESTS)
enable_testing()
endif()

View File

@ -33,6 +33,7 @@ else()
endif()
option(BUILD_TESTS "Build tests" OFF)
option(REGISTER_TESTS "Register tests in CTest" ON)
option(ENABLE_CHECK_INTERNAL "Enable internal checks" OFF)
option(ENABLE_OSS_FUZZ "Enable the OSS-Fuzz related targets" ON)
option(BUILD_GUI "Build the qt application" OFF)

View File

@ -31,7 +31,11 @@ if(NOT DEFINED BUILD_SHARED_LIBS)
else()
message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
endif(NOT DEFINED BUILD_SHARED_LIBS)
message( STATUS "LIBXML2_XMLLINT_EXECUTABLE = ${LIBXML2_XMLLINT_EXECUTABLE}" )
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
if(BUILD_TESTS)
message( STATUS "REGISTER_TESTS = ${REGISTER_TESTS}" )
endif()
message( STATUS "ENABLE_CHECK_INTERNAL = ${ENABLE_CHECK_INTERNAL}" )
message( STATUS "ENABLE_OSS_FUZZ = ${ENABLE_OSS_FUZZ}" )
message( STATUS )

View File

@ -3239,7 +3239,7 @@ void CheckOther::knownArgumentError(const Token *tok, const Token *ftok, const V
const std::string &expr = tok->expressionString();
const std::string &fun = ftok->str();
const char *id;;
const char *id;
std::string errmsg = "Argument '" + expr + "' to function " + fun + " is always " + std::to_string(intvalue) + ". ";
if (!isVariableExpressionHidden) {
id = "knownArgument";

View File

@ -1,17 +1,4 @@
if (BUILD_TESTS)
cmake_minimum_required(VERSION 3.4) # cmake_policy(SET CMP0064 NEW)
cmake_policy(SET CMP0064 NEW)
cmake_policy(SET CMP0057 NEW)
include(CTest)
find_package(Threads REQUIRED)
include(ProcessorCount)
ProcessorCount(N)
set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${CTEST_PARALLEL_LEVEL} -C ${CMAKE_CFG_INTDIR} --timeout 90)
include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml)
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
@ -26,24 +13,41 @@ if (BUILD_TESTS)
if (USE_Z3)
target_link_libraries(testrunner ${Z3_LIBRARIES})
endif()
if (WIN32 AND NOT BORLAND)
target_link_libraries(testrunner Shlwapi.lib)
endif()
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(testrunner PRIVATE precompiled.h)
endif()
add_custom_target(copy_cfg ALL
${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cfg"
COMMENT "Copying cfg files")
add_custom_command(
TARGET copy_cfg
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cfg")
add_dependencies(testrunner copy_cfg)
if (WIN32 AND NOT BORLAND)
target_link_libraries(testrunner Shlwapi.lib)
if (LIBXML2_XMLLINT_EXECUTABLE)
# TODO: get rid of the copy
add_custom_target(checkcfg ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cppcheck> ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cfg/runtests.sh
DEPENDS cppcheck validateCFG
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cfg)
endif()
add_dependencies(testrunner copy_cfg)
add_dependencies(check testrunner cppcheck)
if (REGISTER_TESTS)
cmake_minimum_required(VERSION 3.4) # cmake_policy(SET CMP0064 NEW)
cmake_policy(SET CMP0064 NEW)
cmake_policy(SET CMP0057 NEW)
include(CTest)
find_package(Threads REQUIRED)
include(ProcessorCount)
ProcessorCount(N)
set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
add_custom_target(check ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${CTEST_PARALLEL_LEVEL} -C ${CMAKE_CFG_INTDIR} --timeout 90
DEPENDS testrunner cppcheck)
set(SKIP_TESTS "" CACHE STRING "A list of tests to skip")
@ -71,6 +75,7 @@ if (BUILD_TESTS)
endif()
endfunction()
# TODO: what is this?
add_fixture(TestSamples WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
foreach(SRC ${srcs})
file(STRINGS ${SRC} FIXTURE_LINE REGEX "TestFixture\\(" LIMIT_COUNT 1)
@ -78,6 +83,7 @@ if (BUILD_TESTS)
add_fixture(${CMAKE_MATCH_1})
endif()
endforeach()
# TODO: parse files for REGISTER_TEST macro
add_fixture(TestLeakAutoVarStrcpy)
add_fixture(TestLeakAutoVarWindows)
add_fixture(TestMemleakInFunction)
@ -111,6 +117,7 @@ if (BUILD_TESTS)
endif()
if (${TEST_NAME} IN_LIST SKIP_TESTS)
else()
# TODO: add syntax check
add_test(NAME cfg-${TEST_NAME}
COMMAND $<TARGET_FILE:cppcheck>
--check-library
@ -121,29 +128,35 @@ if (BUILD_TESTS)
--error-exitcode=1
--suppress=missingIncludeSystem
--inline-suppr
--template="{file}:{line}:{severity}:{id}:{message}"
${INCONCLUSIVE}
${CMAKE_CURRENT_SOURCE_DIR}/cfg/${CFG_TEST}
)
endif()
endfunction()
add_cfg(boost.cpp INCONCLUSIVE)
add_cfg(bsd.c)
add_cfg(gnu.c LIBRARY posix gnu)
add_cfg(googletest.cpp)
add_cfg(gtk.c INCONCLUSIVE)
add_cfg(libcurl.c)
add_cfg(lua.c)
add_cfg(openmp.c)
add_cfg(posix.c)
add_cfg(python.c)
add_cfg(qt.cpp)
add_cfg(sqlite3.c INCONCLUSIVE)
add_cfg(gnu.c LIBRARY posix;gnu)
add_cfg(qt.cpp INCONCLUSIVE)
add_cfg(bsd.c)
add_cfg(std.c INCONCLUSIVE)
add_cfg(std.cpp INCONCLUSIVE)
add_cfg(windows.cpp INCONCLUSIVE NAME windows32A PLATFORM win32A)
add_cfg(windows.cpp INCONCLUSIVE NAME windows32W PLATFORM win32W)
add_cfg(windows.cpp INCONCLUSIVE NAME windows64 PLATFORM win64)
add_cfg(wxwidgets.cpp INCONCLUSIVE)
add_cfg(gtk.c INCONCLUSIVE)
add_cfg(boost.cpp INCONCLUSIVE)
add_cfg(sqlite3.c INCONCLUSIVE)
add_cfg(openmp.c)
add_cfg(python.c)
add_cfg(lua.c)
add_cfg(libcurl.c)
add_cfg(cairo.c)
add_cfg(googletest.cpp INCONCLUSIVE)
add_cfg(kde.cpp INCONCLUSIVE)
add_cfg(libsigc++.cpp)
add_cfg(openssl.c)
add_cfg(opencv2.cpp)
# Set cost of the more expensive tests to help improve parallel scheduling
# of tests
@ -152,4 +165,5 @@ if (BUILD_TESTS)
fixture_cost(TestThreadExecutor 5)
fixture_cost(TestLeakAutoVar 4)
fixture_cost(TestTokenizer 4)
endif()
endif()

View File

@ -84,6 +84,7 @@ private:
exec.check(7, argv);
std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt";
std::ifstream ifs(expected_filename);
// TODO: this contains stray \n at the start of each line when the out.txt files have CRLF
std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
std::string actual = GET_REDIRECT_ERROUT;
// We need some uniformization to make this work on Unix and Windows