Skip to content

Commit

Permalink
cmake: Add CMake presets for running tests with logging
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LukasWoodtli authored and mlasch committed May 29, 2024
1 parent df92701 commit b0d8b97
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 120
---
Language: Json
BasedOnStyle: llvm

88 changes: 88 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -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": {
"WAKAAMA_LOG_CUSTOM_HANDLER": {
"type": "BOOL",
"value": "ON"
},
"WAKAAMA_ENABLE_EXAMPLES": {
"type": "BOOL",
"value": "OFF"
}
}
},
{
"name": "log_dbg",
"description": "Run the tests with debug log level",
"inherits": "log_base",
"cacheVariables": {
"WAKAAMA_LOG_LEVEL": {
"type": "STRING",
"value": "DBG"
}
}
},
{
"name": "log_info",
"description": "Run the tests with info log level",
"inherits": "log_base",
"cacheVariables": {
"WAKAAMA_LOG_LEVEL": {
"type": "STRING",
"value": "INFO"
}
}
},
{
"name": "log_warn",
"description": "Run the tests with warning log level",
"inherits": "log_base",
"cacheVariables": {
"WAKAAMA_LOG_LEVEL": {
"type": "STRING",
"value": "WARN"
}
}
},
{
"name": "log_fatal",
"description": "Run the tests with fatal log level",
"inherits": "log_base",
"cacheVariables": {
"WAKAAMA_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"
}
]
}
16 changes: 16 additions & 0 deletions tools/ci/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b0d8b97

Please sign in to comment.