Skip to content

Commit

Permalink
[expect] split and extend tests for discovery (#8832)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Duda <[email protected]>
  • Loading branch information
LuDuda authored and jwhui committed Mar 30, 2023
1 parent 7ec184d commit 1c190a4
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 125 deletions.
33 changes: 27 additions & 6 deletions tests/scripts/expect/_common.exp
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,23 @@ proc switch_node {id} {
set spawn_id $spawn_ids($id)
}

proc attach {{role "leader"}} {
send "ifconfig up\n"
expect_line "Done"
send "thread start\n"
expect_line "Done"
wait_for "state" $role
expect_line "Done"
}

proc setup_leader {} {
send "dataset init new\n"
expect_line "Done"
send "dataset networkkey 00112233445566778899aabbccddeeff\n"
expect_line "Done"
send "dataset commit active\n"
expect_line "Done"
send "ifconfig up\n"
expect_line "Done"
send "thread start\n"
expect_line "Done"
wait_for "state" "leader"
expect_line "Done"
attach
}

proc dispose_node {id} {
Expand Down Expand Up @@ -173,6 +177,23 @@ proc get_extaddr {} {
return $rval
}

proc get_extpanid {} {
send "extpanid\n"
set rval [expect_line {[0-9a-fA-F]{16}}]
expect_line "Done"

return $rval
}

proc get_panid {} {
send "panid\n"
expect -re {0x([0-9a-fA-F]{4})}
set rval $expect_out(1,string)
expect_line "Done"

return $rval
}

proc get_meshlocal_prefix {} {
send "prefix meshlocal\n"
expect -re {[\r\n ](([0-9a-fA-F]{1,4}:){3}[0-9a-fA-f]{1,4})::/64(?=[\r\n>])}
Expand Down
146 changes: 146 additions & 0 deletions tests/scripts/expect/cli-discover.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/expect -f
#
# Copyright (c) 2023, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

source "tests/scripts/expect/_common.exp"
source "tests/scripts/expect/_multinode.exp"

for {set i 1} {$i <= 5} {incr i} {
spawn_node $i
}

switch_node 1

send "dataset init new\n"
expect_line "Done"
send "dataset networkkey 00112233445566778899aabbccddeeff\n"
expect_line "Done"
send "dataset channel 12\n"
expect_line "Done"
send "dataset networkname OpenThread-ch12\n"
expect_line "Done"
send "dataset commit active\n"
expect_line "Done"
send "dataset active -x\n"
expect -re {([0-9a-f]+)[\r\n]+Done}
set dataset $expect_out(1,string)
attach

set extaddr_1 [get_extaddr]
set extpan_1 [get_extpanid]
set pan_1 [get_panid]

switch_node 2

send "dataset init new\n"
expect_line "Done"
send "dataset channel 23\n"
expect_line "Done"
send "dataset networkname OpenThread-ch23\n"
expect_line "Done"
send "dataset commit active\n"
expect_line "Done"
attach

set extaddr_2 [get_extaddr]
set extpan_2 [get_extpanid]
set pan_2 [get_panid]

switch_node 3

send "dataset set active $dataset\n"
expect_line "Done"
send "mode r\n"
expect_line "Done"
attach "child"

switch_node 4

send "dataset set active $dataset\n"
expect_line "Done"
send "mode -\n"
expect_line "Done"
attach "child"

for {set i 3} {$i <= 4} {incr i} {
switch_node $i

send "discover\n"
expect "| Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |"
expect "+------------------+------------------+------+------------------+----+-----+-----+"
wait_for "" "\\| OpenThread-ch12 +\\| $extpan_1 \\| $pan_1 \\| $extaddr_1 \\| 12 \\| +-?\\d+ \\| +\\d \\|"
wait_for "" "\\| OpenThread-ch23 +\\| $extpan_2 \\| $pan_2 \\| $extaddr_2 \\| 23 \\| +-?\\d+ \\| +\\d \\|"
wait_for "" "Done"
}

if {$::env(THREAD_VERSION) != "1.1" && $::env(OT_NODE_TYPE) == "cli"} {
send "csl channel 12\n"
expect_line "Done"
send "csl period 3125\n"
expect_line "Done"

sleep 1

send "discover\n"
expect "| Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |"
expect "+------------------+------------------+------+------------------+----+-----+-----+"
wait_for "" "\\| OpenThread-ch12 +\\| $extpan_1 \\| $pan_1 \\| $extaddr_1 \\| 12 \\| +-?\\d+ \\| +\\d \\|"
wait_for "" "\\| OpenThread-ch23 +\\| $extpan_2 \\| $pan_2 \\| $extaddr_2 \\| 23 \\| +-?\\d+ \\| +\\d \\|"
wait_for "" "Done"
}

switch_node 1
send "discover reqcallback enable\n"
expect_line "Done"

switch_node 5
send "discover\n"
expect "Error 13: InvalidState"
send "ifconfig up\n"
expect_line "Done"
send "discover 12\n"

expect "| Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |"
expect "+------------------+------------------+------+------------------+----+-----+-----+"
wait_for "" "\\| OpenThread-ch12 +\\| $extpan_1 \\| $pan_1 \\| $extaddr_1 \\| 12 \\| +-?\\d+ \\| +\\d \\|"
wait_for "" "Done"

switch_node 1
expect -re {version=\d,joiner=0}

switch_node 5
send "ifconfig up\n"
expect_line "Done"
send "joiner start 123456\n"
set timeout 10
expect "NotFound"

switch_node 1
expect -re {version=\d,joiner=1}

dispose_all
34 changes: 4 additions & 30 deletions tests/scripts/expect/cli-multicast-loop.exp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ set timeout 1
send "panid 0xface\n"
expect_line "Done"

send "ifconfig up\n"
expect_line "Done"

send "thread start\n"
expect_line "Done"

wait_for "state" "leader"
expect_line "Done"
attach

set extaddr1 [get_extaddr]

Expand All @@ -63,14 +56,8 @@ setup_default_network
send "panid 0xface\n"
expect_line "Done"

send "ifconfig up\n"
expect_line "Done"

send "thread start\n"
expect_line "Done"
attach "router"

wait_for "state" "router"
expect_line "Done"
sleep 3

get_rloc16
Expand All @@ -87,14 +74,8 @@ expect_line "Done"
send "macfilter addr denylist\n"
expect_line "Done"

send "ifconfig up\n"
expect_line "Done"

send "thread start\n"
expect_line "Done"
attach "router"

wait_for "state" "router"
expect_line "Done"
sleep 4

set extaddr3 [get_extaddr]
Expand All @@ -116,14 +97,7 @@ expect_line "Done"
send "macfilter addr allowlist\n"
expect_line "Done"

send "ifconfig up\n"
expect_line "Done"

send "thread start\n"
expect_line "Done"

wait_for "state" "child"
expect_line "Done"
attach "child"

get_rloc16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,12 @@ expect "panid"
expect -re {([0-9a-f]{4})}
set pan $expect_out(1,string)
expect_line "Done"
send "extpanid\n"
expect "extpanid"
expect -re {([0-9a-f]{16})}
set extpan $expect_out(1,string)
expect_line "Done"
expect "> "
send "networkname\n"
expect "networkname"
expect -re {[\r\n]([^\r\n]+?)[\r\n]}
set network $expect_out(1,string)
expect_line "Done"
send "channel\n"
expect "channel"
expect -re {(\d+)}
set channel $expect_out(1,string)
expect_line "Done"
send "discover reqcallback enable\n"
expect_line "Done"

switch_node 3
send "scan $channel\n"
Expand All @@ -79,28 +67,4 @@ expect "+----+------+"
expect -re "\\| +$channel \\| +-?\\d+ \\|"
expect_line "Done"

switch_node 3
send "discover\n"
expect "Error 13: InvalidState"
send "ifconfig up\n"
expect_line "Done"
send "discover $channel\n"
expect "| Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |"
expect "+------------------+------------------+------+------------------+----+-----+-----+"
wait_for "" "\\| $network +\\| $extpan \\| $pan \\| $extaddr \\| +$channel \\| +-?\\d+ \\| +\\d \\|"
wait_for "" "Done"
send "discover something_invalid\n"
expect "Error 7: InvalidArgs"

switch_node 1
expect -re {version=\d,joiner=0}

switch_node 3
send "joiner start 123456\n"
set timeout 10
expect "NotFound"

switch_node 1
expect -re {version=\d,joiner=1}

dispose_all
7 changes: 1 addition & 6 deletions tests/scripts/expect/posix-rcp-restoration.exp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,7 @@ try {
puts "While energy scanning"

spawn_node 1 "rcp" "spinel+hdlc_uart://$host_pty"
send "ifconfig up\n"
expect_line "Done"
send "thread start\n"
expect_line "Done"
wait_for "state" "leader"
expect_line "Done"
attach

send "scan energy 100\n"
expect "| Ch | RSSI |"
Expand Down
7 changes: 1 addition & 6 deletions tests/scripts/expect/posix-scan-tx-to-sleep.exp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ send "dataset panid 0xface\n"
expect_line "Done"
send "dataset commit active\n"
expect_line "Done"
send "ifconfig up\n"
expect_line "Done"
send "thread start\n"
expect_line "Done"
wait_for "state" "leader"
expect_line "Done"
attach

set extaddr [get_extaddr]
send "panid\n"
Expand Down
Loading

0 comments on commit 1c190a4

Please sign in to comment.