xref: /aosp_15_r20/external/ot-br-posix/tests/dbus/test-client (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
1*4a64e381SAndroid Build Coastguard Worker#!/bin/bash
2*4a64e381SAndroid Build Coastguard Worker#
3*4a64e381SAndroid Build Coastguard Worker#  Copyright (c) 2020, 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 build and run otbr dbus server
30*4a64e381SAndroid Build Coastguard Worker#
31*4a64e381SAndroid Build Coastguard Worker
32*4a64e381SAndroid Build Coastguard Workerset -euxo pipefail
33*4a64e381SAndroid Build Coastguard Worker
34*4a64e381SAndroid Build Coastguard WorkerOTBR_DBUS_SERVER_CONF=otbr-test-agent.conf
35*4a64e381SAndroid Build Coastguard Workerreadonly OTBR_DBUS_SERVER_CONF
36*4a64e381SAndroid Build Coastguard Worker
37*4a64e381SAndroid Build Coastguard Workeron_exit()
38*4a64e381SAndroid Build Coastguard Worker{
39*4a64e381SAndroid Build Coastguard Worker    local status=$?
40*4a64e381SAndroid Build Coastguard Worker
41*4a64e381SAndroid Build Coastguard Worker    sudo systemctl stop test-otbr-agent || true
42*4a64e381SAndroid Build Coastguard Worker    if [[ -v LEADER_PID ]]; then
43*4a64e381SAndroid Build Coastguard Worker        kill "$LEADER_PID" || true
44*4a64e381SAndroid Build Coastguard Worker    fi
45*4a64e381SAndroid Build Coastguard Worker    if [[ -v CHILD_PID ]]; then
46*4a64e381SAndroid Build Coastguard Worker        kill "$CHILD_PID" || true
47*4a64e381SAndroid Build Coastguard Worker    fi
48*4a64e381SAndroid Build Coastguard Worker    sudo killall dbus-monitor || true
49*4a64e381SAndroid Build Coastguard Worker    sudo rm "/etc/dbus-1/system.d/${OTBR_DBUS_SERVER_CONF}" || true
50*4a64e381SAndroid Build Coastguard Worker
51*4a64e381SAndroid Build Coastguard Worker    sed -n "/$TEST_HELLO/,\$p" /var/log/syslog | grep 'ot-cli\|otbr'
52*4a64e381SAndroid Build Coastguard Worker
53*4a64e381SAndroid Build Coastguard Worker    return "${status}"
54*4a64e381SAndroid Build Coastguard Worker}
55*4a64e381SAndroid Build Coastguard Worker
56*4a64e381SAndroid Build Coastguard Workerot_ctl()
57*4a64e381SAndroid Build Coastguard Worker{
58*4a64e381SAndroid Build Coastguard Worker    sudo "${CMAKE_BINARY_DIR}"/third_party/openthread/repo/src/posix/ot-ctl "$@"
59*4a64e381SAndroid Build Coastguard Worker}
60*4a64e381SAndroid Build Coastguard Worker
61*4a64e381SAndroid Build Coastguard Workerotbr_factoryreset()
62*4a64e381SAndroid Build Coastguard Worker{
63*4a64e381SAndroid Build Coastguard Worker    ot_ctl factoryreset
64*4a64e381SAndroid Build Coastguard Worker    timeout 2 bash -c "while ! ot_ctl state; do sleep 1; done"
65*4a64e381SAndroid Build Coastguard Worker}
66*4a64e381SAndroid Build Coastguard Worker
67*4a64e381SAndroid Build Coastguard Workerscan_meshcop_service()
68*4a64e381SAndroid Build Coastguard Worker{
69*4a64e381SAndroid Build Coastguard Worker    if command -v dns-sd; then
70*4a64e381SAndroid Build Coastguard Worker        timeout 5 dns-sd -Z _meshcop._udp local. || true
71*4a64e381SAndroid Build Coastguard Worker    else
72*4a64e381SAndroid Build Coastguard Worker        avahi-browse -aprt || true
73*4a64e381SAndroid Build Coastguard Worker    fi
74*4a64e381SAndroid Build Coastguard Worker}
75*4a64e381SAndroid Build Coastguard Worker
76*4a64e381SAndroid Build Coastguard Workerupdate_meshcop_txt_and_check()
77*4a64e381SAndroid Build Coastguard Worker{
78*4a64e381SAndroid Build Coastguard Worker    sudo gdbus call --system --dest io.openthread.BorderRouter.wpan0 --method=io.openthread.BorderRouter.UpdateVendorMeshCopTxtEntries --object-path /io/openthread/BorderRouter/wpan0 "[('nn',[97])]" || true
79*4a64e381SAndroid Build Coastguard Worker    sleep 5
80*4a64e381SAndroid Build Coastguard Worker    service="$(scan_meshcop_service)"
81*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "nn=OpenThread" <<<"${service}"
82*4a64e381SAndroid Build Coastguard Worker
83*4a64e381SAndroid Build Coastguard Worker    sudo gdbus call --system --dest io.openthread.BorderRouter.wpan0 --method=io.openthread.BorderRouter.UpdateVendorMeshCopTxtEntries --object-path /io/openthread/BorderRouter/wpan0 "[('vn',[118,101,110,100,111,114])]"
84*4a64e381SAndroid Build Coastguard Worker    sleep 5
85*4a64e381SAndroid Build Coastguard Worker    service="$(scan_meshcop_service)"
86*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "vn=vendor" <<<"${service}"
87*4a64e381SAndroid Build Coastguard Worker
88*4a64e381SAndroid Build Coastguard Worker    sudo gdbus call --system --dest io.openthread.BorderRouter.wpan0 --method=io.openthread.BorderRouter.UpdateVendorMeshCopTxtEntries --object-path /io/openthread/BorderRouter/wpan0 "[]"
89*4a64e381SAndroid Build Coastguard Worker    sleep 5
90*4a64e381SAndroid Build Coastguard Worker    service="$(scan_meshcop_service)"
91*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "vn=OpenThread" <<<"${service}"
92*4a64e381SAndroid Build Coastguard Worker
93*4a64e381SAndroid Build Coastguard Worker    sudo gdbus call --system --dest io.openthread.BorderRouter.wpan0 --method=io.openthread.BorderRouter.UpdateVendorMeshCopTxtEntries --object-path /io/openthread/BorderRouter/wpan0 "[('A',[97,98,99]),('B',[49,50])]"
94*4a64e381SAndroid Build Coastguard Worker    sleep 5
95*4a64e381SAndroid Build Coastguard Worker    service="$(scan_meshcop_service)"
96*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "A=abc" <<<"${service}"
97*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "B=12" <<<"${service}"
98*4a64e381SAndroid Build Coastguard Worker
99*4a64e381SAndroid Build Coastguard Worker    sudo gdbus call --system --dest io.openthread.BorderRouter.wpan0 --method=io.openthread.BorderRouter.Reset --object-path /io/openthread/BorderRouter/wpan0
100*4a64e381SAndroid Build Coastguard Worker    sleep 5
101*4a64e381SAndroid Build Coastguard Worker    service="$(scan_meshcop_service)"
102*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "A=abc" <<<"${service}"
103*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "B=12" <<<"${service}"
104*4a64e381SAndroid Build Coastguard Worker
105*4a64e381SAndroid Build Coastguard Worker    sudo gdbus call --system --dest io.openthread.BorderRouter.wpan0 --method=io.openthread.BorderRouter.UpdateVendorMeshCopTxtEntries --object-path /io/openthread/BorderRouter/wpan0 "[('A',[97,99]),('B',[49,50])]"
106*4a64e381SAndroid Build Coastguard Worker    sleep 5
107*4a64e381SAndroid Build Coastguard Worker    service="$(scan_meshcop_service)"
108*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "A=ac" <<<"${service}"
109*4a64e381SAndroid Build Coastguard Worker    grep --binary-files=text "B=12" <<<"${service}"
110*4a64e381SAndroid Build Coastguard Worker}
111*4a64e381SAndroid Build Coastguard Worker
112*4a64e381SAndroid Build Coastguard Workertest_get_properties()
113*4a64e381SAndroid Build Coastguard Worker{
114*4a64e381SAndroid Build Coastguard Worker    local ot_version
115*4a64e381SAndroid Build Coastguard Worker    local rcp_version
116*4a64e381SAndroid Build Coastguard Worker    local thread_version
117*4a64e381SAndroid Build Coastguard Worker
118*4a64e381SAndroid Build Coastguard Worker    ot_version=$(ot_ctl version | grep -oE '^OPENTHREAD.*$' | tr -d '\r\n')
119*4a64e381SAndroid Build Coastguard Worker    rcp_version=$(ot_ctl rcp version | grep -oE '^OPENTHREAD.*$' | tr -d '\r\n')
120*4a64e381SAndroid Build Coastguard Worker    thread_version=$(ot_ctl thread version | grep -oE '^[0-9]+' | tr -d '\r\n')
121*4a64e381SAndroid Build Coastguard Worker
122*4a64e381SAndroid Build Coastguard Worker    local property_names="array:string:"
123*4a64e381SAndroid Build Coastguard Worker    property_names+="OtHostVersion,"
124*4a64e381SAndroid Build Coastguard Worker    property_names+="OtRcpVersion,"
125*4a64e381SAndroid Build Coastguard Worker    property_names+="ThreadVersion,"
126*4a64e381SAndroid Build Coastguard Worker    property_names+="Uptime,"
127*4a64e381SAndroid Build Coastguard Worker    property_names+="RadioCoexMetrics,"
128*4a64e381SAndroid Build Coastguard Worker    property_names+="RadioSpinelMetrics,"
129*4a64e381SAndroid Build Coastguard Worker    property_names+="RcpInterfaceMetrics"
130*4a64e381SAndroid Build Coastguard Worker    local result_pattern="\s+variant\s+string\s+\"${ot_version}\""
131*4a64e381SAndroid Build Coastguard Worker    result_pattern+="\s+variant\s+string\s+\"${rcp_version}\""
132*4a64e381SAndroid Build Coastguard Worker    result_pattern+="\s+variant\s+uint16\s+${thread_version}"
133*4a64e381SAndroid Build Coastguard Worker    result_pattern+="\s+variant\s+uint64\s+\d+"                                                 # Uptime
134*4a64e381SAndroid Build Coastguard Worker    result_pattern+="\s+variant\s+struct\s+{(\s+uint32\s+\d+){18}\s+boolean\s+(true|false)\s+}" # RadioCoexMetrics
135*4a64e381SAndroid Build Coastguard Worker    result_pattern+="\s+variant\s+struct\s+{(\s+uint32\s+\d+){4}\s+}"                           # RadioSpinelMetrics
136*4a64e381SAndroid Build Coastguard Worker    result_pattern+="\s+variant\s+struct\s+{\s+byte\s+\d+(\s+uint64\s+\d+){7}\s+}"              # RcpInterfaceMetrics
137*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 --print-reply \
138*4a64e381SAndroid Build Coastguard Worker        /io/openthread/BorderRouter/wpan0 \
139*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.GetProperties \
140*4a64e381SAndroid Build Coastguard Worker        "${property_names}" \
141*4a64e381SAndroid Build Coastguard Worker        | grep -oPz "${result_pattern}"
142*4a64e381SAndroid Build Coastguard Worker}
143*4a64e381SAndroid Build Coastguard Worker
144*4a64e381SAndroid Build Coastguard Workerotbr_agent_service_start()
145*4a64e381SAndroid Build Coastguard Worker{
146*4a64e381SAndroid Build Coastguard Worker    local -r EXIT_CODE_SHOULD_RESTART=7
147*4a64e381SAndroid Build Coastguard Worker
148*4a64e381SAndroid Build Coastguard Worker    sudo systemd-run --collect --no-ask-password -u test-otbr-agent -p "RestartForceExitStatus=$EXIT_CODE_SHOULD_RESTART" "${CMAKE_BINARY_DIR}"/src/agent/otbr-agent -d7 -I wpan0 -B lo "spinel+hdlc+forkpty://$(command -v ot-rcp)?forkpty-arg=1"
149*4a64e381SAndroid Build Coastguard Worker    timeout 2 bash -c "while ! ot_ctl state; do sleep 1; done"
150*4a64e381SAndroid Build Coastguard Worker}
151*4a64e381SAndroid Build Coastguard Worker
152*4a64e381SAndroid Build Coastguard Workersuite_setup()
153*4a64e381SAndroid Build Coastguard Worker{
154*4a64e381SAndroid Build Coastguard Worker    TEST_HELLO="$(basename "$0") started at $(date +%s)"
155*4a64e381SAndroid Build Coastguard Worker    logger "$TEST_HELLO"
156*4a64e381SAndroid Build Coastguard Worker    [[ -f /etc/dbus-1/system.d/"${OTBR_DBUS_SERVER_CONF}" ]] || {
157*4a64e381SAndroid Build Coastguard Worker        local CONFIG_FILE_PATH="third_party/openthread/repo/src/posix/platform"
158*4a64e381SAndroid Build Coastguard Worker        mkdir -p "${PWD}/${CONFIG_FILE_PATH}" && cp "${PROJECT_SOURCE_DIR}/${CONFIG_FILE_PATH}/openthread.conf.example" "${PWD}/${CONFIG_FILE_PATH}"
159*4a64e381SAndroid Build Coastguard Worker
160*4a64e381SAndroid Build Coastguard Worker        sudo rm -rf tmp
161*4a64e381SAndroid Build Coastguard Worker        sudo install -m 644 "${CMAKE_BINARY_DIR}"/src/agent/otbr-agent.conf /etc/dbus-1/system.d/"${OTBR_DBUS_SERVER_CONF}"
162*4a64e381SAndroid Build Coastguard Worker        sudo service dbus reload
163*4a64e381SAndroid Build Coastguard Worker    }
164*4a64e381SAndroid Build Coastguard Worker    trap on_exit EXIT
165*4a64e381SAndroid Build Coastguard Worker
166*4a64e381SAndroid Build Coastguard Worker    sudo systemctl start avahi-daemon
167*4a64e381SAndroid Build Coastguard Worker
168*4a64e381SAndroid Build Coastguard Worker    export -f ot_ctl
169*4a64e381SAndroid Build Coastguard Worker}
170*4a64e381SAndroid Build Coastguard Worker
171*4a64e381SAndroid Build Coastguard Workertest_ready_signal()
172*4a64e381SAndroid Build Coastguard Worker{
173*4a64e381SAndroid Build Coastguard Worker    # Because we do want to run the command as root but redirect as the normal user.
174*4a64e381SAndroid Build Coastguard Worker    # shellcheck disable=SC2024
175*4a64e381SAndroid Build Coastguard Worker    sudo expect <<EOF
176*4a64e381SAndroid Build Coastguard Workerspawn dbus-monitor --system path=/io/openthread/BorderRouter/wpan0,member=Ready
177*4a64e381SAndroid Build Coastguard Workerset dbus_monitor \$spawn_id
178*4a64e381SAndroid Build Coastguard Workerspawn ${CMAKE_BINARY_DIR}/src/agent/otbr-agent -d7 -I wpan0 -B lo spinel+hdlc+forkpty://$(command -v ot-rcp)?forkpty-arg=1
179*4a64e381SAndroid Build Coastguard Workerset spawn_id \$dbus_monitor
180*4a64e381SAndroid Build Coastguard Workerexpect {
181*4a64e381SAndroid Build Coastguard Worker    "member=Ready" { exit }
182*4a64e381SAndroid Build Coastguard Worker    timeout { error "Failed to find Ready signal\n" }
183*4a64e381SAndroid Build Coastguard Worker}
184*4a64e381SAndroid Build Coastguard WorkerEOF
185*4a64e381SAndroid Build Coastguard Worker    timeout 2 bash -c "while pidof ot-rcp; do logger -t otbr-test-dbus-client; sleep 1; done"
186*4a64e381SAndroid Build Coastguard Worker}
187*4a64e381SAndroid Build Coastguard Worker
188*4a64e381SAndroid Build Coastguard Workermain()
189*4a64e381SAndroid Build Coastguard Worker{
190*4a64e381SAndroid Build Coastguard Worker    suite_setup
191*4a64e381SAndroid Build Coastguard Worker
192*4a64e381SAndroid Build Coastguard Worker    sudo "${CMAKE_BINARY_DIR}"/src/agent/otbr-agent -d7 -I wpan0 --radio-version "spinel+hdlc+forkpty://$(command -v ot-rcp)?forkpty-arg=1" | grep "OPENTHREAD"
193*4a64e381SAndroid Build Coastguard Worker
194*4a64e381SAndroid Build Coastguard Worker    test_ready_signal
195*4a64e381SAndroid Build Coastguard Worker
196*4a64e381SAndroid Build Coastguard Worker    otbr_agent_service_start
197*4a64e381SAndroid Build Coastguard Worker
198*4a64e381SAndroid Build Coastguard Worker    otbr_factoryreset
199*4a64e381SAndroid Build Coastguard Worker
200*4a64e381SAndroid Build Coastguard Worker    test_get_properties
201*4a64e381SAndroid Build Coastguard Worker
202*4a64e381SAndroid Build Coastguard Worker    ot_ctl ifconfig up
203*4a64e381SAndroid Build Coastguard Worker    ot_ctl thread start
204*4a64e381SAndroid Build Coastguard Worker
205*4a64e381SAndroid Build Coastguard Worker    update_meshcop_txt_and_check
206*4a64e381SAndroid Build Coastguard Worker
207*4a64e381SAndroid Build Coastguard Worker    otbr_factoryreset
208*4a64e381SAndroid Build Coastguard Worker
209*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
210*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
211*4a64e381SAndroid Build Coastguard Worker        org.freedesktop.DBus.Introspectable.Introspect | grep JoinerStart
212*4a64e381SAndroid Build Coastguard Worker    (sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
213*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
214*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.JoinerStart \
215*4a64e381SAndroid Build Coastguard Worker        string:ABCDEF string:mock string:mock \
216*4a64e381SAndroid Build Coastguard Worker        string:mock string:mock string:mock 2>&1 || true) | grep NotFound
217*4a64e381SAndroid Build Coastguard Worker
218*4a64e381SAndroid Build Coastguard Worker    # Verify Eui64 property. 0x18b4300000000001 = 1780100529276321793
219*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 --print-reply /io/openthread/BorderRouter/wpan0 org.freedesktop.DBus.Properties.Get string:io.openthread.BorderRouter string:Eui64 \
220*4a64e381SAndroid Build Coastguard Worker        | grep '1780100529276321793'
221*4a64e381SAndroid Build Coastguard Worker
222*4a64e381SAndroid Build Coastguard Worker    # The ot-cli-ftd node is used to test Thread attach.
223*4a64e381SAndroid Build Coastguard Worker    expect <<EOF &
224*4a64e381SAndroid Build Coastguard Workerspawn ot-cli-ftd 3
225*4a64e381SAndroid Build Coastguard Workersend "dataset init new\r\n"
226*4a64e381SAndroid Build Coastguard Workerexpect "Done"
227*4a64e381SAndroid Build Coastguard Workersend "dataset panid 0x7890\r\n"
228*4a64e381SAndroid Build Coastguard Workerexpect "Done"
229*4a64e381SAndroid Build Coastguard Workersend "dataset networkname Test1\r\n"
230*4a64e381SAndroid Build Coastguard Workerexpect "Done"
231*4a64e381SAndroid Build Coastguard Workersend "dataset channel 15\r\n"
232*4a64e381SAndroid Build Coastguard Workerexpect "Done"
233*4a64e381SAndroid Build Coastguard Workersend "dataset commit active\r\n"
234*4a64e381SAndroid Build Coastguard Workerexpect "Done"
235*4a64e381SAndroid Build Coastguard Workersend "ifconfig up\r\n"
236*4a64e381SAndroid Build Coastguard Workerexpect "Done"
237*4a64e381SAndroid Build Coastguard Workersend "thread start\r\n"
238*4a64e381SAndroid Build Coastguard Workerexpect "Done"
239*4a64e381SAndroid Build Coastguard Workersleep 12
240*4a64e381SAndroid Build Coastguard Workersend "state\r\n"
241*4a64e381SAndroid Build Coastguard Workerexpect "leader"
242*4a64e381SAndroid Build Coastguard Workerexpect "Done"
243*4a64e381SAndroid Build Coastguard Workersend "commissioner start\r\n"
244*4a64e381SAndroid Build Coastguard Workerexpect "Commissioner: active"
245*4a64e381SAndroid Build Coastguard Workersend "commissioner joiner add * ABCDEF\r\n"
246*4a64e381SAndroid Build Coastguard Workerexpect "Done"
247*4a64e381SAndroid Build Coastguard Workerexpect "Joiner end"
248*4a64e381SAndroid Build Coastguard Workersend "commissioner stop\r\n"
249*4a64e381SAndroid Build Coastguard Workerset timeout -1
250*4a64e381SAndroid Build Coastguard Workerexpect eof
251*4a64e381SAndroid Build Coastguard WorkerEOF
252*4a64e381SAndroid Build Coastguard Worker    LEADER_PID=$!
253*4a64e381SAndroid Build Coastguard Worker
254*4a64e381SAndroid Build Coastguard Worker    # The ot-cli-mtd node is used to test the child and neighbor table.
255*4a64e381SAndroid Build Coastguard Worker    expect <<EOF &
256*4a64e381SAndroid Build Coastguard Workerspawn ot-cli-mtd 2
257*4a64e381SAndroid Build Coastguard Workersend "dataset clear"
258*4a64e381SAndroid Build Coastguard Workerexpect "Done"
259*4a64e381SAndroid Build Coastguard Workersend "dataset panid 0x3456\r\n"
260*4a64e381SAndroid Build Coastguard Workerexpect "Done"
261*4a64e381SAndroid Build Coastguard Workersend "dataset networkkey 00112233445566778899aabbccddeeff\r\n"
262*4a64e381SAndroid Build Coastguard Workerexpect "Done"
263*4a64e381SAndroid Build Coastguard Workersend "dataset networkname Test\r\n"
264*4a64e381SAndroid Build Coastguard Workerexpect "Done"
265*4a64e381SAndroid Build Coastguard Workersend "dataset channel 11\r\n"
266*4a64e381SAndroid Build Coastguard Workerexpect "Done"
267*4a64e381SAndroid Build Coastguard Workersend "dataset commit active\r\n"
268*4a64e381SAndroid Build Coastguard Workerexpect "Done"
269*4a64e381SAndroid Build Coastguard Workersend "ifconfig up\r\n"
270*4a64e381SAndroid Build Coastguard Workerexpect "Done"
271*4a64e381SAndroid Build Coastguard Workersend "thread start\r\n"
272*4a64e381SAndroid Build Coastguard Workerexpect "Done"
273*4a64e381SAndroid Build Coastguard Workerset timeout -1
274*4a64e381SAndroid Build Coastguard Workerexpect eof
275*4a64e381SAndroid Build Coastguard WorkerEOF
276*4a64e381SAndroid Build Coastguard Worker    CHILD_PID=$!
277*4a64e381SAndroid Build Coastguard Worker
278*4a64e381SAndroid Build Coastguard Worker    sleep 12
279*4a64e381SAndroid Build Coastguard Worker    ot_ctl routerselectionjitter 1
280*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
281*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
282*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.JoinerStart \
283*4a64e381SAndroid Build Coastguard Worker        string:ABCDEF string:mock string:mock \
284*4a64e381SAndroid Build Coastguard Worker        string:mock string:mock string:mock
285*4a64e381SAndroid Build Coastguard Worker    sleep 10
286*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep router
287*4a64e381SAndroid Build Coastguard Worker
288*4a64e381SAndroid Build Coastguard Worker    result_pattern="array\s+\[\s+variant\s+array\s+\[\s+struct\s+{\s+"
289*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint64\s+\d+\s+"
290*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint32\s+\d+\s+"
291*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint16\s+\d+\s+"
292*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint32\s+\d+\s+"
293*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint32\s+\d+\s+"
294*4a64e381SAndroid Build Coastguard Worker    result_pattern+="byte\s+\d+\s+"
295*4a64e381SAndroid Build Coastguard Worker    result_pattern+="byte\s+\d+\s+"
296*4a64e381SAndroid Build Coastguard Worker    result_pattern+="byte\s+\d+\s+"
297*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint16\s+\d+\s+"
298*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint16\s+\d+\s+"
299*4a64e381SAndroid Build Coastguard Worker    result_pattern+="uint16\s+\d+\s+"
300*4a64e381SAndroid Build Coastguard Worker    result_pattern+="boolean\s+(true|false)\s+"
301*4a64e381SAndroid Build Coastguard Worker    result_pattern+="boolean\s+(true|false)\s+"
302*4a64e381SAndroid Build Coastguard Worker    result_pattern+="boolean\s+(true|false)\s+"
303*4a64e381SAndroid Build Coastguard Worker    result_pattern+="boolean\s+(true|false)\s+"
304*4a64e381SAndroid Build Coastguard Worker    result_pattern+="}\s+\]\s+\]"
305*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 --print-reply \
306*4a64e381SAndroid Build Coastguard Worker        /io/openthread/BorderRouter/wpan0 \
307*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.GetProperties \
308*4a64e381SAndroid Build Coastguard Worker        "array:string:NeighborTable" \
309*4a64e381SAndroid Build Coastguard Worker        | grep -oPz "${result_pattern}"
310*4a64e381SAndroid Build Coastguard Worker
311*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
312*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
313*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.Detach
314*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep disabled
315*4a64e381SAndroid Build Coastguard Worker
316*4a64e381SAndroid Build Coastguard Worker    otbr_factoryreset
317*4a64e381SAndroid Build Coastguard Worker
318*4a64e381SAndroid Build Coastguard Worker    sudo "${CMAKE_BINARY_DIR}"/tests/dbus/otbr-test-dbus-client
319*4a64e381SAndroid Build Coastguard Worker
320*4a64e381SAndroid Build Coastguard Worker    otbr_factoryreset
321*4a64e381SAndroid Build Coastguard Worker
322*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
323*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
324*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.Attach \
325*4a64e381SAndroid Build Coastguard Worker        array:byte: \
326*4a64e381SAndroid Build Coastguard Worker        uint16:0xffff \
327*4a64e381SAndroid Build Coastguard Worker        string:OpenThread \
328*4a64e381SAndroid Build Coastguard Worker        uint64:0xffffffffffffffff \
329*4a64e381SAndroid Build Coastguard Worker        array:byte: \
330*4a64e381SAndroid Build Coastguard Worker        uint32:0xffffffff
331*4a64e381SAndroid Build Coastguard Worker
332*4a64e381SAndroid Build Coastguard Worker    local dataset="0x0e,0x08,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x18,"
333*4a64e381SAndroid Build Coastguard Worker    dataset+="0x35,0x06,0x00,0x04,0x00,0x1f,0xff,0xe0,0x02,0x08,0xef,0x18,0xe6,0xa1,0xf3,0xd6,"
334*4a64e381SAndroid Build Coastguard Worker    dataset+="0x86,0xc4,0x07,0x08,0xfd,0x16,0x72,0x24,0xc2,0x4e,0x16,0x00,0x05,0x10,0xbe,0x3b,"
335*4a64e381SAndroid Build Coastguard Worker    dataset+="0xd2,0x44,0xae,0x6d,0x99,0x70,0x20,0xa8,0x82,0xa2,0x4a,0x80,0x40,0xe2,0x03,0x0f,"
336*4a64e381SAndroid Build Coastguard Worker    dataset+="0x4f,0x70,0x65,0x6e,0x54,0x68,0x72,0x65,0x61,0x64,0x2d,0x30,0x36,0x62,0x37,0x01,"
337*4a64e381SAndroid Build Coastguard Worker    dataset+="0x02,0x06,0xb7,0x04,0x10,0xf9,0xc9,0x1b,0x11,0x45,0x02,0x54,0x67,0xbf,0x11,0xed,"
338*4a64e381SAndroid Build Coastguard Worker    dataset+="0xf9,0x01,0x1a,0x58,0x12,0x0c,0x04,0x02,0xa0,0xff,0xf8"
339*4a64e381SAndroid Build Coastguard Worker
340*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
341*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
342*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.AttachAllNodesTo \
343*4a64e381SAndroid Build Coastguard Worker        "array:byte:${dataset}" \
344*4a64e381SAndroid Build Coastguard Worker        | grep "int64 300000"
345*4a64e381SAndroid Build Coastguard Worker
346*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset pending | grep "Active Timestamp: 2"
347*4a64e381SAndroid Build Coastguard Worker
348*4a64e381SAndroid Build Coastguard Worker    sleep 310
349*4a64e381SAndroid Build Coastguard Worker
350*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset active | grep "Active Timestamp: 2"
351*4a64e381SAndroid Build Coastguard Worker    ot_ctl networkkey | grep be3bd244ae6d997020a882a24a8040e2
352*4a64e381SAndroid Build Coastguard Worker
353*4a64e381SAndroid Build Coastguard Worker    otbr_factoryreset
354*4a64e381SAndroid Build Coastguard Worker
355*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
356*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
357*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.AttachAllNodesTo \
358*4a64e381SAndroid Build Coastguard Worker        "array:byte:${dataset}" \
359*4a64e381SAndroid Build Coastguard Worker        | grep "int64 0"
360*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep "leader"
361*4a64e381SAndroid Build Coastguard Worker
362*4a64e381SAndroid Build Coastguard Worker    ot_ctl factoryreset
363*4a64e381SAndroid Build Coastguard Worker    sleep 1
364*4a64e381SAndroid Build Coastguard Worker
365*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
366*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
367*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.Attach \
368*4a64e381SAndroid Build Coastguard Worker        array:byte: \
369*4a64e381SAndroid Build Coastguard Worker        uint16:0xffff \
370*4a64e381SAndroid Build Coastguard Worker        string:OpenThread \
371*4a64e381SAndroid Build Coastguard Worker        uint64:0xffffffffffffffff \
372*4a64e381SAndroid Build Coastguard Worker        array:byte: \
373*4a64e381SAndroid Build Coastguard Worker        uint32:0xffffffff
374*4a64e381SAndroid Build Coastguard Worker
375*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep "leader"
376*4a64e381SAndroid Build Coastguard Worker    ot_ctl thread stop
377*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep "disabled"
378*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset active | grep "Done"
379*4a64e381SAndroid Build Coastguard Worker
380*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
381*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
382*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.AttachAllNodesTo \
383*4a64e381SAndroid Build Coastguard Worker        "array:byte:${dataset}" \
384*4a64e381SAndroid Build Coastguard Worker        | grep "int64 300000"
385*4a64e381SAndroid Build Coastguard Worker
386*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep "leader"
387*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset pending | grep "Active Timestamp: 2"
388*4a64e381SAndroid Build Coastguard Worker
389*4a64e381SAndroid Build Coastguard Worker    sleep 310
390*4a64e381SAndroid Build Coastguard Worker
391*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset active | grep "Active Timestamp: 2"
392*4a64e381SAndroid Build Coastguard Worker    ot_ctl networkkey | grep be3bd244ae6d997020a882a24a8040e2
393*4a64e381SAndroid Build Coastguard Worker
394*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset init new
395*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset commit pending
396*4a64e381SAndroid Build Coastguard Worker
397*4a64e381SAndroid Build Coastguard Worker    sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
398*4a64e381SAndroid Build Coastguard Worker        --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
399*4a64e381SAndroid Build Coastguard Worker        io.openthread.BorderRouter.LeaveNetwork
400*4a64e381SAndroid Build Coastguard Worker    sleep 10
401*4a64e381SAndroid Build Coastguard Worker
402*4a64e381SAndroid Build Coastguard Worker    ot_ctl state | grep disabled
403*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset active | grep NotFound
404*4a64e381SAndroid Build Coastguard Worker    ot_ctl dataset pending | grep NotFound
405*4a64e381SAndroid Build Coastguard Worker}
406*4a64e381SAndroid Build Coastguard Worker
407*4a64e381SAndroid Build Coastguard Workermain "$@"
408