1# 2# Copyright (c) 2020, The OpenThread Authors. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# 2. Redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution. 12# 3. Neither the name of the copyright holder nor the 13# names of its contributors may be used to endorse or promote products 14# derived from this software without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26# POSSIBILITY OF SUCH DAMAGE. 27# 28 29set(COMMON_INCLUDES 30 ${PROJECT_SOURCE_DIR}/include 31 ${PROJECT_SOURCE_DIR}/src 32 ${PROJECT_SOURCE_DIR}/src/core 33) 34 35set(COMMON_INCLUDES_RCP 36 ${COMMON_INCLUDES} 37 ${PROJECT_SOURCE_DIR}/src/core/radio 38) 39 40set(COMMON_COMPILE_OPTIONS 41 -DOPENTHREAD_FTD=1 42 -DOPENTHREAD_MTD=0 43 -DOPENTHREAD_RADIO=0 44 -DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 45) 46 47set(COMMON_COMPILE_OPTIONS_RCP 48 -DOPENTHREAD_FTD=0 49 -DOPENTHREAD_MTD=0 50 -DOPENTHREAD_RADIO=1 51 -DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 52 -DOPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE=0 53) 54 55set(MULTIPAN_RCP_COMPILE_OPTIONS 56 -DOPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE=1 57 -DOPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE=1 58 -DOPENTHREAD_CONFIG_LOG_PREPEND_UPTIME=0 59 -DOPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE=0 # used to skip backoff and request tx from platform directly. 60 -DOPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE=1 61) 62 63add_library(ot-test-platform-ftd 64 test_platform.cpp 65 test_util.cpp 66) 67add_library(ot-test-platform-rcp 68 test_platform.cpp 69 test_util.cpp 70) 71 72target_include_directories(ot-test-platform-ftd 73 PRIVATE 74 ${COMMON_INCLUDES} 75) 76 77target_include_directories(ot-test-platform-rcp 78 PRIVATE 79 ${COMMON_INCLUDES} 80) 81 82target_compile_options(ot-test-platform-ftd 83 PRIVATE 84 ${COMMON_COMPILE_OPTIONS} 85) 86 87target_compile_options(ot-test-platform-rcp 88 PRIVATE 89 ${COMMON_COMPILE_OPTIONS_RCP} 90) 91 92if(OT_MULTIPAN_RCP) 93 target_compile_options(ot-test-platform-rcp 94 PRIVATE 95 "-DOPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE=1" 96 "-DOPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE=1" 97 "-DOPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE=1" 98 ) 99endif() 100 101target_link_libraries(ot-test-platform-ftd 102 PRIVATE 103 ot-config 104 ${OT_MBEDTLS} 105) 106 107target_link_libraries(ot-test-platform-rcp 108 PRIVATE 109 ot-config 110 ${OT_MBEDTLS} 111) 112 113set(COMMON_LIBS 114 openthread-spinel-ncp 115 openthread-hdlc 116 ot-test-platform-ftd 117 openthread-ftd 118 ot-test-platform-ftd 119 ${OT_MBEDTLS} 120 ot-config 121 openthread-ftd 122 openthread-url 123) 124 125set(COMMON_LIBS_RCP 126 ot-test-platform-rcp 127 openthread-rcp 128 ${OT_MBEDTLS} 129 ot-config 130) 131 132#---------------------------------------------------------------------------------------------------------------------- 133 134macro(ot_unit_test name) 135 136 # Macro to add an OpenThread unit test. 137 # 138 # Unit test name will be `ot-test-{name}`. Test source file of 139 # `test_{name}.cpp` is used. Optional extra arguments can be 140 # passed to provide additional source files. 141 142 add_executable(ot-test-${name} 143 test_${name}.cpp ${ARGN} 144 ) 145 146 target_include_directories(ot-test-${name} 147 PRIVATE 148 ${COMMON_INCLUDES} 149 ) 150 151 target_link_libraries(ot-test-${name} 152 PRIVATE 153 ${COMMON_LIBS} 154 ) 155 156 target_compile_options(ot-test-${name} 157 PRIVATE 158 ${COMMON_COMPILE_OPTIONS} 159 ) 160 161 add_test(NAME ot-test-${name} COMMAND ot-test-${name}) 162endmacro() 163 164#---------------------------------------------------------------------------------------------------------------------- 165 166macro(ot_unit_ncp_test name) 167 168 # Macro to add an OpenThread unit test for NCP functions. 169 # 170 # Unit test name will be `ot-test-ncp-{name}`. Test source file of 171 # `test_ncp_{name}.cpp` is used. Optional extra arguments can be 172 # passed to provide additional source files. 173 174 add_executable(ot-test-ncp-${name} 175 test_ncp_${name}.cpp ${ARGN} 176 ) 177 178 target_include_directories(ot-test-ncp-${name} 179 PRIVATE 180 ${COMMON_INCLUDES} 181 ) 182 183 target_link_libraries(ot-test-ncp-${name} 184 PRIVATE 185 openthread-ncp-ftd 186 ${COMMON_LIBS} 187 ) 188 189 target_compile_options(ot-test-ncp-${name} 190 PRIVATE 191 -DOPENTHREAD_FTD=1 192 ) 193 194 add_test(NAME ot-test-ncp-${name} COMMAND ot-test-ncp-${name}) 195endmacro() 196 197#---------------------------------------------------------------------------------------------------------------------- 198# Unit tests 199 200ot_unit_test(address_sanitizer) 201ot_unit_test(aes) 202ot_unit_test(array) 203ot_unit_test(binary_search) 204ot_unit_test(checksum) 205ot_unit_test(child) 206ot_unit_test(child_table) 207ot_unit_test(cmd_line_parser) 208ot_unit_test(crc) 209ot_unit_test(data) 210ot_unit_test(dataset) 211ot_unit_test(dns) 212ot_unit_test(dns_client) 213ot_unit_test(dnssd_discovery_proxy) 214ot_unit_test(dso) 215ot_unit_test(ecdsa) 216ot_unit_test(flash) 217ot_unit_test(frame_builder) 218ot_unit_test(hdlc) 219ot_unit_test(heap) 220ot_unit_test(heap_array) 221ot_unit_test(heap_string) 222ot_unit_test(hkdf_sha256) 223ot_unit_test(hmac_sha256) 224ot_unit_test(ip4_header) 225ot_unit_test(ip6_header) 226ot_unit_test(ip_address) 227ot_unit_test(link_metrics_manager) 228ot_unit_test(link_quality) 229ot_unit_test(linked_list) 230ot_unit_test(lowpan) 231ot_unit_test(mac_frame) 232ot_unit_test(macros) 233ot_unit_test(mdns) 234ot_unit_test(meshcop) 235ot_unit_test(message) 236ot_unit_test(message_queue) 237ot_unit_test(mle) 238ot_unit_test(multicast_listeners_table) 239ot_unit_test(nat64) 240ot_unit_test(ndproxy_table) 241ot_unit_test(netif) 242ot_unit_test(network_data) 243ot_unit_test(network_name) 244ot_unit_test(offset_range) 245ot_unit_test(pool) 246ot_unit_test(power_calibration) 247ot_unit_test(priority_queue) 248ot_unit_test(pskc) 249ot_unit_test(routing_manager) 250ot_unit_test(serial_number) 251ot_unit_test(smart_ptrs) 252ot_unit_test(spinel_buffer) 253ot_unit_test(spinel_decoder) 254ot_unit_test(spinel_encoder) 255ot_unit_test(spinel_prop_codec) 256ot_unit_test(srp_adv_proxy) 257ot_unit_test(srp_server) 258ot_unit_test(string) 259ot_unit_test(tasklet) 260ot_unit_test(tcat) 261ot_unit_test(timer) 262ot_unit_test(tlv) 263ot_unit_test(toolchain test_toolchain_c.c) 264ot_unit_test(trickle_timer) 265ot_unit_test(url) 266 267ot_unit_ncp_test(dnssd) 268ot_unit_ncp_test(infra_if) 269ot_unit_ncp_test(srp_server) 270 271# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 272 273if(OT_MULTIPAN_RCP) 274 add_executable(ot-test-multipan-rcp-instances 275 test_multipan_rcp_instances.cpp 276 ) 277 278 target_include_directories(ot-test-multipan-rcp-instances 279 PRIVATE 280 ${COMMON_INCLUDES_RCP} 281 ) 282 283 target_compile_options(ot-test-multipan-rcp-instances 284 PRIVATE 285 ${COMMON_COMPILE_OPTIONS_RCP} 286 ${MULTIPAN_RCP_COMPILE_OPTIONS} 287 ) 288 289 target_compile_definitions(ot-test-multipan-rcp-instances 290 PRIVATE 291 "OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE=1" 292 ) 293 294 target_compile_options(ot-config-radio 295 INTERFACE 296 "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE=0" # used to skip backoff and request tx from platform directly. 297 ) 298 299 target_link_libraries(ot-test-multipan-rcp-instances 300 PRIVATE 301 ${COMMON_LIBS_RCP} 302 ) 303 304 add_test(NAME ot-test-multipan-rcp-instances COMMAND ot-test-multipan-rcp-instances) 305 endif() 306