1#!/usr/bin/expect -f 2# 3# Copyright (c) 2023, The OpenThread Authors. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. Neither the name of the copyright holder nor the 14# names of its contributors may be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30source "tests/scripts/expect/_common.exp" 31source "tests/scripts/expect/_multinode.exp" 32 33setup_two_nodes 34 35switch_node 1 36send "linkmetricsmgr enable\n" 37expect_line "Done" 38send "linkmetricsmgr\n" 39expect_line "Enabled" 40expect_line "Done" 41 42sleep 10 43 44switch_node 2 45set addr [get_ipaddr mleid] 46 47switch_node 1 48send "ping $addr\n" 49expect "16 bytes from $addr: icmp_seq=1" 50send "linkmetricsmgr show\n" 51expect -re {ExtAddr:([0-9a-f]){16}, LinkMargin:\d+, Rssi:\-?\d+} 52expect "Done" 53 54sleep 5 55 56send "linkmetricsmgr disable\n" 57expect_line "Done" 58send "linkmetricsmgr\n" 59expect_line "Disabled" 60expect_line "Done" 61send "linkmetricsmgr show\n" 62expect_line "Done" 63send "linkmetricsmgr xxx\n" 64expect_line "InvalidCommand" 65 66# Test continuous enable 67send "linkmetricsmgr enable\n" 68expect_line "Done" 69send "linkmetricsmgr enable\n" 70expect_line "Done" 71send "linkmetricsmgr enable\n" 72expect_line "Done" 73send "linkmetricsmgr\n" 74expect_line "Enabled" 75expect_line "Done" 76 77send "ping $addr\n" 78expect "16 bytes from $addr: icmp_seq=" 79 80sleep 10 81 82send "ping $addr\n" 83expect "16 bytes from $addr: icmp_seq=" 84 85send "linkmetricsmgr show\n" 86expect -re {ExtAddr:([0-9a-f]){16}, LinkMargin:\d+, Rssi:\-?\d+} 87expect "Done" 88 89# Test continuous disable 90send "linkmetricsmgr disable\n" 91expect_line "Done" 92send "linkmetricsmgr disable\n" 93expect_line "Done" 94send "linkmetricsmgr disable\n" 95expect_line "Done" 96send "linkmetricsmgr\n" 97expect_line "Disabled" 98expect_line "Done" 99 100send "ping $addr\n" 101expect "16 bytes from $addr: icmp_seq=" 102 103sleep 10 104 105send "ping $addr\n" 106expect "16 bytes from $addr: icmp_seq=" 107 108send "linkmetricsmgr show\n" 109expect_line "Done" 110 111# Test continuous switch 112send "linkmetricsmgr enable\n" 113expect_line "Done" 114send "linkmetricsmgr disable\n" 115expect_line "Done" 116send "linkmetricsmgr enable\n" 117expect_line "Done" 118send "linkmetricsmgr\n" 119expect_line "Enabled" 120expect_line "Done" 121 122send "ping $addr\n" 123expect "16 bytes from $addr: icmp_seq=" 124 125sleep 10 126 127send "ping $addr\n" 128expect "16 bytes from $addr: icmp_seq=" 129 130send "linkmetricsmgr show\n" 131expect -re {ExtAddr:([0-9a-f]){16}, LinkMargin:\d+, Rssi:\-?\d+} 132expect "Done" 133 134send "linkmetricsmgr disable\n" 135expect_line "Done" 136send "linkmetricsmgr enable\n" 137expect_line "Done" 138send "linkmetricsmgr disable\n" 139expect_line "Done" 140send "linkmetricsmgr\n" 141expect_line "Disabled" 142expect_line "Done" 143 144send "ping $addr\n" 145expect "16 bytes from $addr: icmp_seq=" 146 147sleep 10 148 149send "ping $addr\n" 150expect "16 bytes from $addr: icmp_seq=" 151 152send "linkmetricsmgr show\n" 153expect_line "Done" 154 155dispose_all 156