From 5acad3079122510806ac007276ad6ab134832182 Mon Sep 17 00:00:00 2001 From: Moandor Date: Tue, 30 Jun 2020 23:40:46 +0800 Subject: [PATCH] [test] include CLI tests in RCP mode (#5159) This makes expect run all cli-*.exp and posix-*.exp tests in RCP mode. New scripts should use the function spawn_node in _common.exp to spawn new processes. This is compatible with both simulation mode and RCP mode. --- script/test | 10 ++--- tests/scripts/expect/_common.exp | 12 +++++ tests/scripts/expect/_multinode.exp | 9 +--- tests/scripts/expect/cli-channel.exp | 5 +-- tests/scripts/expect/cli-coex.exp | 5 +-- tests/scripts/expect/cli-counters.exp | 9 ++-- tests/scripts/expect/cli-extaddr.exp | 26 +++++------ tests/scripts/expect/cli-log-level.exp | 26 ++++++----- tests/scripts/expect/cli-mac.exp | 5 +-- tests/scripts/expect/cli-macfilter.exp | 5 +-- tests/scripts/expect/cli-misc.exp | 10 ----- tests/scripts/expect/cli-ping.exp | 7 ++- tests/scripts/expect/cli-promiscuous.exp | 9 ++-- tests/scripts/expect/cli-pskc.exp | 27 +++++++----- tests/scripts/expect/cli-routereligible.exp | 9 ++-- tests/scripts/expect/cli-scan-discover.exp | 4 +- .../scripts/expect/simulation-networktime.exp | 44 +++++++++++++++++++ 17 files changed, 128 insertions(+), 94 deletions(-) create mode 100755 tests/scripts/expect/simulation-networktime.exp diff --git a/script/test b/script/test index 9aea568dc..85ee827f8 100755 --- a/script/test +++ b/script/test @@ -204,19 +204,19 @@ do_expect() { local ot_command local rcp_command= - local test_pattern + local test_patterns if [[ ${NODE_MODE} == rcp ]]; then ot_command="${OT_CLI_PATH}" rcp_command="${RADIO_DEVICE}" if [[ ${OT_NATIVE_IP} == 1 ]]; then - test_pattern='tun-*.exp' + test_patterns=(-name 'tun-*.exp') else - test_pattern='posix-*.exp' + test_patterns=(-name 'posix-*.exp' -o -name 'cli-*.exp') fi else ot_command="${OT_BUILDDIR}/cmake/openthread-simulation-${THREAD_VERSION}/examples/apps/cli/ot-cli-ftd" - test_pattern='cli-*.exp' + test_patterns=(-name 'cli-*.exp' -o -name 'simulation-*.exp') fi while read -r script; do @@ -237,7 +237,7 @@ do_expect() if [[ $# != 0 ]]; then for script in "$@"; do echo ${script}; done else - find tests/scripts/expect -type f -executable -name "${test_pattern}" + find tests/scripts/expect -type f -executable \( "${test_patterns[@]}" \) fi ) diff --git a/tests/scripts/expect/_common.exp b/tests/scripts/expect/_common.exp index 021d98b62..f95772daa 100644 --- a/tests/scripts/expect/_common.exp +++ b/tests/scripts/expect/_common.exp @@ -48,6 +48,18 @@ proc wait_for {command expected} { } } +proc spawn_node {id} { + if {[info exists ::env(RCP_COMMAND)] && $::env(RCP_COMMAND) != ""} { + spawn $::env(OT_COMMAND) "spinel+hdlc+uart://$::env(RCP_COMMAND)?forkpty-arg=$id" + } else { + spawn $::env(OT_COMMAND) $id + } + expect_after { + timeout { exit 1 } + } + return $spawn_id +} + proc dispose {} { send "\x04" expect eof diff --git a/tests/scripts/expect/_multinode.exp b/tests/scripts/expect/_multinode.exp index c22cb6e1a..3844607ee 100644 --- a/tests/scripts/expect/_multinode.exp +++ b/tests/scripts/expect/_multinode.exp @@ -38,13 +38,8 @@ proc setup_nodes {} { global spawn_id global env - spawn $env(OT_COMMAND) 1 - set spawn_1 $spawn_id - spawn $env(OT_COMMAND) 2 - set spawn_2 $spawn_id - expect_after { - timeout { exit 1 } - } + set spawn_1 [spawn_node 1] + set spawn_2 [spawn_node 2] set psk "J01NME" set spawn_id $spawn_2 diff --git a/tests/scripts/expect/cli-channel.exp b/tests/scripts/expect/cli-channel.exp index 21ed1625a..aba24adc7 100755 --- a/tests/scripts/expect/cli-channel.exp +++ b/tests/scripts/expect/cli-channel.exp @@ -29,11 +29,8 @@ source "tests/scripts/expect/_common.exp" -spawn $env(OT_COMMAND) 1 +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} send "ifconfig up\n" expect "Done" diff --git a/tests/scripts/expect/cli-coex.exp b/tests/scripts/expect/cli-coex.exp index 9eeae2914..adafc0369 100755 --- a/tests/scripts/expect/cli-coex.exp +++ b/tests/scripts/expect/cli-coex.exp @@ -29,11 +29,8 @@ source "tests/scripts/expect/_common.exp" -spawn $env(OT_COMMAND) 1 +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} send "coex disable\n" expect "Done" diff --git a/tests/scripts/expect/cli-counters.exp b/tests/scripts/expect/cli-counters.exp index 6cb332309..b3423f096 100755 --- a/tests/scripts/expect/cli-counters.exp +++ b/tests/scripts/expect/cli-counters.exp @@ -27,11 +27,10 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" + +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} send "counters\n" expect "mac" @@ -51,3 +50,5 @@ send "counters mle 1\n" expect "Error 7: InvalidArgs" send "counters other\n" expect "Error 7: InvalidArgs" + +dispose diff --git a/tests/scripts/expect/cli-extaddr.exp b/tests/scripts/expect/cli-extaddr.exp index e33eace57..1cc812f8f 100755 --- a/tests/scripts/expect/cli-extaddr.exp +++ b/tests/scripts/expect/cli-extaddr.exp @@ -27,24 +27,24 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" + +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} + send "extaddr 99aabbccddeeff00\n" -expect "Done\r\n" +expect "Done" send "extaddr 99AABBCCDDEEFF00\n" -expect "Done\r\n" +expect "Done" send "extaddr\n" -expect "99aabbccddeeff00\r\n" +expect "99aabbccddeeff00" send "extaddr 1\n" -expect "Error 7: InvalidArgs\r\n" +expect "Error 7: InvalidArgs" send "extaddr 0123456789abcdef0\n" -expect "Error 7: InvalidArgs\r\n" +expect "Error 7: InvalidArgs" send "extaddr invalid\n" -expect "Error 7: InvalidArgs\r\n" +expect "Error 7: InvalidArgs" send "extaddr\n" -expect "99aabbccddeeff00\r\n" -send "\x04" -expect eof +expect "99aabbccddeeff00" + +dispose diff --git a/tests/scripts/expect/cli-log-level.exp b/tests/scripts/expect/cli-log-level.exp index 4075375bc..8e3c9031e 100755 --- a/tests/scripts/expect/cli-log-level.exp +++ b/tests/scripts/expect/cli-log-level.exp @@ -27,24 +27,26 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" + +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} + send "log level\n" -expect "1\r\nDone\r\n" +expect "1" +expect "Done" send "log level 5\n" expect "Done" send "log level\n" -expect "5\r\nDone\r\n" +expect "5" +expect "Done" send "log level -1\n" -expect "Error 7: InvalidArgs\r\n" +expect "Error 7: InvalidArgs" send "log level 6\n" -expect "Error 7: InvalidArgs\r\n" +expect "Error 7: InvalidArgs" send "log a\n" -expect "Error 7: InvalidArgs\r\n" +expect "Error 7: InvalidArgs" send "log level 1 2\n" -expect "Error 7: InvalidArgs\r\n" -send "\x04" -expect eof +expect "Error 7: InvalidArgs" + +dispose diff --git a/tests/scripts/expect/cli-mac.exp b/tests/scripts/expect/cli-mac.exp index e1186413e..f51913110 100755 --- a/tests/scripts/expect/cli-mac.exp +++ b/tests/scripts/expect/cli-mac.exp @@ -29,11 +29,8 @@ source "tests/scripts/expect/_common.exp" -spawn $env(OT_COMMAND) 1 +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} send "mac retries direct 5\n" expect "Done" diff --git a/tests/scripts/expect/cli-macfilter.exp b/tests/scripts/expect/cli-macfilter.exp index 06ba92493..dd2d25c82 100755 --- a/tests/scripts/expect/cli-macfilter.exp +++ b/tests/scripts/expect/cli-macfilter.exp @@ -29,11 +29,8 @@ source "tests/scripts/expect/_common.exp" -spawn $env(OT_COMMAND) 1 +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} send "macfilter\n" expect "Address Mode: Disabled" diff --git a/tests/scripts/expect/cli-misc.exp b/tests/scripts/expect/cli-misc.exp index 575a15643..495bc179c 100755 --- a/tests/scripts/expect/cli-misc.exp +++ b/tests/scripts/expect/cli-misc.exp @@ -146,14 +146,4 @@ expect "0:0:0:0::/64 s low" send "route remove ::/64\n" expect "Done" -send "networktime 20 200\n" -expect "Done" -send "networktime\n" -expect -re {Network Time: \d+us \((unsynchronized|resync needed|synchronized)\)} -expect "Time Sync Period: 20s" -expect "XTAL Threshold: 200ppm" -expect "Done" -send "networktime something_invalid\n" -expect "Error 7: InvalidArgs" - dispose_nodes diff --git a/tests/scripts/expect/cli-ping.exp b/tests/scripts/expect/cli-ping.exp index c86a30fb4..a738c9fa5 100755 --- a/tests/scripts/expect/cli-ping.exp +++ b/tests/scripts/expect/cli-ping.exp @@ -34,10 +34,8 @@ source "tests/scripts/expect/_multinode.exp" set timeout 1 -spawn $env(OT_COMMAND) 1 -expect_after { - timeout { exit 1 } -} +set spawn_id [spawn_node 1] + send "ping ::1 1 2 1 1\n" expect "Done" send "ping stop\n" @@ -48,6 +46,7 @@ send "ping stop\n" expect "Done" send "ping ::1 1 2 1 1 1\n" expect "Error 7: InvalidArgs" + dispose diff --git a/tests/scripts/expect/cli-promiscuous.exp b/tests/scripts/expect/cli-promiscuous.exp index e1817f4d5..3ab35f206 100755 --- a/tests/scripts/expect/cli-promiscuous.exp +++ b/tests/scripts/expect/cli-promiscuous.exp @@ -34,10 +34,8 @@ source "tests/scripts/expect/_multinode.exp" set timeout 1 -spawn $env(OT_COMMAND) 1 -expect_after { - timeout { exit 1 } -} +set spawn_id [spawn_node 1] + send "promiscuous\n" expect "Disabled" expect "Done" @@ -50,6 +48,7 @@ send "promiscuous disable\n" expect "Done" send "promiscuous a\n" expect "Error 7: InvalidArgs" + dispose @@ -62,7 +61,7 @@ expect -re {(\d+)} set channel $expect_out(1,string) expect "Done" -spawn $env(OT_COMMAND) 3 +set spawn_id [spawn_node 3] set spawn_3 $spawn_id send "channel $channel\n" expect "Done" diff --git a/tests/scripts/expect/cli-pskc.exp b/tests/scripts/expect/cli-pskc.exp index f720a5c08..e12528dd4 100755 --- a/tests/scripts/expect/cli-pskc.exp +++ b/tests/scripts/expect/cli-pskc.exp @@ -27,27 +27,30 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" + +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} + send "pskc 00112233445566778899aabbccddeeff\n" -expect "Done\r\n" +expect "Done" send "pskc\n" -expect "00112233445566778899aabbccddeeff\r\nDone\r\n" +expect "00112233445566778899aabbccddeeff" +expect "Done" send "factoryreset\n" sleep 0.1 send "networkname Test\\ Network\n" -expect "Done\r\n" +expect "Done" send "extpanid 0001020304050607\n" -expect "Done\r\n" +expect "Done" send "pskc -p 12SECRETPASSWORD34\n" -expect "Done\r\n" +expect "Done" send "pskc\n" -expect "c3f59368445a1b6106be420a706d4cc9\r\nDone\r\n" +expect "c3f59368445a1b6106be420a706d4cc9" +expect "Done" send "factoryreset\n" sleep 0.1 send "pskc -x\n" -expect "Error 7: InvalidArgs\r\n" -send_user "\r\n" +expect "Error 7: InvalidArgs" + +dispose diff --git a/tests/scripts/expect/cli-routereligible.exp b/tests/scripts/expect/cli-routereligible.exp index 20ee5fc1d..0fc6d51cf 100755 --- a/tests/scripts/expect/cli-routereligible.exp +++ b/tests/scripts/expect/cli-routereligible.exp @@ -27,11 +27,10 @@ # POSSIBILITY OF SUCH DAMAGE. # -spawn $env(OT_COMMAND) 1 +source "tests/scripts/expect/_common.exp" + +set spawn_id [spawn_node 1] set timeout 1 -expect_after { - timeout { exit 1 } -} send "routereligible disable\n" expect "Done" @@ -52,3 +51,5 @@ expect "Disabled" expect "Done" send "routereligible enable\n" expect "Error 27: NotCapable" + +dispose diff --git a/tests/scripts/expect/cli-scan-discover.exp b/tests/scripts/expect/cli-scan-discover.exp index 16f8b3d96..a605e8275 100755 --- a/tests/scripts/expect/cli-scan-discover.exp +++ b/tests/scripts/expect/cli-scan-discover.exp @@ -33,7 +33,7 @@ source "tests/scripts/expect/_multinode.exp" set timeout 1 setup_nodes -spawn $env(OT_COMMAND) 3 +set spawn_id [spawn_node 3] set spawn_3 $spawn_id set spawn_id $spawn_1 @@ -54,7 +54,7 @@ set extpan $expect_out(1,string) expect "Done" send "networkname\n" expect "networkname" -expect -re {\r\n(.*?)\r\n} +expect -re {[\r\n]([^\r\n]+?)[\r\n]} set network $expect_out(1,string) expect "Done" send "channel\n" diff --git a/tests/scripts/expect/simulation-networktime.exp b/tests/scripts/expect/simulation-networktime.exp new file mode 100755 index 000000000..99af19d87 --- /dev/null +++ b/tests/scripts/expect/simulation-networktime.exp @@ -0,0 +1,44 @@ +#!/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/_common.exp" + +set spawn_id [spawn_node 1] + +send "networktime 20 200\n" +expect "Done" +send "networktime\n" +expect -re {Network Time: \d+us \((unsynchronized|resync needed|synchronized)\)} +expect "Time Sync Period: 20s" +expect "XTAL Threshold: 200ppm" +expect "Done" +send "networktime something_invalid\n" +expect "Error 7: InvalidArgs" + +dispose