1*4a64e381SAndroid Build Coastguard Worker#!/bin/bash 2*4a64e381SAndroid Build Coastguard Worker# 3*4a64e381SAndroid Build Coastguard Worker# Copyright (c) 2017, The OpenThread Authors. 4*4a64e381SAndroid Build Coastguard Worker# All rights reserved. 5*4a64e381SAndroid Build Coastguard Worker# 6*4a64e381SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 7*4a64e381SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met: 8*4a64e381SAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright 9*4a64e381SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 10*4a64e381SAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright 11*4a64e381SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer in the 12*4a64e381SAndroid Build Coastguard Worker# documentation and/or other materials provided with the distribution. 13*4a64e381SAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the 14*4a64e381SAndroid Build Coastguard Worker# names of its contributors may be used to endorse or promote products 15*4a64e381SAndroid Build Coastguard Worker# derived from this software without specific prior written permission. 16*4a64e381SAndroid Build Coastguard Worker# 17*4a64e381SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18*4a64e381SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*4a64e381SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*4a64e381SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21*4a64e381SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*4a64e381SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*4a64e381SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*4a64e381SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*4a64e381SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*4a64e381SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*4a64e381SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE. 28*4a64e381SAndroid Build Coastguard Worker# 29*4a64e381SAndroid Build Coastguard Worker# Test thread commissioning along with openthread. 30*4a64e381SAndroid Build Coastguard Worker# 31*4a64e381SAndroid Build Coastguard Worker# Usage: 32*4a64e381SAndroid Build Coastguard Worker# ./meshcop # test with latest openthread. 33*4a64e381SAndroid Build Coastguard Worker# NO_CLEAN=1 ./meshcop # test with existing binaries in ${TEST_BASE}. 34*4a64e381SAndroid Build Coastguard Worker# TEST_CASE=mdns_service ./meshcop # test the meshcop mDNS service. 35*4a64e381SAndroid Build Coastguard Workerset -euxo pipefail 36*4a64e381SAndroid Build Coastguard Worker 37*4a64e381SAndroid Build Coastguard Worker# The test case to run. available cases are: 38*4a64e381SAndroid Build Coastguard Worker# - commissioning 39*4a64e381SAndroid Build Coastguard Worker# - mdns_service 40*4a64e381SAndroid Build Coastguard WorkerTEST_CASE="${TEST_CASE:-commissioning}" 41*4a64e381SAndroid Build Coastguard Workerreadonly TEST_CASE 42*4a64e381SAndroid Build Coastguard Worker 43*4a64e381SAndroid Build Coastguard Worker# Get our starting directory and remember it 44*4a64e381SAndroid Build Coastguard WorkerORIGIN_PWD="$(pwd)" 45*4a64e381SAndroid Build Coastguard Workerreadonly ORIGIN_PWD 46*4a64e381SAndroid Build Coastguard Worker 47*4a64e381SAndroid Build Coastguard WorkerSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 48*4a64e381SAndroid Build Coastguard Workerreadonly SCRIPT_DIR 49*4a64e381SAndroid Build Coastguard Worker 50*4a64e381SAndroid Build Coastguard Worker#--------------------------------------- 51*4a64e381SAndroid Build Coastguard Worker# Configurations 52*4a64e381SAndroid Build Coastguard Worker#--------------------------------------- 53*4a64e381SAndroid Build Coastguard WorkerOT_RCP="ot-rcp" 54*4a64e381SAndroid Build Coastguard Workerreadonly OT_RCP 55*4a64e381SAndroid Build Coastguard Worker 56*4a64e381SAndroid Build Coastguard WorkerOT_CLI="${OT_CLI:-ot-cli-ftd}" 57*4a64e381SAndroid Build Coastguard Workerreadonly OT_CLI 58*4a64e381SAndroid Build Coastguard Worker 59*4a64e381SAndroid Build Coastguard WorkerABS_TOP_BUILDDIR="$(cd "${top_builddir:-"${SCRIPT_DIR}"/../../}" && pwd)" 60*4a64e381SAndroid Build Coastguard Workerreadonly ABS_TOP_BUILDDIR 61*4a64e381SAndroid Build Coastguard Worker 62*4a64e381SAndroid Build Coastguard WorkerABS_TOP_SRCDIR="$(cd "${top_srcdir:-"${SCRIPT_DIR}"/../../}" && pwd)" 63*4a64e381SAndroid Build Coastguard Workerreadonly ABS_TOP_SRCDIR 64*4a64e381SAndroid Build Coastguard Worker 65*4a64e381SAndroid Build Coastguard WorkerNO_CLEAN="${NO_CLEAN:-1}" 66*4a64e381SAndroid Build Coastguard Workerreadonly NO_CLEAN 67*4a64e381SAndroid Build Coastguard Worker 68*4a64e381SAndroid Build Coastguard WorkerIGNORE_INSTALLED="${IGNORE_INSTALLED:-0}" 69*4a64e381SAndroid Build Coastguard Workerreadonly IGNORE_INSTALLED 70*4a64e381SAndroid Build Coastguard Worker 71*4a64e381SAndroid Build Coastguard WorkerOTBR_USE_WEB_COMMISSIONER="${USE_WEB_COMMISSIONER:-0}" 72*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_USE_WEB_COMMISSIONER 73*4a64e381SAndroid Build Coastguard Worker 74*4a64e381SAndroid Build Coastguard Worker#---------------------------------------- 75*4a64e381SAndroid Build Coastguard Worker# Test constants 76*4a64e381SAndroid Build Coastguard Worker#---------------------------------------- 77*4a64e381SAndroid Build Coastguard WorkerTEST_BASE=/tmp/test-otbr 78*4a64e381SAndroid Build Coastguard Workerreadonly TEST_BASE 79*4a64e381SAndroid Build Coastguard Worker 80*4a64e381SAndroid Build Coastguard WorkerOTBR_AGENT=otbr-agent 81*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_AGENT 82*4a64e381SAndroid Build Coastguard Worker 83*4a64e381SAndroid Build Coastguard WorkerOTBR_WEB=otbr-web 84*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_WEB 85*4a64e381SAndroid Build Coastguard Worker 86*4a64e381SAndroid Build Coastguard WorkerOT_COMMISSIONER_CLI=commissioner-cli 87*4a64e381SAndroid Build Coastguard Workerreadonly OT_COMMISSIONER_CLI 88*4a64e381SAndroid Build Coastguard Worker 89*4a64e381SAndroid Build Coastguard WorkerSTAGE_DIR="${TEST_BASE}/stage" 90*4a64e381SAndroid Build Coastguard Workerreadonly STAGE_DIR 91*4a64e381SAndroid Build Coastguard Worker 92*4a64e381SAndroid Build Coastguard WorkerBUILD_DIR="${TEST_BASE}/build" 93*4a64e381SAndroid Build Coastguard Workerreadonly BUILD_DIR 94*4a64e381SAndroid Build Coastguard Worker 95*4a64e381SAndroid Build Coastguard WorkerOTBR_PSKC_PATH="${ABS_TOP_BUILDDIR}/tools/pskc" 96*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_PSKC_PATH 97*4a64e381SAndroid Build Coastguard Worker 98*4a64e381SAndroid Build Coastguard WorkerOTBR_AGENT_PATH="${ABS_TOP_BUILDDIR}/src/agent/${OTBR_AGENT}" 99*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_AGENT_PATH 100*4a64e381SAndroid Build Coastguard Worker 101*4a64e381SAndroid Build Coastguard WorkerOTBR_DBUS_CONF="${ABS_TOP_BUILDDIR}/src/agent/otbr-agent.conf" 102*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_DBUS_CONF 103*4a64e381SAndroid Build Coastguard Worker 104*4a64e381SAndroid Build Coastguard WorkerOTBR_WEB_PATH="${ABS_TOP_BUILDDIR}/src/web/${OTBR_WEB}" 105*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_WEB_PATH 106*4a64e381SAndroid Build Coastguard Worker 107*4a64e381SAndroid Build Coastguard WorkerOT_CTL="${ABS_TOP_BUILDDIR}/third_party/openthread/repo/src/posix/ot-ctl" 108*4a64e381SAndroid Build Coastguard Workerreadonly OT_CTL 109*4a64e381SAndroid Build Coastguard Worker 110*4a64e381SAndroid Build Coastguard Worker# The node ids 111*4a64e381SAndroid Build Coastguard WorkerLEADER_NODE_ID=1 112*4a64e381SAndroid Build Coastguard Workerreadonly LEADER_NODE_ID 113*4a64e381SAndroid Build Coastguard Worker 114*4a64e381SAndroid Build Coastguard WorkerJOINER_NODE_ID=2 115*4a64e381SAndroid Build Coastguard Workerreadonly JOINER_NODE_ID 116*4a64e381SAndroid Build Coastguard Worker 117*4a64e381SAndroid Build Coastguard Worker# Web GUI 118*4a64e381SAndroid Build Coastguard WorkerOTBR_WEB_HOST=127.0.0.1 119*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_WEB_HOST 120*4a64e381SAndroid Build Coastguard Worker 121*4a64e381SAndroid Build Coastguard WorkerOTBR_WEB_PORT=8773 122*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_WEB_PORT 123*4a64e381SAndroid Build Coastguard Worker 124*4a64e381SAndroid Build Coastguard WorkerOTBR_WEB_URL="http://${OTBR_WEB_HOST}:${OTBR_WEB_PORT}" 125*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_WEB_URL 126*4a64e381SAndroid Build Coastguard Worker 127*4a64e381SAndroid Build Coastguard Worker# External commissioner 128*4a64e381SAndroid Build Coastguard WorkerOT_COMMISSIONER_PATH=${BUILD_DIR}/ot-commissioner/build/src/app/cli/commissioner-cli 129*4a64e381SAndroid Build Coastguard Workerreadonly OT_COMMISSIONER_PATH 130*4a64e381SAndroid Build Coastguard Worker 131*4a64e381SAndroid Build Coastguard WorkerOT_COMMISSIONER_CONFIG=${BUILD_DIR}/ot-commissioner/src/app/etc/commissioner/non-ccm-config.json 132*4a64e381SAndroid Build Coastguard Workerreadonly OT_COMMISSIONER_CONFIG 133*4a64e381SAndroid Build Coastguard Worker 134*4a64e381SAndroid Build Coastguard Worker# 135*4a64e381SAndroid Build Coastguard Worker# NOTE Joiner pass phrase: 136*4a64e381SAndroid Build Coastguard Worker# Must be at least 6 bytes long 137*4a64e381SAndroid Build Coastguard Worker# And this example has: J ZERO ONE N E R 138*4a64e381SAndroid Build Coastguard Worker# We cannot use letter O and I because Q O I Z are not allowed per spec 139*4a64e381SAndroid Build Coastguard WorkerOT_JOINER_PASSPHRASE=J01NER 140*4a64e381SAndroid Build Coastguard Workerreadonly OT_JOINER_PASSPHRASE 141*4a64e381SAndroid Build Coastguard Worker 142*4a64e381SAndroid Build Coastguard Worker# 18b430 is the nest EUI prefix. 143*4a64e381SAndroid Build Coastguard WorkerOT_JOINER_EUI64="18b430000000000${JOINER_NODE_ID}" 144*4a64e381SAndroid Build Coastguard Workerreadonly OT_JOINER_EUI64 145*4a64e381SAndroid Build Coastguard Worker 146*4a64e381SAndroid Build Coastguard Worker# The border agent, and ncp needs a pass phrase. 147*4a64e381SAndroid Build Coastguard WorkerOT_AGENT_PASSPHRASE=MYPASSPHRASE 148*4a64e381SAndroid Build Coastguard Workerreadonly OT_AGENT_PASSPHRASE 149*4a64e381SAndroid Build Coastguard Worker 150*4a64e381SAndroid Build Coastguard Worker# The network needs a name. 151*4a64e381SAndroid Build Coastguard WorkerOT_NETWORK_NAME=MyTestNetwork 152*4a64e381SAndroid Build Coastguard Workerreadonly OT_NETWORK_NAME 153*4a64e381SAndroid Build Coastguard Worker 154*4a64e381SAndroid Build Coastguard Worker# The TUN device for OpenThread border router. 155*4a64e381SAndroid Build Coastguard WorkerTUN_NAME=wpan0 156*4a64e381SAndroid Build Coastguard Workerreadonly TUN_NAME 157*4a64e381SAndroid Build Coastguard Worker 158*4a64e381SAndroid Build Coastguard Worker# The default meshcop service instance name 159*4a64e381SAndroid Build Coastguard WorkerOT_SERVICE_INSTANCE='OpenThread\(\\032\| \)BorderRouter\(\\032\| \)#[0-9A-F][0-9A-F][0-9A-F][0-9A-F]' 160*4a64e381SAndroid Build Coastguard Workerreadonly OT_SERVICE_INSTANCE 161*4a64e381SAndroid Build Coastguard Worker 162*4a64e381SAndroid Build Coastguard Workerecho "ORIGIN_PWD: ${ORIGIN_PWD}" 163*4a64e381SAndroid Build Coastguard Workerecho "TEST_BASE: ${TEST_BASE}" 164*4a64e381SAndroid Build Coastguard Workerecho "ABS_TOP_SRCDIR=${ABS_TOP_SRCDIR}" 165*4a64e381SAndroid Build Coastguard Workerecho "ABS_TOP_BUILDDIR=${ABS_TOP_BUILDDIR}" 166*4a64e381SAndroid Build Coastguard Worker 167*4a64e381SAndroid Build Coastguard Worker#---------------------------------------- 168*4a64e381SAndroid Build Coastguard Worker# Helper functions 169*4a64e381SAndroid Build Coastguard Worker#---------------------------------------- 170*4a64e381SAndroid Build Coastguard Worker 171*4a64e381SAndroid Build Coastguard Workerdie() 172*4a64e381SAndroid Build Coastguard Worker{ 173*4a64e381SAndroid Build Coastguard Worker exit_message="$*" 174*4a64e381SAndroid Build Coastguard Worker echo " *** ERROR: $*" 175*4a64e381SAndroid Build Coastguard Worker exit 1 176*4a64e381SAndroid Build Coastguard Worker} 177*4a64e381SAndroid Build Coastguard Worker 178*4a64e381SAndroid Build Coastguard Workerexists_or_die() 179*4a64e381SAndroid Build Coastguard Worker{ 180*4a64e381SAndroid Build Coastguard Worker [[ -f $1 ]] || die "Missing file: $1" 181*4a64e381SAndroid Build Coastguard Worker} 182*4a64e381SAndroid Build Coastguard Worker 183*4a64e381SAndroid Build Coastguard Workerexecutable_or_die() 184*4a64e381SAndroid Build Coastguard Worker{ 185*4a64e381SAndroid Build Coastguard Worker [[ -x $1 ]] || die "Missing executable: $1" 186*4a64e381SAndroid Build Coastguard Worker} 187*4a64e381SAndroid Build Coastguard Worker 188*4a64e381SAndroid Build Coastguard Workerrandom_channel() 189*4a64e381SAndroid Build Coastguard Worker{ 190*4a64e381SAndroid Build Coastguard Worker echo $((11 + "${RANDOM}" % 16)) 191*4a64e381SAndroid Build Coastguard Worker} 192*4a64e381SAndroid Build Coastguard Worker 193*4a64e381SAndroid Build Coastguard Workerrandom_panid() 194*4a64e381SAndroid Build Coastguard Worker{ 195*4a64e381SAndroid Build Coastguard Worker printf "0x%04x" "${RANDOM}" 196*4a64e381SAndroid Build Coastguard Worker} 197*4a64e381SAndroid Build Coastguard Worker 198*4a64e381SAndroid Build Coastguard Workerrandom_xpanid() 199*4a64e381SAndroid Build Coastguard Worker{ 200*4a64e381SAndroid Build Coastguard Worker printf "%04x%04x%04x%04x" "${RANDOM}" "${RANDOM}" "${RANDOM}" "${RANDOM}" 201*4a64e381SAndroid Build Coastguard Worker} 202*4a64e381SAndroid Build Coastguard Worker 203*4a64e381SAndroid Build Coastguard Workerrandom_networkkey() 204*4a64e381SAndroid Build Coastguard Worker{ 205*4a64e381SAndroid Build Coastguard Worker printf "%04x%04x%04x%04x%04x%04x%04x%04x" "${RANDOM}" "${RANDOM}" "${RANDOM}" "${RANDOM}" "${RANDOM}" "${RANDOM}" "${RANDOM}" "${RANDOM}" 206*4a64e381SAndroid Build Coastguard Worker} 207*4a64e381SAndroid Build Coastguard Worker 208*4a64e381SAndroid Build Coastguard Workerwrite_syslog() 209*4a64e381SAndroid Build Coastguard Worker{ 210*4a64e381SAndroid Build Coastguard Worker logger -s -p syslog.alert "OPENTHREAD_TEST: $*" 211*4a64e381SAndroid Build Coastguard Worker} 212*4a64e381SAndroid Build Coastguard Worker 213*4a64e381SAndroid Build Coastguard Workeroutput_logs() 214*4a64e381SAndroid Build Coastguard Worker{ 215*4a64e381SAndroid Build Coastguard Worker write_syslog 'All apps should be dead now' 216*4a64e381SAndroid Build Coastguard Worker 217*4a64e381SAndroid Build Coastguard Worker # part 1 218*4a64e381SAndroid Build Coastguard Worker # ------ 219*4a64e381SAndroid Build Coastguard Worker # 220*4a64e381SAndroid Build Coastguard Worker # On travis (the CI server), we can't see what went into the 221*4a64e381SAndroid Build Coastguard Worker # syslog. So this is here so we can see the output. 222*4a64e381SAndroid Build Coastguard Worker # 223*4a64e381SAndroid Build Coastguard Worker # part 2 224*4a64e381SAndroid Build Coastguard Worker # ------ 225*4a64e381SAndroid Build Coastguard Worker # 226*4a64e381SAndroid Build Coastguard Worker # If we run locally, it is sometimes helpful for our victim (you 227*4a64e381SAndroid Build Coastguard Worker # the developer) to have logs split upto various files to help 228*4a64e381SAndroid Build Coastguard Worker # that victim, we'll GREP the log files according. 229*4a64e381SAndroid Build Coastguard Worker # 230*4a64e381SAndroid Build Coastguard Worker # Wait 5 seconds for the "logs to flush" 231*4a64e381SAndroid Build Coastguard Worker sleep 5 232*4a64e381SAndroid Build Coastguard Worker 233*4a64e381SAndroid Build Coastguard Worker cd "${ORIGIN_PWD}" 234*4a64e381SAndroid Build Coastguard Worker echo 'START_LOG: SYSLOG ===================' 235*4a64e381SAndroid Build Coastguard Worker tee complete-syslog.log </var/log/syslog 236*4a64e381SAndroid Build Coastguard Worker echo 'START_LOG: BR-AGENT =================' 237*4a64e381SAndroid Build Coastguard Worker grep "${OTBR_AGENT}" /var/log/syslog | tee otbr-agent.log 238*4a64e381SAndroid Build Coastguard Worker echo 'START_LOG: OT-COMISSIONER =========' 239*4a64e381SAndroid Build Coastguard Worker cat "${OT_COMMISSIONER_LOG}" 240*4a64e381SAndroid Build Coastguard Worker echo 'START_LOG: OT-RCP ===================' 241*4a64e381SAndroid Build Coastguard Worker grep "${OT_RCP}" /var/log/syslog | tee "${OT_RCP}.log" 242*4a64e381SAndroid Build Coastguard Worker echo 'START_LOG: OT-CLI ===================' 243*4a64e381SAndroid Build Coastguard Worker grep "${OT_CLI}" /var/log/syslog | tee "${OT_CLI}.log" 244*4a64e381SAndroid Build Coastguard Worker echo '=====================================' 245*4a64e381SAndroid Build Coastguard Worker echo 'Hint, for each log Search backwards for: "START_LOG: <NAME>"' 246*4a64e381SAndroid Build Coastguard Worker echo '=====================================' 247*4a64e381SAndroid Build Coastguard Worker} 248*4a64e381SAndroid Build Coastguard Worker 249*4a64e381SAndroid Build Coastguard Workerbuild_dependencies() 250*4a64e381SAndroid Build Coastguard Worker{ 251*4a64e381SAndroid Build Coastguard Worker # Clean up old stuff 252*4a64e381SAndroid Build Coastguard Worker if [[ ${NO_CLEAN} != 1 ]]; then 253*4a64e381SAndroid Build Coastguard Worker [[ ! -d ${STAGE_DIR} ]] || rm -rf "${STAGE_DIR}" 254*4a64e381SAndroid Build Coastguard Worker [[ ! -d ${BUILD_DIR} ]] || rm -rf "${BUILD_DIR}" 255*4a64e381SAndroid Build Coastguard Worker fi 256*4a64e381SAndroid Build Coastguard Worker 257*4a64e381SAndroid Build Coastguard Worker [[ -d ${STAGE_DIR} ]] || mkdir -p "${STAGE_DIR}" 258*4a64e381SAndroid Build Coastguard Worker [[ -d ${BUILD_DIR} ]] || mkdir -p "${BUILD_DIR}" 259*4a64e381SAndroid Build Coastguard Worker 260*4a64e381SAndroid Build Coastguard Worker # As above, these steps are broken up 261*4a64e381SAndroid Build Coastguard Worker ot_cli=$(command -v "${OT_CLI}") 262*4a64e381SAndroid Build Coastguard Worker ot_rcp=$(command -v "${OT_RCP}") 263*4a64e381SAndroid Build Coastguard Worker 264*4a64e381SAndroid Build Coastguard Worker if 265*4a64e381SAndroid Build Coastguard Worker [ "${TEST_CASE}" == "commissioning" ] \ 266*4a64e381SAndroid Build Coastguard Worker && [[ ${OTBR_USE_WEB_COMMISSIONER} != 1 ]] 267*4a64e381SAndroid Build Coastguard Worker then 268*4a64e381SAndroid Build Coastguard Worker ot_commissioner_build 269*4a64e381SAndroid Build Coastguard Worker fi 270*4a64e381SAndroid Build Coastguard Worker 271*4a64e381SAndroid Build Coastguard Worker write_syslog "TEST: BUILD COMPLETE" 272*4a64e381SAndroid Build Coastguard Worker} 273*4a64e381SAndroid Build Coastguard Worker 274*4a64e381SAndroid Build Coastguard Workertest_setup() 275*4a64e381SAndroid Build Coastguard Worker{ 276*4a64e381SAndroid Build Coastguard Worker # message for general failures 277*4a64e381SAndroid Build Coastguard Worker exit_message="JOINER FAILED" 278*4a64e381SAndroid Build Coastguard Worker 279*4a64e381SAndroid Build Coastguard Worker executable_or_die "${OTBR_AGENT_PATH}" 280*4a64e381SAndroid Build Coastguard Worker executable_or_die "${OTBR_WEB_PATH}" 281*4a64e381SAndroid Build Coastguard Worker 282*4a64e381SAndroid Build Coastguard Worker # Remove flashes 283*4a64e381SAndroid Build Coastguard Worker sudo rm -vrf "${TEST_BASE}/tmp" 284*4a64e381SAndroid Build Coastguard Worker # OPENTHREAD_POSIX_DAEMON_SOCKET_LOCK 285*4a64e381SAndroid Build Coastguard Worker sudo rm -vf "/tmp/openthread.lock" 286*4a64e381SAndroid Build Coastguard Worker 287*4a64e381SAndroid Build Coastguard Worker build_dependencies 288*4a64e381SAndroid Build Coastguard Worker 289*4a64e381SAndroid Build Coastguard Worker # We will be creating a lot of log information 290*4a64e381SAndroid Build Coastguard Worker # Rotate logs so we have a clean and empty set of logs uncluttered with other stuff 291*4a64e381SAndroid Build Coastguard Worker if [[ -f /etc/logrotate.conf ]]; then 292*4a64e381SAndroid Build Coastguard Worker sudo logrotate -f /etc/logrotate.conf || true 293*4a64e381SAndroid Build Coastguard Worker fi 294*4a64e381SAndroid Build Coastguard Worker 295*4a64e381SAndroid Build Coastguard Worker # From now on - all exits are TRAPPED 296*4a64e381SAndroid Build Coastguard Worker # When they occur, we call the function: output_logs'. 297*4a64e381SAndroid Build Coastguard Worker trap test_teardown EXIT 298*4a64e381SAndroid Build Coastguard Worker} 299*4a64e381SAndroid Build Coastguard Worker 300*4a64e381SAndroid Build Coastguard Workertest_teardown() 301*4a64e381SAndroid Build Coastguard Worker{ 302*4a64e381SAndroid Build Coastguard Worker # Capture the exit code so we can return it below 303*4a64e381SAndroid Build Coastguard Worker EXIT_CODE=$? 304*4a64e381SAndroid Build Coastguard Worker readonly EXIT_CODE 305*4a64e381SAndroid Build Coastguard Worker write_syslog "EXIT ${EXIT_CODE} - output logs" 306*4a64e381SAndroid Build Coastguard Worker 307*4a64e381SAndroid Build Coastguard Worker sudo pkill -f "${OTBR_AGENT}" || true 308*4a64e381SAndroid Build Coastguard Worker sudo pkill -f "${OTBR_WEB}" || true 309*4a64e381SAndroid Build Coastguard Worker sudo pkill -f "${OT_COMMISSIONER_CLI}" || true 310*4a64e381SAndroid Build Coastguard Worker sudo pkill -f "${OT_CLI}" || true 311*4a64e381SAndroid Build Coastguard Worker wait 312*4a64e381SAndroid Build Coastguard Worker 313*4a64e381SAndroid Build Coastguard Worker if [[ ${NO_CLEAN} != 1 ]]; then 314*4a64e381SAndroid Build Coastguard Worker echo 'clearing all' 315*4a64e381SAndroid Build Coastguard Worker sudo rm /etc/dbus-1/system.d/otbr-agent.conf || true 316*4a64e381SAndroid Build Coastguard Worker sudo rm -rf "${STAGE_DIR}" || true 317*4a64e381SAndroid Build Coastguard Worker sudo rm -rf "${BUILD_DIR}" || true 318*4a64e381SAndroid Build Coastguard Worker 319*4a64e381SAndroid Build Coastguard Worker output_logs 320*4a64e381SAndroid Build Coastguard Worker fi 321*4a64e381SAndroid Build Coastguard Worker 322*4a64e381SAndroid Build Coastguard Worker echo "EXIT ${EXIT_CODE}: MESSAGE: ${exit_message}" 323*4a64e381SAndroid Build Coastguard Worker exit ${EXIT_CODE} 324*4a64e381SAndroid Build Coastguard Worker} 325*4a64e381SAndroid Build Coastguard Worker 326*4a64e381SAndroid Build Coastguard Workerba_start() 327*4a64e381SAndroid Build Coastguard Worker{ 328*4a64e381SAndroid Build Coastguard Worker exists_or_die "${OTBR_DBUS_CONF}" 329*4a64e381SAndroid Build Coastguard Worker sudo cp "${OTBR_DBUS_CONF}" /etc/dbus-1/system.d 330*4a64e381SAndroid Build Coastguard Worker 331*4a64e381SAndroid Build Coastguard Worker write_syslog "AGENT: kill old" 332*4a64e381SAndroid Build Coastguard Worker sudo killall "${OTBR_AGENT}" || true 333*4a64e381SAndroid Build Coastguard Worker sleep 5 334*4a64e381SAndroid Build Coastguard Worker write_syslog "AGENT: starting" 335*4a64e381SAndroid Build Coastguard Worker 336*4a64e381SAndroid Build Coastguard Worker # we launch this in the background 337*4a64e381SAndroid Build Coastguard Worker ( 338*4a64e381SAndroid Build Coastguard Worker set -e 339*4a64e381SAndroid Build Coastguard Worker set -x 340*4a64e381SAndroid Build Coastguard Worker 341*4a64e381SAndroid Build Coastguard Worker cd "${ORIGIN_PWD}" 342*4a64e381SAndroid Build Coastguard Worker 343*4a64e381SAndroid Build Coastguard Worker # check version 344*4a64e381SAndroid Build Coastguard Worker sudo "${OTBR_AGENT_PATH}" -V 345*4a64e381SAndroid Build Coastguard Worker # check invalid arguments 346*4a64e381SAndroid Build Coastguard Worker sudo "${OTBR_AGENT_PATH}" -x && exit $? 347*4a64e381SAndroid Build Coastguard Worker 348*4a64e381SAndroid Build Coastguard Worker [[ ! -d tmp ]] || sudo rm -rf tmp 349*4a64e381SAndroid Build Coastguard Worker sudo "${OTBR_AGENT_PATH}" -I "${TUN_NAME}" -v -d 6 "spinel+hdlc+forkpty://${ot_rcp}?forkpty-arg=${LEADER_NODE_ID}" & 350*4a64e381SAndroid Build Coastguard Worker ) 351*4a64e381SAndroid Build Coastguard Worker 352*4a64e381SAndroid Build Coastguard Worker # wait for it to complete 353*4a64e381SAndroid Build Coastguard Worker sleep 10 354*4a64e381SAndroid Build Coastguard Worker 355*4a64e381SAndroid Build Coastguard Worker pidof ${OTBR_AGENT} || die "AGENT: failed to start" 356*4a64e381SAndroid Build Coastguard Worker write_syslog "AGENT: start complete" 357*4a64e381SAndroid Build Coastguard Worker} 358*4a64e381SAndroid Build Coastguard Worker 359*4a64e381SAndroid Build Coastguard Workerweb_start() 360*4a64e381SAndroid Build Coastguard Worker{ 361*4a64e381SAndroid Build Coastguard Worker write_syslog "WEB: kill old" 362*4a64e381SAndroid Build Coastguard Worker sudo killall "${OTBR_WEB}" || true 363*4a64e381SAndroid Build Coastguard Worker write_syslog "WEB: starting" 364*4a64e381SAndroid Build Coastguard Worker ( 365*4a64e381SAndroid Build Coastguard Worker set -e 366*4a64e381SAndroid Build Coastguard Worker set -x 367*4a64e381SAndroid Build Coastguard Worker 368*4a64e381SAndroid Build Coastguard Worker cd "${ORIGIN_PWD}" 369*4a64e381SAndroid Build Coastguard Worker sudo "${OTBR_WEB_PATH}" -I "${TUN_NAME}" -p "${OTBR_WEB_PORT}" -a "${OTBR_WEB_HOST}" & 370*4a64e381SAndroid Build Coastguard Worker ) 371*4a64e381SAndroid Build Coastguard Worker sleep 15 372*4a64e381SAndroid Build Coastguard Worker 373*4a64e381SAndroid Build Coastguard Worker pidof ${OTBR_WEB} || die "WEB: failed to start" 374*4a64e381SAndroid Build Coastguard Worker write_syslog "WEB: start complete" 375*4a64e381SAndroid Build Coastguard Worker} 376*4a64e381SAndroid Build Coastguard Worker 377*4a64e381SAndroid Build Coastguard Workernetwork_form() 378*4a64e381SAndroid Build Coastguard Worker{ 379*4a64e381SAndroid Build Coastguard Worker OT_PANID="$(random_panid)" 380*4a64e381SAndroid Build Coastguard Worker readonly OT_PANID 381*4a64e381SAndroid Build Coastguard Worker 382*4a64e381SAndroid Build Coastguard Worker OT_XPANID="$(random_xpanid)" 383*4a64e381SAndroid Build Coastguard Worker readonly OT_XPANID 384*4a64e381SAndroid Build Coastguard Worker 385*4a64e381SAndroid Build Coastguard Worker OT_NETWORK_KEY="$(random_networkkey)" 386*4a64e381SAndroid Build Coastguard Worker readonly OT_NETWORK_KEY 387*4a64e381SAndroid Build Coastguard Worker 388*4a64e381SAndroid Build Coastguard Worker OT_CHANNEL="$(random_channel)" 389*4a64e381SAndroid Build Coastguard Worker readonly OT_CHANNEL 390*4a64e381SAndroid Build Coastguard Worker 391*4a64e381SAndroid Build Coastguard Worker curl --header "Content-Type: application/json" --request POST --data "{\"networkKey\":\"${OT_NETWORK_KEY}\",\"prefix\":\"fd11:22::\",\"defaultRoute\":true,\"extPanId\":\"${OT_XPANID}\",\"panId\":\"${OT_PANID}\",\"passphrase\":\"${OT_AGENT_PASSPHRASE}\",\"channel\":${OT_CHANNEL},\"networkName\":\"${OT_NETWORK_NAME}\"}" "${OTBR_WEB_URL}"/form_network | grep "success" || die "WEB: form failed" 392*4a64e381SAndroid Build Coastguard Worker sleep 15 393*4a64e381SAndroid Build Coastguard Worker # verify mDNS is working as expected. 394*4a64e381SAndroid Build Coastguard Worker local mdns_result="${TEST_BASE}"/mdns_result.log 395*4a64e381SAndroid Build Coastguard Worker avahi-browse -art | tee "${mdns_result}" 396*4a64e381SAndroid Build Coastguard Worker OT_BORDER_AGENT_PORT=$(grep -GA3 '^=.\+'"${OT_SERVICE_INSTANCE}"'.\+_meshcop._udp' "${mdns_result}" | head -n4 | grep port | grep -ao '[0-9]\{5\}') 397*4a64e381SAndroid Build Coastguard Worker rm "${mdns_result}" 398*4a64e381SAndroid Build Coastguard Worker} 399*4a64e381SAndroid Build Coastguard Worker 400*4a64e381SAndroid Build Coastguard Workerot_commissioner_build() 401*4a64e381SAndroid Build Coastguard Worker{ 402*4a64e381SAndroid Build Coastguard Worker if [[ -x ${OT_COMMISSIONER_PATH} ]]; then 403*4a64e381SAndroid Build Coastguard Worker return 0 404*4a64e381SAndroid Build Coastguard Worker fi 405*4a64e381SAndroid Build Coastguard Worker 406*4a64e381SAndroid Build Coastguard Worker (mkdir -p "${BUILD_DIR}/ot-commissioner" \ 407*4a64e381SAndroid Build Coastguard Worker && cd "${BUILD_DIR}/ot-commissioner" \ 408*4a64e381SAndroid Build Coastguard Worker && (git --git-dir=.git rev-parse --is-inside-work-tree || git --git-dir=.git init .) \ 409*4a64e381SAndroid Build Coastguard Worker && git fetch --depth 1 https://github.com/openthread/ot-commissioner.git main \ 410*4a64e381SAndroid Build Coastguard Worker && git checkout FETCH_HEAD \ 411*4a64e381SAndroid Build Coastguard Worker && ./script/bootstrap.sh \ 412*4a64e381SAndroid Build Coastguard Worker && mkdir build && cd build \ 413*4a64e381SAndroid Build Coastguard Worker && cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. \ 414*4a64e381SAndroid Build Coastguard Worker && ninja) 415*4a64e381SAndroid Build Coastguard Worker} 416*4a64e381SAndroid Build Coastguard Worker 417*4a64e381SAndroid Build Coastguard Workerot_commissioner_start() 418*4a64e381SAndroid Build Coastguard Worker{ 419*4a64e381SAndroid Build Coastguard Worker write_syslog "COMMISSIONER: kill old" 420*4a64e381SAndroid Build Coastguard Worker sudo killall "${OT_COMMISSIONER_CLI}" || true 421*4a64e381SAndroid Build Coastguard Worker 422*4a64e381SAndroid Build Coastguard Worker OT_PSKC="$("${OTBR_PSKC_PATH}" "${OT_AGENT_PASSPHRASE}" "${OT_XPANID}" "${OT_NETWORK_NAME}")" 423*4a64e381SAndroid Build Coastguard Worker readonly OT_PSKC 424*4a64e381SAndroid Build Coastguard Worker 425*4a64e381SAndroid Build Coastguard Worker OT_COMMISSIONER_LOG="${TEST_BASE}"/commissioner.log 426*4a64e381SAndroid Build Coastguard Worker readonly OT_COMMISSIONER_LOG 427*4a64e381SAndroid Build Coastguard Worker 428*4a64e381SAndroid Build Coastguard Worker local commissioner_config_file="${TEST_BASE}"/ot-commissioner.json 429*4a64e381SAndroid Build Coastguard Worker local commissioner_config_file="${TEST_BASE}"/ot-commissioner.json 430*4a64e381SAndroid Build Coastguard Worker 431*4a64e381SAndroid Build Coastguard Worker sed "s/3aa55f91ca47d1e4e71a08cb35e91591/${OT_PSKC}/g" "${OT_COMMISSIONER_CONFIG}" >"${commissioner_config_file}" 432*4a64e381SAndroid Build Coastguard Worker 433*4a64e381SAndroid Build Coastguard Worker expect -f- <<EOF & 434*4a64e381SAndroid Build Coastguard Workerspawn ${OT_COMMISSIONER_PATH} ${commissioner_config_file} 435*4a64e381SAndroid Build Coastguard Workerset timeout 1 436*4a64e381SAndroid Build Coastguard Workerexpect_after { 437*4a64e381SAndroid Build Coastguard Worker timeout { exit 1 } 438*4a64e381SAndroid Build Coastguard Worker} 439*4a64e381SAndroid Build Coastguard Workersend "start :: $OT_BORDER_AGENT_PORT\n" 440*4a64e381SAndroid Build Coastguard Workerexpect "done" 441*4a64e381SAndroid Build Coastguard Workersleep 5 442*4a64e381SAndroid Build Coastguard Workersend "active\n" 443*4a64e381SAndroid Build Coastguard Workerexpect "true" 444*4a64e381SAndroid Build Coastguard Workersend "joiner enable meshcop 0x${OT_JOINER_EUI64} ${OT_JOINER_PASSPHRASE}\n" 445*4a64e381SAndroid Build Coastguard Workerexpect "done" 446*4a64e381SAndroid Build Coastguard Workerwait 447*4a64e381SAndroid Build Coastguard WorkerEOF 448*4a64e381SAndroid Build Coastguard Worker 449*4a64e381SAndroid Build Coastguard Worker sleep 10 450*4a64e381SAndroid Build Coastguard Worker} 451*4a64e381SAndroid Build Coastguard Worker 452*4a64e381SAndroid Build Coastguard Workerweb_commissioner_start() 453*4a64e381SAndroid Build Coastguard Worker{ 454*4a64e381SAndroid Build Coastguard Worker curl --header "Content-Type: application/json" --request POST --data "{\"pskd\":\"${OT_JOINER_PASSPHRASE}\", \"passphrase\":\"${OT_AGENT_PASSPHRASE}\"}" "${OTBR_WEB_URL}"/commission 455*4a64e381SAndroid Build Coastguard Worker sleep 15 456*4a64e381SAndroid Build Coastguard Worker} 457*4a64e381SAndroid Build Coastguard Worker 458*4a64e381SAndroid Build Coastguard Workerjoiner_start() 459*4a64e381SAndroid Build Coastguard Worker{ 460*4a64e381SAndroid Build Coastguard Worker write_syslog 'JOINER START' 461*4a64e381SAndroid Build Coastguard Worker cd ${TEST_BASE} 462*4a64e381SAndroid Build Coastguard Worker sudo expect -f- <<EOF || die 'JOINER FAILED' 463*4a64e381SAndroid Build Coastguard Workerspawn ${ot_cli} ${JOINER_NODE_ID} 464*4a64e381SAndroid Build Coastguard Workersend "ifconfig up\r\n" 465*4a64e381SAndroid Build Coastguard Workerexpect "Done" 466*4a64e381SAndroid Build Coastguard Workersend "joiner start ${OT_JOINER_PASSPHRASE}\r\n" 467*4a64e381SAndroid Build Coastguard Workerset timeout 20 468*4a64e381SAndroid Build Coastguard Workerexpect { 469*4a64e381SAndroid Build Coastguard Worker "Join success" { 470*4a64e381SAndroid Build Coastguard Worker send_user "succeeded to find join success" 471*4a64e381SAndroid Build Coastguard Worker send "exit\r\n" 472*4a64e381SAndroid Build Coastguard Worker } 473*4a64e381SAndroid Build Coastguard Worker timeout { 474*4a64e381SAndroid Build Coastguard Worker send_user "Failed to find join success" 475*4a64e381SAndroid Build Coastguard Worker exit 1 476*4a64e381SAndroid Build Coastguard Worker } 477*4a64e381SAndroid Build Coastguard Worker} 478*4a64e381SAndroid Build Coastguard WorkerEOF 479*4a64e381SAndroid Build Coastguard Worker exit_message="JOINER SUCCESS COMPLETE" 480*4a64e381SAndroid Build Coastguard Worker} 481*4a64e381SAndroid Build Coastguard Worker 482*4a64e381SAndroid Build Coastguard Workerscan_meshcop_service() 483*4a64e381SAndroid Build Coastguard Worker{ 484*4a64e381SAndroid Build Coastguard Worker if command -v dns-sd; then 485*4a64e381SAndroid Build Coastguard Worker timeout 2 dns-sd -Z _meshcop._udp local. || true 486*4a64e381SAndroid Build Coastguard Worker else 487*4a64e381SAndroid Build Coastguard Worker avahi-browse -aprt || true 488*4a64e381SAndroid Build Coastguard Worker fi 489*4a64e381SAndroid Build Coastguard Worker} 490*4a64e381SAndroid Build Coastguard Worker 491*4a64e381SAndroid Build Coastguard Workertest_meshcop_service() 492*4a64e381SAndroid Build Coastguard Worker{ 493*4a64e381SAndroid Build Coastguard Worker local network_name="ot-test-net" 494*4a64e381SAndroid Build Coastguard Worker local xpanid="4142434445464748" 495*4a64e381SAndroid Build Coastguard Worker local xpanid_txt="ABCDEFGH" 496*4a64e381SAndroid Build Coastguard Worker local extaddr="4142434445464748" 497*4a64e381SAndroid Build Coastguard Worker local extaddr_txt="ABCDEFGH" 498*4a64e381SAndroid Build Coastguard Worker local passphrase="SECRET" 499*4a64e381SAndroid Build Coastguard Worker local service 500*4a64e381SAndroid Build Coastguard Worker 501*4a64e381SAndroid Build Coastguard Worker test_setup 502*4a64e381SAndroid Build Coastguard Worker ba_start 503*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" factoryreset 504*4a64e381SAndroid Build Coastguard Worker sleep 1 505*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset init new 506*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset networkname ${network_name} 507*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset extpanid ${xpanid} 508*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset pskc -p ${passphrase} 509*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset commit active 510*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" ifconfig up 511*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" extaddr ${extaddr} 512*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" thread start 513*4a64e381SAndroid Build Coastguard Worker sleep 20 514*4a64e381SAndroid Build Coastguard Worker 515*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" state | grep "leader" 516*4a64e381SAndroid Build Coastguard Worker 517*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 518*4a64e381SAndroid Build Coastguard Worker grep "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 519*4a64e381SAndroid Build Coastguard Worker grep "rv=1" <<<"${service}" 520*4a64e381SAndroid Build Coastguard Worker grep "tv=1\.3\.0" <<<"${service}" 521*4a64e381SAndroid Build Coastguard Worker grep "nn=${network_name}" <<<"${service}" 522*4a64e381SAndroid Build Coastguard Worker grep "xp=${xpanid_txt}" <<<"${service}" 523*4a64e381SAndroid Build Coastguard Worker grep "xa=${extaddr_txt}" <<<"${service}" 524*4a64e381SAndroid Build Coastguard Worker 525*4a64e381SAndroid Build Coastguard Worker # TODO: enable the checks after enabling Thread 1.2 for tests. 526*4a64e381SAndroid Build Coastguard Worker #grep "dn=${domain_name}" <<< "${service}" 527*4a64e381SAndroid Build Coastguard Worker #grep "sq=" <<< "${service}" 528*4a64e381SAndroid Build Coastguard Worker #grep "bb=" <<< "${service}" 529*4a64e381SAndroid Build Coastguard Worker 530*4a64e381SAndroid Build Coastguard Worker # The binary values are not printable with dns-sd. 531*4a64e381SAndroid Build Coastguard Worker grep "sb=" <<<"${service}" 532*4a64e381SAndroid Build Coastguard Worker grep "at=" <<<"${service}" 533*4a64e381SAndroid Build Coastguard Worker grep "pt=" <<<"${service}" 534*4a64e381SAndroid Build Coastguard Worker 535*4a64e381SAndroid Build Coastguard Worker # Test if the meshcop service is published when thread is not on 536*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset init active 537*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset pskc 00000000000000000000000000000000 538*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset commit active 539*4a64e381SAndroid Build Coastguard Worker sleep 2 540*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 541*4a64e381SAndroid Build Coastguard Worker grep -q "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 542*4a64e381SAndroid Build Coastguard Worker 543*4a64e381SAndroid Build Coastguard Worker # Test if the meshcop service is published again when a non-zero 544*4a64e381SAndroid Build Coastguard Worker # PSKc is set back. 545*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset init active 546*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset pskc 11223344556677889900aabbccddeeff 547*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset commit active 548*4a64e381SAndroid Build Coastguard Worker sleep 2 549*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 550*4a64e381SAndroid Build Coastguard Worker grep "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 551*4a64e381SAndroid Build Coastguard Worker 552*4a64e381SAndroid Build Coastguard Worker # Test if the meshcop service's 'nn' field is updated 553*4a64e381SAndroid Build Coastguard Worker # when the network name is changed. 554*4a64e381SAndroid Build Coastguard Worker local new_network_name="ot-test-net-new" 555*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset init active 556*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset networkname ${new_network_name} 557*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" dataset commit active 558*4a64e381SAndroid Build Coastguard Worker sleep 2 559*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 560*4a64e381SAndroid Build Coastguard Worker grep "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 561*4a64e381SAndroid Build Coastguard Worker grep "nn=${new_network_name}" <<<"${service}" 562*4a64e381SAndroid Build Coastguard Worker 563*4a64e381SAndroid Build Coastguard Worker # Test if the discriminator is updated when extaddr is changed. 564*4a64e381SAndroid Build Coastguard Worker local new_extaddr="4847464544434241" 565*4a64e381SAndroid Build Coastguard Worker local new_extaddr_txt="HGFEDCBA" 566*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" thread stop 567*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" extaddr ${new_extaddr} 568*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" thread start 569*4a64e381SAndroid Build Coastguard Worker sleep 5 570*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 571*4a64e381SAndroid Build Coastguard Worker grep "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 572*4a64e381SAndroid Build Coastguard Worker grep "xa=${new_extaddr_txt}" <<<"${service}" 573*4a64e381SAndroid Build Coastguard Worker 574*4a64e381SAndroid Build Coastguard Worker # Test if the meshcop service is published when Thread is stopped. 575*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" thread stop 576*4a64e381SAndroid Build Coastguard Worker sleep 2 577*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 578*4a64e381SAndroid Build Coastguard Worker grep -q "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 579*4a64e381SAndroid Build Coastguard Worker 580*4a64e381SAndroid Build Coastguard Worker sudo "${OT_CTL}" thread start 581*4a64e381SAndroid Build Coastguard Worker sleep 5 582*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 583*4a64e381SAndroid Build Coastguard Worker grep "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}" 584*4a64e381SAndroid Build Coastguard Worker 585*4a64e381SAndroid Build Coastguard Worker # Test if the the meshcop service is unpublished when otbr-agent stops. 586*4a64e381SAndroid Build Coastguard Worker sudo killall "${OTBR_AGENT}" 587*4a64e381SAndroid Build Coastguard Worker sleep 10 588*4a64e381SAndroid Build Coastguard Worker service="$(scan_meshcop_service)" 589*4a64e381SAndroid Build Coastguard Worker if grep -q "${OT_SERVICE_INSTANCE}._meshcop\._udp" <<<"${service}"; then 590*4a64e381SAndroid Build Coastguard Worker die "unexpect meshcop service when otbr-agent exits!" 591*4a64e381SAndroid Build Coastguard Worker fi 592*4a64e381SAndroid Build Coastguard Worker} 593*4a64e381SAndroid Build Coastguard Worker 594*4a64e381SAndroid Build Coastguard Workertest_commissioning() 595*4a64e381SAndroid Build Coastguard Worker{ 596*4a64e381SAndroid Build Coastguard Worker test_setup 597*4a64e381SAndroid Build Coastguard Worker ba_start 598*4a64e381SAndroid Build Coastguard Worker web_start 599*4a64e381SAndroid Build Coastguard Worker network_form 600*4a64e381SAndroid Build Coastguard Worker if [[ ${OTBR_USE_WEB_COMMISSIONER} == 1 ]]; then 601*4a64e381SAndroid Build Coastguard Worker web_commissioner_start 602*4a64e381SAndroid Build Coastguard Worker else 603*4a64e381SAndroid Build Coastguard Worker ot_commissioner_start 604*4a64e381SAndroid Build Coastguard Worker fi 605*4a64e381SAndroid Build Coastguard Worker joiner_start 606*4a64e381SAndroid Build Coastguard Worker} 607*4a64e381SAndroid Build Coastguard Worker 608*4a64e381SAndroid Build Coastguard Workermain() 609*4a64e381SAndroid Build Coastguard Worker{ 610*4a64e381SAndroid Build Coastguard Worker if [ "${TEST_CASE}" == "mdns_service" ]; then 611*4a64e381SAndroid Build Coastguard Worker test_meshcop_service 612*4a64e381SAndroid Build Coastguard Worker else 613*4a64e381SAndroid Build Coastguard Worker test_commissioning 614*4a64e381SAndroid Build Coastguard Worker fi 615*4a64e381SAndroid Build Coastguard Worker} 616*4a64e381SAndroid Build Coastguard Worker 617*4a64e381SAndroid Build Coastguard Workermain "$@" 618