xref: /aosp_15_r20/external/openthread/script/test (revision cfb92d1480a9e65faed56933e9c12405f45898b4)
1*cfb92d14SAndroid Build Coastguard Worker#!/bin/bash
2*cfb92d14SAndroid Build Coastguard Worker#
3*cfb92d14SAndroid Build Coastguard Worker#  Copyright (c) 2018, The OpenThread Authors.
4*cfb92d14SAndroid Build Coastguard Worker#  All rights reserved.
5*cfb92d14SAndroid Build Coastguard Worker#
6*cfb92d14SAndroid Build Coastguard Worker#  Redistribution and use in source and binary forms, with or without
7*cfb92d14SAndroid Build Coastguard Worker#  modification, are permitted provided that the following conditions are met:
8*cfb92d14SAndroid Build Coastguard Worker#  1. Redistributions of source code must retain the above copyright
9*cfb92d14SAndroid Build Coastguard Worker#     notice, this list of conditions and the following disclaimer.
10*cfb92d14SAndroid Build Coastguard Worker#  2. Redistributions in binary form must reproduce the above copyright
11*cfb92d14SAndroid Build Coastguard Worker#     notice, this list of conditions and the following disclaimer in the
12*cfb92d14SAndroid Build Coastguard Worker#     documentation and/or other materials provided with the distribution.
13*cfb92d14SAndroid Build Coastguard Worker#  3. Neither the name of the copyright holder nor the
14*cfb92d14SAndroid Build Coastguard Worker#     names of its contributors may be used to endorse or promote products
15*cfb92d14SAndroid Build Coastguard Worker#     derived from this software without specific prior written permission.
16*cfb92d14SAndroid Build Coastguard Worker#
17*cfb92d14SAndroid Build Coastguard Worker#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18*cfb92d14SAndroid Build Coastguard Worker#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*cfb92d14SAndroid Build Coastguard Worker#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*cfb92d14SAndroid Build Coastguard Worker#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21*cfb92d14SAndroid Build Coastguard Worker#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*cfb92d14SAndroid Build Coastguard Worker#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*cfb92d14SAndroid Build Coastguard Worker#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*cfb92d14SAndroid Build Coastguard Worker#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*cfb92d14SAndroid Build Coastguard Worker#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*cfb92d14SAndroid Build Coastguard Worker#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*cfb92d14SAndroid Build Coastguard Worker#  POSSIBILITY OF SUCH DAMAGE.
28*cfb92d14SAndroid Build Coastguard Worker#
29*cfb92d14SAndroid Build Coastguard Worker#    Description:
30*cfb92d14SAndroid Build Coastguard Worker#      This file runs various tests of OpenThread.
31*cfb92d14SAndroid Build Coastguard Worker#
32*cfb92d14SAndroid Build Coastguard Worker
33*cfb92d14SAndroid Build Coastguard Workerset -euo pipefail
34*cfb92d14SAndroid Build Coastguard Worker
35*cfb92d14SAndroid Build Coastguard WorkerOT_BUILDDIR="${OT_BUILDDIR:-${PWD}/build}"
36*cfb92d14SAndroid Build Coastguard Workerreadonly OT_BUILDDIR
37*cfb92d14SAndroid Build Coastguard Worker
38*cfb92d14SAndroid Build Coastguard WorkerOT_SRCDIR="${PWD}"
39*cfb92d14SAndroid Build Coastguard Workerreadonly OT_SRCDIR
40*cfb92d14SAndroid Build Coastguard Worker
41*cfb92d14SAndroid Build Coastguard WorkerOT_COLOR_PASS='\033[0;32m'
42*cfb92d14SAndroid Build Coastguard Workerreadonly OT_COLOR_PASS
43*cfb92d14SAndroid Build Coastguard Worker
44*cfb92d14SAndroid Build Coastguard WorkerOT_COLOR_FAIL='\033[0;31m'
45*cfb92d14SAndroid Build Coastguard Workerreadonly OT_COLOR_FAIL
46*cfb92d14SAndroid Build Coastguard Worker
47*cfb92d14SAndroid Build Coastguard WorkerOT_COLOR_SKIP='\033[0;33m'
48*cfb92d14SAndroid Build Coastguard Workerreadonly OT_COLOR_SKIP
49*cfb92d14SAndroid Build Coastguard Worker
50*cfb92d14SAndroid Build Coastguard WorkerOT_COLOR_NONE='\033[0m'
51*cfb92d14SAndroid Build Coastguard Workerreadonly OT_COLOR_NONE
52*cfb92d14SAndroid Build Coastguard Worker
53*cfb92d14SAndroid Build Coastguard WorkerOT_NODE_TYPE="${OT_NODE_TYPE:-cli}"
54*cfb92d14SAndroid Build Coastguard Workerreadonly OT_NODE_TYPE
55*cfb92d14SAndroid Build Coastguard Worker
56*cfb92d14SAndroid Build Coastguard WorkerOT_NATIVE_IP="${OT_NATIVE_IP:-0}"
57*cfb92d14SAndroid Build Coastguard Workerreadonly OT_NATIVE_IP
58*cfb92d14SAndroid Build Coastguard Worker
59*cfb92d14SAndroid Build Coastguard WorkerTHREAD_VERSION="${THREAD_VERSION:-1.3}"
60*cfb92d14SAndroid Build Coastguard Workerreadonly THREAD_VERSION
61*cfb92d14SAndroid Build Coastguard Worker
62*cfb92d14SAndroid Build Coastguard WorkerINTER_OP="${INTER_OP:-0}"
63*cfb92d14SAndroid Build Coastguard Workerreadonly INTER_OP
64*cfb92d14SAndroid Build Coastguard Worker
65*cfb92d14SAndroid Build Coastguard WorkerVERBOSE="${VERBOSE:-0}"
66*cfb92d14SAndroid Build Coastguard Workerreadonly VERBOSE
67*cfb92d14SAndroid Build Coastguard Worker
68*cfb92d14SAndroid Build Coastguard WorkerBORDER_ROUTING="${BORDER_ROUTING:-1}"
69*cfb92d14SAndroid Build Coastguard Workerreadonly BORDER_ROUTING
70*cfb92d14SAndroid Build Coastguard Worker
71*cfb92d14SAndroid Build Coastguard WorkerNAT64="${NAT64:-0}"
72*cfb92d14SAndroid Build Coastguard Workerreadonly NAT64
73*cfb92d14SAndroid Build Coastguard Worker
74*cfb92d14SAndroid Build Coastguard WorkerNAT64_SERVICE="${NAT64_SERVICE:-openthread}"
75*cfb92d14SAndroid Build Coastguard Workerreadonly NAT64_SERVICE
76*cfb92d14SAndroid Build Coastguard Worker
77*cfb92d14SAndroid Build Coastguard WorkerINTER_OP_BBR="${INTER_OP_BBR:-0}"
78*cfb92d14SAndroid Build Coastguard Workerreadonly INTER_OP_BBR
79*cfb92d14SAndroid Build Coastguard Worker
80*cfb92d14SAndroid Build Coastguard WorkerOT_COREDUMP_DIR="${PWD}/ot-core-dump"
81*cfb92d14SAndroid Build Coastguard Workerreadonly OT_COREDUMP_DIR
82*cfb92d14SAndroid Build Coastguard Worker
83*cfb92d14SAndroid Build Coastguard WorkerFULL_LOGS=${FULL_LOGS:-0}
84*cfb92d14SAndroid Build Coastguard Workerreadonly FULL_LOGS
85*cfb92d14SAndroid Build Coastguard Worker
86*cfb92d14SAndroid Build Coastguard WorkerTREL=${TREL:-0}
87*cfb92d14SAndroid Build Coastguard Workerreadonly TREL
88*cfb92d14SAndroid Build Coastguard Worker
89*cfb92d14SAndroid Build Coastguard WorkerLOCAL_OTBR_DIR=${LOCAL_OTBR_DIR:-""}
90*cfb92d14SAndroid Build Coastguard Workerreadonly LOCAL_OTBR_DIR
91*cfb92d14SAndroid Build Coastguard Worker
92*cfb92d14SAndroid Build Coastguard Workerbuild_simulation()
93*cfb92d14SAndroid Build Coastguard Worker{
94*cfb92d14SAndroid Build Coastguard Worker    local version="$1"
95*cfb92d14SAndroid Build Coastguard Worker    local options=(
96*cfb92d14SAndroid Build Coastguard Worker        "-DBUILD_TESTING=ON"
97*cfb92d14SAndroid Build Coastguard Worker        "-DOT_ANYCAST_LOCATOR=ON"
98*cfb92d14SAndroid Build Coastguard Worker        "-DOT_DNS_CLIENT=ON"
99*cfb92d14SAndroid Build Coastguard Worker        "-DOT_DNS_DSO=ON"
100*cfb92d14SAndroid Build Coastguard Worker        "-DOT_DNSSD_SERVER=ON"
101*cfb92d14SAndroid Build Coastguard Worker        "-DOT_ECDSA=ON"
102*cfb92d14SAndroid Build Coastguard Worker        "-DOT_EXTERNAL_HEAP=ON"
103*cfb92d14SAndroid Build Coastguard Worker        "-DOT_HISTORY_TRACKER=ON"
104*cfb92d14SAndroid Build Coastguard Worker        "-DOT_MESSAGE_USE_HEAP=OFF"
105*cfb92d14SAndroid Build Coastguard Worker        "-DOT_NETDATA_PUBLISHER=ON"
106*cfb92d14SAndroid Build Coastguard Worker        "-DOT_PING_SENDER=ON"
107*cfb92d14SAndroid Build Coastguard Worker        "-DOT_PLATFORM_LOG_CRASH_DUMP=ON"
108*cfb92d14SAndroid Build Coastguard Worker        "-DOT_REFERENCE_DEVICE=ON"
109*cfb92d14SAndroid Build Coastguard Worker        "-DOT_SERVICE=ON"
110*cfb92d14SAndroid Build Coastguard Worker        "-DOT_SRP_CLIENT=ON"
111*cfb92d14SAndroid Build Coastguard Worker        "-DOT_SRP_SERVER=ON"
112*cfb92d14SAndroid Build Coastguard Worker        "-DOT_UPTIME=ON"
113*cfb92d14SAndroid Build Coastguard Worker        "-DOT_THREAD_VERSION=${version}"
114*cfb92d14SAndroid Build Coastguard Worker    )
115*cfb92d14SAndroid Build Coastguard Worker
116*cfb92d14SAndroid Build Coastguard Worker    if [[ ${FULL_LOGS} == 1 ]]; then
117*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_FULL_LOGS=ON")
118*cfb92d14SAndroid Build Coastguard Worker    fi
119*cfb92d14SAndroid Build Coastguard Worker
120*cfb92d14SAndroid Build Coastguard Worker    if [[ ${version} != "1.1" ]]; then
121*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_DUA=ON")
122*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_MLR=ON")
123*cfb92d14SAndroid Build Coastguard Worker    fi
124*cfb92d14SAndroid Build Coastguard Worker
125*cfb92d14SAndroid Build Coastguard Worker    if [[ ${VIRTUAL_TIME} == 1 ]]; then
126*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_SIMULATION_VIRTUAL_TIME=ON")
127*cfb92d14SAndroid Build Coastguard Worker    fi
128*cfb92d14SAndroid Build Coastguard Worker
129*cfb92d14SAndroid Build Coastguard Worker    if [[ ${version} != "1.1" ]]; then
130*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_CSL_RECEIVER=ON")
131*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_LINK_METRICS_INITIATOR=ON")
132*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_LINK_METRICS_SUBJECT=ON")
133*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_LINK_METRICS_MANAGER=ON")
134*cfb92d14SAndroid Build Coastguard Worker    fi
135*cfb92d14SAndroid Build Coastguard Worker
136*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_NODE_TYPE} == cli* ]]; then
137*cfb92d14SAndroid Build Coastguard Worker        # Only enable OT_PLATFORM_BOOTLOADER_MODE when testing cli.
138*cfb92d14SAndroid Build Coastguard Worker        # This is intended to test that the "reset bootloader" CLI command returns a "NotCapable" error
139*cfb92d14SAndroid Build Coastguard Worker
140*cfb92d14SAndroid Build Coastguard Worker        # Note: Setting this option to ON for all OT_NODE_TYPEs will cause the posix/expects CI check to fail.
141*cfb92d14SAndroid Build Coastguard Worker        #       This is because the simulation RCP will have the SPINEL_CAP_RCP_RESET_TO_BOOTLOADER capability,
142*cfb92d14SAndroid Build Coastguard Worker        #       causing the ot-cli POSIX app to send the reset to simulation RCP successfully instead of printing
143*cfb92d14SAndroid Build Coastguard Worker        #       the expected error.
144*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_PLATFORM_BOOTLOADER_MODE=ON")
145*cfb92d14SAndroid Build Coastguard Worker    fi
146*cfb92d14SAndroid Build Coastguard Worker
147*cfb92d14SAndroid Build Coastguard Worker    if [[ ${ot_extra_options[*]+x} ]]; then
148*cfb92d14SAndroid Build Coastguard Worker        options+=("${ot_extra_options[@]}")
149*cfb92d14SAndroid Build Coastguard Worker    fi
150*cfb92d14SAndroid Build Coastguard Worker
151*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_NODE_TYPE} == rcp* ]]; then
152*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_SIMULATION_INFRA_IF=OFF")
153*cfb92d14SAndroid Build Coastguard Worker    fi
154*cfb92d14SAndroid Build Coastguard Worker
155*cfb92d14SAndroid Build Coastguard Worker    OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/openthread-simulation-${version}" "${OT_SRCDIR}"/script/cmake-build simulation "${options[@]}"
156*cfb92d14SAndroid Build Coastguard Worker
157*cfb92d14SAndroid Build Coastguard Worker    if [[ ${VIRTUAL_TIME} == 1 ]] && [[ ${OT_NODE_TYPE} == rcp* ]]; then
158*cfb92d14SAndroid Build Coastguard Worker        OT_CMAKE_NINJA_TARGET=ot-rcp OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/openthread-simulation-${version}" "${OT_SRCDIR}"/script/cmake-build simulation "${options[@]}" "-DOT_SIMULATION_VIRTUAL_TIME_UART=ON"
159*cfb92d14SAndroid Build Coastguard Worker    fi
160*cfb92d14SAndroid Build Coastguard Worker
161*cfb92d14SAndroid Build Coastguard Worker    if [[ ${version} != "1.1" && ${INTER_OP_BBR} == 1 ]]; then
162*cfb92d14SAndroid Build Coastguard Worker
163*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_BACKBONE_ROUTER=ON")
164*cfb92d14SAndroid Build Coastguard Worker
165*cfb92d14SAndroid Build Coastguard Worker        OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/openthread-simulation-${version}-bbr" "${OT_SRCDIR}"/script/cmake-build simulation "${options[@]}"
166*cfb92d14SAndroid Build Coastguard Worker
167*cfb92d14SAndroid Build Coastguard Worker        if [[ ${VIRTUAL_TIME} == 1 ]] && [[ ${OT_NODE_TYPE} == rcp* ]]; then
168*cfb92d14SAndroid Build Coastguard Worker            OT_CMAKE_NINJA_TARGET=ot-rcp OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/openthread-simulation-${version}-bbr" "${OT_SRCDIR}"/script/cmake-build simulation "${options[@]}" "-DOT_SIMULATION_VIRTUAL_TIME_UART=ON"
169*cfb92d14SAndroid Build Coastguard Worker        fi
170*cfb92d14SAndroid Build Coastguard Worker
171*cfb92d14SAndroid Build Coastguard Worker    fi
172*cfb92d14SAndroid Build Coastguard Worker}
173*cfb92d14SAndroid Build Coastguard Worker
174*cfb92d14SAndroid Build Coastguard Workerbuild_posix()
175*cfb92d14SAndroid Build Coastguard Worker{
176*cfb92d14SAndroid Build Coastguard Worker    local version="$1"
177*cfb92d14SAndroid Build Coastguard Worker    local options=(
178*cfb92d14SAndroid Build Coastguard Worker        "-DBUILD_TESTING=ON"
179*cfb92d14SAndroid Build Coastguard Worker        "-DOT_MESSAGE_USE_HEAP=ON"
180*cfb92d14SAndroid Build Coastguard Worker        "-DOT_PLATFORM_BOOTLOADER_MODE=ON"
181*cfb92d14SAndroid Build Coastguard Worker        "-DOT_PLATFORM_LOG_CRASH_DUMP=ON"
182*cfb92d14SAndroid Build Coastguard Worker        "-DOT_THREAD_VERSION=${version}"
183*cfb92d14SAndroid Build Coastguard Worker    )
184*cfb92d14SAndroid Build Coastguard Worker
185*cfb92d14SAndroid Build Coastguard Worker    if [[ ${version} != "1.1" ]]; then
186*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_DUA=ON")
187*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_MLR=ON")
188*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_LINK_METRICS_INITIATOR=ON")
189*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_LINK_METRICS_SUBJECT=ON")
190*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_LINK_METRICS_MANAGER=ON")
191*cfb92d14SAndroid Build Coastguard Worker    fi
192*cfb92d14SAndroid Build Coastguard Worker
193*cfb92d14SAndroid Build Coastguard Worker    if [[ ${FULL_LOGS} == 1 ]]; then
194*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_FULL_LOGS=ON")
195*cfb92d14SAndroid Build Coastguard Worker    fi
196*cfb92d14SAndroid Build Coastguard Worker
197*cfb92d14SAndroid Build Coastguard Worker    if [[ ${VIRTUAL_TIME} == 1 ]]; then
198*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_POSIX_VIRTUAL_TIME=ON")
199*cfb92d14SAndroid Build Coastguard Worker    fi
200*cfb92d14SAndroid Build Coastguard Worker
201*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_NATIVE_IP} == 1 ]]; then
202*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_PLATFORM_UDP=ON" "-DOT_PLATFORM_NETIF=ON")
203*cfb92d14SAndroid Build Coastguard Worker    fi
204*cfb92d14SAndroid Build Coastguard Worker
205*cfb92d14SAndroid Build Coastguard Worker    if [[ ${ot_extra_options[*]+x} ]]; then
206*cfb92d14SAndroid Build Coastguard Worker        options+=("${ot_extra_options[@]}")
207*cfb92d14SAndroid Build Coastguard Worker    fi
208*cfb92d14SAndroid Build Coastguard Worker
209*cfb92d14SAndroid Build Coastguard Worker    OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/openthread-posix-${version}" "${OT_SRCDIR}"/script/cmake-build posix "${options[@]}"
210*cfb92d14SAndroid Build Coastguard Worker
211*cfb92d14SAndroid Build Coastguard Worker    if [[ ${version} != "1.1" && ${INTER_OP_BBR} == 1 ]]; then
212*cfb92d14SAndroid Build Coastguard Worker
213*cfb92d14SAndroid Build Coastguard Worker        options+=("-DOT_BACKBONE_ROUTER=ON")
214*cfb92d14SAndroid Build Coastguard Worker
215*cfb92d14SAndroid Build Coastguard Worker        OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/openthread-posix-${version}-bbr" "${OT_SRCDIR}"/script/cmake-build posix "${options[@]}"
216*cfb92d14SAndroid Build Coastguard Worker    fi
217*cfb92d14SAndroid Build Coastguard Worker}
218*cfb92d14SAndroid Build Coastguard Worker
219*cfb92d14SAndroid Build Coastguard Workerbuild_for_one_version()
220*cfb92d14SAndroid Build Coastguard Worker{
221*cfb92d14SAndroid Build Coastguard Worker    local version="$1"
222*cfb92d14SAndroid Build Coastguard Worker
223*cfb92d14SAndroid Build Coastguard Worker    build_simulation "${version}"
224*cfb92d14SAndroid Build Coastguard Worker
225*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_NODE_TYPE} == rcp* ]]; then
226*cfb92d14SAndroid Build Coastguard Worker        build_posix "${version}"
227*cfb92d14SAndroid Build Coastguard Worker    fi
228*cfb92d14SAndroid Build Coastguard Worker}
229*cfb92d14SAndroid Build Coastguard Worker
230*cfb92d14SAndroid Build Coastguard Workerdo_build()
231*cfb92d14SAndroid Build Coastguard Worker{
232*cfb92d14SAndroid Build Coastguard Worker    build_for_one_version "${THREAD_VERSION}"
233*cfb92d14SAndroid Build Coastguard Worker
234*cfb92d14SAndroid Build Coastguard Worker    if [[ ${THREAD_VERSION} != "1.1" && ${INTER_OP} == "1" ]]; then
235*cfb92d14SAndroid Build Coastguard Worker        build_for_one_version 1.1
236*cfb92d14SAndroid Build Coastguard Worker    fi
237*cfb92d14SAndroid Build Coastguard Worker}
238*cfb92d14SAndroid Build Coastguard Worker
239*cfb92d14SAndroid Build Coastguard Workerdo_clean()
240*cfb92d14SAndroid Build Coastguard Worker{
241*cfb92d14SAndroid Build Coastguard Worker    ./script/gcda-tool clean
242*cfb92d14SAndroid Build Coastguard Worker    rm -rfv "${OT_BUILDDIR}" || sudo rm -rfv "${OT_BUILDDIR}"
243*cfb92d14SAndroid Build Coastguard Worker}
244*cfb92d14SAndroid Build Coastguard Worker
245*cfb92d14SAndroid Build Coastguard Workerdo_unit_version()
246*cfb92d14SAndroid Build Coastguard Worker{
247*cfb92d14SAndroid Build Coastguard Worker    local version=$1
248*cfb92d14SAndroid Build Coastguard Worker    local builddir="${OT_BUILDDIR}/openthread-simulation-${version}"
249*cfb92d14SAndroid Build Coastguard Worker
250*cfb92d14SAndroid Build Coastguard Worker    if [[ ! -d ${builddir} ]]; then
251*cfb92d14SAndroid Build Coastguard Worker        echo "Cannot find build directory: ${builddir}"
252*cfb92d14SAndroid Build Coastguard Worker        exit 1
253*cfb92d14SAndroid Build Coastguard Worker    fi
254*cfb92d14SAndroid Build Coastguard Worker
255*cfb92d14SAndroid Build Coastguard Worker    (
256*cfb92d14SAndroid Build Coastguard Worker        cd "${builddir}"
257*cfb92d14SAndroid Build Coastguard Worker        ninja test
258*cfb92d14SAndroid Build Coastguard Worker    )
259*cfb92d14SAndroid Build Coastguard Worker}
260*cfb92d14SAndroid Build Coastguard Worker
261*cfb92d14SAndroid Build Coastguard Workerdo_unit()
262*cfb92d14SAndroid Build Coastguard Worker{
263*cfb92d14SAndroid Build Coastguard Worker    do_unit_version "${THREAD_VERSION}"
264*cfb92d14SAndroid Build Coastguard Worker
265*cfb92d14SAndroid Build Coastguard Worker    if [[ ${THREAD_VERSION} != "1.1" && ${INTER_OP_BBR} == 1 ]]; then
266*cfb92d14SAndroid Build Coastguard Worker        do_unit_version "1.3-bbr"
267*cfb92d14SAndroid Build Coastguard Worker    fi
268*cfb92d14SAndroid Build Coastguard Worker}
269*cfb92d14SAndroid Build Coastguard Worker
270*cfb92d14SAndroid Build Coastguard Workerdo_cert()
271*cfb92d14SAndroid Build Coastguard Worker{
272*cfb92d14SAndroid Build Coastguard Worker    export top_builddir="${OT_BUILDDIR}/openthread-simulation-${THREAD_VERSION}"
273*cfb92d14SAndroid Build Coastguard Worker    export top_srcdir="${OT_SRCDIR}"
274*cfb92d14SAndroid Build Coastguard Worker
275*cfb92d14SAndroid Build Coastguard Worker    case "${OT_NODE_TYPE}" in
276*cfb92d14SAndroid Build Coastguard Worker        rcp | rcp-cli | cli)
277*cfb92d14SAndroid Build Coastguard Worker            export NODE_TYPE=sim
278*cfb92d14SAndroid Build Coastguard Worker            ;;
279*cfb92d14SAndroid Build Coastguard Worker        rcp-ncp | ncp)
280*cfb92d14SAndroid Build Coastguard Worker            export NODE_TYPE=ncp-sim
281*cfb92d14SAndroid Build Coastguard Worker            ;;
282*cfb92d14SAndroid Build Coastguard Worker    esac
283*cfb92d14SAndroid Build Coastguard Worker
284*cfb92d14SAndroid Build Coastguard Worker    if [[ ${THREAD_VERSION} != "1.1" ]]; then
285*cfb92d14SAndroid Build Coastguard Worker        export top_builddir_1_3_bbr="${OT_BUILDDIR}/openthread-simulation-1.3-bbr"
286*cfb92d14SAndroid Build Coastguard Worker        if [[ ${INTER_OP} == "1" ]]; then
287*cfb92d14SAndroid Build Coastguard Worker            export top_builddir_1_1="${OT_BUILDDIR}/openthread-simulation-1.1"
288*cfb92d14SAndroid Build Coastguard Worker        fi
289*cfb92d14SAndroid Build Coastguard Worker    fi
290*cfb92d14SAndroid Build Coastguard Worker
291*cfb92d14SAndroid Build Coastguard Worker    export PYTHONPATH=tests/scripts/thread-cert
292*cfb92d14SAndroid Build Coastguard Worker
293*cfb92d14SAndroid Build Coastguard Worker    [[ ! -d tmp ]] || rm -rvf tmp
294*cfb92d14SAndroid Build Coastguard Worker    PYTHONUNBUFFERED=1 "$@"
295*cfb92d14SAndroid Build Coastguard Worker    exit 0
296*cfb92d14SAndroid Build Coastguard Worker}
297*cfb92d14SAndroid Build Coastguard Worker
298*cfb92d14SAndroid Build Coastguard Workerdo_cert_suite()
299*cfb92d14SAndroid Build Coastguard Worker{
300*cfb92d14SAndroid Build Coastguard Worker    export top_builddir="${OT_BUILDDIR}/openthread-simulation-${THREAD_VERSION}"
301*cfb92d14SAndroid Build Coastguard Worker    export top_srcdir="${OT_SRCDIR}"
302*cfb92d14SAndroid Build Coastguard Worker
303*cfb92d14SAndroid Build Coastguard Worker    if [[ ${THREAD_VERSION} != "1.1" ]]; then
304*cfb92d14SAndroid Build Coastguard Worker        export top_builddir_1_3_bbr="${OT_BUILDDIR}/openthread-simulation-1.3-bbr"
305*cfb92d14SAndroid Build Coastguard Worker        if [[ ${INTER_OP} == "1" ]]; then
306*cfb92d14SAndroid Build Coastguard Worker            export top_builddir_1_1="${OT_BUILDDIR}/openthread-simulation-1.1"
307*cfb92d14SAndroid Build Coastguard Worker        fi
308*cfb92d14SAndroid Build Coastguard Worker    fi
309*cfb92d14SAndroid Build Coastguard Worker
310*cfb92d14SAndroid Build Coastguard Worker    export PYTHONPATH=tests/scripts/thread-cert
311*cfb92d14SAndroid Build Coastguard Worker    export VIRTUAL_TIME
312*cfb92d14SAndroid Build Coastguard Worker
313*cfb92d14SAndroid Build Coastguard Worker    sudo modprobe ip6table_filter
314*cfb92d14SAndroid Build Coastguard Worker
315*cfb92d14SAndroid Build Coastguard Worker    mkdir -p ot_testing
316*cfb92d14SAndroid Build Coastguard Worker    ./tests/scripts/thread-cert/run_cert_suite.py --run-directory ot_testing --multiply "${MULTIPLY:-1}" "$@"
317*cfb92d14SAndroid Build Coastguard Worker    exit 0
318*cfb92d14SAndroid Build Coastguard Worker}
319*cfb92d14SAndroid Build Coastguard Worker
320*cfb92d14SAndroid Build Coastguard Workerdo_get_thread_wireshark()
321*cfb92d14SAndroid Build Coastguard Worker{
322*cfb92d14SAndroid Build Coastguard Worker    echo "Downloading thread-wireshark from https://github.com/openthread/wireshark/releases ..."
323*cfb92d14SAndroid Build Coastguard Worker    local download_url=https://github.com/openthread/wireshark/releases/download/ot-pktverify-20200727/thread-wireshark.tar.gz
324*cfb92d14SAndroid Build Coastguard Worker    local save_file=/tmp/thread-wireshark.tar.gz
325*cfb92d14SAndroid Build Coastguard Worker
326*cfb92d14SAndroid Build Coastguard Worker    rm -rf /tmp/thread-wireshark || true
327*cfb92d14SAndroid Build Coastguard Worker    rm -rf "${save_file}" || true
328*cfb92d14SAndroid Build Coastguard Worker    curl -L "${download_url}" -o "${save_file}"
329*cfb92d14SAndroid Build Coastguard Worker    tar -C /tmp -xvzf "${save_file}"
330*cfb92d14SAndroid Build Coastguard Worker
331*cfb92d14SAndroid Build Coastguard Worker    LD_LIBRARY_PATH=/tmp/thread-wireshark /tmp/thread-wireshark/tshark -v
332*cfb92d14SAndroid Build Coastguard Worker    LD_LIBRARY_PATH=/tmp/thread-wireshark /tmp/thread-wireshark/dumpcap -v
333*cfb92d14SAndroid Build Coastguard Worker    rm -rf "${save_file}"
334*cfb92d14SAndroid Build Coastguard Worker}
335*cfb92d14SAndroid Build Coastguard Worker
336*cfb92d14SAndroid Build Coastguard Workerdo_build_otbr_docker()
337*cfb92d14SAndroid Build Coastguard Worker{
338*cfb92d14SAndroid Build Coastguard Worker    echo "Building OTBR Docker ..."
339*cfb92d14SAndroid Build Coastguard Worker    local otdir
340*cfb92d14SAndroid Build Coastguard Worker    local otbrdir
341*cfb92d14SAndroid Build Coastguard Worker    local otbr_options=(
342*cfb92d14SAndroid Build Coastguard Worker        "-DOT_ANYCAST_LOCATOR=ON"
343*cfb92d14SAndroid Build Coastguard Worker        "-DOT_COVERAGE=ON"
344*cfb92d14SAndroid Build Coastguard Worker        "-DOT_DNS_CLIENT=ON"
345*cfb92d14SAndroid Build Coastguard Worker        "-DOT_DUA=ON"
346*cfb92d14SAndroid Build Coastguard Worker        "-DOT_MLR=ON"
347*cfb92d14SAndroid Build Coastguard Worker        "-DOT_NETDATA_PUBLISHER=ON"
348*cfb92d14SAndroid Build Coastguard Worker        "-DOT_SLAAC=ON"
349*cfb92d14SAndroid Build Coastguard Worker        "-DOT_SRP_CLIENT=ON"
350*cfb92d14SAndroid Build Coastguard Worker        "-DOT_FULL_LOGS=ON"
351*cfb92d14SAndroid Build Coastguard Worker        "-DOT_UPTIME=ON"
352*cfb92d14SAndroid Build Coastguard Worker        "-DOTBR_DNS_UPSTREAM_QUERY=ON"
353*cfb92d14SAndroid Build Coastguard Worker        "-DOTBR_DUA_ROUTING=ON"
354*cfb92d14SAndroid Build Coastguard Worker    )
355*cfb92d14SAndroid Build Coastguard Worker    local args=(
356*cfb92d14SAndroid Build Coastguard Worker        "BORDER_ROUTING=${BORDER_ROUTING}"
357*cfb92d14SAndroid Build Coastguard Worker        "INFRA_IF_NAME=eth0"
358*cfb92d14SAndroid Build Coastguard Worker        "BACKBONE_ROUTER=1"
359*cfb92d14SAndroid Build Coastguard Worker        "REFERENCE_DEVICE=1"
360*cfb92d14SAndroid Build Coastguard Worker        "OT_BACKBONE_CI=1"
361*cfb92d14SAndroid Build Coastguard Worker        "NAT64=${NAT64}"
362*cfb92d14SAndroid Build Coastguard Worker        "NAT64_SERVICE=${NAT64_SERVICE}"
363*cfb92d14SAndroid Build Coastguard Worker        "DNS64=${NAT64}"
364*cfb92d14SAndroid Build Coastguard Worker        "REST_API=0"
365*cfb92d14SAndroid Build Coastguard Worker        "WEB_GUI=0"
366*cfb92d14SAndroid Build Coastguard Worker        "MDNS=${OTBR_MDNS:-mDNSResponder}"
367*cfb92d14SAndroid Build Coastguard Worker        "FIREWALL=${FIREWALL:-1}"
368*cfb92d14SAndroid Build Coastguard Worker    )
369*cfb92d14SAndroid Build Coastguard Worker
370*cfb92d14SAndroid Build Coastguard Worker    if [[ ${NAT64} != 1 ]]; then
371*cfb92d14SAndroid Build Coastguard Worker        # We are testing upstream DNS forwarding in the NAT64 tests, and OPENTHREAD_CONFIG_DNSSD_SERVER_BIND_UNSPECIFIED_NETIF will block OpenThread's DNSSD server since we already have bind9 running.
372*cfb92d14SAndroid Build Coastguard Worker        otbr_options+=("-DCMAKE_CXX_FLAGS='-DOPENTHREAD_CONFIG_DNSSD_SERVER_BIND_UNSPECIFIED_NETIF=1'")
373*cfb92d14SAndroid Build Coastguard Worker    fi
374*cfb92d14SAndroid Build Coastguard Worker
375*cfb92d14SAndroid Build Coastguard Worker    if [[ ${TREL} == 1 ]]; then
376*cfb92d14SAndroid Build Coastguard Worker        otbr_options+=("-DOTBR_TREL=ON")
377*cfb92d14SAndroid Build Coastguard Worker    else
378*cfb92d14SAndroid Build Coastguard Worker        otbr_options+=("-DOTBR_TREL=OFF")
379*cfb92d14SAndroid Build Coastguard Worker    fi
380*cfb92d14SAndroid Build Coastguard Worker
381*cfb92d14SAndroid Build Coastguard Worker    local otbr_docker_image=${OTBR_DOCKER_IMAGE:-otbr-ot12-backbone-ci}
382*cfb92d14SAndroid Build Coastguard Worker    local docker_build_args=()
383*cfb92d14SAndroid Build Coastguard Worker
384*cfb92d14SAndroid Build Coastguard Worker    for arg in "${args[@]}"; do
385*cfb92d14SAndroid Build Coastguard Worker        docker_build_args+=("--build-arg" "$arg")
386*cfb92d14SAndroid Build Coastguard Worker    done
387*cfb92d14SAndroid Build Coastguard Worker
388*cfb92d14SAndroid Build Coastguard Worker    otbrdir=$(mktemp -d -t otbr_XXXXXX)
389*cfb92d14SAndroid Build Coastguard Worker    otdir=$(pwd)
390*cfb92d14SAndroid Build Coastguard Worker
391*cfb92d14SAndroid Build Coastguard Worker    (
392*cfb92d14SAndroid Build Coastguard Worker        if [[ -z ${LOCAL_OTBR_DIR} ]]; then
393*cfb92d14SAndroid Build Coastguard Worker            ./script/git-tool clone https://github.com/openthread/ot-br-posix.git --depth 1 "${otbrdir}"
394*cfb92d14SAndroid Build Coastguard Worker        else
395*cfb92d14SAndroid Build Coastguard Worker            rsync -r \
396*cfb92d14SAndroid Build Coastguard Worker                --exclude=third_party/openthread/repo \
397*cfb92d14SAndroid Build Coastguard Worker                --exclude=.git \
398*cfb92d14SAndroid Build Coastguard Worker                --exclude=build \
399*cfb92d14SAndroid Build Coastguard Worker                "${LOCAL_OTBR_DIR}/." \
400*cfb92d14SAndroid Build Coastguard Worker                "${otbrdir}"
401*cfb92d14SAndroid Build Coastguard Worker        fi
402*cfb92d14SAndroid Build Coastguard Worker
403*cfb92d14SAndroid Build Coastguard Worker        cd "${otbrdir}"
404*cfb92d14SAndroid Build Coastguard Worker        rm -rf third_party/openthread/repo
405*cfb92d14SAndroid Build Coastguard Worker        rsync -r \
406*cfb92d14SAndroid Build Coastguard Worker            --exclude=build \
407*cfb92d14SAndroid Build Coastguard Worker            --exclude=ot_testing \
408*cfb92d14SAndroid Build Coastguard Worker            --exclude=__pycache__ \
409*cfb92d14SAndroid Build Coastguard Worker            "${otdir}/." \
410*cfb92d14SAndroid Build Coastguard Worker            third_party/openthread/repo
411*cfb92d14SAndroid Build Coastguard Worker        rm -rf .git
412*cfb92d14SAndroid Build Coastguard Worker
413*cfb92d14SAndroid Build Coastguard Worker        docker build -t "${otbr_docker_image}" -f etc/docker/Dockerfile . \
414*cfb92d14SAndroid Build Coastguard Worker            "${docker_build_args[@]}" \
415*cfb92d14SAndroid Build Coastguard Worker            --build-arg OTBR_OPTIONS="${otbr_options[*]}"
416*cfb92d14SAndroid Build Coastguard Worker    )
417*cfb92d14SAndroid Build Coastguard Worker
418*cfb92d14SAndroid Build Coastguard Worker    rm -rf "${otbrdir}"
419*cfb92d14SAndroid Build Coastguard Worker}
420*cfb92d14SAndroid Build Coastguard Worker
421*cfb92d14SAndroid Build Coastguard Workerdo_pktverify()
422*cfb92d14SAndroid Build Coastguard Worker{
423*cfb92d14SAndroid Build Coastguard Worker    ./tests/scripts/thread-cert/pktverify/verify.py "$1"
424*cfb92d14SAndroid Build Coastguard Worker}
425*cfb92d14SAndroid Build Coastguard Worker
426*cfb92d14SAndroid Build Coastguard Workerot_exec_expect_script()
427*cfb92d14SAndroid Build Coastguard Worker{
428*cfb92d14SAndroid Build Coastguard Worker    local log_file="tmp/log_expect"
429*cfb92d14SAndroid Build Coastguard Worker
430*cfb92d14SAndroid Build Coastguard Worker    for script in "$@"; do
431*cfb92d14SAndroid Build Coastguard Worker        echo -e "\n${OT_COLOR_PASS}EXEC${OT_COLOR_NONE} ${script}"
432*cfb92d14SAndroid Build Coastguard Worker        sudo killall ot-rcp || true
433*cfb92d14SAndroid Build Coastguard Worker        sudo killall ot-cli || true
434*cfb92d14SAndroid Build Coastguard Worker        sudo killall ot-cli-ftd || true
435*cfb92d14SAndroid Build Coastguard Worker        sudo killall ot-cli-mtd || true
436*cfb92d14SAndroid Build Coastguard Worker        sudo rm -rf tmp
437*cfb92d14SAndroid Build Coastguard Worker        mkdir tmp
438*cfb92d14SAndroid Build Coastguard Worker        {
439*cfb92d14SAndroid Build Coastguard Worker            if [[ ${OT_NATIVE_IP} == 1 ]]; then
440*cfb92d14SAndroid Build Coastguard Worker                sudo -E expect -df "${script}" 2>"${log_file}"
441*cfb92d14SAndroid Build Coastguard Worker            else
442*cfb92d14SAndroid Build Coastguard Worker                expect -df "${script}" 2>"${log_file}"
443*cfb92d14SAndroid Build Coastguard Worker            fi
444*cfb92d14SAndroid Build Coastguard Worker        } || {
445*cfb92d14SAndroid Build Coastguard Worker            local EXIT_CODE=$?
446*cfb92d14SAndroid Build Coastguard Worker
447*cfb92d14SAndroid Build Coastguard Worker            # The exit status 77 for skipping is inherited from automake's test driver for script-based testsuites
448*cfb92d14SAndroid Build Coastguard Worker            if [[ ${EXIT_CODE} == 77 ]]; then
449*cfb92d14SAndroid Build Coastguard Worker                echo -e "\n${OT_COLOR_SKIP}SKIP${OT_COLOR_NONE} ${script}"
450*cfb92d14SAndroid Build Coastguard Worker                return 0
451*cfb92d14SAndroid Build Coastguard Worker            else
452*cfb92d14SAndroid Build Coastguard Worker                echo -e "\n${OT_COLOR_FAIL}FAIL${OT_COLOR_NONE} ${script}"
453*cfb92d14SAndroid Build Coastguard Worker                cat "${log_file}" >&2
454*cfb92d14SAndroid Build Coastguard Worker                return "${EXIT_CODE}"
455*cfb92d14SAndroid Build Coastguard Worker            fi
456*cfb92d14SAndroid Build Coastguard Worker        }
457*cfb92d14SAndroid Build Coastguard Worker        echo -e "\n${OT_COLOR_PASS}PASS${OT_COLOR_NONE} ${script}"
458*cfb92d14SAndroid Build Coastguard Worker        if [[ ${VERBOSE} == 1 ]]; then
459*cfb92d14SAndroid Build Coastguard Worker            cat "${log_file}" >&2
460*cfb92d14SAndroid Build Coastguard Worker        fi
461*cfb92d14SAndroid Build Coastguard Worker    done
462*cfb92d14SAndroid Build Coastguard Worker}
463*cfb92d14SAndroid Build Coastguard Worker
464*cfb92d14SAndroid Build Coastguard Workerdo_expect()
465*cfb92d14SAndroid Build Coastguard Worker{
466*cfb92d14SAndroid Build Coastguard Worker    local test_patterns
467*cfb92d14SAndroid Build Coastguard Worker
468*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_NODE_TYPE} == rcp* ]]; then
469*cfb92d14SAndroid Build Coastguard Worker        if [[ ${OT_NATIVE_IP} == 1 ]]; then
470*cfb92d14SAndroid Build Coastguard Worker            test_patterns=(-name 'tun-*.exp')
471*cfb92d14SAndroid Build Coastguard Worker        else
472*cfb92d14SAndroid Build Coastguard Worker            test_patterns=(-name 'posix-*.exp' -o -name 'cli-*.exp')
473*cfb92d14SAndroid Build Coastguard Worker            if [[ ${THREAD_VERSION} != "1.1" ]]; then
474*cfb92d14SAndroid Build Coastguard Worker                test_patterns+=(-o -name 'v1_2-*.exp')
475*cfb92d14SAndroid Build Coastguard Worker            fi
476*cfb92d14SAndroid Build Coastguard Worker        fi
477*cfb92d14SAndroid Build Coastguard Worker    else
478*cfb92d14SAndroid Build Coastguard Worker        test_patterns=(-name 'cli-*.exp' -o -name 'simulation-*.exp' -o -name 'cli_non_rcp-*.exp')
479*cfb92d14SAndroid Build Coastguard Worker    fi
480*cfb92d14SAndroid Build Coastguard Worker
481*cfb92d14SAndroid Build Coastguard Worker    if [[ $# != 0 ]]; then
482*cfb92d14SAndroid Build Coastguard Worker        ot_exec_expect_script "$@"
483*cfb92d14SAndroid Build Coastguard Worker    else
484*cfb92d14SAndroid Build Coastguard Worker        export OT_COLOR_PASS OT_COLOR_FAIL OT_COLOR_SKIP OT_COLOR_NONE OT_NATIVE_IP VERBOSE
485*cfb92d14SAndroid Build Coastguard Worker        export -f ot_exec_expect_script
486*cfb92d14SAndroid Build Coastguard Worker
487*cfb92d14SAndroid Build Coastguard Worker        find tests/scripts/expect -type f -perm "$([[ $OSTYPE == darwin* ]] && echo '+' || echo '/')"111 \( "${test_patterns[@]}" \) -exec bash -c 'set -euo pipefail;ot_exec_expect_script "$@"' _ {} +
488*cfb92d14SAndroid Build Coastguard Worker    fi
489*cfb92d14SAndroid Build Coastguard Worker
490*cfb92d14SAndroid Build Coastguard Worker    exit 0
491*cfb92d14SAndroid Build Coastguard Worker}
492*cfb92d14SAndroid Build Coastguard Worker
493*cfb92d14SAndroid Build Coastguard Workerprint_usage()
494*cfb92d14SAndroid Build Coastguard Worker{
495*cfb92d14SAndroid Build Coastguard Worker    echo "USAGE: [ENVIRONMENTS] $0 COMMANDS
496*cfb92d14SAndroid Build Coastguard Worker
497*cfb92d14SAndroid Build Coastguard WorkerENVIRONMENTS:
498*cfb92d14SAndroid Build Coastguard Worker    OT_NODE_TYPE    'cli' for CLI simulation, 'ncp' for NCP simulation.
499*cfb92d14SAndroid Build Coastguard Worker                    'rcp' or 'rcp-cli' for CLI on POSIX platform.
500*cfb92d14SAndroid Build Coastguard Worker                    'rcp-ncp' for NCP on POSIX platform.
501*cfb92d14SAndroid Build Coastguard Worker                    The default is 'cli'.
502*cfb92d14SAndroid Build Coastguard Worker    OT_NATIVE_IP    1 to enable platform UDP and netif on POSIX platform. The default is 0.
503*cfb92d14SAndroid Build Coastguard Worker    OT_BUILDDIR     The output directory for cmake build. By default the directory is './build'. For example,
504*cfb92d14SAndroid Build Coastguard Worker                    'OT_BUILDDIR=\${PWD}/my_awesome_build ./script/test clean build'.
505*cfb92d14SAndroid Build Coastguard Worker    VERBOSE         1 to build or test verbosely. The default is 0.
506*cfb92d14SAndroid Build Coastguard Worker    VIRTUAL_TIME    1 for virtual time, otherwise real time. The default value is 0 when running expect tests,
507*cfb92d14SAndroid Build Coastguard Worker                    otherwise default value is 1.
508*cfb92d14SAndroid Build Coastguard Worker    THREAD_VERSION  1.1 for Thread 1.1 stack, 1.3 for Thread 1.3 stack. The default is 1.3.
509*cfb92d14SAndroid Build Coastguard Worker    INTER_OP        1 to build 1.1 together. Only works when THREAD_VERSION is 1.3. The default is 0.
510*cfb92d14SAndroid Build Coastguard Worker    INTER_OP_BBR    1 to build bbr version together. Only works when THREAD_VERSION is 1.3. The default is 1.
511*cfb92d14SAndroid Build Coastguard Worker
512*cfb92d14SAndroid Build Coastguard WorkerCOMMANDS:
513*cfb92d14SAndroid Build Coastguard Worker    clean           Clean built files to prepare for new build.
514*cfb92d14SAndroid Build Coastguard Worker    build           Build project for running tests. This can be used to rebuild the project for changes.
515*cfb92d14SAndroid Build Coastguard Worker    cert            Run a single thread-cert test. ENVIRONMENTS should be the same as those given to build or update.
516*cfb92d14SAndroid Build Coastguard Worker    cert_suite      Run a batch of thread-cert tests and summarize the test results. Only echo logs for failing tests.
517*cfb92d14SAndroid Build Coastguard Worker    unit            Run all the unit tests. This should be called after simulation is built.
518*cfb92d14SAndroid Build Coastguard Worker    expect          Run expect tests.
519*cfb92d14SAndroid Build Coastguard Worker    help            Print this help.
520*cfb92d14SAndroid Build Coastguard Worker
521*cfb92d14SAndroid Build Coastguard WorkerEXAMPLES:
522*cfb92d14SAndroid Build Coastguard Worker    # Test CLI with default settings
523*cfb92d14SAndroid Build Coastguard Worker    $0 clean build cert tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py
524*cfb92d14SAndroid Build Coastguard Worker    $0 cert tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py
525*cfb92d14SAndroid Build Coastguard Worker
526*cfb92d14SAndroid Build Coastguard Worker    # Test NCP with default settings
527*cfb92d14SAndroid Build Coastguard Worker    $0 clean build cert tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py
528*cfb92d14SAndroid Build Coastguard Worker    $0 cert tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py
529*cfb92d14SAndroid Build Coastguard Worker
530*cfb92d14SAndroid Build Coastguard Worker    # Test CLI with radio only
531*cfb92d14SAndroid Build Coastguard Worker    $0 clean build cert tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py
532*cfb92d14SAndroid Build Coastguard Worker    $0 cert tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py
533*cfb92d14SAndroid Build Coastguard Worker
534*cfb92d14SAndroid Build Coastguard Worker    # Test CLI with real time
535*cfb92d14SAndroid Build Coastguard Worker    VIRTUAL_TIME=0 $0 clean build cert tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py
536*cfb92d14SAndroid Build Coastguard Worker    VIRTUAL_TIME=0 $0 cert tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py
537*cfb92d14SAndroid Build Coastguard Worker
538*cfb92d14SAndroid Build Coastguard Worker    # Test Thread 1.1 CLI with real time
539*cfb92d14SAndroid Build Coastguard Worker    THREAD_VERSION=1.1 VIRTUAL_TIME=0 $0 clean build cert tests/scripts/thread-cert/Cert_5_1_01_RouterAttach.py
540*cfb92d14SAndroid Build Coastguard Worker    THREAD_VERSION=1.1 VIRTUAL_TIME=0 $0 cert tests/scripts/thread-cert/Cert_5_1_02_ChildAddressTimeout.py
541*cfb92d14SAndroid Build Coastguard Worker
542*cfb92d14SAndroid Build Coastguard Worker    # Test Thread 1.3 with real time, use 'INTER_OP=1' when the case needs both versions.
543*cfb92d14SAndroid Build Coastguard Worker    VIRTUAL_TIME=0 $0 clean build cert tests/scripts/thread-cert/v1_2_test_enhanced_keep_alive.py
544*cfb92d14SAndroid Build Coastguard Worker    INTER_OP=1 VIRTUAL_TIME=0 $0 clean build cert tests/scripts/thread-cert/v1_2_router_5_1_1.py
545*cfb92d14SAndroid Build Coastguard Worker    INTER_OP=1 VIRTUAL_TIME=0 $0 clean build cert_suite tests/scripts/thread-cert/v1_2_*
546*cfb92d14SAndroid Build Coastguard Worker
547*cfb92d14SAndroid Build Coastguard Worker    # Run a single expect test
548*cfb92d14SAndroid Build Coastguard Worker    $0 clean build expect tests/scripts/expect/cli-log-level.exp
549*cfb92d14SAndroid Build Coastguard Worker
550*cfb92d14SAndroid Build Coastguard Worker    # Run all expect tests
551*cfb92d14SAndroid Build Coastguard Worker    $0 clean build expect
552*cfb92d14SAndroid Build Coastguard Worker    "
553*cfb92d14SAndroid Build Coastguard Worker
554*cfb92d14SAndroid Build Coastguard Worker    exit "$1"
555*cfb92d14SAndroid Build Coastguard Worker}
556*cfb92d14SAndroid Build Coastguard Worker
557*cfb92d14SAndroid Build Coastguard Workerdo_prepare_coredump_upload()
558*cfb92d14SAndroid Build Coastguard Worker{
559*cfb92d14SAndroid Build Coastguard Worker    echo "$OT_COREDUMP_DIR/corefile-%e-%p-%t" | sudo tee /proc/sys/kernel/core_pattern
560*cfb92d14SAndroid Build Coastguard Worker    rm -rf "$OT_COREDUMP_DIR"
561*cfb92d14SAndroid Build Coastguard Worker    mkdir -p "$OT_COREDUMP_DIR"
562*cfb92d14SAndroid Build Coastguard Worker}
563*cfb92d14SAndroid Build Coastguard Worker
564*cfb92d14SAndroid Build Coastguard Workerdo_copy_so_lib()
565*cfb92d14SAndroid Build Coastguard Worker{
566*cfb92d14SAndroid Build Coastguard Worker    mkdir -p "$OT_COREDUMP_DIR/so-lib"
567*cfb92d14SAndroid Build Coastguard Worker    cp /lib/x86_64-linux-gnu/libgcc_s.so.1 "$OT_COREDUMP_DIR/so-lib"
568*cfb92d14SAndroid Build Coastguard Worker    cp /lib/x86_64-linux-gnu/libc.so.6 "$OT_COREDUMP_DIR/so-lib"
569*cfb92d14SAndroid Build Coastguard Worker    cp /lib64/ld-linux-x86-64.so.2 "$OT_COREDUMP_DIR/so-lib"
570*cfb92d14SAndroid Build Coastguard Worker}
571*cfb92d14SAndroid Build Coastguard Worker
572*cfb92d14SAndroid Build Coastguard Workerdo_check_crash()
573*cfb92d14SAndroid Build Coastguard Worker{
574*cfb92d14SAndroid Build Coastguard Worker    shopt -s nullglob
575*cfb92d14SAndroid Build Coastguard Worker
576*cfb92d14SAndroid Build Coastguard Worker    # Scan core dumps and collect binaries which crashed
577*cfb92d14SAndroid Build Coastguard Worker    declare -A bin_list=([dummy]='')
578*cfb92d14SAndroid Build Coastguard Worker    for f in "$OT_COREDUMP_DIR"/core*; do
579*cfb92d14SAndroid Build Coastguard Worker        bin=$(file "$f" | grep -E -o "execfn: '(.*')," | sed -r "s/execfn: '(.*)',/\1/")
580*cfb92d14SAndroid Build Coastguard Worker        bin_list[$bin]=''
581*cfb92d14SAndroid Build Coastguard Worker    done
582*cfb92d14SAndroid Build Coastguard Worker
583*cfb92d14SAndroid Build Coastguard Worker    for key in "${!bin_list[@]}"; do
584*cfb92d14SAndroid Build Coastguard Worker        if [ "$key" != "dummy" ]; then
585*cfb92d14SAndroid Build Coastguard Worker            # Add postfix for binaries to avoid conflicts caused by different Thread version
586*cfb92d14SAndroid Build Coastguard Worker            postfix=""
587*cfb92d14SAndroid Build Coastguard Worker            if [[ $key =~ openthread-(simulation|posix)-([0-9]\.[0-9]) ]]; then
588*cfb92d14SAndroid Build Coastguard Worker                postfix="-$(echo "$key" | sed -r "s/.*openthread-(simulation|posix)-([0-9]\.[0-9]).*/\2/")"
589*cfb92d14SAndroid Build Coastguard Worker            fi
590*cfb92d14SAndroid Build Coastguard Worker            bin_name=$(basename "$key")
591*cfb92d14SAndroid Build Coastguard Worker            cp "$key" "$OT_COREDUMP_DIR"/"$bin_name""$postfix"
592*cfb92d14SAndroid Build Coastguard Worker        fi
593*cfb92d14SAndroid Build Coastguard Worker    done
594*cfb92d14SAndroid Build Coastguard Worker
595*cfb92d14SAndroid Build Coastguard Worker    # echo 1 and copy so libs if crash found, echo 0 otherwise
596*cfb92d14SAndroid Build Coastguard Worker    [[ ${#bin_list[@]} -gt 1 ]] && (
597*cfb92d14SAndroid Build Coastguard Worker        echo 1
598*cfb92d14SAndroid Build Coastguard Worker        do_copy_so_lib
599*cfb92d14SAndroid Build Coastguard Worker    ) || echo 0
600*cfb92d14SAndroid Build Coastguard Worker}
601*cfb92d14SAndroid Build Coastguard Worker
602*cfb92d14SAndroid Build Coastguard Workerdo_generate_coverage()
603*cfb92d14SAndroid Build Coastguard Worker{
604*cfb92d14SAndroid Build Coastguard Worker    mkdir -p tmp/
605*cfb92d14SAndroid Build Coastguard Worker    sudo chmod 777 tmp/
606*cfb92d14SAndroid Build Coastguard Worker    rm -f tmp/coverage.lcov
607*cfb92d14SAndroid Build Coastguard Worker    if [[ $1 == "llvm" ]]; then
608*cfb92d14SAndroid Build Coastguard Worker        local llvm_gcov
609*cfb92d14SAndroid Build Coastguard Worker        llvm_gcov="$(mktemp -d)/llvm-gcov"
610*cfb92d14SAndroid Build Coastguard Worker        echo '#!/bin/bash' >>"$llvm_gcov"
611*cfb92d14SAndroid Build Coastguard Worker        echo 'exec llvm-cov gcov "$@"' >>"$llvm_gcov"
612*cfb92d14SAndroid Build Coastguard Worker        chmod +x "$llvm_gcov"
613*cfb92d14SAndroid Build Coastguard Worker        lcov --gcov-tool "$llvm_gcov" --directory . --capture --output-file tmp/coverage.info
614*cfb92d14SAndroid Build Coastguard Worker    else
615*cfb92d14SAndroid Build Coastguard Worker        ./script/gcda-tool collect
616*cfb92d14SAndroid Build Coastguard Worker        ./script/gcda-tool install
617*cfb92d14SAndroid Build Coastguard Worker
618*cfb92d14SAndroid Build Coastguard Worker        lcov --directory . --capture --output-file tmp/coverage.info
619*cfb92d14SAndroid Build Coastguard Worker    fi
620*cfb92d14SAndroid Build Coastguard Worker    lcov --list tmp/coverage.info
621*cfb92d14SAndroid Build Coastguard Worker    lcov --extract tmp/coverage.info "$PWD/src/core/common/message.cpp" | c++filt
622*cfb92d14SAndroid Build Coastguard Worker}
623*cfb92d14SAndroid Build Coastguard Worker
624*cfb92d14SAndroid Build Coastguard Workerdo_combine_coverage()
625*cfb92d14SAndroid Build Coastguard Worker{
626*cfb92d14SAndroid Build Coastguard Worker    ls -R coverage/
627*cfb92d14SAndroid Build Coastguard Worker
628*cfb92d14SAndroid Build Coastguard Worker    readarray -d '' files < <(find coverage/ -type f -name 'coverage*.info' -print0)
629*cfb92d14SAndroid Build Coastguard Worker
630*cfb92d14SAndroid Build Coastguard Worker    local args=()
631*cfb92d14SAndroid Build Coastguard Worker    for i in "${files[@]}"; do
632*cfb92d14SAndroid Build Coastguard Worker        args+=('-a')
633*cfb92d14SAndroid Build Coastguard Worker        args+=("$i")
634*cfb92d14SAndroid Build Coastguard Worker    done
635*cfb92d14SAndroid Build Coastguard Worker    lcov "${args[@]}" -o final.info
636*cfb92d14SAndroid Build Coastguard Worker}
637*cfb92d14SAndroid Build Coastguard Worker
638*cfb92d14SAndroid Build Coastguard Workerenvsetup()
639*cfb92d14SAndroid Build Coastguard Worker{
640*cfb92d14SAndroid Build Coastguard Worker    export THREAD_VERSION
641*cfb92d14SAndroid Build Coastguard Worker
642*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_NODE_TYPE} == rcp* ]]; then
643*cfb92d14SAndroid Build Coastguard Worker        export RADIO_DEVICE="${OT_BUILDDIR}/openthread-simulation-${THREAD_VERSION}/examples/apps/ncp/ot-rcp"
644*cfb92d14SAndroid Build Coastguard Worker        export OT_CLI_PATH="${OT_BUILDDIR}/openthread-posix-${THREAD_VERSION}/src/posix/ot-cli"
645*cfb92d14SAndroid Build Coastguard Worker
646*cfb92d14SAndroid Build Coastguard Worker        if [[ ${THREAD_VERSION} != "1.1" ]]; then
647*cfb92d14SAndroid Build Coastguard Worker            export RADIO_DEVICE_1_1="${OT_BUILDDIR}/openthread-simulation-1.1/examples/apps/ncp/ot-rcp"
648*cfb92d14SAndroid Build Coastguard Worker            export OT_CLI_PATH_1_1="${OT_BUILDDIR}/openthread-posix-1.1/src/posix/ot-cli"
649*cfb92d14SAndroid Build Coastguard Worker            export OT_CLI_PATH_BBR="${OT_BUILDDIR}/openthread-posix-1.3-bbr/src/posix/ot-cli"
650*cfb92d14SAndroid Build Coastguard Worker        fi
651*cfb92d14SAndroid Build Coastguard Worker    fi
652*cfb92d14SAndroid Build Coastguard Worker
653*cfb92d14SAndroid Build Coastguard Worker    export OT_SIMULATION_APPS="${OT_BUILDDIR}/openthread-simulation-${THREAD_VERSION}/examples/apps"
654*cfb92d14SAndroid Build Coastguard Worker    export OT_POSIX_APPS="${OT_BUILDDIR}/openthread-posix-${THREAD_VERSION}/src/posix"
655*cfb92d14SAndroid Build Coastguard Worker
656*cfb92d14SAndroid Build Coastguard Worker    if [[ ! ${VIRTUAL_TIME+x} ]]; then
657*cfb92d14SAndroid Build Coastguard Worker        # All expect tests only works in real time mode.
658*cfb92d14SAndroid Build Coastguard Worker        VIRTUAL_TIME=1
659*cfb92d14SAndroid Build Coastguard Worker        for arg in "$@"; do
660*cfb92d14SAndroid Build Coastguard Worker            if [[ $arg == expect ]]; then
661*cfb92d14SAndroid Build Coastguard Worker                VIRTUAL_TIME=0
662*cfb92d14SAndroid Build Coastguard Worker                break
663*cfb92d14SAndroid Build Coastguard Worker            fi
664*cfb92d14SAndroid Build Coastguard Worker        done
665*cfb92d14SAndroid Build Coastguard Worker    fi
666*cfb92d14SAndroid Build Coastguard Worker
667*cfb92d14SAndroid Build Coastguard Worker    readonly VIRTUAL_TIME
668*cfb92d14SAndroid Build Coastguard Worker    export OT_NODE_TYPE VIRTUAL_TIME
669*cfb92d14SAndroid Build Coastguard Worker
670*cfb92d14SAndroid Build Coastguard Worker    # CMake always works in verbose mode if VERBOSE exists in environments.
671*cfb92d14SAndroid Build Coastguard Worker    if [[ ${VERBOSE} == 1 ]]; then
672*cfb92d14SAndroid Build Coastguard Worker        export VERBOSE
673*cfb92d14SAndroid Build Coastguard Worker    else
674*cfb92d14SAndroid Build Coastguard Worker        export -n VERBOSE
675*cfb92d14SAndroid Build Coastguard Worker    fi
676*cfb92d14SAndroid Build Coastguard Worker
677*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_OPTIONS+x} ]]; then
678*cfb92d14SAndroid Build Coastguard Worker        read -r -a ot_extra_options <<<"${OT_OPTIONS}"
679*cfb92d14SAndroid Build Coastguard Worker    else
680*cfb92d14SAndroid Build Coastguard Worker        ot_extra_options=()
681*cfb92d14SAndroid Build Coastguard Worker    fi
682*cfb92d14SAndroid Build Coastguard Worker}
683*cfb92d14SAndroid Build Coastguard Worker
684*cfb92d14SAndroid Build Coastguard Workermain()
685*cfb92d14SAndroid Build Coastguard Worker{
686*cfb92d14SAndroid Build Coastguard Worker    envsetup "$@"
687*cfb92d14SAndroid Build Coastguard Worker
688*cfb92d14SAndroid Build Coastguard Worker    if [[ -z ${1-} ]]; then
689*cfb92d14SAndroid Build Coastguard Worker        print_usage 1
690*cfb92d14SAndroid Build Coastguard Worker    fi
691*cfb92d14SAndroid Build Coastguard Worker
692*cfb92d14SAndroid Build Coastguard Worker    [[ ${VIRTUAL_TIME} == 1 ]] && echo "Using virtual time" || echo "Using real time"
693*cfb92d14SAndroid Build Coastguard Worker    [[ ${THREAD_VERSION} != "1.1" ]] && echo "Using Thread 1.3 stack" || echo "Using Thread 1.1 stack"
694*cfb92d14SAndroid Build Coastguard Worker
695*cfb92d14SAndroid Build Coastguard Worker    while [[ $# != 0 ]]; do
696*cfb92d14SAndroid Build Coastguard Worker        case "$1" in
697*cfb92d14SAndroid Build Coastguard Worker            clean)
698*cfb92d14SAndroid Build Coastguard Worker                do_clean
699*cfb92d14SAndroid Build Coastguard Worker                ;;
700*cfb92d14SAndroid Build Coastguard Worker            build)
701*cfb92d14SAndroid Build Coastguard Worker                do_build
702*cfb92d14SAndroid Build Coastguard Worker                ;;
703*cfb92d14SAndroid Build Coastguard Worker            cert)
704*cfb92d14SAndroid Build Coastguard Worker                shift
705*cfb92d14SAndroid Build Coastguard Worker                do_cert "$@"
706*cfb92d14SAndroid Build Coastguard Worker                shift $#
707*cfb92d14SAndroid Build Coastguard Worker                ;;
708*cfb92d14SAndroid Build Coastguard Worker            cert_suite)
709*cfb92d14SAndroid Build Coastguard Worker                shift
710*cfb92d14SAndroid Build Coastguard Worker                do_cert_suite "$@"
711*cfb92d14SAndroid Build Coastguard Worker                shift $#
712*cfb92d14SAndroid Build Coastguard Worker                ;;
713*cfb92d14SAndroid Build Coastguard Worker            get_thread_wireshark)
714*cfb92d14SAndroid Build Coastguard Worker                do_get_thread_wireshark
715*cfb92d14SAndroid Build Coastguard Worker                ;;
716*cfb92d14SAndroid Build Coastguard Worker            build_otbr_docker)
717*cfb92d14SAndroid Build Coastguard Worker                do_build_otbr_docker
718*cfb92d14SAndroid Build Coastguard Worker                ;;
719*cfb92d14SAndroid Build Coastguard Worker            pktverify)
720*cfb92d14SAndroid Build Coastguard Worker                shift
721*cfb92d14SAndroid Build Coastguard Worker                do_pktverify "$1"
722*cfb92d14SAndroid Build Coastguard Worker                ;;
723*cfb92d14SAndroid Build Coastguard Worker            unit)
724*cfb92d14SAndroid Build Coastguard Worker                do_unit
725*cfb92d14SAndroid Build Coastguard Worker                ;;
726*cfb92d14SAndroid Build Coastguard Worker            help)
727*cfb92d14SAndroid Build Coastguard Worker                print_usage
728*cfb92d14SAndroid Build Coastguard Worker                ;;
729*cfb92d14SAndroid Build Coastguard Worker            package)
730*cfb92d14SAndroid Build Coastguard Worker                ./script/package "${ot_extra_options[@]}"
731*cfb92d14SAndroid Build Coastguard Worker                ;;
732*cfb92d14SAndroid Build Coastguard Worker            expect)
733*cfb92d14SAndroid Build Coastguard Worker                shift
734*cfb92d14SAndroid Build Coastguard Worker                do_expect "$@"
735*cfb92d14SAndroid Build Coastguard Worker                ;;
736*cfb92d14SAndroid Build Coastguard Worker            prepare_coredump_upload)
737*cfb92d14SAndroid Build Coastguard Worker                do_prepare_coredump_upload
738*cfb92d14SAndroid Build Coastguard Worker                ;;
739*cfb92d14SAndroid Build Coastguard Worker            check_crash)
740*cfb92d14SAndroid Build Coastguard Worker                do_check_crash
741*cfb92d14SAndroid Build Coastguard Worker                ;;
742*cfb92d14SAndroid Build Coastguard Worker            generate_coverage)
743*cfb92d14SAndroid Build Coastguard Worker                shift
744*cfb92d14SAndroid Build Coastguard Worker                do_generate_coverage "$1"
745*cfb92d14SAndroid Build Coastguard Worker                ;;
746*cfb92d14SAndroid Build Coastguard Worker            combine_coverage)
747*cfb92d14SAndroid Build Coastguard Worker                do_combine_coverage
748*cfb92d14SAndroid Build Coastguard Worker                ;;
749*cfb92d14SAndroid Build Coastguard Worker            *)
750*cfb92d14SAndroid Build Coastguard Worker                echo
751*cfb92d14SAndroid Build Coastguard Worker                echo -e "${OT_COLOR_FAIL}Warning:${OT_COLOR_NONE} Ignoring: '$1'"
752*cfb92d14SAndroid Build Coastguard Worker                ;;
753*cfb92d14SAndroid Build Coastguard Worker        esac
754*cfb92d14SAndroid Build Coastguard Worker        shift
755*cfb92d14SAndroid Build Coastguard Worker    done
756*cfb92d14SAndroid Build Coastguard Worker}
757*cfb92d14SAndroid Build Coastguard Worker
758*cfb92d14SAndroid Build Coastguard Workermain "$@"
759