Add CMake and tests
- Port tests to GitLab - Add GitLab CI test matrix - Remove gtest submodule
This commit is contained in:
parent
7056638935
commit
f07596dbb5
19 changed files with 1760 additions and 28 deletions
66
ci/ctest/Sanitizers-ASAN-CTest.cmake
Normal file
66
ci/ctest/Sanitizers-ASAN-CTest.cmake
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# Run locally the -asanSanitizer with:
|
||||
# rm -rf build/
|
||||
# ./dk dksdk.cmake.link
|
||||
# .ci/cmake/bin/cmake --preset=ci-linux_x86_64-sanitizers-asan
|
||||
# .ci/cmake/bin/ctest -S ci/ctest/Sanitizers-ASAN-CTest.cmake --extra-verbose
|
||||
|
||||
# Determine project directories
|
||||
set(OUR_PROJECT_SOURCE_DIR "${CTEST_SCRIPT_DIRECTORY}/../..")
|
||||
cmake_path(NORMAL_PATH OUR_PROJECT_SOURCE_DIR)
|
||||
cmake_path(APPEND OUR_PROJECT_SOURCE_DIR build OUTPUT_VARIABLE OUR_PROJECT_BINARY_DIR)
|
||||
|
||||
# Re-use test details
|
||||
include(${OUR_PROJECT_SOURCE_DIR}/CTestConfig.cmake)
|
||||
|
||||
# Read the CI generated CMakeCache.txt
|
||||
load_cache("${OUR_PROJECT_BINARY_DIR}"
|
||||
READ_WITH_PREFIX CACHED_
|
||||
CMAKE_BUILD_TYPE)
|
||||
|
||||
# Basic information every run should set
|
||||
site_name(CTEST_SITE)
|
||||
set(CTEST_BUILD_NAME ${CMAKE_HOST_SYSTEM_NAME})
|
||||
set(CTEST_SOURCE_DIRECTORY "${OUR_PROJECT_SOURCE_DIR}")
|
||||
set(CTEST_BINARY_DIRECTORY "${OUR_PROJECT_BINARY_DIR}")
|
||||
set(CTEST_CMAKE_GENERATOR Ninja)
|
||||
if(CACHED_CMAKE_BUILD_TYPE)
|
||||
set(CTEST_CONFIGURATION_TYPE ${CACHED_CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(CTEST_CONFIGURATION_TYPE Debug)
|
||||
endif()
|
||||
|
||||
set(CTEST_MEMORYCHECK_TYPE AddressSanitizer)
|
||||
|
||||
# ASAN_OPTIONS
|
||||
# --------
|
||||
#
|
||||
# Even if we have [ASAN_OPTIONS] defined in CMakePresets.json,
|
||||
# that will not impact this script which is invoked by `ctest` not
|
||||
# `cmake`, and [CTEST_MEMORYCHECK_TYPE] will overwrite it anyway.
|
||||
#
|
||||
# Valgrind makes ASAN memory leaks redundant. And the unforked
|
||||
# c-capnproto code disabled memory leaks anyway. So we use the
|
||||
# same options.
|
||||
set(extra_OPTIONS detect_leaks=0,detect_odr_violation=0,allocator_may_return_null=1)
|
||||
# Apply to ctest_memcheck()
|
||||
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS ${extra_OPTIONS})
|
||||
# Apply to ctest_build()
|
||||
if(extra_OPTIONS)
|
||||
if(ENV{ASAN_OPTIONS})
|
||||
set(ENV{ASAN_OPTIONS} ${extra_OPTIONS}:$ENV{ASAN_OPTIONS})
|
||||
else()
|
||||
set(ENV{ASAN_OPTIONS} ${extra_OPTIONS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ctest_start(Experimental)
|
||||
|
||||
ctest_build(RETURN_VALUE err)
|
||||
if(err)
|
||||
message(FATAL_ERROR "CTest build error ${err}")
|
||||
endif()
|
||||
|
||||
ctest_memcheck(RETURN_VALUE err)
|
||||
if(err)
|
||||
message(FATAL_ERROR "CTest memcheck error ${err}")
|
||||
endif()
|
||||
69
ci/ctest/Sanitizers-UBSAN-CTest.cmake
Normal file
69
ci/ctest/Sanitizers-UBSAN-CTest.cmake
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# Run locally the -ubsan Sanitizer with:
|
||||
# rm -rf build/
|
||||
# ./dk dksdk.cmake.link
|
||||
# .ci/cmake/bin/cmake --preset=ci-linux_x86_64-sanitizers-ubsan
|
||||
# .ci/cmake/bin/ctest -S ci/ctest/Sanitizers-UBSAN-CTest.cmake --extra-verbose
|
||||
|
||||
# Determine project directories
|
||||
if(NOT OUR_PROJECT_SOURCE_DIR)
|
||||
set(OUR_PROJECT_SOURCE_DIR "${CTEST_SCRIPT_DIRECTORY}/../..")
|
||||
cmake_path(NORMAL_PATH OUR_PROJECT_SOURCE_DIR)
|
||||
endif()
|
||||
if(NOT OUR_PROJECT_BINARY_DIR)
|
||||
cmake_path(APPEND OUR_PROJECT_SOURCE_DIR build OUTPUT_VARIABLE OUR_PROJECT_BINARY_DIR)
|
||||
endif()
|
||||
|
||||
# Re-use test details
|
||||
include(${OUR_PROJECT_SOURCE_DIR}/CTestConfig.cmake)
|
||||
|
||||
# Read the CI generated CMakeCache.txt
|
||||
load_cache("${OUR_PROJECT_BINARY_DIR}"
|
||||
READ_WITH_PREFIX CACHED_
|
||||
CMAKE_BUILD_TYPE)
|
||||
|
||||
# Basic information every run should set
|
||||
site_name(CTEST_SITE)
|
||||
set(CTEST_BUILD_NAME ${CMAKE_HOST_SYSTEM_NAME})
|
||||
set(CTEST_SOURCE_DIRECTORY "${OUR_PROJECT_SOURCE_DIR}")
|
||||
set(CTEST_BINARY_DIRECTORY "${OUR_PROJECT_BINARY_DIR}")
|
||||
set(CTEST_CMAKE_GENERATOR Ninja)
|
||||
if(CACHED_CMAKE_BUILD_TYPE)
|
||||
set(CTEST_CONFIGURATION_TYPE ${CACHED_CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(CTEST_CONFIGURATION_TYPE Debug)
|
||||
endif()
|
||||
|
||||
# Tell CTest to add to UBSAN_OPTIONS to capture its logs
|
||||
set(CTEST_MEMORYCHECK_TYPE UndefinedBehaviorSanitizer)
|
||||
|
||||
# UBSAN_OPTIONS
|
||||
# --------
|
||||
#
|
||||
# Even if we have [UBSAN_OPTIONS] defined in CMakePresets.json,
|
||||
# that will not impact this script which is invoked by `ctest` not
|
||||
# `cmake`, and [CTEST_MEMORYCHECK_TYPE] will overwrite it anyway.
|
||||
#
|
||||
# Enable stack traces
|
||||
set(extra_OPTIONS print_stacktrace=1)
|
||||
# Apply to ctest_memcheck()
|
||||
set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS ${extra_OPTIONS})
|
||||
# Apply to ctest_build()
|
||||
if(extra_OPTIONS)
|
||||
if(ENV{UBSAN_OPTIONS})
|
||||
set(ENV{UBSAN_OPTIONS} ${extra_OPTIONS}:$ENV{UBSAN_OPTIONS})
|
||||
else()
|
||||
set(ENV{UBSAN_OPTIONS} ${extra_OPTIONS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ctest_start(Experimental)
|
||||
|
||||
ctest_build(RETURN_VALUE err)
|
||||
if(err)
|
||||
message(FATAL_ERROR "CTest build error ${err}")
|
||||
endif()
|
||||
|
||||
ctest_memcheck(RETURN_VALUE err)
|
||||
if(err)
|
||||
message(FATAL_ERROR "CTest memcheck error ${err}")
|
||||
endif()
|
||||
155
ci/gitlab/test.gitlab-ci.yml
Normal file
155
ci/gitlab/test.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
.unit-test:
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "next"'
|
||||
artifacts:
|
||||
paths:
|
||||
- build/Testing/Temporary/LastBuild_*.log
|
||||
- build/Testing/Temporary/LastTest.log
|
||||
- build/Testing/Temporary/LastTests_*.log
|
||||
- build/Testing/Temporary/MemoryChecker.*.log
|
||||
reports:
|
||||
junit:
|
||||
- build/cmakespec.xml
|
||||
- build/tests/*-Results.xml
|
||||
when: always
|
||||
|
||||
unit-test-debian:
|
||||
stage: test
|
||||
# The original c-capnproto unit tests were full of memory leaks (not closing test
|
||||
# structures). Sigh. Until those are fixed, we can't detect real memory leaks.
|
||||
allow_failure: true
|
||||
extends:
|
||||
- .c-cmake-debian:before
|
||||
- .unit-test
|
||||
script:
|
||||
- export PATH="$PWD/.ci/cmake/bin:$PATH"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:configure[collapsed=true]\r\e[0KConfiguring build scripts"
|
||||
- rm -rf build/
|
||||
- cmake --preset=ci-linux_x86_64 -D BUILD_HYGIENE=ENABLED
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:configure\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:build[collapsed=true]\r\e[0KBuilding test targets"
|
||||
- cmake --build --preset=ci-tests
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:build\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:unittest[collapsed=true]\r\e[0KUnit Testing"
|
||||
- ctest --output-junit cmakespec.xml --verbose --preset=ci-test
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:unittest\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:memcheck[collapsed=true]\r\e[0KMemory Testing"
|
||||
- ctest -T memcheck --test-dir build --verbose
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:memcheck\r\e[0K"
|
||||
|
||||
unit-test-android_x86_64:
|
||||
stage: test
|
||||
extends:
|
||||
- .c-cmake-debian:before
|
||||
- .unit-test
|
||||
script:
|
||||
- export PATH="$PWD/.ci/cmake/bin:$PATH"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:installandroid[collapsed=true]\r\e[0KInstalling Android NDK"
|
||||
- ./dk dksdk.android.ndk.download
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:installandroid\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:configure[collapsed=true]\r\e[0KConfiguring build scripts"
|
||||
- rm -rf build/
|
||||
- cmake --preset=ci-linux_x86_64_X_android_x86_64
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:configure\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:build[collapsed=true]\r\e[0KBuilding test targets"
|
||||
- cmake --build --preset=ci-tests
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:build\r\e[0K"
|
||||
|
||||
- echo 'No unit tests and no memory tests for a cross-compiled target'
|
||||
|
||||
unit-test-windows:
|
||||
stage: test
|
||||
extends:
|
||||
- .c-cmake-windows:before
|
||||
- .unit-test
|
||||
script:
|
||||
- $env:Path += ';C:\Program Files\CMake\bin'
|
||||
|
||||
- $esc="$([char]27)"; $cr="$([char]13)"; $TXT_SECTION="${esc}[36m"; $TXT_CLEAR="${esc}[0m"
|
||||
- |
|
||||
function Get-CurrentEpochSecs {
|
||||
[long]$timestamp = [math]::Round((([datetime]::UtcNow) - (Get-Date -Date '1/1/1970')).TotalMilliseconds)
|
||||
[math]::Round($timestamp / 1000)
|
||||
}
|
||||
|
||||
- Write-Host "${esc}[0Ksection_start:$(Get-CurrentEpochSecs):configure[collapsed=true]${cr}${esc}[0K"$TXT_SECTION"Configuring build scripts"
|
||||
- if (Test-Path build) { Remove-Item -Recurse -Force build }
|
||||
# Linux can test with BUILD_HYGIENE=ENABLED. Don't want to install clang-tidy through
|
||||
# Chocolatey because huge LLVM download (`choco install llvm`).
|
||||
- ci/run-with-msvc.cmd cmake --preset=ci-windows_x86_64 -D BUILD_HYGIENE=DISABLED
|
||||
- Write-Host "${esc}[0Ksection_end:$(Get-CurrentEpochSecs):configure${cr}${esc}[0K"
|
||||
|
||||
- Write-Host "${esc}[0Ksection_start:$(Get-CurrentEpochSecs):build[collapsed=true]${cr}${esc}[0K"$TXT_SECTION"Building test targets"
|
||||
- ci/run-with-msvc.cmd cmake --build --preset=ci-tests
|
||||
- Write-Host "${esc}[0Ksection_end:$(Get-CurrentEpochSecs):build${cr}${esc}[0K"
|
||||
|
||||
- Write-Host "${esc}[0Ksection_start:$(Get-CurrentEpochSecs):unittest[collapsed=true]${cr}${esc}[0K"$TXT_SECTION"Unit Testing"
|
||||
- ci/run-with-msvc.cmd ctest --output-junit cmakespec.xml --verbose --preset=ci-test
|
||||
- Write-Host "${esc}[0Ksection_end:$(Get-CurrentEpochSecs):unittest${cr}${esc}[0K"
|
||||
|
||||
sanitizers-debian-asan:
|
||||
stage: test
|
||||
extends:
|
||||
- .c-cmake-debian:before
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "next"'
|
||||
artifacts:
|
||||
paths:
|
||||
- build/Testing/Temporary/LastBuild_*.log
|
||||
- build/Testing/Temporary/LastDynamicAnalysis_*.log
|
||||
- build/Testing/Temporary/LastTest.log
|
||||
- build/Testing/Temporary/LastTests_*.log
|
||||
- build/Testing/Temporary/MemoryChecker.*.log
|
||||
reports:
|
||||
junit:
|
||||
- build/cmakespec.xml
|
||||
- build/tests/*-Results.xml
|
||||
when: always
|
||||
script:
|
||||
- export PATH="$PWD/.ci/cmake/bin:$PATH"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:configure[collapsed=true]\r\e[0KConfiguring build scripts"
|
||||
- rm -rf build/
|
||||
- cmake --preset=ci-linux_x86_64-sanitizers-asan
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:configure\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:build[collapsed=true]\r\e[0KRunning ASAN sanitizers build and check"
|
||||
- ctest -S ci/ctest/Sanitizers-ASAN-CTest.cmake
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:build\r\e[0K"
|
||||
|
||||
sanitizers-debian-ubsan:
|
||||
stage: test
|
||||
extends:
|
||||
- .c-cmake-debian:before
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "next"'
|
||||
artifacts:
|
||||
paths:
|
||||
- build/Testing/Temporary/LastBuild_*.log
|
||||
- build/Testing/Temporary/LastDynamicAnalysis_*.log
|
||||
- build/Testing/Temporary/LastTest.log
|
||||
- build/Testing/Temporary/LastTests_*.log
|
||||
- build/Testing/Temporary/MemoryChecker.*.log
|
||||
reports:
|
||||
junit:
|
||||
- build/cmakespec.xml
|
||||
- build/tests/*-Results.xml
|
||||
when: always
|
||||
script:
|
||||
- export PATH="$PWD/.ci/cmake/bin:$PATH"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:configure[collapsed=true]\r\e[0KConfiguring build scripts"
|
||||
- rm -rf build/
|
||||
- cmake --preset=ci-linux_x86_64-sanitizers-ubsan
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:configure\r\e[0K"
|
||||
|
||||
- echo -e "\e[0Ksection_start:`date +%s`:build[collapsed=true]\r\e[0KRunning UBSAN sanitizers build and check"
|
||||
- ctest -S ci/ctest/Sanitizers-UBSAN-CTest.cmake
|
||||
- echo -e "\e[0Ksection_end:`date +%s`:build\r\e[0K"
|
||||
3
ci/run-with-msvc.cmd
Normal file
3
ci/run-with-msvc.cmd
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
CALL "%VSDIR%\VC\Auxiliary\Build\vcvars64.bat"
|
||||
ECHO ON
|
||||
%*
|
||||
Loading…
Add table
Add a link
Reference in a new issue