mirror of
https://github.com/FreeRTOS/coreMQTT
synced 2025-06-08 04:20:56 +08:00
Add the updates to Cmake files to build unit tests on Mac (#306)
<!--- Title --> Description ----------- <!--- Describe your changes in detail. --> Updated the coverage.cmake and create_test.cmake files to build the unit tests on Mac Updated the README file to include the correct Cmake command for the users to use to build the unit tests Checklist: ---------- <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have tested my changes. No regression in existing tests. - [x] I have modified and/or added unit-tests to cover the code changes in this Pull Request. Related Issue ----------- <!-- If any, please provide issue ID. --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Dakshit Babbar <dakshba@amazon.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
e7322e88a8
commit
c0c05f9fd4
5
.github/.cSpellWords.txt
vendored
5
.github/.cSpellWords.txt
vendored
@ -11,11 +11,14 @@ coverity
|
||||
Coverity
|
||||
CSDK
|
||||
ctest
|
||||
DCMAKE
|
||||
DCMOCK
|
||||
decihours
|
||||
Decihours
|
||||
DECIHOURS
|
||||
DLIBRARY
|
||||
DNDEBUG
|
||||
DUNITTEST
|
||||
DUNITY
|
||||
getpacketid
|
||||
isystem
|
||||
@ -44,4 +47,6 @@ vect
|
||||
Vect
|
||||
VECT
|
||||
Werror
|
||||
Wextra
|
||||
Wsign
|
||||
Wunused
|
||||
|
17
README.md
17
README.md
@ -176,14 +176,27 @@ or the following:
|
||||
1. Go to the root directory of this repository. (Make sure that the **CMock**
|
||||
submodule is cloned as described [above](#checkout-cmock-submodule))
|
||||
|
||||
1. Run the _cmake_ command: `cmake -S test -B build`
|
||||
1. Run the _cmake_ command:
|
||||
```
|
||||
cmake -S test -B build/ \
|
||||
-G "Unix Makefiles" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DBUILD_CLONE_SUBMODULES=ON \
|
||||
-DUNITTEST=1 \
|
||||
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Wsign-compare -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG'
|
||||
```
|
||||
Note: For Mac users, additionally add the `-DCMAKE_C_STANDARD=99` flag to the
|
||||
above command.
|
||||
|
||||
1. Run this command to build the library and unit tests: `make -C build all`
|
||||
1. Run this command to build the library and unit tests: `make -C build all`.
|
||||
|
||||
1. The generated test executables will be present in `build/bin/tests` folder.
|
||||
|
||||
1. Run `cd build && ctest` to execute all tests and view the test run summary.
|
||||
|
||||
1. Run `make coverage` to generate coverage report in the `build/coverage`
|
||||
folder.
|
||||
|
||||
## CBMC
|
||||
|
||||
To learn more about CBMC and proofs specifically, review the training material
|
||||
|
@ -15,7 +15,7 @@ execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
|
||||
--initial
|
||||
--capture
|
||||
--rc lcov_branch_coverage=1
|
||||
--rc genhtml_branch_coverage=1
|
||||
--include "*source*"
|
||||
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info
|
||||
)
|
||||
file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*")
|
||||
@ -46,10 +46,10 @@ execute_process(COMMAND ruby
|
||||
execute_process(
|
||||
COMMAND lcov --capture
|
||||
--rc lcov_branch_coverage=1
|
||||
--rc genhtml_branch_coverage=1
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--directory ${CMAKE_BINARY_DIR}
|
||||
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info
|
||||
--include "*source*"
|
||||
)
|
||||
|
||||
# combile baseline results (zeros) with the one after running the tests
|
||||
@ -59,7 +59,7 @@ execute_process(
|
||||
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
|
||||
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
|
||||
--output-file ${CMAKE_BINARY_DIR}/coverage.info
|
||||
--no-external
|
||||
--include "*source*"
|
||||
--rc lcov_branch_coverage=1
|
||||
)
|
||||
execute_process(
|
||||
|
@ -22,9 +22,6 @@ function(create_test test_name
|
||||
COMPILE_FLAG "-O0 -ggdb"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests"
|
||||
INSTALL_RPATH_USE_LINK_PATH TRUE
|
||||
LINK_FLAGS " \
|
||||
-Wl,-rpath,${CMAKE_BINARY_DIR}/lib \
|
||||
-Wl,-rpath,${CMAKE_CURRENT_BINARY_DIR}/lib"
|
||||
)
|
||||
target_include_directories(${test_name} PUBLIC
|
||||
${mocks_dir}
|
||||
@ -45,7 +42,7 @@ function(create_test test_name
|
||||
add_dependencies(${test_name} ${dependency})
|
||||
target_link_libraries(${test_name} ${dependency})
|
||||
endforeach()
|
||||
target_link_libraries(${test_name} -lgcov unity)
|
||||
target_link_libraries(${test_name} unity)
|
||||
target_link_directories(${test_name} PUBLIC
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lib
|
||||
)
|
||||
@ -129,10 +126,19 @@ function(create_mock_list mock_name
|
||||
${mocks_dir}
|
||||
${mock_include_list}
|
||||
)
|
||||
set_target_properties(${mock_name} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
if (APPLE)
|
||||
set_target_properties(${mock_name} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
LINK_FLAGS "-Wl,-undefined,dynamic_lookup"
|
||||
)
|
||||
else()
|
||||
set_target_properties(${mock_name} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${mock_name} PUBLIC
|
||||
${mock_define_list}
|
||||
)
|
||||
@ -151,18 +157,14 @@ function(create_real_library target
|
||||
${real_include_list}
|
||||
)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
COMPILE_FLAGS "-Wextra -Wpedantic \
|
||||
COMPILE_FLAGS "-Wextra -Wpedantic \
|
||||
-fprofile-arcs -ftest-coverage -fprofile-generate \
|
||||
-Wno-unused-but-set-variable"
|
||||
LINK_FLAGS "-fprofile-arcs -ftest-coverage \
|
||||
LINK_FLAGS "-fprofile-arcs -ftest-coverage \
|
||||
-fprofile-generate "
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
|
||||
)
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
|
||||
)
|
||||
if(NOT(mock_name STREQUAL ""))
|
||||
add_dependencies(${target} ${mock_name})
|
||||
target_link_libraries(${target}
|
||||
-l${mock_name}
|
||||
-lgcov
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
Loading…
x
Reference in New Issue
Block a user