CI: Enable 32bit unit test

This commit is contained in:
Florian Albrechtskirchinger 2022-06-11 14:55:18 +02:00
parent eef7437738
commit 4be1e2bd0e
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
2 changed files with 57 additions and 50 deletions

View File

@ -529,6 +529,13 @@ add_custom_target(ci_test_coverage
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage
COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
COMMAND CXX=g++ ${CMAKE_COMMAND}
-DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="-m32;--coverage;-fprofile-arcs;-ftest-coverage"
-DJSON_BuildTests=ON -DJSON_32bitTest=ONLY
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_coverage32
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage32
COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage32 && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
COMMAND ${LCOV_TOOL} --directory . --capture --output-file json.info --rc lcov_branch_coverage=1 COMMAND ${LCOV_TOOL} --directory . --capture --output-file json.info --rc lcov_branch_coverage=1
COMMAND ${LCOV_TOOL} -e json.info ${SRC_FILES} --output-file json.info.filtered --rc lcov_branch_coverage=1 COMMAND ${LCOV_TOOL} -e json.info ${SRC_FILES} --output-file json.info.filtered --rc lcov_branch_coverage=1
COMMAND ${CMAKE_SOURCE_DIR}/tests/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept COMMAND ${CMAKE_SOURCE_DIR}/tests/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept

View File

@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.13)
option(JSON_Valgrind "Execute test suite with Valgrind." OFF) option(JSON_Valgrind "Execute test suite with Valgrind." OFF)
option(JSON_FastTests "Skip expensive/slow tests." OFF) option(JSON_FastTests "Skip expensive/slow tests." OFF)
option(JSON_32bitTest "Enable the 32bit unit test." OFF)
set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUTO/ONLY).")
set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.") set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.")
include(test) include(test)
@ -34,13 +34,12 @@ endif()
# test_main library with shared code to speed up build and common settings # test_main library with shared code to speed up build and common settings
############################################################################# #############################################################################
set(test_main_SOURCES src/unit.cpp) add_library(test_main OBJECT src/unit.cpp)
set(test_main_COMPILE_DEFINITIONS PUBLIC target_compile_definitions(test_main PUBLIC
DOCTEST_CONFIG_SUPER_FAST_ASSERTS DOCTEST_CONFIG_SUPER_FAST_ASSERTS
JSON_TEST_KEEP_MACROS) JSON_TEST_KEEP_MACROS)
set(test_main_COMPILE_FEATURES PRIVATE cxx_std_11) target_compile_features(test_main PRIVATE cxx_std_11)
set(test_main_COMPILE_OPTIONS target_compile_options(test_main PUBLIC
PUBLIC
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>> $<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
# MSVC: Force to always compile with W4 # MSVC: Force to always compile with W4
# Disable warning C4566: character represented by universal-character-name '\uFF01' # Disable warning C4566: character represented by universal-character-name '\uFF01'
@ -56,18 +55,11 @@ set(test_main_COMPILE_OPTIONS
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal> $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations> $<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>) $<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
set(test_main_INCLUDE_DIRECTORIES PUBLIC target_include_directories(test_main PUBLIC
thirdparty/doctest thirdparty/doctest
thirdparty/fifo_map thirdparty/fifo_map
${PROJECT_BINARY_DIR}/include) ${PROJECT_BINARY_DIR}/include)
set(test_main_LINK_LIBRARIES PUBLIC ${NLOHMANN_JSON_TARGET_NAME}) target_link_libraries(test_main PUBLIC ${NLOHMANN_JSON_TARGET_NAME})
add_library(test_main OBJECT ${test_main_SOURCES})
target_compile_definitions(test_main ${test_main_COMPILE_DEFINITIONS})
target_compile_features(test_main ${test_main_COMPILE_FEATURES})
target_compile_options(test_main ${test_main_COMPILE_OPTIONS})
target_include_directories(test_main ${test_main_INCLUDE_DIRECTORIES})
target_link_libraries(test_main ${test_main_LINK_LIBRARIES})
############################################################################# #############################################################################
# define test- and standard-specific build settings # define test- and standard-specific build settings
@ -124,25 +116,32 @@ message(STATUS "${msg}")
# *DO* use json_test_set_test_options() above this line # *DO* use json_test_set_test_options() above this line
string(TOUPPER "${JSON_32bitTest}" json_32bit_test)
if("${json_32bit_test}" STREQUAL AUTO)
# check if compiler is targeting 32bit by default
include(CheckTypeSize)
check_type_size("size_t" sizeof_size_t LANGUAGE CXX)
if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4)
message(STATUS "Auto-enabling 32bit unit test.")
set(json_32bit_test ON)
else()
set(json_32bit_test OFF)
endif()
endif()
if("${json_32bit_test}" STREQUAL ONLY)
set(files src/unit-32bit.cpp)
else()
file(GLOB files src/unit-*.cpp) file(GLOB files src/unit-*.cpp)
list(FILTER files EXCLUDE REGEX "src/unit-32bit.cpp") if("${json_32bit_test}" STREQUAL OFF)
list(FILTER files EXCLUDE REGEX src/unit-32bit.cpp)
endif()
endif()
foreach(file ${files}) foreach(file ${files})
json_test_add_test_for(${file} MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force}) json_test_add_test_for(${file} MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force})
endforeach() endforeach()
if(JSON_32bitTest) if(NOT "${json_32bit_test}" STREQUAL ONLY)
add_library(test_main32 OBJECT ${test_main_SOURCES})
target_compile_definitions(test_main32 ${test_main_COMPILE_DEFINITIONS})
target_compile_features(test_main32 ${test_main_COMPILE_FEATURES})
target_compile_options(test_main32 ${test_main_COMPILE_OPTIONS} -m32)
target_include_directories(test_main32 ${test_main_INCLUDE_DIRECTORIES})
target_link_libraries(test_main32 ${test_main_LINK_LIBRARIES})
target_link_options(test_main32 PUBLIC -m32)
json_test_add_test_for("src/unit-32bit.cpp" MAIN test_main32
CXX_STANDARDS ${test_cxx_standards} ${test_force})
endif()
# test legacy comparison of discarded values # test legacy comparison of discarded values
json_test_set_test_options(test-comparison_legacy json_test_set_test_options(test-comparison_legacy
COMPILE_DEFINITIONS JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1 COMPILE_DEFINITIONS JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1
@ -151,6 +150,7 @@ json_test_add_test_for(src/unit-comparison.cpp
NAME test-comparison_legacy NAME test-comparison_legacy
MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force} MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force}
) )
endif()
# *DO NOT* use json_test_set_test_options() below this line # *DO NOT* use json_test_set_test_options() below this line