From 4d1197a34af2616c2a00865221d73b47cbfbbbaf Mon Sep 17 00:00:00 2001 From: Moandor Date: Wed, 10 Jun 2020 10:05:05 +0800 Subject: [PATCH] [test] split cli-2-nodes.exp into multiple files (#5066) This splits cli-2-nodes.exp into multiple files each of which contains tests for a single command. --- tests/scripts/expect/cli-child.exp | 62 ++++++++++++ tests/scripts/expect/cli-ping.exp | 30 +++++- tests/scripts/expect/cli-promiscuous.exp | 62 ++++++++++-- tests/scripts/expect/cli-router.exp | 56 +++++++++++ .../expect/{cli-2-nodes.exp => cli-scan.exp} | 94 ++----------------- 5 files changed, 209 insertions(+), 95 deletions(-) create mode 100755 tests/scripts/expect/cli-child.exp create mode 100755 tests/scripts/expect/cli-router.exp rename tests/scripts/expect/{cli-2-nodes.exp => cli-scan.exp} (56%) diff --git a/tests/scripts/expect/cli-child.exp b/tests/scripts/expect/cli-child.exp new file mode 100755 index 000000000..e49165c53 --- /dev/null +++ b/tests/scripts/expect/cli-child.exp @@ -0,0 +1,62 @@ +#!/usr/bin/expect -f +# +# Copyright (c) 2020, 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/_multinode.exp" + +set timeout 1 +setup_nodes + +set spawn_id $spawn_2 +send "extaddr\n" +expect "extaddr" +expect -re {([0-9a-f]{16})} +set extaddr $expect_out(1,string) +expect "Done" +send "rloc16\n" +expect "rloc16" +expect -re {([0-9a-f]{4})} +set rloc $expect_out(1,string) +expect "Done" + +set spawn_id $spawn_1 +send "child table\n" +expect "| ID | RLOC16 | Timeout | Age | LQ In | C_VN |R|S|D|N| Extended MAC |" +expect "+-----+--------+------------+------------+-------+------+-+-+-+-+------------------+" +expect -re "\\| +(\\d+) \\| 0x$rloc \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| +\\d+ \\|\\d\\|\\d\\|\\d\\|\\d\\| $extaddr \\|" +set child_id $expect_out(1,string) +expect "Done" +send "child list\n" +expect "child list" +expect $child_id +expect "Done" +send "child $child_id\n" +expect "Ext Addr: $extaddr" +expect "Done" + +dispose_nodes diff --git a/tests/scripts/expect/cli-ping.exp b/tests/scripts/expect/cli-ping.exp index df5735997..c86a30fb4 100755 --- a/tests/scripts/expect/cli-ping.exp +++ b/tests/scripts/expect/cli-ping.exp @@ -27,8 +27,14 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" +source "tests/scripts/expect/_multinode.exp" + + set timeout 1 + + +spawn $env(OT_COMMAND) 1 expect_after { timeout { exit 1 } } @@ -42,5 +48,23 @@ send "ping stop\n" expect "Done" send "ping ::1 1 2 1 1 1\n" expect "Error 7: InvalidArgs" -send "\x04" -expect eof +dispose + + +setup_nodes + +set spawn_id $spawn_2 +send "ipaddr\n" +expect -re {(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4})} +set addr $expect_out(1,string) +expect "Done" + +set spawn_id $spawn_1 +send "ping $addr\n" +expect "16 bytes from $addr: icmp_seq=1" +send "ping $addr 20 10 0.00123456 255\n" +for {set i 2} {$i <= 11} {incr i} { + expect "28 bytes from $addr: icmp_seq=$i" +} + +dispose_nodes diff --git a/tests/scripts/expect/cli-promiscuous.exp b/tests/scripts/expect/cli-promiscuous.exp index d49054b4d..e1817f4d5 100755 --- a/tests/scripts/expect/cli-promiscuous.exp +++ b/tests/scripts/expect/cli-promiscuous.exp @@ -27,20 +27,66 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" +source "tests/scripts/expect/_multinode.exp" + + set timeout 1 + + +spawn $env(OT_COMMAND) 1 expect_after { timeout { exit 1 } } send "promiscuous\n" -expect "Disabled\r\nDone\r\n" +expect "Disabled" +expect "Done" send "promiscuous enable\n" -expect "Done\r\n" +expect "Done" send "promiscuous\n" -expect "Enabled\r\nDone\r\n" +expect "Enabled" +expect "Done" send "promiscuous disable\n" -expect "Done\r\n" +expect "Done" send "promiscuous a\n" -expect "Error 7: InvalidArgs\r\n" -send "\x04" -expect eof +expect "Error 7: InvalidArgs" +dispose + + +setup_nodes + +set spawn_id $spawn_1 +send "channel\n" +expect "channel" +expect -re {(\d+)} +set channel $expect_out(1,string) +expect "Done" + +spawn $env(OT_COMMAND) 3 +set spawn_3 $spawn_id +send "channel $channel\n" +expect "Done" +send "promiscuous enable\n" +expect "Done" + +set spawn_id $spawn_2 +send "ipaddr\n" +expect -re {(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4})} +set addr $expect_out(1,string) +expect "Done" + +set spawn_id $spawn_1 +send "ping $addr\n" +expect "16 bytes from $addr: icmp_seq=1" + +set spawn_id $spawn_3 +expect -re {============================================\[len = +\d+]============================} +expect -re {\|( ([0-9A-Z]{2}|\.\.)){16}\|( .){16}\|} +expect -- "-----------------------------------------------------------------------------------" +send "promiscuous disable\n" +expect "Done" + +set spawn_id $spawn_3 +dispose + +dispose_nodes diff --git a/tests/scripts/expect/cli-router.exp b/tests/scripts/expect/cli-router.exp new file mode 100755 index 000000000..6c32363e6 --- /dev/null +++ b/tests/scripts/expect/cli-router.exp @@ -0,0 +1,56 @@ +#!/usr/bin/expect -f +# +# Copyright (c) 2020, 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/_multinode.exp" + +set timeout 1 +setup_nodes + +set spawn_id $spawn_1 +send "extaddr\n" +expect "extaddr" +expect -re {([0-9a-f]{16})} +set extaddr $expect_out(1,string) +expect "Done" +send "router list\n" +expect "router list" +expect -re {(\d+)} +set router_id $expect_out(1,string) +expect "Done" +send "router $router_id\n" +expect -re {Rloc: ([0-9a-f]{4})} +set rloc $expect_out(1,string) +expect "Done" +send "router table\n" +expect "| ID | RLOC16 | Next Hop | Path Cost | LQ In | LQ Out | Age | Extended MAC |" +expect "+----+--------+----------+-----------+-------+--------+-----+------------------+" +expect -re "\\| +$router_id \\| 0x$rloc \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| $extaddr \\|" +expect "Done" + +dispose_nodes diff --git a/tests/scripts/expect/cli-2-nodes.exp b/tests/scripts/expect/cli-scan.exp similarity index 56% rename from tests/scripts/expect/cli-2-nodes.exp rename to tests/scripts/expect/cli-scan.exp index 255899e98..27cd7bcf9 100755 --- a/tests/scripts/expect/cli-2-nodes.exp +++ b/tests/scripts/expect/cli-scan.exp @@ -27,105 +27,28 @@ # POSSIBILITY OF SUCH DAMAGE. # +source "tests/scripts/expect/_common.exp" source "tests/scripts/expect/_multinode.exp" - set timeout 1 setup_nodes + spawn $env(OT_COMMAND) 3 set spawn_3 $spawn_id - -set spawn_id $spawn_1 -send "channel\n" -expect "channel" -expect -re {(\d+)} -set channel $expect_out(1,string) -expect "Done" - -set spawn_id $spawn_3 -send "channel $channel\n" -expect "Done" -send "promiscuous enable\n" -expect "Done" - - -# ping -set spawn_id $spawn_2 -send "ipaddr\n" -expect -re {(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4})} -set addr $expect_out(1,string) - -set spawn_id $spawn_1 -send "ping $addr\n" -expect "16 bytes from $addr: icmp_seq=1" -send "ping $addr 20 10 0.00123456 255\n" -for {set i 2} {$i <= 11} {incr i} { - expect "28 bytes from $addr: icmp_seq=$i" -} - - -# pcap receive -set spawn_id $spawn_3 -expect -re {============================================\[len = +\d+]============================} -expect -re {\|( ([0-9A-Z]{2}|\.\.)){16}\|( .){16}\|} -expect -- "-----------------------------------------------------------------------------------" -send "promiscuous disable\n" -expect "Done" - - -# child -set spawn_id $spawn_2 -send "extaddr\n" -expect -re {([0-9a-f]{16})} -set extaddr $expect_out(1,string) -expect "Done" - -set spawn_id $spawn_1 -send "child table\n" -expect "$extaddr" -expect "Done" -send "child list\n" -expect -re {(\d+)} -set child_id $expect_out(1,string) -expect "Done" -send "child $child_id\n" -expect "Ext Addr: $extaddr" -expect "Done" - - -# router -set spawn_id $spawn_1 -send "extaddr\n" -expect -re {([0-9a-f]{16})} -set extaddr $expect_out(1,string) -expect "Done" -send "router list\n" -expect -re {(\d+)} -set router_id $expect_out(1,string) -expect "Done" -send "router $router_id\n" -expect -re {Rloc: ([0-9a-f]{4})} -set rloc $expect_out(1,string) -expect "Done" -send "router table\n" -expect "| ID | RLOC16 | Next Hop | Path Cost | LQ In | LQ Out | Age | Extended MAC |" -expect "+----+--------+----------+-----------+-------+--------+-----+------------------+" -expect -re "\\| +$router_id +\\| +0x$rloc +\\| +\\d+ +\\| +\\d+ +\\| +\\d+ +\\| +\\d+ +\\| +\\d+ +\\| +$extaddr +\\|" -expect "Done" - - -# scan set spawn_id $spawn_1 send "extaddr\n" +expect "extaddr" expect -re {([0-9a-f]{16})} set extaddr $expect_out(1,string) expect "Done" send "panid\n" +expect "panid" expect -re {([0-9a-f]{4})} set pan $expect_out(1,string) expect "Done" send "extpanid\n" +expect "extpanid" expect -re {([0-9a-f]{16})} set extpan $expect_out(1,string) expect "Done" @@ -135,6 +58,7 @@ expect -re {\r\n(.*?)\r\n} set network $expect_out(1,string) expect "Done" send "channel\n" +expect "channel" expect -re {(\d+)} set channel $expect_out(1,string) expect "Done" @@ -143,15 +67,17 @@ set spawn_id $spawn_3 send "scan $channel\n" expect "| J | Network Name | Extended PAN | PAN | MAC Address | Ch | dBm | LQI |" expect "+---+------------------+------------------+------+------------------+----+-----+-----+" -wait_for "" "\\| +\\d +\\| +$network +\\| +$extpan +\\| +$pan +\\| +$extaddr +\\| +$channel +\\| +-?\\d+ +\\| +\\d +\\|" +wait_for "" "\\| \\d \\| $network +\\| $extpan \\| $pan \\| $extaddr \\| +$channel \\| +-?\\d+ \\| +\\d \\|" wait_for "" "Done" send "scan energy 100\n" expect "| Ch | RSSI |" expect "+----+------+" for {set i 11} {$i <= 26} {incr i} { - expect -re "\\| $i \\| +-?\\d+ \\|" + expect -re "\\| +$i \\| +-?\\d+ \\|" } expect "Done" +set spawn_id $spawn_3 +dispose dispose_nodes