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 puts "Queued parent-to-child packets, as parent" 58 59 spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty" 60 spawn_node 2 61 62 setup_two_nodes "-" false 63 64 switch_node 2 65 set addr_2 [get_ipaddr mleid] 66 send "udp open\n" 67 expect_line "Done" 68 send "udp bind :: 11003\n" 69 expect_line "Done" 70 send "pollperiod 100000\n" 71 expect_line "Done" 72 73 sleep 1 74 75 switch_node 1 76 set addr_1 [get_ipaddr mleid] 77 send "udp open\n" 78 expect_line "Done" 79 send "udp bind :: 11004\n" 80 expect_line "Done" 81 send "udp connect $addr_2 11003\n" 82 expect_line "Done" 83 send "udp send hello\n" 84 expect_line "Done" 85 send "udp send there\n" 86 expect_line "Done" 87 88 sleep 1 89 90 exec kill $rcp_pid 91 puts "Killed $rcp_pid" 92 sleep 1 93 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &] 94 puts "RCP PID: $rcp_pid" 95 96 sleep 1 97 98 switch_node 2 99 send "pollperiod 1000\n" 100 expect_line "Done" 101 expect "5 bytes from $addr_1 11004 hello" 102 expect "5 bytes from $addr_1 11004 there" 103 104 dispose_all 105 106 107 puts "Queued parent-to-child packets, as child" 108 109 exec kill $rcp_pid 110 puts "Killed $rcp_pid" 111 sleep 1 112 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 2 < $radio_pty > $radio_pty &] 113 puts "RCP PID: $rcp_pid" 114 115 spawn_node 1 116 spawn_node 2 "rcp" "spinel+hdlc_uart://$host_pty" 117 118 setup_two_nodes "-" false 119 120 switch_node 2 121 set addr_2 [get_ipaddr mleid] 122 send "udp open\n" 123 expect_line "Done" 124 send "udp bind :: 11003\n" 125 expect_line "Done" 126 send "pollperiod 100000\n" 127 expect_line "Done" 128 129 sleep 1 130 131 switch_node 1 132 set addr_1 [get_ipaddr mleid] 133 send "udp open\n" 134 expect_line "Done" 135 send "udp bind :: 11004\n" 136 expect_line "Done" 137 send "udp connect $addr_2 11003\n" 138 expect_line "Done" 139 send "udp send hello\n" 140 expect_line "Done" 141 142 sleep 1 143 144 exec kill $rcp_pid 145 puts "Killed $rcp_pid" 146 sleep 1 147 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 2 < $radio_pty > $radio_pty &] 148 puts "RCP PID: $rcp_pid" 149 150 sleep 1 151 152 switch_node 2 153 send "pollperiod 1000\n" 154 expect_line "Done" 155 expect "5 bytes from $addr_1 11004 hello" 156 157 dispose_all 158 159 exec kill $rcp_pid 160 puts "Killed $rcp_pid" 161 sleep 1 162 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &] 163 puts "RCP PID: $rcp_pid" 164 165 166 puts "Many children, queued child-to-child packets" 167 168 spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty" 169 setup_leader 170 set addr(1) [get_ipaddr mleid] 171 send "udp open\n" 172 expect_line "Done" 173 send "udp bind :: 11004\n" 174 expect_line "Done" 175 176 set max_children 10 177 for {set i 2} {$i <= $max_children + 1} {incr i} { 178 spawn_node $i 179 setup_node $i "-" 180 switch_node $i 181 set addr($i) [get_ipaddr mleid] 182 send "udp open\n" 183 expect_line "Done" 184 send "udp bind :: 11003\n" 185 expect_line "Done" 186 send "pollperiod 100000\n" 187 expect_line "Done" 188 } 189 190 sleep 1 191 192 switch_node 1 193 for {set i 2} {$i <= $max_children + 1} {incr i} { 194 send "udp send $addr($i) 11003 hello\n" 195 expect_line "Done" 196 } 197 198 sleep 1 199 200 exec kill $rcp_pid 201 puts "Killed $rcp_pid" 202 sleep 1 203 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &] 204 puts "RCP PID: $rcp_pid" 205 206 sleep 1 207 208 for {set i 7} {$i <= 9} {incr i} { 209 switch_node $i 210 send "pollperiod 1000\n" 211 expect_line "Done" 212 expect "5 bytes from $addr(1) 11004 hello" 213 } 214 215 switch_node 4 216 send "udp send $addr(5) 11003 hello_from_node_4\n" 217 expect_line "Done" 218 if {$::env(THREAD_VERSION) != "1.1"} { 219 expect "5 bytes from $addr(1) 11004 hello" 220 } 221 222 sleep 1 223 224 exec kill $rcp_pid 225 puts "Killed $rcp_pid" 226 sleep 1 227 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &] 228 puts "RCP PID: $rcp_pid" 229 230 sleep 1 231 232 switch_node 5 233 send "pollperiod 1000\n" 234 expect_line "Done" 235 expect "17 bytes from $addr(4) 11003 hello_from_node_4" 236 237 dispose_all 238 239 240 puts "While energy scanning" 241 242 spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty" 243 setup_default_network 244 attach 245 246 send "scan energy 100\n" 247 expect "| Ch | RSSI |" 248 expect "+----+------+" 249 250 sleep 1 251 252 exec kill $rcp_pid 253 puts "Killed $rcp_pid" 254 sleep 1 255 set rcp_pid [exec $::env(OT_SIMULATION_APPS)/ncp/ot-rcp 1 < $radio_pty > $radio_pty &] 256 puts "RCP PID: $rcp_pid" 257 258 sleep 1 259 260 for {set i 11} {$i <= 26} {incr i} { 261 expect -re "\\| +$i \\| +-?\\d+ \\|" 262 } 263 expect_line "Done" 264 265 dispose_all 266} finally { 267 exec kill $rcp_pid 268 exec kill $socat_pid 269} 270