Skip to content

Commit 587b6b6

Browse files
Luiskyrzr
authored andcommitted
libs2/tf: SWPROT-8720: remove unity bundled with TestFramwork as it was outdated (#57)
remove unity bundled with TestFramwork as it was outdated, we are now using the unity bundled with cmock in ThirdParty/cmock/vendor/unity. libs2 standalone unit tests were updated as well. (cherry picked from commit ba375ff2e7580da7a716697a5d39922adc09e888) Forwarded: #57 Relate-to: #50 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 79f89f4 commit 587b6b6

20 files changed

+117
-3725
lines changed

applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/TestFramework/CMakeFunctions.cmake

-99
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,115 @@
11
# Prevent multiple "inclusions" of TestFramework
2-
if (NOT TARGET unity)
2+
if (NOT COMMAND ADD_UNITY_TEST)
33
message(STATUS "TestFramework from ${CMAKE_CURRENT_SOURCE_DIR} included")
44
add_definitions( -DUNIT_TEST )
55

66
set(TEST_TOOLS_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL test_tools_dir)
77

88
find_package(Python3 COMPONENTS Interpreter)
99

10-
include(CMakeFunctions.cmake)
10+
##
11+
# @b Syntax
12+
#
13+
# &emsp; @c add_unity_test( \b NAME \<name\> [TEST_BASE \<file.\<c|cpp\>\>] FILES \<fileN\> LIBRARIES \<libN\> [USE_CPP])
14+
#
15+
# Function for adding a unit test CMake target.
16+
#
17+
#
18+
# @b Example @b 1
19+
#
20+
#
21+
# from @b Components\\FileSystem\\Test\\CMakeLists.txt file
22+
# @code{.py}
23+
# add_unity_test(NAME TestFileSystem FILES ../FileSystem.c TestFileSystem.cpp LIBRARIES Assert USE_CPP)
24+
# @endcode
25+
#
26+
#
27+
# @b Example @b 2
28+
#
29+
#
30+
# from @b ZWave\\Protocol\\Test\\CMakeLists.txt file
31+
# @code{.py}
32+
# add_unity_test(NAME TestTransmitSingleCastLinkLayer
33+
# FILES ../ZW_DataLinkLayer.c TestTransmitSingleCastLinkLayer.c
34+
# LIBRARIES mock ZW_RadioPhyMock Assert )
35+
# @endcode
36+
#
37+
#
38+
# @b Parameters
39+
# <TABLE cellspacing=0 cellborder=0>
40+
# <TR>
41+
# <TD>&emsp;&emsp;&emsp;</TD><TD><TT>\[in\]</TT></TD><TD><b>NAME \<name\></b></TD>
42+
# <TD>Name of test executeable to build</TD>
43+
# </TR>
44+
# <TR>
45+
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>TEST_BASE \<file.\<c|cpp\>\></b></TD>
46+
# <TD>\[Optional\] Unit test file from which the runner should be generated, if TEST_BASE is not
47+
# provided, the \<name\>.\<c|cpp\> from first parameter will be used.</TD>
48+
# </TR>
49+
# <TR>
50+
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>FILES \<fileN\></b></TD>
51+
# <TD>List of files used for building the test</TD>
52+
# </TR>
53+
# <TR>
54+
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>LIBRARIES \<libN\></b></TD>
55+
# <TD>List of libraries to link for the test executable (unity is automatically included)</TD>
56+
# </TR>
57+
# <TR>
58+
# <TD></TD><TD><TT>\[in\]</TT></TD><TD><b>USE_CPP</b></TD>
59+
# <TD>\[Optional\] Set this flag if the test executable must be compiled using C++</TD>
60+
# </TR>
61+
# </TABLE>
62+
#
63+
function(ADD_UNITY_TEST)
64+
set(OPTIONS USE_CPP DISABLED USE_UNITY_WITH_CMOCK)
65+
set(SINGLE_VALUE_ARGS "NAME" "TEST_BASE")
66+
set(MULTI_VALUE_ARGS "FILES" "LIBRARIES" "INCLUDES")
67+
cmake_parse_arguments(ADD_UNITY_TEST "${OPTIONS}" "${SINGLE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN} )
68+
69+
set(RUNNER_EXTENSION c)
70+
if (ADD_UNITY_TEST_USE_CPP)
71+
set(RUNNER_EXTENSION cpp)
72+
endif (ADD_UNITY_TEST_USE_CPP)
73+
74+
set(RUNNER_BASE "${ADD_UNITY_TEST_NAME}.${RUNNER_EXTENSION}")
75+
if (NOT ${ADD_UNITY_TEST_TEST_BASE} STREQUAL "")
76+
set(RUNNER_BASE "${ADD_UNITY_TEST_TEST_BASE}")
77+
endif (NOT ${ADD_UNITY_TEST_TEST_BASE} STREQUAL "")
78+
79+
if ("${ADD_UNITY_TEST_NAME}" STREQUAL "")
80+
list(GET ADD_UNITY_TEST_UNPARSED_ARGUMENTS 0 ADD_UNITY_TEST_NAME)
81+
list(REMOVE_AT ADD_UNITY_TEST_UNPARSED_ARGUMENTS 0)
82+
set(RUNNER_BASE "${ADD_UNITY_TEST_NAME}.${RUNNER_EXTENSION}")
83+
set(ADD_UNITY_TEST_FILES "${ADD_UNITY_TEST_UNPARSED_ARGUMENTS}")
84+
endif ("${ADD_UNITY_TEST_NAME}" STREQUAL "")
85+
86+
add_executable(${ADD_UNITY_TEST_NAME} ${ADD_UNITY_TEST_NAME}_runner.${RUNNER_EXTENSION} ${RUNNER_BASE} ${ADD_UNITY_TEST_FILES})
87+
88+
add_custom_command(OUTPUT ${ADD_UNITY_TEST_NAME}_runner.${RUNNER_EXTENSION}
89+
COMMAND ${PYTHON_EXECUTABLE} ${TEST_TOOLS_DIR}/gen_test_runner.py ${RUNNER_BASE} > ${CMAKE_CURRENT_BINARY_DIR}/${ADD_UNITY_TEST_NAME}_runner.${RUNNER_EXTENSION}
90+
DEPENDS ${RUNNER_BASE} ${TEST_TOOLS_DIR}/gen_test_runner.py
91+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
92+
)
93+
add_test(${ADD_UNITY_TEST_NAME} ${ADD_UNITY_TEST_NAME} )
94+
target_link_libraries( ${ADD_UNITY_TEST_NAME} ${ADD_UNITY_TEST_LIBRARIES})
95+
if (NOT ADD_UNITY_TEST_USE_UNITY_WITH_CMOCK)
96+
target_link_libraries( ${ADD_UNITY_TEST_NAME} unity)
97+
endif (NOT ADD_UNITY_TEST_USE_UNITY_WITH_CMOCK)
98+
99+
target_include_directories(${ADD_UNITY_TEST_NAME} PRIVATE . ${ADD_UNITY_TEST_INCLUDES})
100+
101+
if(${ADD_UNITY_TEST_DISABLED})
102+
set_tests_properties(${TEST_NAME} PROPERTIES DISABLED True)
103+
endif()
104+
endfunction(ADD_UNITY_TEST)
11105

12-
add_subdirectory(unity)
13106
# Check whether the building of mock framework is disabled.
14-
# 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:
107+
# Building of the mock framework can be disabled by chip vendors simply by adding the following line to the specific project at higher level:
15108
# e.g.: set(DISABLE_MOCK 1)
16109
# Warning, Do not set DISABLE_MOCK in this file.
17110
if (NOT DEFINED DISABLE_MOCK)
18111
add_subdirectory(mock)
19112
endif (NOT DEFINED DISABLE_MOCK)
20-
else()
113+
else(NOT COMMAND ADD_UNITY_TEST)
21114
message(STATUS "TestFramework from ${CMAKE_CURRENT_SOURCE_DIR} NOT included")
22-
endif()
115+
endif(NOT COMMAND ADD_UNITY_TEST)

applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/TestFramework/gen_test_runner.py

+15-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from io import open
99
from string import Template
1010

11+
# in https://github.com/ThrowTheSwitch/Unity/issues/438 it was decided that it was the generator responsability
12+
# to handle the definition of setUp, tearDown, setUpSuite and tearDownSuite (which are called suiteSetUp and suiteTearDown in unity btw)
13+
# this is why these functions are defined as weak functions.
14+
1115
test_runner_template = '''
1216
/* AUTOGENERATED FILE. DO NOT EDIT. */
1317
@@ -21,23 +25,13 @@
2125
2226
${FUNCTION_PROTOTYPES}
2327
24-
// Inspired by how Unity creates the setUp and tearDown functions
25-
// Purpose is a setup and teardown method called before suite is run,
26-
// and after suite is run.
27-
#if defined(UNITY_WEAK_ATTRIBUTE)
28-
void setUpSuite(void);
29-
void tearDownSuite(void);
30-
UNITY_WEAK_ATTRIBUTE void setUpSuite(void) { }
31-
UNITY_WEAK_ATTRIBUTE void tearDownSuite(void) { }
32-
#elif defined(UNITY_WEAK_PRAGMA)
33-
#pragma weak setUpSuite
34-
void setUpSuite(void);
35-
#pragma weak tearDownSuite
36-
void tearDownSuite(void);
37-
#else
38-
void setUpSuite(void);
39-
void tearDownSuite(void);
40-
#endif
28+
void setUpSuite(void);
29+
void tearDownSuite(void);
30+
31+
void __attribute__((weak)) setUp(void) { }
32+
void __attribute__((weak)) tearDown(void) { }
33+
void __attribute__((weak)) setUpSuite(void) { }
34+
void __attribute__((weak)) tearDownSuite(void) { }
4135
4236
int main(int argc, char** argp) {
4337
int ret;
@@ -76,11 +70,10 @@
7670
filename, file_type = os.path.splitext(sys.argv[1])
7771

7872
funcs = []
79-
function_prototypes = ''
80-
function_calls_verbose = ''
81-
function_calls = ''
82-
83-
regexp = r'^void (test_[A-Za-z0-9_]+)\(.*\).*'
73+
function_prototypes = ''
74+
function_calls_verbose = ''
75+
function_calls = ''
76+
regexp = r'^void (test_[A-Za-z0-9_]+)\(.*\).*'
8477

8578
line = 0
8679
for l in open(sys.argv[1], encoding='utf-8'):

applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/TestFramework/mock/CMakeLists.txt

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
# This test ensures that the target named 'mock' will only be declared if it is not already declared.
44
if (NOT TARGET mock)
55
add_library(mock mock_control.c)
6-
if (TARGET unity2)
7-
target_link_libraries(mock unity2)
8-
target_compile_definitions(mock PUBLIC USE_UNITY2)
9-
message(STATUS "Linking mock framework with unity2")
10-
else()
11-
target_link_libraries(mock unity)
12-
endif (TARGET unity2)
6+
target_link_libraries(mock unity)
7+
target_compile_definitions(mock PUBLIC USE_UNITY)
8+
message(STATUS "Linking mock framework with unity (from ThirdParty/cmock/vendor/unity)")
139
target_include_directories(mock PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
1410
add_subdirectory(test)
1511
endif (NOT TARGET mock)

applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/TestFramework/mock/mock_control.h

-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131
#define NUMBER_OF_ARGS 9
3232

3333
extern uint32_t g_mock_index;
34-
#if defined(USE_UNITY2)
3534
extern struct UNITY_STORAGE_T Unity;
36-
#else
37-
extern struct _Unity Unity;
38-
#endif
3935

4036
typedef enum
4137
{

applications/zpc/components/zwave/zwave_transports/s2/libs/zw-libs2/TestFramework/unity/CMakeLists.txt

-10
This file was deleted.

0 commit comments

Comments
 (0)