From c7c3022698535e862b044f02f39d48b2431b3dd4 Mon Sep 17 00:00:00 2001 From: Lukas Woodtli Date: Wed, 24 Apr 2024 21:45:11 +0200 Subject: [PATCH] cmake: Add CMake presets for running tests with logging Using cache variables to configure the logging infrastructure requires a different handling for testing. CMake's preset functionality helps to build the project with different settings and run the corresponding tests. --- .clang-format | 4 +++ CMakePresets.json | 88 ++++++++++++++++++++++++++++++++++++++++++++++ tools/ci/run_ci.sh | 16 +++++++++ 3 files changed, 108 insertions(+) create mode 100644 CMakePresets.json diff --git a/.clang-format b/.clang-format index 8d41d7a4b..397c85c0c 100644 --- a/.clang-format +++ b/.clang-format @@ -3,3 +3,7 @@ Language: Cpp BasedOnStyle: LLVM IndentWidth: 4 ColumnLimit: 120 +--- +Language: Json +BasedOnStyle: llvm + diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..4483cb021 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,88 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "log_base", + "description": "Run the tests with corresponding log level", + "hidden": true, + "binaryDir": "${sourceDir}/build-presets/log_tests/${presetName}", + "cacheVariables": { + "LOG_CUSTOM_HANDLER": { + "type": "BOOL", + "value": "ON" + }, + "ENABLE_EXAMPLES": { + "type": "BOOL", + "value": "OFF" + } + } + }, + { + "name": "log_dbg", + "description": "Run the tests with debug log level", + "inherits": "log_base", + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "DBG" + } + } + }, + { + "name": "log_info", + "description": "Run the tests with info log level", + "inherits": "log_base", + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "INFO" + } + } + }, + { + "name": "log_warn", + "description": "Run the tests with warning log level", + "inherits": "log_base", + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "WARN" + } + } + }, + { + "name": "log_fatal", + "description": "Run the tests with fatal log level", + "inherits": "log_base", + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "FATAL" + } + } + } + ], + "buildPresets": [ + { + "name": "log_dbg", + "configurePreset": "log_dbg" + }, + { + "name": "log_info", + "configurePreset": "log_info" + }, + { + "name": "log_warn", + "configurePreset": "log_warn" + }, + { + "name": "log_fatal", + "configurePreset": "log_fatal" + } + ] +} diff --git a/tools/ci/run_ci.sh b/tools/ci/run_ci.sh index 1ed86b490..2dc1b9d41 100755 --- a/tools/ci/run_ci.sh +++ b/tools/ci/run_ci.sh @@ -148,13 +148,29 @@ function run_build() { # Existing directory needed by SonarQube build-wrapper mkdir -p build-wakaama + echo "Default build" ${OPT_WRAPPER_CMD} cmake -GNinja -S ${OPT_SOURCE_DIRECTORY} -B build-wakaama ${CMAKE_ARGS} ${OPT_WRAPPER_CMD} cmake --build build-wakaama + + # CMake presets + echo "CMake presets build" + for i in $(cmake --list-presets build | awk '/"/{ print $1 }' | tr -d '"');do + echo "CMake preset $i" + ${OPT_WRAPPER_CMD} cmake --preset "$i" -G Ninja ${CMAKE_ARGS} + ${OPT_WRAPPER_CMD} cmake --build --preset "$i" + done } function run_tests() { + echo "Default test run" cmake --build build-wakaama --target test + echo "CMake presets test run" + for i in $(cmake --list-presets build | awk '/"/{ print $1 }' | tr -d '"');do + echo "CMake preset $i" + cmake --build --preset "$i" --target test + done + mkdir -p "${REPO_ROOT_DIR}/build-wakaama/coverage" if [ -z "${OPT_TEST_COVERAGE_REPORT}" ]; then