• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/expect -f
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
30source "tests/scripts/expect/_common.exp"
31source "tests/scripts/expect/_multinode.exp"
32
33
34# The expect on macOS doesn't support `try` or `file tempfile`.
35skip_on_macos
36
37file tempfile socat_out
38set socat_pid [exec socat -d -d pty,raw,echo=0 pty,raw,echo=0 >/dev/null 2>$socat_out &]
39while {true} {
40    if {[exec head -n2 $socat_out | wc -l] == 2} {
41        set radio_pty [exec head -n1 $socat_out | grep -o {/dev/.\+}]
42        set host_pty [exec head -n2 $socat_out | tail -n1 | grep -o {/dev/.\+}]
43        break
44    }
45    sleep 1
46}
47
48puts "Radio PTY: $radio_pty"
49puts "Host PTY: $host_pty"
50
51set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
52puts "RCP PID: $rcp_pid"
53
54try {
55    puts "Before enabling"
56
57    spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty"
58
59    exec kill $rcp_pid
60    puts "Killed $rcp_pid"
61    sleep 1
62    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
63    puts "RCP PID: $rcp_pid"
64
65    expect eof
66
67
68    puts "Queued parent-to-child packets, as parent"
69
70    spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty"
71    spawn_node 2
72
73    setup_two_nodes "-" false
74
75    switch_node 2
76    set addr_2 [get_ipaddr mleid]
77    send "udp open\n"
78    expect_line "Done"
79    send "udp bind :: 11003\n"
80    expect_line "Done"
81    send "pollperiod 100000\n"
82    expect_line "Done"
83
84    sleep 1
85
86    switch_node 1
87    set addr_1 [get_ipaddr mleid]
88    send "udp open\n"
89    expect_line "Done"
90    send "udp bind :: 11004\n"
91    expect_line "Done"
92    send "udp connect $addr_2 11003\n"
93    expect_line "Done"
94    send "udp send hello\n"
95    expect_line "Done"
96    send "udp send there\n"
97    expect_line "Done"
98
99    sleep 1
100
101    exec kill $rcp_pid
102    puts "Killed $rcp_pid"
103    sleep 1
104    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
105    puts "RCP PID: $rcp_pid"
106
107    sleep 1
108
109    switch_node 2
110    send "pollperiod 1000\n"
111    expect_line "Done"
112    expect "5 bytes from $addr_1 11004 hello"
113    expect "5 bytes from $addr_1 11004 there"
114
115    dispose_all
116
117
118    puts "Queued parent-to-child packets, as child"
119
120    exec kill $rcp_pid
121    puts "Killed $rcp_pid"
122    sleep 1
123    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 2 < $radio_pty > $radio_pty &]
124    puts "RCP PID: $rcp_pid"
125
126    spawn_node 1
127    spawn_node 2 "rcp" "spinel+hdlc_uart://$host_pty"
128
129    setup_two_nodes "-" false
130
131    switch_node 2
132    set addr_2 [get_ipaddr mleid]
133    send "udp open\n"
134    expect_line "Done"
135    send "udp bind :: 11003\n"
136    expect_line "Done"
137    send "pollperiod 100000\n"
138    expect_line "Done"
139
140    sleep 1
141
142    switch_node 1
143    set addr_1 [get_ipaddr mleid]
144    send "udp open\n"
145    expect_line "Done"
146    send "udp bind :: 11004\n"
147    expect_line "Done"
148    send "udp connect $addr_2 11003\n"
149    expect_line "Done"
150    send "udp send hello\n"
151    expect_line "Done"
152
153    sleep 1
154
155    exec kill $rcp_pid
156    puts "Killed $rcp_pid"
157    sleep 1
158    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 2 < $radio_pty > $radio_pty &]
159    puts "RCP PID: $rcp_pid"
160
161    sleep 1
162
163    switch_node 2
164    send "pollperiod 1000\n"
165    expect_line "Done"
166    expect "5 bytes from $addr_1 11004 hello"
167
168    dispose_all
169
170    exec kill $rcp_pid
171    puts "Killed $rcp_pid"
172    sleep 1
173    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
174    puts "RCP PID: $rcp_pid"
175
176
177    puts "Many children, queued child-to-child packets"
178
179    spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty"
180    setup_leader
181    set addr(1) [get_ipaddr mleid]
182    send "udp open\n"
183    expect_line "Done"
184    send "udp bind :: 11004\n"
185    expect_line "Done"
186
187    set max_children 10
188    for {set i 2} {$i <= $max_children + 1} {incr i} {
189        spawn_node $i
190        setup_node $i "-"
191        switch_node $i
192        set addr($i) [get_ipaddr mleid]
193        send "udp open\n"
194        expect_line "Done"
195        send "udp bind :: 11003\n"
196        expect_line "Done"
197        send "pollperiod 100000\n"
198        expect_line "Done"
199    }
200
201    sleep 1
202
203    switch_node 1
204    for {set i 2} {$i <= $max_children + 1} {incr i} {
205        send "udp send $addr($i) 11003 hello\n"
206        expect_line "Done"
207    }
208
209    sleep 1
210
211    exec kill $rcp_pid
212    puts "Killed $rcp_pid"
213    sleep 1
214    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
215    puts "RCP PID: $rcp_pid"
216
217    sleep 1
218
219    for {set i 7} {$i <= 9} {incr i} {
220        switch_node $i
221        send "pollperiod 1000\n"
222        expect_line "Done"
223        expect "5 bytes from $addr(1) 11004 hello"
224    }
225
226    switch_node 4
227    send "udp send $addr(5) 11003 hello_from_node_4\n"
228    expect_line "Done"
229    if {$::env(THREAD_VERSION) != "1.1"} {
230        expect "5 bytes from $addr(1) 11004 hello"
231    }
232
233    sleep 1
234
235    exec kill $rcp_pid
236    puts "Killed $rcp_pid"
237    sleep 1
238    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
239    puts "RCP PID: $rcp_pid"
240
241    sleep 1
242
243    switch_node 5
244    send "pollperiod 1000\n"
245    expect_line "Done"
246    expect "17 bytes from $addr(4) 11003 hello_from_node_4"
247
248    dispose_all
249
250
251    puts "While energy scanning"
252
253    spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty"
254    send "ifconfig up\n"
255    expect_line "Done"
256    send "thread start\n"
257    expect_line "Done"
258    wait_for "state" "leader"
259    expect_line "Done"
260
261    send "scan energy 100\n"
262    expect "| Ch | RSSI |"
263    expect "+----+------+"
264
265    sleep 1
266
267    exec kill $rcp_pid
268    puts "Killed $rcp_pid"
269    sleep 1
270    set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &]
271    puts "RCP PID: $rcp_pid"
272
273    sleep 1
274
275    for {set i 11} {$i <= 26} {incr i} {
276        expect -re "\\| +$i \\| +-?\\d+ \\|"
277    }
278    expect_line "Done"
279
280    dispose_all
281} finally {
282    exec kill $rcp_pid
283    exec kill $socat_pid
284}
285