Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / ot-br-posix / repo / tests / dbus / test-client
1 #!/bin/bash
2 #
3 #  Copyright (c) 2020, 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 # Test build and run otbr dbus server
30 #
31
32 set -euxo pipefail
33
34 readonly OTBR_DBUS_SERVER_CONF=otbr-test-agent.conf
35
36 on_exit()
37 {
38     local status=$?
39
40     sudo killall otbr-agent || true
41     sudo killall expect || true
42     sudo killall ot-cli-ftd || true
43     sudo killall ot-cli-mtd || true
44     sudo rm "/etc/dbus-1/system.d/${OTBR_DBUS_SERVER_CONF}" || true
45
46     grep -iE 'ot-cli|otbr' </var/log/syslog
47
48     return "${status}"
49 }
50
51 main()
52 {
53     sudo rm -rf tmp
54     sudo install -m 644 "${CMAKE_BINARY_DIR}"/src/agent/otbr-agent.conf /etc/dbus-1/system.d/"${OTBR_DBUS_SERVER_CONF}"
55     sudo service dbus reload
56     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"
57     sudo "${CMAKE_BINARY_DIR}"/src/agent/otbr-agent -d7 -I wpan0 "spinel+hdlc+forkpty://$(command -v ot-rcp)?forkpty-arg=1" &
58     trap on_exit EXIT
59     sleep 5
60     sudo "${CMAKE_BINARY_DIR}"/third_party/openthread/repo/src/posix/ot-ctl factoryreset
61     sleep 1
62     sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
63         --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
64         org.freedesktop.DBus.Introspectable.Introspect | grep JoinerStart
65     (sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
66         --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
67         io.openthread.BorderRouter.JoinerStart \
68         string:ABCDEF string:mock string:mock \
69         string:mock string:mock string:mock 2>&1 || true) | grep NotFound
70     # The ot-cli-ftd node is used to test Thread attach.
71     expect <<EOF &
72 spawn ot-cli-ftd 3
73 send "panid 0x7890\r\n"
74 expect "Done"
75 send "networkname Test1\r\n"
76 expect "Done"
77 send "channel 15\r\n"
78 expect "Done"
79 send "ifconfig up\r\n"
80 expect "Done"
81 send "thread start\r\n"
82 expect "Done"
83 sleep 5
84 send "state\r\n"
85 expect "leader"
86 expect "Done"
87 send "commissioner start\r\n"
88 expect "Commissioner: active"
89 send "commissioner joiner add * ABCDEF\r\n"
90 expect "Done"
91 expect "Joiner end"
92 send "commissioner stop\r\n"
93 wait
94 EOF
95     # The ot-cli-mtd node is used to test the child and neighbor table.
96     expect <<EOF &
97 spawn ot-cli-mtd 2
98 send "panid 0x3456\r\n"
99 expect "Done"
100 send "masterkey 00112233445566778899aabbccddeeff\r\n"
101 expect "Done"
102 send "networkname Test\r\n"
103 expect "Done"
104 send "channel 11\r\n"
105 expect "Done"
106 send "ifconfig up\r\n"
107 expect "Done"
108 send "thread start\r\n"
109 expect "Done"
110 wait
111 EOF
112     sleep 5
113     sudo dbus-send --system --dest=io.openthread.BorderRouter.wpan0 \
114         --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 \
115         io.openthread.BorderRouter.JoinerStart \
116         string:ABCDEF string:mock string:mock \
117         string:mock string:mock string:mock
118     sudo "${CMAKE_BINARY_DIR}"/third_party/openthread/repo/src/posix/ot-ctl factoryreset
119     sleep 1
120     sudo "${CMAKE_BINARY_DIR}"/tests/dbus/otbr-test-dbus-client
121 }
122
123 main "$@"