From 1cd9bb30744c9c499e1c4e07fa56f2def8e42fb9 Mon Sep 17 00:00:00 2001 From: Moandor Date: Thu, 25 Jun 2020 03:48:03 +0800 Subject: [PATCH] [test] add expect tests for dataset and networktime (#5145) --- .github/workflows/simulation.yml | 2 +- tests/scripts/expect/cli-dataset.exp | 160 +++++++++++++++++++++++++++ tests/scripts/expect/cli-misc.exp | 10 ++ 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100755 tests/scripts/expect/cli-dataset.exp diff --git a/.github/workflows/simulation.yml b/.github/workflows/simulation.yml index aea4859d1..e4e6e029b 100644 --- a/.github/workflows/simulation.yml +++ b/.github/workflows/simulation.yml @@ -179,7 +179,7 @@ jobs: OT_OPTIONS=-DOT_READLINE=OFF sudo apt-get --no-install-recommends install -y expect ninja-build - name: Run run: | - VIRTUAL_TIME=0 ./script/test build expect + OT_OPTIONS=-DOT_TIME_SYNC=ON VIRTUAL_TIME=0 ./script/test build expect - name: Codecov uses: codecov/codecov-action@v1 - name: Run RCP Mode diff --git a/tests/scripts/expect/cli-dataset.exp b/tests/scripts/expect/cli-dataset.exp new file mode 100755 index 000000000..7a213c65e --- /dev/null +++ b/tests/scripts/expect/cli-dataset.exp @@ -0,0 +1,160 @@ +#!/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" +source "tests/scripts/expect/_multinode.exp" + +set timeout 1 +setup_nodes + +set spawn_id $spawn_1 +send "dataset active\n" +expect -re {Active Timestamp: \d+} +expect -re {Channel: (\d+)} +set channel $expect_out(1,string) +expect -re {Channel Mask: [0-9a-f]{8}} +expect -re {Ext PAN ID: [0-9a-f]{16}} +expect -re {Mesh Local Prefix: ([0-9a-f]{1,4}:){3}[0-9a-f]{1,4}\/64} +expect -re {Master Key: [0-9a-f]{32}} +expect -re {Network Name: [^\r\n]+} +expect -re {PAN ID: 0x[0-9a-f]{4}} +expect -re {PSKc: [0-9a-f]{32}} +expect -re {Security Policy: \d+, o?n?r?c?b?} +send "dataset pending\n" +expect "Error 23: NotFound" +send "dataset init active\n" +expect "Done" +send "dataset activetimestamp 100\n" +expect "Done" +if {$channel == 11} { + send "dataset channel 18\n" +} else { + send "dataset channel 11\n" +} +expect "Done" +send "dataset channelmask 0x03fff800\n" +expect "Done" +send "dataset extpanid aabbccddeeff0011\n" +expect "Done" +send "dataset masterkey aabbccddeeff00112233445566778899\n" +expect "Done" +send "dataset meshlocalprefix fdde:4860::\n" +expect "Done" +send "dataset networkname OT-network\n" +expect "Done" +send "dataset panid 0xface\n" +expect "Done" +send "dataset pskc 00112233445566778899aabbccddeeff\n" +expect "Done" +send "dataset securitypolicy 678 onrcb\n" +expect "Done" +send "dataset pendingtimestamp 100\n" +expect "Done" +send "dataset delay 30000\n" +expect "Done" +send "dataset commit pending\n" +expect "Done" +send "dataset pending\n" +expect "Pending Timestamp: 100" +expect "Active Timestamp: 100" +if {$channel == 11} { + expect "Channel: 18" +} else { + expect "Channel: 11" +} +expect "Channel Mask: 03fff800" +expect -re {Delay: \d+} +expect "Ext PAN ID: aabbccddeeff0011" +expect "Mesh Local Prefix: fdde:4860:0:0/64" +expect "Master Key: aabbccddeeff00112233445566778899" +expect "Network Name: OT-network" +expect "PAN ID: 0xface" +expect "PSKc: 00112233445566778899aabbccddeeff" +expect "Security Policy: 678, onrcb" +expect "Done" + +sleep 30 + +set spawn_id $spawn_2 +wait_for "dataset active" "Active Timestamp: 100" +expect "Done" +send "dataset active\n" +expect "Active Timestamp: 100" +if {$channel == 11} { + expect "Channel: 18" +} else { + expect "Channel: 11" +} +expect "Channel Mask: 03fff800" +expect "Ext PAN ID: aabbccddeeff0011" +expect "Mesh Local Prefix: fdde:4860:0:0/64" +expect "Master Key: aabbccddeeff00112233445566778899" +expect "Network Name: OT-network" +expect "PAN ID: 0xface" +expect "PSKc: 00112233445566778899aabbccddeeff" +expect "Security Policy: 678, onrcb" +expect "Done" +send "dataset clear\n" +expect "Done" +send "dataset init active\n" +expect "Done" +send "dataset\n" +expect "Active Timestamp: 100" +if {$channel == 11} { + expect "Channel: 18" +} else { + expect "Channel: 11" +} +expect "Channel Mask: 03fff800" +expect "Ext PAN ID: aabbccddeeff0011" +expect "Mesh Local Prefix: fdde:4860:0:0/64" +expect "Master Key: aabbccddeeff00112233445566778899" +expect "Network Name: OT-network" +expect "PAN ID: 0xface" +expect "PSKc: 00112233445566778899aabbccddeeff" +expect "Security Policy: 678, onrcb" +expect "Done" +send "dataset init pending\n" +expect "Error 23: NotFound" +send "dataset active binary\n" +expect "dataset active binary" +expect -re {([0-9a-f]+)} +set binary $expect_out(1,string) +expect "Done" +send "dataset set pending $binary\n" +expect "Done" +send "dataset pending binary\n" +expect $binary +expect "Done" +send "dataset set active $binary\n" +expect "Done" +send "help\n" +expect "Done" + +dispose_nodes diff --git a/tests/scripts/expect/cli-misc.exp b/tests/scripts/expect/cli-misc.exp index 495bc179c..575a15643 100755 --- a/tests/scripts/expect/cli-misc.exp +++ b/tests/scripts/expect/cli-misc.exp @@ -146,4 +146,14 @@ 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