From 1c190a4f6d6ad9cc4e852213539d268ad82ccd94 Mon Sep 17 00:00:00 2001 From: Lukasz Duda Date: Mon, 6 Mar 2023 01:24:08 +0100 Subject: [PATCH] [expect] split and extend tests for discovery (#8832) Signed-off-by: Lukasz Duda --- tests/scripts/expect/_common.exp | 33 +++- tests/scripts/expect/cli-discover.exp | 146 ++++++++++++++++++ tests/scripts/expect/cli-multicast-loop.exp | 34 +--- .../{cli-scan-discover.exp => cli-scan.exp} | 36 ----- .../scripts/expect/posix-rcp-restoration.exp | 7 +- .../scripts/expect/posix-scan-tx-to-sleep.exp | 7 +- .../expect/tun-realm-local-multicast.exp | 31 +--- tests/scripts/expect/tun-sntp.exp | 7 +- tests/scripts/expect/tun-udp.exp | 9 +- 9 files changed, 185 insertions(+), 125 deletions(-) create mode 100755 tests/scripts/expect/cli-discover.exp rename tests/scripts/expect/{cli-scan-discover.exp => cli-scan.exp} (72%) diff --git a/tests/scripts/expect/_common.exp b/tests/scripts/expect/_common.exp index 263ed687d..820a0c674 100644 --- a/tests/scripts/expect/_common.exp +++ b/tests/scripts/expect/_common.exp @@ -126,6 +126,15 @@ 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" @@ -133,12 +142,7 @@ proc setup_leader {} { 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} { @@ -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>])} diff --git a/tests/scripts/expect/cli-discover.exp b/tests/scripts/expect/cli-discover.exp new file mode 100755 index 000000000..6c769f735 --- /dev/null +++ b/tests/scripts/expect/cli-discover.exp @@ -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 diff --git a/tests/scripts/expect/cli-multicast-loop.exp b/tests/scripts/expect/cli-multicast-loop.exp index ef6c8b68b..14f07bd60 100755 --- a/tests/scripts/expect/cli-multicast-loop.exp +++ b/tests/scripts/expect/cli-multicast-loop.exp @@ -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] @@ -63,14 +56,8 @@ setup_default_network send "panid 0xface\n" expect_line "Done" -send "ifconfig up\n" -expect_line "Done" +attach "router" -send "thread start\n" -expect_line "Done" - -wait_for "state" "router" -expect_line "Done" sleep 3 get_rloc16 @@ -87,14 +74,8 @@ expect_line "Done" send "macfilter addr denylist\n" expect_line "Done" -send "ifconfig up\n" -expect_line "Done" +attach "router" -send "thread start\n" -expect_line "Done" - -wait_for "state" "router" -expect_line "Done" sleep 4 set extaddr3 [get_extaddr] @@ -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 diff --git a/tests/scripts/expect/cli-scan-discover.exp b/tests/scripts/expect/cli-scan.exp similarity index 72% rename from tests/scripts/expect/cli-scan-discover.exp rename to tests/scripts/expect/cli-scan.exp index 52b6883f8..1bb20ebec 100755 --- a/tests/scripts/expect/cli-scan-discover.exp +++ b/tests/scripts/expect/cli-scan.exp @@ -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" @@ -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 diff --git a/tests/scripts/expect/posix-rcp-restoration.exp b/tests/scripts/expect/posix-rcp-restoration.exp index c0dac4c24..1d3fac227 100755 --- a/tests/scripts/expect/posix-rcp-restoration.exp +++ b/tests/scripts/expect/posix-rcp-restoration.exp @@ -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 |" diff --git a/tests/scripts/expect/posix-scan-tx-to-sleep.exp b/tests/scripts/expect/posix-scan-tx-to-sleep.exp index 2ac44a81f..eea15b679 100755 --- a/tests/scripts/expect/posix-scan-tx-to-sleep.exp +++ b/tests/scripts/expect/posix-scan-tx-to-sleep.exp @@ -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" diff --git a/tests/scripts/expect/tun-realm-local-multicast.exp b/tests/scripts/expect/tun-realm-local-multicast.exp index b18ffba22..7be7c5e43 100755 --- a/tests/scripts/expect/tun-realm-local-multicast.exp +++ b/tests/scripts/expect/tun-realm-local-multicast.exp @@ -39,27 +39,15 @@ source "tests/scripts/expect/_common.exp" spawn_node 1 setup_default_network -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] spawn_node 2 cli setup_default_network -send "ifconfig up\n" -expect_line "Done" +attach "router" -send "thread start\n" -expect_line "Done" - -wait_for "state" "router" sleep 3 spawn_node 3 cli @@ -71,13 +59,8 @@ expect_line "Done" send "macfilter addr denylist\n" expect_line "Done" -send "ifconfig up\n" -expect_line "Done" +attach "router" -send "thread start\n" -expect_line "Done" - -wait_for "state" "router" sleep 4 set extaddr3 [get_extaddr] @@ -94,13 +77,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" +attach "child" set mleid4 [get_ipaddr "mleid"] diff --git a/tests/scripts/expect/tun-sntp.exp b/tests/scripts/expect/tun-sntp.exp index a72439004..fe91233d0 100755 --- a/tests/scripts/expect/tun-sntp.exp +++ b/tests/scripts/expect/tun-sntp.exp @@ -35,12 +35,7 @@ spawn_node 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 send "sntp query ::1 123\n" expect -re {SNTP response - Unix time: \d+ \(era: \d+\)} diff --git a/tests/scripts/expect/tun-udp.exp b/tests/scripts/expect/tun-udp.exp index 03ba12f15..53cff14e7 100755 --- a/tests/scripts/expect/tun-udp.exp +++ b/tests/scripts/expect/tun-udp.exp @@ -38,14 +38,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 send "udp open\n" expect_line "Done"