xref: /aosp_15_r20/external/openthread/script/check-posix-pty (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
30*cfb92d14SAndroid Build Coastguard Workerset -e
31*cfb92d14SAndroid Build Coastguard Workerset -x
32*cfb92d14SAndroid Build Coastguard Worker
33*cfb92d14SAndroid Build Coastguard Workerdie()
34*cfb92d14SAndroid Build Coastguard Worker{
35*cfb92d14SAndroid Build Coastguard Worker    echo " *** ERROR: " "$*"
36*cfb92d14SAndroid Build Coastguard Worker    exit 1
37*cfb92d14SAndroid Build Coastguard Worker}
38*cfb92d14SAndroid Build Coastguard Worker
39*cfb92d14SAndroid Build Coastguard Workerat_exit()
40*cfb92d14SAndroid Build Coastguard Worker{
41*cfb92d14SAndroid Build Coastguard Worker    EXIT_CODE=$?
42*cfb92d14SAndroid Build Coastguard Worker
43*cfb92d14SAndroid Build Coastguard Worker    sudo killall expect || true
44*cfb92d14SAndroid Build Coastguard Worker    sudo killall ot-ctl || true
45*cfb92d14SAndroid Build Coastguard Worker    sudo killall ot-daemon || true
46*cfb92d14SAndroid Build Coastguard Worker    sudo killall ot-cli || true
47*cfb92d14SAndroid Build Coastguard Worker    sudo killall ot-rcp || true
48*cfb92d14SAndroid Build Coastguard Worker    sudo killall socat || true
49*cfb92d14SAndroid Build Coastguard Worker
50*cfb92d14SAndroid Build Coastguard Worker    exit $EXIT_CODE
51*cfb92d14SAndroid Build Coastguard Worker}
52*cfb92d14SAndroid Build Coastguard Worker
53*cfb92d14SAndroid Build Coastguard Workerwait_for_socat()
54*cfb92d14SAndroid Build Coastguard Worker{
55*cfb92d14SAndroid Build Coastguard Worker    if [[ "$(head -n2 "$SOCAT_OUTPUT" | wc -l | tr -d ' ')" == 2 ]]; then
56*cfb92d14SAndroid Build Coastguard Worker        RADIO_PTY=$(head -n1 "$SOCAT_OUTPUT" | grep -o '/dev/.\+')
57*cfb92d14SAndroid Build Coastguard Worker        CORE_PTY=$(head -n2 "$SOCAT_OUTPUT" | tail -n1 | grep -o '/dev/.\+')
58*cfb92d14SAndroid Build Coastguard Worker        return 0
59*cfb92d14SAndroid Build Coastguard Worker    else
60*cfb92d14SAndroid Build Coastguard Worker        echo 'Still waiting for socat'
61*cfb92d14SAndroid Build Coastguard Worker    fi
62*cfb92d14SAndroid Build Coastguard Worker    return 1
63*cfb92d14SAndroid Build Coastguard Worker}
64*cfb92d14SAndroid Build Coastguard Worker
65*cfb92d14SAndroid Build Coastguard Workerwait_for_leader()
66*cfb92d14SAndroid Build Coastguard Worker{
67*cfb92d14SAndroid Build Coastguard Worker    if grep -q leader "$OT_OUTPUT"; then
68*cfb92d14SAndroid Build Coastguard Worker        return 0
69*cfb92d14SAndroid Build Coastguard Worker    else
70*cfb92d14SAndroid Build Coastguard Worker        echo 'Still waiting for leader'
71*cfb92d14SAndroid Build Coastguard Worker    fi
72*cfb92d14SAndroid Build Coastguard Worker    return 1
73*cfb92d14SAndroid Build Coastguard Worker}
74*cfb92d14SAndroid Build Coastguard Worker
75*cfb92d14SAndroid Build Coastguard Workertimeout_run()
76*cfb92d14SAndroid Build Coastguard Worker{
77*cfb92d14SAndroid Build Coastguard Worker    local count="$1"
78*cfb92d14SAndroid Build Coastguard Worker    local exit_code
79*cfb92d14SAndroid Build Coastguard Worker    shift 1
80*cfb92d14SAndroid Build Coastguard Worker
81*cfb92d14SAndroid Build Coastguard Worker    while [[ $count != 0 && $exit_code != 0 ]]; do
82*cfb92d14SAndroid Build Coastguard Worker        count=$((count - 1))
83*cfb92d14SAndroid Build Coastguard Worker        "$@" && return 0 || exit_code=$?
84*cfb92d14SAndroid Build Coastguard Worker        sleep 1
85*cfb92d14SAndroid Build Coastguard Worker    done
86*cfb92d14SAndroid Build Coastguard Worker
87*cfb92d14SAndroid Build Coastguard Worker    return $exit_code
88*cfb92d14SAndroid Build Coastguard Worker}
89*cfb92d14SAndroid Build Coastguard Worker
90*cfb92d14SAndroid Build Coastguard Workerdo_build()
91*cfb92d14SAndroid Build Coastguard Worker{
92*cfb92d14SAndroid Build Coastguard Worker    ./script/cmake-build simulation
93*cfb92d14SAndroid Build Coastguard Worker    ./script/cmake-build posix -DOT_PLATFORM_NETIF=1 -DOT_PLATFORM_UDP=1 -DOT_UDP_FORWARD=0 -DOT_POSIX_MAX_POWER_TABLE=1 -DOT_DAEMON="${OT_DAEMON}" -DOT_READLINE="${OT_READLINE}"
94*cfb92d14SAndroid Build Coastguard Worker}
95*cfb92d14SAndroid Build Coastguard Worker
96*cfb92d14SAndroid Build Coastguard Workerdo_check()
97*cfb92d14SAndroid Build Coastguard Worker{
98*cfb92d14SAndroid Build Coastguard Worker    trap at_exit INT TERM EXIT
99*cfb92d14SAndroid Build Coastguard Worker
100*cfb92d14SAndroid Build Coastguard Worker    sudo rm -rf tmp
101*cfb92d14SAndroid Build Coastguard Worker
102*cfb92d14SAndroid Build Coastguard Worker    SOCAT_OUTPUT=/tmp/ot-socat
103*cfb92d14SAndroid Build Coastguard Worker    OT_OUTPUT=/tmp/ot-output
104*cfb92d14SAndroid Build Coastguard Worker    socat -d -d pty,raw,echo=0 pty,raw,echo=0 >/dev/null 2>$SOCAT_OUTPUT &
105*cfb92d14SAndroid Build Coastguard Worker    timeout_run 10 wait_for_socat
106*cfb92d14SAndroid Build Coastguard Worker    echo 'RADIO_PTY' "$RADIO_PTY"
107*cfb92d14SAndroid Build Coastguard Worker    echo 'CORE_PTY' "$CORE_PTY"
108*cfb92d14SAndroid Build Coastguard Worker
109*cfb92d14SAndroid Build Coastguard Worker    RADIO_NCP_PATH="$PWD/build/simulation/examples/apps/ncp/ot-rcp"
110*cfb92d14SAndroid Build Coastguard Worker
111*cfb92d14SAndroid Build Coastguard Worker    # shellcheck disable=SC2094
112*cfb92d14SAndroid Build Coastguard Worker    $RADIO_NCP_PATH 1 >"$RADIO_PTY" <"$RADIO_PTY" &
113*cfb92d14SAndroid Build Coastguard Worker
114*cfb92d14SAndroid Build Coastguard Worker    # Cover setting a valid network interface name.
115*cfb92d14SAndroid Build Coastguard Worker    VALID_NETIF_NAME="wan$(date +%H%M%S)"
116*cfb92d14SAndroid Build Coastguard Worker    readonly VALID_NETIF_NAME
117*cfb92d14SAndroid Build Coastguard Worker
118*cfb92d14SAndroid Build Coastguard Worker    RADIO_URL="spinel+hdlc+uart://${CORE_PTY}?region=US&max-power-table=11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26"
119*cfb92d14SAndroid Build Coastguard Worker
120*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_DAEMON} == 'on' ]]; then
121*cfb92d14SAndroid Build Coastguard Worker        sudo -E "$PWD/build/posix/src/posix/ot-daemon" -d7 -v -I "${VALID_NETIF_NAME}" "${RADIO_URL}" 2>&1 | tee "${OT_OUTPUT}" &
122*cfb92d14SAndroid Build Coastguard Worker        sleep 3
123*cfb92d14SAndroid Build Coastguard Worker        # macOS cannot explicitly set network interface name
124*cfb92d14SAndroid Build Coastguard Worker        NETIF_NAME=$(grep -o 'Thread interface: .\+' "${OT_OUTPUT}" | cut -d: -f2 | tr -d ' \r\n')
125*cfb92d14SAndroid Build Coastguard Worker        OT_CTL_PATH="$PWD/build/posix/src/posix/ot-ctl"
126*cfb92d14SAndroid Build Coastguard Worker        if [[ ${OT_DAEMON_ALLOW_ALL} == 1 ]]; then
127*cfb92d14SAndroid Build Coastguard Worker            OT_CTL=("${OT_CTL_PATH}")
128*cfb92d14SAndroid Build Coastguard Worker        else
129*cfb92d14SAndroid Build Coastguard Worker            OT_CTL=(sudo "${OT_CTL_PATH}")
130*cfb92d14SAndroid Build Coastguard Worker        fi
131*cfb92d14SAndroid Build Coastguard Worker        "${OT_CTL[@]}" -I "${NETIF_NAME}" panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
132*cfb92d14SAndroid Build Coastguard Worker
133*cfb92d14SAndroid Build Coastguard Worker        # verify supports options in OpenThread commands without separator --
134*cfb92d14SAndroid Build Coastguard Worker        "${OT_CTL[@]}" -I "${NETIF_NAME}" pskc -p 123456 | grep 'Done' || die 'unable to set pskc'
135*cfb92d14SAndroid Build Coastguard Worker
136*cfb92d14SAndroid Build Coastguard Worker        # verify this reset and factoryreset end immediately
137*cfb92d14SAndroid Build Coastguard Worker        "${OT_CTL[@]}" -I "${NETIF_NAME}" reset
138*cfb92d14SAndroid Build Coastguard Worker        # sleep a while for daemon ready
139*cfb92d14SAndroid Build Coastguard Worker        sleep 2
140*cfb92d14SAndroid Build Coastguard Worker        "${OT_CTL[@]}" -I "${NETIF_NAME}" factoryreset
141*cfb92d14SAndroid Build Coastguard Worker        # sleep a while for daemon ready
142*cfb92d14SAndroid Build Coastguard Worker        sleep 2
143*cfb92d14SAndroid Build Coastguard Worker
144*cfb92d14SAndroid Build Coastguard Worker        OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH=640
145*cfb92d14SAndroid Build Coastguard Worker        readonly OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH
146*cfb92d14SAndroid Build Coastguard Worker        local -r kMaxStringLength="$((OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH - 1))"
147*cfb92d14SAndroid Build Coastguard Worker
148*cfb92d14SAndroid Build Coastguard Worker        # verify success if command length doesn't exceed the limit
149*cfb92d14SAndroid Build Coastguard Worker        for len in $(seq 1 ${kMaxStringLength}); do
150*cfb92d14SAndroid Build Coastguard Worker            "${OT_CTL[@]}" -I "${NETIF_NAME}" "$(printf '1%.0s' $(seq 1 "${len}"))"
151*cfb92d14SAndroid Build Coastguard Worker        done
152*cfb92d14SAndroid Build Coastguard Worker
153*cfb92d14SAndroid Build Coastguard Worker        # verify failure if command length exceeds the limit
154*cfb92d14SAndroid Build Coastguard Worker        len=${OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH}
155*cfb92d14SAndroid Build Coastguard Worker        if "${OT_CTL[@]}" -I "${NETIF_NAME}" "$(printf '1%.0s' $(seq 1 "${len}"))"; then
156*cfb92d14SAndroid Build Coastguard Worker            die
157*cfb92d14SAndroid Build Coastguard Worker        fi
158*cfb92d14SAndroid Build Coastguard Worker        OT_CLI_CMD="${OT_CTL[*]} -I ${NETIF_NAME}"
159*cfb92d14SAndroid Build Coastguard Worker    else
160*cfb92d14SAndroid Build Coastguard Worker        OT_CLI="$PWD/build/posix/src/posix/ot-cli"
161*cfb92d14SAndroid Build Coastguard Worker        sudo "${OT_CLI}" -I "${VALID_NETIF_NAME}" -n "${RADIO_URL}"
162*cfb92d14SAndroid Build Coastguard Worker
163*cfb92d14SAndroid Build Coastguard Worker        # Cover setting a too long(max is 15 characters) network interface name.
164*cfb92d14SAndroid Build Coastguard Worker        # Expect exit code to be 2(OT_EXIT_INVALID_ARGUMENTS).
165*cfb92d14SAndroid Build Coastguard Worker        INVALID_NETIF_NAME="wan0123456789123"
166*cfb92d14SAndroid Build Coastguard Worker        readonly INVALID_NETIF_NAME
167*cfb92d14SAndroid Build Coastguard Worker        sudo "${OT_CLI}" -I "${INVALID_NETIF_NAME}" -n "${RADIO_URL}" || test $? = 2
168*cfb92d14SAndroid Build Coastguard Worker
169*cfb92d14SAndroid Build Coastguard Worker        OT_CLI_CMD="$PWD/build/posix/src/posix/ot-cli ${RADIO_URL}"
170*cfb92d14SAndroid Build Coastguard Worker    fi
171*cfb92d14SAndroid Build Coastguard Worker
172*cfb92d14SAndroid Build Coastguard Worker    sudo expect <<EOF | tee "${OT_OUTPUT}" &
173*cfb92d14SAndroid Build Coastguard Workerspawn ${OT_CLI_CMD}
174*cfb92d14SAndroid Build Coastguard Workerexpect_after {
175*cfb92d14SAndroid Build Coastguard Worker    timeout { error }
176*cfb92d14SAndroid Build Coastguard Worker}
177*cfb92d14SAndroid Build Coastguard Workersend "region\r\n"
178*cfb92d14SAndroid Build Coastguard Workerexpect "US"
179*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
180*cfb92d14SAndroid Build Coastguard Workersend "dataset init new\r\n"
181*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
182*cfb92d14SAndroid Build Coastguard Workersend "dataset commit active\r\n"
183*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
184*cfb92d14SAndroid Build Coastguard Workersend "routerselectionjitter 1\r\n"
185*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
186*cfb92d14SAndroid Build Coastguard Workersend "ifconfig up\r\n"
187*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
188*cfb92d14SAndroid Build Coastguard Workersend "thread start\r\n"
189*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
190*cfb92d14SAndroid Build Coastguard Workersleep 10
191*cfb92d14SAndroid Build Coastguard Workersend "state\r\n"
192*cfb92d14SAndroid Build Coastguard Workerexpect "leader"
193*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
194*cfb92d14SAndroid Build Coastguard Workersend "extaddr\r\n"
195*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
196*cfb92d14SAndroid Build Coastguard Workersend "dataset active\r\n"
197*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
198*cfb92d14SAndroid Build Coastguard Workersend "ipaddr\r\n"
199*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
200*cfb92d14SAndroid Build Coastguard Workersend "coex\r\n"
201*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
202*cfb92d14SAndroid Build Coastguard Workersend "coap start\r\n"
203*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
204*cfb92d14SAndroid Build Coastguard Workersend "coap resource TestResource\r\n"
205*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
206*cfb92d14SAndroid Build Coastguard Workersend "coap set TestContent\r\n"
207*cfb92d14SAndroid Build Coastguard Workerexpect "Done"
208*cfb92d14SAndroid Build Coastguard Workerset timeout -1
209*cfb92d14SAndroid Build Coastguard Workerexpect eof
210*cfb92d14SAndroid Build Coastguard WorkerEOF
211*cfb92d14SAndroid Build Coastguard Worker
212*cfb92d14SAndroid Build Coastguard Worker    sleep 5
213*cfb92d14SAndroid Build Coastguard Worker
214*cfb92d14SAndroid Build Coastguard Worker    # wait until the node becomes leader
215*cfb92d14SAndroid Build Coastguard Worker    timeout_run 10 wait_for_leader
216*cfb92d14SAndroid Build Coastguard Worker
217*cfb92d14SAndroid Build Coastguard Worker    # wait coap service start
218*cfb92d14SAndroid Build Coastguard Worker    sleep 5
219*cfb92d14SAndroid Build Coastguard Worker
220*cfb92d14SAndroid Build Coastguard Worker    netstat -an | grep -q 5683 || die 'Application CoAP port is not available!'
221*cfb92d14SAndroid Build Coastguard Worker
222*cfb92d14SAndroid Build Coastguard Worker    extaddr=$(grep -ao -A +1 'extaddr' $OT_OUTPUT | tail -n1 | tr -d '\r\n\0')
223*cfb92d14SAndroid Build Coastguard Worker    echo "Extended address is: ${extaddr}"
224*cfb92d14SAndroid Build Coastguard Worker
225*cfb92d14SAndroid Build Coastguard Worker    prefix=$(grep -ao 'Mesh Local Prefix: [0-9a-f:]\+' $OT_OUTPUT | cut -d: -f2- | tr -d ' \r\n')
226*cfb92d14SAndroid Build Coastguard Worker    LEADER_ALOC="${prefix}ff:fe00:fc00"
227*cfb92d14SAndroid Build Coastguard Worker
228*cfb92d14SAndroid Build Coastguard Worker    # skip testing CoAP for https://github.com/openthread/openthread/issues/6363
229*cfb92d14SAndroid Build Coastguard Worker    [[ $OSTYPE == "linux-gnu"* ]] || return 0
230*cfb92d14SAndroid Build Coastguard Worker
231*cfb92d14SAndroid Build Coastguard Worker    if [[ ${OT_DAEMON} == 'on' ]]; then
232*cfb92d14SAndroid Build Coastguard Worker        sudo killall -9 expect || true
233*cfb92d14SAndroid Build Coastguard Worker        sudo killall -9 ot-ctl || true
234*cfb92d14SAndroid Build Coastguard Worker        NETIF_INDEX=$(ip link show "${NETIF_NAME}" | cut -f 1 -d ":" | head -n 1)
235*cfb92d14SAndroid Build Coastguard Worker        sudo PATH="$(dirname "${OT_CTL_PATH}"):${PATH}" \
236*cfb92d14SAndroid Build Coastguard Worker            python3 "$PWD/tests/scripts/misc/test_multicast_join.py" "${NETIF_INDEX}" "${NETIF_NAME}" \
237*cfb92d14SAndroid Build Coastguard Worker            || die 'multicast group join failed'
238*cfb92d14SAndroid Build Coastguard Worker    fi
239*cfb92d14SAndroid Build Coastguard Worker
240*cfb92d14SAndroid Build Coastguard Worker    # Retrievie test resource through application CoAP
241*cfb92d14SAndroid Build Coastguard Worker    coap_response=$(coap-client -B 5 -m GET "coap://[${LEADER_ALOC}]:5683/TestResource")
242*cfb92d14SAndroid Build Coastguard Worker    echo "CoAP response is: ${coap_response}"
243*cfb92d14SAndroid Build Coastguard Worker
244*cfb92d14SAndroid Build Coastguard Worker    # Verify CoAP response contains the test content
245*cfb92d14SAndroid Build Coastguard Worker    if [[ ${coap_response} == *TestContent* ]]; then
246*cfb92d14SAndroid Build Coastguard Worker        echo 'Success'
247*cfb92d14SAndroid Build Coastguard Worker    else
248*cfb92d14SAndroid Build Coastguard Worker        die 'Failed to access application CoAP'
249*cfb92d14SAndroid Build Coastguard Worker    fi
250*cfb92d14SAndroid Build Coastguard Worker
251*cfb92d14SAndroid Build Coastguard Worker    # Retrievie extended address through network diagnostic get
252*cfb92d14SAndroid Build Coastguard Worker    coap_response=$(echo -n '120100' | xxd -r -p | coap-client -B 5 -m POST "coap://[${LEADER_ALOC}]:61631/d/dg" -f-)
253*cfb92d14SAndroid Build Coastguard Worker
254*cfb92d14SAndroid Build Coastguard Worker    # Verify Tmf CoAP is blocked
255*cfb92d14SAndroid Build Coastguard Worker    if [[ -z ${coap_response} ]]; then
256*cfb92d14SAndroid Build Coastguard Worker        die 'Tmf is not blocked'
257*cfb92d14SAndroid Build Coastguard Worker    fi
258*cfb92d14SAndroid Build Coastguard Worker}
259*cfb92d14SAndroid Build Coastguard Worker
260*cfb92d14SAndroid Build Coastguard Workermain()
261*cfb92d14SAndroid Build Coastguard Worker{
262*cfb92d14SAndroid Build Coastguard Worker    if [[ $# == 0 ]]; then
263*cfb92d14SAndroid Build Coastguard Worker        do_build
264*cfb92d14SAndroid Build Coastguard Worker        do_check
265*cfb92d14SAndroid Build Coastguard Worker        return 0
266*cfb92d14SAndroid Build Coastguard Worker    fi
267*cfb92d14SAndroid Build Coastguard Worker
268*cfb92d14SAndroid Build Coastguard Worker    while [[ $# != 0 ]]; do
269*cfb92d14SAndroid Build Coastguard Worker        case $1 in
270*cfb92d14SAndroid Build Coastguard Worker            build)
271*cfb92d14SAndroid Build Coastguard Worker                do_build
272*cfb92d14SAndroid Build Coastguard Worker                ;;
273*cfb92d14SAndroid Build Coastguard Worker            check)
274*cfb92d14SAndroid Build Coastguard Worker                do_check
275*cfb92d14SAndroid Build Coastguard Worker                ;;
276*cfb92d14SAndroid Build Coastguard Worker            *)
277*cfb92d14SAndroid Build Coastguard Worker                echo "Unknown action: $1"
278*cfb92d14SAndroid Build Coastguard Worker                return 1
279*cfb92d14SAndroid Build Coastguard Worker                ;;
280*cfb92d14SAndroid Build Coastguard Worker        esac
281*cfb92d14SAndroid Build Coastguard Worker        shift
282*cfb92d14SAndroid Build Coastguard Worker    done
283*cfb92d14SAndroid Build Coastguard Worker}
284*cfb92d14SAndroid Build Coastguard Worker
285*cfb92d14SAndroid Build Coastguard Workermain "$@"
286