From ede592918c624d9d574129dd7f27ced9ba79e818 Mon Sep 17 00:00:00 2001 From: Moandor Date: Tue, 23 Jun 2020 01:11:55 +0800 Subject: [PATCH] [test] add expect tests for sntp, mac, netif, and more (#5140) Also does some minor enhancements. --- .github/workflows/simulation.yml | 4 +- tests/scripts/expect/_multinode.exp | 4 +- tests/scripts/expect/cli-mac.exp | 63 +++++++++++++++++++ tests/scripts/expect/cli-router.exp | 18 ++++++ tests/scripts/expect/posix-rcp.exp | 43 +++++++++++++ .../scripts/expect/posix-scan-tx-to-sleep.exp | 1 + tests/scripts/expect/tun-dns-client.exp | 14 +++-- tests/scripts/expect/tun-netif.exp | 42 +++++++++++++ tests/scripts/expect/tun-sntp.exp | 52 +++++++++++++++ 9 files changed, 232 insertions(+), 9 deletions(-) create mode 100755 tests/scripts/expect/cli-mac.exp create mode 100755 tests/scripts/expect/posix-rcp.exp create mode 100755 tests/scripts/expect/tun-netif.exp create mode 100755 tests/scripts/expect/tun-sntp.exp diff --git a/.github/workflows/simulation.yml b/.github/workflows/simulation.yml index a00b00374..aea4859d1 100644 --- a/.github/workflows/simulation.yml +++ b/.github/workflows/simulation.yml @@ -189,8 +189,8 @@ jobs: uses: codecov/codecov-action@v1 - name: Run TUN Mode run: | - sudo apt-get install --no-install-recommends -y dnsmasq bind9-host - sudo systemctl start dnsmasq + sudo apt-get install --no-install-recommends -y dnsmasq bind9-host ntp + sudo systemctl start dnsmasq ntp host ipv6.google.com 127.0.0.1 echo 'listen-address=::1' | sudo tee /etc/dnsmasq.conf echo 0 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6 diff --git a/tests/scripts/expect/_multinode.exp b/tests/scripts/expect/_multinode.exp index 4a07f0345..c22cb6e1a 100644 --- a/tests/scripts/expect/_multinode.exp +++ b/tests/scripts/expect/_multinode.exp @@ -63,6 +63,7 @@ proc setup_nodes {} { send "thread start\n" expect "Done" wait_for "state" "leader" + expect "Done" send "commissioner start\n" expect "Done" expect "Commissioner: active" @@ -80,10 +81,11 @@ proc setup_nodes {} { expect "Done" send "joiner start $psk\n" expect "Done" - wait_for "" {Join success} + wait_for "" "Join success" send "thread start\n" expect "Done" wait_for "state" "child" + expect "Done" } proc dispose_nodes {} { diff --git a/tests/scripts/expect/cli-mac.exp b/tests/scripts/expect/cli-mac.exp new file mode 100755 index 000000000..e1186413e --- /dev/null +++ b/tests/scripts/expect/cli-mac.exp @@ -0,0 +1,63 @@ +#!/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" + +spawn $env(OT_COMMAND) 1 +set timeout 1 +expect_after { + timeout { exit 1 } +} + +send "mac retries direct 5\n" +expect "Done" +send "mac retries direct\n" +expect "5" +expect "Done" + +send "mac retries indirect 2\n" +expect "Done" +send "mac retries indirect\n" +expect "2" +expect "Done" + +send "mac\n" +expect "Error 7: InvalidArgs" +send "mac something_invalid\n" +expect "Error 35: InvalidCommand" +send "mac retries\n" +expect "Error 7: InvalidArgs" +send "mac retries something_invalid\n" +expect "Error 7: InvalidArgs" +send "mac retries direct 256\n" +expect "Error 7: InvalidArgs" +send "mac retries indirect 256\n" +expect "Error 7: InvalidArgs" + +dispose diff --git a/tests/scripts/expect/cli-router.exp b/tests/scripts/expect/cli-router.exp index 6c32363e6..4a0d6e649 100755 --- a/tests/scripts/expect/cli-router.exp +++ b/tests/scripts/expect/cli-router.exp @@ -27,6 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. # +source "tests/scripts/expect/_common.exp" source "tests/scripts/expect/_multinode.exp" set timeout 1 @@ -53,4 +54,21 @@ expect "+----+--------+----------+-----------+-------+--------+-----+----------- expect -re "\\| +$router_id \\| 0x$rloc \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| +\\d+ \\| $extaddr \\|" expect "Done" +set spawn_id $spawn_2 +send "mode rsdn\n" +expect "Done" +send "state router\n" +expect "Done" +wait_for "router list" $router_id +send "router $router_id\n" +expect "Router ID: $router_id" +expect "Rloc: $rloc" +expect "Next Hop: fc00" +expect "Link: 1" +expect "Ext Addr: $extaddr" +expect -re {Cost: \d+} +expect -re {Link Quality In: \d+} +expect -re {Link Quality Out: \d+} +expect -re {Age: \d+} + dispose_nodes diff --git a/tests/scripts/expect/posix-rcp.exp b/tests/scripts/expect/posix-rcp.exp new file mode 100755 index 000000000..41e9c3887 --- /dev/null +++ b/tests/scripts/expect/posix-rcp.exp @@ -0,0 +1,43 @@ +#!/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" + +spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?forkpty-arg=1" +set timeout 1 +expect_after { + timeout { exit 1 } +} + +send "rcp version\n" +expect "Done" +send "rcp something_invalid\n" +expect "Error 7: InvalidArgs" + +dispose diff --git a/tests/scripts/expect/posix-scan-tx-to-sleep.exp b/tests/scripts/expect/posix-scan-tx-to-sleep.exp index ee6357056..d93563bae 100755 --- a/tests/scripts/expect/posix-scan-tx-to-sleep.exp +++ b/tests/scripts/expect/posix-scan-tx-to-sleep.exp @@ -48,6 +48,7 @@ expect "Done" send "thread start\n" expect "Done" wait_for "state" "leader" +expect "Done" send "extaddr\n" expect "extaddr" diff --git a/tests/scripts/expect/tun-dns-client.exp b/tests/scripts/expect/tun-dns-client.exp index 571c58875..f7568881a 100755 --- a/tests/scripts/expect/tun-dns-client.exp +++ b/tests/scripts/expect/tun-dns-client.exp @@ -27,24 +27,26 @@ # POSSIBILITY OF SUCH DAMAGE. # +source "tests/scripts/expect/_common.exp" + spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?forkpty-arg=1" set timeout 1 expect_after { timeout { exit 1 } } + send "panid 0xface\n" expect "Done" send "ifconfig up\n" expect "Done" send "thread start\n" expect "Done" -sleep 5 -send "state\n" -expect "leader" +wait_for "state" "leader" expect "Done" -send "dns resolve ipv6.google.com ::1 53\n" + set timeout 2 +send "dns resolve ipv6.google.com ::1 53\n" expect "DNS response for ipv6.google.com" expect "Done" -send "\x04" -expect eof + +dispose diff --git a/tests/scripts/expect/tun-netif.exp b/tests/scripts/expect/tun-netif.exp new file mode 100755 index 000000000..dfcf96687 --- /dev/null +++ b/tests/scripts/expect/tun-netif.exp @@ -0,0 +1,42 @@ +#!/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" + +spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?forkpty-arg=1" +set timeout 1 +expect_after { + timeout { exit 1 } +} + +send "netif\n" +expect -re {[\r\n][^\r\n:]+?:\d+} +expect "Done" + +dispose diff --git a/tests/scripts/expect/tun-sntp.exp b/tests/scripts/expect/tun-sntp.exp new file mode 100755 index 000000000..ba73ae8f0 --- /dev/null +++ b/tests/scripts/expect/tun-sntp.exp @@ -0,0 +1,52 @@ +#!/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" + +spawn $env(OT_COMMAND) "spinel+hdlc+uart://$env(RCP_COMMAND)?forkpty-arg=1" +set timeout 1 +expect_after { + timeout { exit 1 } +} + +send "panid 0xface\n" +expect "Done" +send "ifconfig up\n" +expect "Done" +send "thread start\n" +expect "Done" +wait_for "state" "leader" +expect "Done" + +set timeout 2 +send "sntp query ::1 123\n" +expect -re {SNTP response - Unix time: \d+ \(era: \d+\)} +expect "Done" + +dispose