-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add cmocka to perform unit-testing
Signed-off-by: Daniel Skinstad Drabitzius <[email protected]>
- Loading branch information
1 parent
b872082
commit 9120eda
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#https://github.com/OlivierLDff/cmocka-cmake-example | ||
include(FetchContent) | ||
|
||
# Declare our target. We want the lastest stable version, not the master. | ||
# Also specify GIT_SHALLOW to avoid cloning branch we don't care about | ||
FetchContent_Declare( | ||
cmocka | ||
GIT_REPOSITORY https://git.cryptomilk.org/projects/cmocka.git | ||
GIT_TAG cmocka-1.1.5 | ||
GIT_SHALLOW 1 | ||
) | ||
|
||
# We want to link to cmocka-static, so we need to set this option before calling the FetchContent_MakeAvailable | ||
# We also don't care about example and tests | ||
set(WITH_STATIC_LIB ON CACHE BOOL "CMocka: Build with a static library" FORCE) | ||
set(WITH_CMOCKERY_SUPPORT OFF CACHE BOOL "CMocka: Install a cmockery header" FORCE) | ||
set(WITH_EXAMPLES OFF CACHE BOOL "CMocka: Build examples" FORCE) | ||
set(UNIT_TESTING OFF CACHE BOOL "CMocka: Build with unit testing" FORCE) | ||
set(PICKY_DEVELOPER OFF CACHE BOOL "CMocka: Build with picky developer flags" FORCE) | ||
|
||
# Download cmocka, and execute its cmakelists.txt | ||
FetchContent_MakeAvailable(cmocka) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../include) | ||
set(MCU_LIBRARIES "mender-mcu-client;pthread;cjson;mbedtls;mbedx509;mbedcrypto") | ||
|
||
# Add tests by adding the target name to this list | ||
# Example: | ||
# list(APPEND TEST_TARGETS mender_test_target) | ||
|
||
foreach(TEST_TARGET IN LISTS TEST_TARGETS) | ||
add_cmocka_test( | ||
${TEST_TARGET} | ||
SOURCES ${TEST_TARGET}.c | ||
LINK_LIBRARIES ${CMOCKA_LIBRARIES} ${MCU_LIBRARIES}) | ||
|
||
target_link_libraries(${TEST_TARGET} PRIVATE cmocka-static) | ||
endforeach() |