Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Integrate internal changes progressively:

```
applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2: zw-libs2#zwave-sdk-7.21.0-ga-68-gbd9c072a
applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/TestFramework: zw-testframework#zwave-sdk-7.20.0-ga-15-gccbd3fb
```

## ver_1.7.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cmock"]
path = cmock
url = https://github.com/throwtheswitch/cmock.git

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,126 @@
# Prevent multiple "inclusions" of TestFramework
if (NOT TARGET unity)
if (NOT COMMAND ADD_UNITY_TEST)
message(STATUS "TestFramework from ${CMAKE_CURRENT_SOURCE_DIR} included")
add_definitions( -DUNIT_TEST )

set(TEST_TOOLS_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL test_tools_dir)

find_package(PythonInterp)
find_package(Python3 COMPONENTS Interpreter)

include(CMakeFunctions.cmake)
##
# @b Syntax
#
# &emsp; @c add_unity_test( \b NAME \<name\> [TEST_BASE \<file.\<c|cpp\>\>] FILES \<fileN\> LIBRARIES \<libN\> [USE_CPP])
#
# Function for adding a unit test CMake target.
#
#
# @b Example @b 1
#
#
# from @b Components\\FileSystem\\Test\\CMakeLists.txt file
# @code{.py}
# add_unity_test(NAME TestFileSystem FILES ../FileSystem.c TestFileSystem.cpp LIBRARIES Assert USE_CPP)
# @endcode
#
#
# @b Example @b 2
#
#
# from @b ZWave\\Protocol\\Test\\CMakeLists.txt file
# @code{.py}
# add_unity_test(NAME TestTransmitSingleCastLinkLayer
# FILES ../ZW_DataLinkLayer.c TestTransmitSingleCastLinkLayer.c
# LIBRARIES mock ZW_RadioPhyMock Assert )
# @endcode
#
#
# @b Parameters
# <TABLE cellspacing=0 cellborder=0>
# <TR>
# <TD>&emsp;&emsp;&emsp;</TD><TD><TT>\[in\]</TT></TD><TD><b>NAME \<name\></b></TD>
# <TD>Name of test executeable to build</TD>
# </TR>
# <TR>
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>TEST_BASE \<file.\<c|cpp\>\></b></TD>
# <TD>\[Optional\] Unit test file from which the runner should be generated, if TEST_BASE is not
# provided, the \<name\>.\<c|cpp\> from first parameter will be used.</TD>
# </TR>
# <TR>
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>FILES \<fileN\></b></TD>
# <TD>List of files used for building the test</TD>
# </TR>
# <TR>
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>LIBRARIES \<libN\></b></TD>
# <TD>List of libraries to link for the test executable (unity is automatically included)</TD>
# </TR>
# <TR>
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>USE_CPP</b></TD>
# <TD>\[Optional\] Set this flag if the test executable must be compiled using C++</TD>
# </TR>
# </TABLE>
#
function(ADD_UNITY_TEST)
set(OPTIONS USE_CPP DISABLED USE_UNITY_WITH_CMOCK)
set(SINGLE_VALUE_ARGS "NAME" "TEST_BASE")
set(MULTI_VALUE_ARGS "FILES" "LIBRARIES" "INCLUDES")
cmake_parse_arguments(ADD_UNITY_TEST "${OPTIONS}" "${SINGLE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN} )

set(RUNNER_EXTENSION c)
if (ADD_UNITY_TEST_USE_CPP)
set(RUNNER_EXTENSION cpp)
endif (ADD_UNITY_TEST_USE_CPP)

set(RUNNER_BASE "${ADD_UNITY_TEST_NAME}.${RUNNER_EXTENSION}")
if (NOT ${ADD_UNITY_TEST_TEST_BASE} STREQUAL "")
set(RUNNER_BASE "${ADD_UNITY_TEST_TEST_BASE}")
endif (NOT ${ADD_UNITY_TEST_TEST_BASE} STREQUAL "")

if ("${ADD_UNITY_TEST_NAME}" STREQUAL "")
list(GET ADD_UNITY_TEST_UNPARSED_ARGUMENTS 0 ADD_UNITY_TEST_NAME)
list(REMOVE_AT ADD_UNITY_TEST_UNPARSED_ARGUMENTS 0)
set(RUNNER_BASE "${ADD_UNITY_TEST_NAME}.${RUNNER_EXTENSION}")
set(ADD_UNITY_TEST_FILES "${ADD_UNITY_TEST_UNPARSED_ARGUMENTS}")
endif ("${ADD_UNITY_TEST_NAME}" STREQUAL "")

add_executable(${ADD_UNITY_TEST_NAME} ${ADD_UNITY_TEST_NAME}_runner.${RUNNER_EXTENSION} ${RUNNER_BASE} ${ADD_UNITY_TEST_FILES})

add_custom_command(OUTPUT ${ADD_UNITY_TEST_NAME}_runner.${RUNNER_EXTENSION}
COMMAND ${PYTHON_EXECUTABLE} ${TEST_TOOLS_DIR}/gen_test_runner.py ${RUNNER_BASE} > ${CMAKE_CURRENT_BINARY_DIR}/${ADD_UNITY_TEST_NAME}_runner.${RUNNER_EXTENSION}
DEPENDS ${RUNNER_BASE} ${TEST_TOOLS_DIR}/gen_test_runner.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_test(${ADD_UNITY_TEST_NAME} ${ADD_UNITY_TEST_NAME} )
target_link_libraries( ${ADD_UNITY_TEST_NAME} ${ADD_UNITY_TEST_LIBRARIES})
if (NOT ADD_UNITY_TEST_USE_UNITY_WITH_CMOCK)
target_link_libraries( ${ADD_UNITY_TEST_NAME} unity)
endif (NOT ADD_UNITY_TEST_USE_UNITY_WITH_CMOCK)

target_include_directories(${ADD_UNITY_TEST_NAME} PRIVATE . ${ADD_UNITY_TEST_INCLUDES})

if(${ADD_UNITY_TEST_DISABLED})
set_tests_properties(${TEST_NAME} PROPERTIES DISABLED True)
endif()
endfunction(ADD_UNITY_TEST)

# compile the unity version bundled along with cmock sources.
add_library(unity cmock/vendor/unity/src/unity.c)
target_include_directories(unity PUBLIC cmock/vendor/unity/src)
target_compile_options(unity PRIVATE "-fPIC")

# Build the cmock library and link the above compiled unity with the cmock library
add_library(cmock STATIC cmock/src/cmock.c)
target_include_directories(cmock PUBLIC cmock/src)
target_link_libraries(cmock PUBLIC unity)
target_compile_options(cmock PRIVATE "-fPIC")

add_subdirectory(unity)
# Check whether the building of mock framework is disabled.
# Building of the mock framework can be disabled for the c51 or asip simply by adding the following line to the specific project at higher level:
# Building of the mock framework can be disabled by chip vendors simply by adding the following line to the specific project at higher level:
# e.g.: set(DISABLE_MOCK 1)
# Warning, Do not set DISABLE_MOCK in this file.
if (NOT DEFINED DISABLE_MOCK)
add_subdirectory(mock)
endif (NOT DEFINED DISABLE_MOCK)
else()
else(NOT COMMAND ADD_UNITY_TEST)
message(STATUS "TestFramework from ${CMAKE_CURRENT_SOURCE_DIR} NOT included")
endif()
endif(NOT COMMAND ADD_UNITY_TEST)
Submodule cmock added at 9d0928
Loading