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# Unit tests 166 167ot_unit_test(address_sanitizer) 168ot_unit_test(aes) 169ot_unit_test(array) 170ot_unit_test(binary_search) 171ot_unit_test(checksum) 172ot_unit_test(child) 173ot_unit_test(child_table) 174ot_unit_test(cmd_line_parser) 175ot_unit_test(data) 176ot_unit_test(dataset) 177ot_unit_test(dns) 178ot_unit_test(dns_client) 179ot_unit_test(dnssd_discovery_proxy) 180ot_unit_test(dso) 181ot_unit_test(ecdsa) 182ot_unit_test(flash) 183ot_unit_test(frame_builder) 184ot_unit_test(hdlc) 185ot_unit_test(heap) 186ot_unit_test(heap_array) 187ot_unit_test(heap_string) 188ot_unit_test(hkdf_sha256) 189ot_unit_test(hmac_sha256) 190ot_unit_test(ip4_header) 191ot_unit_test(ip6_header) 192ot_unit_test(ip_address) 193ot_unit_test(link_metrics_manager) 194ot_unit_test(link_quality) 195ot_unit_test(linked_list) 196ot_unit_test(lowpan) 197ot_unit_test(mac_frame) 198ot_unit_test(macros) 199ot_unit_test(mdns) 200ot_unit_test(meshcop) 201ot_unit_test(message) 202ot_unit_test(message_queue) 203ot_unit_test(mle) 204ot_unit_test(multicast_listeners_table) 205ot_unit_test(nat64) 206ot_unit_test(ndproxy_table) 207ot_unit_test(netif) 208ot_unit_test(network_data) 209ot_unit_test(network_name) 210ot_unit_test(offset_range) 211ot_unit_test(pool) 212ot_unit_test(power_calibration) 213ot_unit_test(priority_queue) 214ot_unit_test(pskc) 215ot_unit_test(routing_manager) 216ot_unit_test(serial_number) 217ot_unit_test(smart_ptrs) 218ot_unit_test(spinel_buffer) 219ot_unit_test(spinel_decoder) 220ot_unit_test(spinel_encoder) 221ot_unit_test(srp_adv_proxy) 222ot_unit_test(srp_server) 223ot_unit_test(string) 224ot_unit_test(tcat) 225ot_unit_test(timer) 226ot_unit_test(tlv) 227ot_unit_test(toolchain test_toolchain_c.c) 228ot_unit_test(trickle_timer) 229ot_unit_test(url) 230 231# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 232 233if(OT_MULTIPAN_RCP) 234 add_executable(ot-test-multipan-rcp-instances 235 test_multipan_rcp_instances.cpp 236 ) 237 238 target_include_directories(ot-test-multipan-rcp-instances 239 PRIVATE 240 ${COMMON_INCLUDES_RCP} 241 ) 242 243 target_compile_options(ot-test-multipan-rcp-instances 244 PRIVATE 245 ${COMMON_COMPILE_OPTIONS_RCP} 246 ${MULTIPAN_RCP_COMPILE_OPTIONS} 247 ) 248 249 target_compile_definitions(ot-test-multipan-rcp-instances 250 PRIVATE 251 "OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE=1" 252 ) 253 254 target_compile_options(ot-config-radio 255 INTERFACE 256 "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE=0" # used to skip backoff and request tx from platform directly. 257 ) 258 259 target_link_libraries(ot-test-multipan-rcp-instances 260 PRIVATE 261 ${COMMON_LIBS_RCP} 262 ) 263 264 add_test(NAME ot-test-multipan-rcp-instances COMMAND ot-test-multipan-rcp-instances) 265 endif() 266