1#!/bin/bash 2# 3# Copyright (c) 2018, The OpenThread Authors. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. Neither the name of the copyright holder nor the 14# names of its contributors may be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30die() 31{ 32 echo " *** ERROR: " "$*" 33 exit 1 34} 35 36cleanup() 37{ 38 # Clear logs and flash files 39 sudo rm tmp/*.flash tmp/*.data tmp/*.swap >/dev/null 2>&1 40 sudo rm ./*.log >/dev/null 2>&1 41 42 if [ "$TORANJ_CLI" != 1 ]; then 43 # Clear any wpantund instances 44 sudo killall wpantund >/dev/null 2>&1 45 46 while read -r interface; do 47 sudo ip link delete "$interface" >/dev/null 2>&1 48 done < <(ifconfig 2>/dev/null | grep -o "wpan[0-9]*") 49 fi 50 51 sleep 0.3 52} 53 54run() 55{ 56 counter=0 57 while true; do 58 if sudo -E "${python_app}" "$1"; then 59 cleanup 60 return 61 fi 62 63 # We allow a failed test to be retried up to 7 attempts. 64 if [ "$counter" -lt 7 ]; then 65 counter=$((counter + 1)) 66 echo Attempt $counter running "$1" failed. Trying again. 67 cleanup 68 sleep 10 69 continue 70 fi 71 72 echo " *** TEST FAILED" 73 tail -n 40 "${log_file_name}"*.log 74 exit 1 75 done 76} 77 78install_wpantund() 79{ 80 echo "Installing wpantund" 81 sudo apt-get --no-install-recommends install -y dbus libdbus-1-dev 82 sudo apt-get --no-install-recommends install -y autoconf-archive 83 sudo apt-get --no-install-recommends install -y libarchive-tools 84 sudo apt-get --no-install-recommends install -y libtool 85 sudo apt-get --no-install-recommends install -y libglib2.0-dev 86 sudo apt-get --no-install-recommends install -y lcov 87 88 sudo add-apt-repository universe 89 sudo apt-get update 90 sudo apt-get --no-install-recommends install -y libboost-all-dev python2 91 92 git clone --depth=1 --branch=master https://github.com/openthread/wpantund.git || die "wpandtund clone" 93 cd wpantund || die "cd wpantund failed" 94 ./bootstrap.sh 95 ./configure 96 sudo make -j2 || die "wpantund make failed" 97 sudo make install || die "wpantund make install failed" 98 cd .. || die "cd .. failed" 99} 100 101cd "$(dirname "$0")" || die "cd failed" 102 103if [ "$TORANJ_NCP" = 1 ]; then 104 echo "========================================================================" 105 echo "Running toranj-ncp triggered by event ${TORANJ_EVENT_NAME}" 106 107 if [ "$TORANJ_EVENT_NAME" = "pull_request" ]; then 108 cd ../.. 109 OT_SHA_OLD="$(git cat-file -p HEAD | grep 'parent ' | head -n1 | cut -d' ' -f2)" 110 git fetch --depth 1 --no-recurse-submodules origin "${OT_SHA_OLD}" 111 if git diff --name-only --exit-code "${OT_SHA_OLD}" -- src/ncp; then 112 echo "No changes to any of src/ncp files - skip running tests." 113 echo "========================================================================" 114 exit 0 115 fi 116 cd tests/toranj || die "cd tests/toranj failed" 117 echo "There are change in src/ncp files, running toranj-ncp tests" 118 fi 119 120 echo "========================================================================" 121 install_wpantund 122fi 123 124if [ -z "${top_builddir}" ]; then 125 top_builddir=. 126fi 127 128if [ "$COVERAGE" = 1 ]; then 129 coverage_option="--enable-coverage" 130else 131 coverage_option="" 132fi 133 134if [ "$TORANJ_CLI" = 1 ]; then 135 app_name="cli" 136 python_app="python3" 137 log_file_name="ot-logs" 138else 139 app_name="ncp" 140 python_app="python2" 141 log_file_name="wpantund-logs" 142fi 143 144if [ "$TORANJ_RADIO" = "multi" ]; then 145 # Build all combinations 146 ./build.sh "${coverage_option}" "${app_name}"-15.4 || die "${app_name}-15.4 build failed" 147 ./build.sh "${coverage_option}" "${app_name}"-trel || die "${app_name}-trel build failed" 148 ./build.sh "${coverage_option}" "${app_name}"-15.4+trel || die "${app_name}-15.4+trel build failed" 149else 150 ./build.sh "${coverage_option}" "${app_name}"-"${TORANJ_RADIO}" || die "build failed" 151fi 152 153cleanup 154 155if [ "$TORANJ_CLI" = 1 ]; then 156 157 if [ "$TORANJ_RADIO" = "multi" ]; then 158 run cli/test-700-multi-radio-join.py 159 run cli/test-701-multi-radio-probe.py 160 run cli/test-702-multi-radio-discover-by-rx.py 161 run cli/test-703-multi-radio-mesh-header-msg.py 162 run cli/test-704-multi-radio-scan.py 163 run cli/test-705-multi-radio-discover-scan.py 164 165 exit 0 166 fi 167 168 run cli/test-001-get-set.py 169 run cli/test-002-form.py 170 run cli/test-003-join.py 171 run cli/test-004-scan.py 172 run cli/test-005-traffic-router-to-child.py 173 run cli/test-006-traffic-multi-hop.py 174 run cli/test-007-off-mesh-route-traffic.py 175 run cli/test-008-multicast-traffic.py 176 run cli/test-009-router-table.py 177 run cli/test-010-partition-merge.py 178 run cli/test-011-network-data-timeout.py 179 run cli/test-012-reset-recovery.py 180 run cli/test-013-address-cache-parent-switch.py 181 run cli/test-014-address-resolver.py 182 run cli/test-015-clear-addresss-cache-for-sed.py 183 run cli/test-016-child-mode-change.py 184 run cli/test-017-network-data-versions.py 185 run cli/test-018-next-hop-and-path-cost.py 186 run cli/test-019-netdata-context-id.py 187 run cli/test-020-net-diag-vendor-info.py 188 run cli/test-021-br-route-prf.py 189 run cli/test-022-netdata-full.py 190 run cli/test-023-mesh-diag.py 191 run cli/test-024-mle-adv-imax-change.py 192 run cli/test-025-mesh-local-prefix-change.py 193 run cli/test-026-coaps-conn-limit.py 194 run cli/test-027-slaac-address.py 195 run cli/test-028-border-agent-ephemeral-key.py 196 run cli/test-029-pending-dataset-key-change.py 197 run cli/test-030-anycast-forwarding.py 198 run cli/test-031-service-aloc-route-lookup.py 199 run cli/test-032-leader-take-over.py 200 run cli/test-400-srp-client-server.py 201 run cli/test-401-srp-server-address-cache-snoop.py 202 run cli/test-500-two-brs-two-networks.py 203 run cli/test-501-multi-br-failure-recovery.py 204 run cli/test-502-multi-br-leader-failure-recovery.py 205 run cli/test-503-peer-tbr-discovery.py 206 run cli/test-504-br-icmp-unreach-err.py 207 run cli/test-601-channel-manager-channel-change.py 208 # Skip the "channel-select" test on a TREL only radio link, since it 209 # requires energy scan which is not supported in this case. 210 if [ "$TORANJ_RADIO" != "trel" ]; then 211 run cli/test-602-channel-manager-channel-select.py 212 fi 213 run cli/test-603-channel-announce-recovery.py 214 215 exit 0 216fi 217 218if [ "$TORANJ_RADIO" = "multi" ]; then 219 run ncp/test-700-multi-radio-join.py 220 run ncp/test-701-multi-radio-probe.py 221 run ncp/test-702-multi-radio-discovery-by-rx.py 222 run ncp/test-703-multi-radio-mesh-header-msg.py 223 run ncp/test-704-multi-radio-scan.py 224 run ncp/test-705-multi-radio-discover-scan.py 225 226 exit 0 227fi 228 229run ncp/test-001-get-set.py 230run ncp/test-002-form.py 231run ncp/test-003-join.py 232run ncp/test-004-scan.py 233run ncp/test-005-discover-scan.py 234run ncp/test-006-traffic-router-end-device.py 235run ncp/test-007-traffic-router-sleepy.py 236run ncp/test-009-insecure-traffic-join.py 237run ncp/test-010-on-mesh-prefix-config-gateway.py 238run ncp/test-011-child-table.py 239run ncp/test-012-multi-hop-traffic.py 240run ncp/test-013-off-mesh-route-traffic.py 241run ncp/test-014-ip6-address-add.py 242run ncp/test-015-same-prefix-on-multiple-nodes.py 243run ncp/test-016-neighbor-table.py 244run ncp/test-017-parent-reset-child-recovery.py 245run ncp/test-019-inform-previous-parent.py 246run ncp/test-020-router-table.py 247run ncp/test-021-address-cache-table.py 248run ncp/test-022-multicast-ip6-address.py 249run ncp/test-023-multicast-traffic.py 250run ncp/test-024-partition-merge.py 251run ncp/test-025-network-data-timeout.py 252run ncp/test-026-slaac-address-wpantund.py 253run ncp/test-027-child-mode-change.py 254run ncp/test-028-router-leader-reset-recovery.py 255run ncp/test-029-data-poll-interval.py 256# run ncp/test-030-slaac-address-ncp.py 257run ncp/test-031-meshcop-joiner-commissioner.py 258run ncp/test-032-child-attach-with-multiple-ip-addresses.py 259run ncp/test-033-mesh-local-prefix-change.py 260run ncp/test-034-poor-link-parent-child-attach.py 261run ncp/test-035-child-timeout-large-data-poll.py 262run ncp/test-036-wpantund-host-route-management.py 263run ncp/test-037-wpantund-auto-add-route-for-on-mesh-prefix.py 264run ncp/test-038-clear-address-cache-for-sed.py 265run ncp/test-039-address-cache-table-snoop.py 266run ncp/test-040-network-data-stable-full.py 267run ncp/test-041-lowpan-fragmentation.py 268run ncp/test-042-meshcop-joiner-discerner.py 269run ncp/test-043-meshcop-joiner-router.py 270run ncp/test-100-mcu-power-state.py 271run ncp/test-600-channel-manager-properties.py 272run ncp/test-601-channel-manager-channel-change.py 273 274# Skip the "channel-select" test on a TREL only radio link, since it 275# requires energy scan which is not supported in this case. 276 277if [ "$TORANJ_RADIO" != "trel" ]; then 278 run ncp/test-602-channel-manager-channel-select.py 279fi 280 281run ncp/test-603-channel-manager-announce-recovery.py 282 283exit 0 284