1*cfb92d14SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*cfb92d14SAndroid Build Coastguard Worker# 3*cfb92d14SAndroid Build Coastguard Worker# Copyright (c) 2018, The OpenThread Authors. 4*cfb92d14SAndroid Build Coastguard Worker# All rights reserved. 5*cfb92d14SAndroid Build Coastguard Worker# 6*cfb92d14SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 7*cfb92d14SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met: 8*cfb92d14SAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright 9*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 10*cfb92d14SAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright 11*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer in the 12*cfb92d14SAndroid Build Coastguard Worker# documentation and/or other materials provided with the distribution. 13*cfb92d14SAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the 14*cfb92d14SAndroid Build Coastguard Worker# names of its contributors may be used to endorse or promote products 15*cfb92d14SAndroid Build Coastguard Worker# derived from this software without specific prior written permission. 16*cfb92d14SAndroid Build Coastguard Worker# 17*cfb92d14SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18*cfb92d14SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*cfb92d14SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*cfb92d14SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21*cfb92d14SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*cfb92d14SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*cfb92d14SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*cfb92d14SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*cfb92d14SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*cfb92d14SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*cfb92d14SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE. 28*cfb92d14SAndroid Build Coastguard Worker# 29*cfb92d14SAndroid Build Coastguard Worker 30*cfb92d14SAndroid Build Coastguard Workerimport time 31*cfb92d14SAndroid Build Coastguard Workerimport unittest 32*cfb92d14SAndroid Build Coastguard Worker 33*cfb92d14SAndroid Build Coastguard Workerimport thread_cert 34*cfb92d14SAndroid Build Coastguard Worker 35*cfb92d14SAndroid Build Coastguard Worker 36*cfb92d14SAndroid Build Coastguard Workerclass TestDiag(thread_cert.TestCase): 37*cfb92d14SAndroid Build Coastguard Worker SUPPORT_NCP = False 38*cfb92d14SAndroid Build Coastguard Worker 39*cfb92d14SAndroid Build Coastguard Worker TOPOLOGY = {1: None} 40*cfb92d14SAndroid Build Coastguard Worker 41*cfb92d14SAndroid Build Coastguard Worker def test(self): 42*cfb92d14SAndroid Build Coastguard Worker node = self.nodes[1] 43*cfb92d14SAndroid Build Coastguard Worker 44*cfb92d14SAndroid Build Coastguard Worker cases = [ 45*cfb92d14SAndroid Build Coastguard Worker ('diag\n', 'diagnostics mode is disabled\r\n'), 46*cfb92d14SAndroid Build Coastguard Worker ('diag send 10 100\n', 'Error 13: InvalidState\r\n'), 47*cfb92d14SAndroid Build Coastguard Worker ('diag start\n', 'Done\r\n'), 48*cfb92d14SAndroid Build Coastguard Worker ('diag invalid test\n', 'diag feature \'invalid\' is not supported'), 49*cfb92d14SAndroid Build Coastguard Worker ('diag', 'diagnostics mode is enabled\r\n'), 50*cfb92d14SAndroid Build Coastguard Worker ('diag channel 10\n', 'failed\r\nstatus 0x7\r\n'), 51*cfb92d14SAndroid Build Coastguard Worker ('diag channel 11\n', 'set channel to 11\r\nstatus 0x00\r\n'), 52*cfb92d14SAndroid Build Coastguard Worker ('diag channel\n', 'channel: 11\r\n'), 53*cfb92d14SAndroid Build Coastguard Worker ('diag power -10\n', 'set tx power to -10 dBm\r\nstatus 0x00\r\n'), 54*cfb92d14SAndroid Build Coastguard Worker ('diag power\n', 'tx power: -10 dBm\r\n'), 55*cfb92d14SAndroid Build Coastguard Worker ( 56*cfb92d14SAndroid Build Coastguard Worker 'diag stats\n', 57*cfb92d14SAndroid Build Coastguard Worker 'received packets: 0\r\nsent packets: 0\r\n' 58*cfb92d14SAndroid Build Coastguard Worker 'first received packet: rssi=0, lqi=0\r\n' 59*cfb92d14SAndroid Build Coastguard Worker 'last received packet: rssi=0, lqi=0\r\n', 60*cfb92d14SAndroid Build Coastguard Worker ), 61*cfb92d14SAndroid Build Coastguard Worker ( 62*cfb92d14SAndroid Build Coastguard Worker 'diag send 20 100\n', 63*cfb92d14SAndroid Build Coastguard Worker r'sending 0x14 packet\(s\), length 0x64\r\nstatus 0x00\r\n', 64*cfb92d14SAndroid Build Coastguard Worker ), 65*cfb92d14SAndroid Build Coastguard Worker ( 66*cfb92d14SAndroid Build Coastguard Worker ' diag \t send \t 20\t100', 67*cfb92d14SAndroid Build Coastguard Worker r'sending 0x14 packet\(s\), length 0x64\r\nstatus 0x00\r\n', 68*cfb92d14SAndroid Build Coastguard Worker ), 69*cfb92d14SAndroid Build Coastguard Worker ( 70*cfb92d14SAndroid Build Coastguard Worker 'diag repeat 100 100\n', 71*cfb92d14SAndroid Build Coastguard Worker 'sending packets of length 0x64 at the delay of 0x64 ms\r\nstatus 0x00\r\n', 72*cfb92d14SAndroid Build Coastguard Worker ), 73*cfb92d14SAndroid Build Coastguard Worker ( 74*cfb92d14SAndroid Build Coastguard Worker 'diag repeat stop\n', 75*cfb92d14SAndroid Build Coastguard Worker 'repeated packet transmission is stopped\r\nstatus 0x00\r\n', 76*cfb92d14SAndroid Build Coastguard Worker ), 77*cfb92d14SAndroid Build Coastguard Worker ( 78*cfb92d14SAndroid Build Coastguard Worker 'diag stop\n', 79*cfb92d14SAndroid Build Coastguard Worker r'received packets: 0\r\nsent packets: ([1-9]\d*)\r\n' 80*cfb92d14SAndroid Build Coastguard Worker 'first received packet: rssi=0, lqi=0\r\n' 81*cfb92d14SAndroid Build Coastguard Worker 'last received packet: rssi=0, lqi=0\r\n\n' 82*cfb92d14SAndroid Build Coastguard Worker r'stop diagnostics mode\r\nstatus 0x00\r\n', 83*cfb92d14SAndroid Build Coastguard Worker ), 84*cfb92d14SAndroid Build Coastguard Worker ('diag', 'diagnostics mode is disabled\r\n'), 85*cfb92d14SAndroid Build Coastguard Worker ( 86*cfb92d14SAndroid Build Coastguard Worker 'diag 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32', 87*cfb92d14SAndroid Build Coastguard Worker r'Error 7: InvalidArgs\r\n', 88*cfb92d14SAndroid Build Coastguard Worker ), 89*cfb92d14SAndroid Build Coastguard Worker ] 90*cfb92d14SAndroid Build Coastguard Worker 91*cfb92d14SAndroid Build Coastguard Worker for case in cases: 92*cfb92d14SAndroid Build Coastguard Worker node.send_command(case[0], expect_command_echo=False) 93*cfb92d14SAndroid Build Coastguard Worker self.simulator.go(1) 94*cfb92d14SAndroid Build Coastguard Worker if type(self.simulator).__name__ == 'VirtualTime': 95*cfb92d14SAndroid Build Coastguard Worker time.sleep(0.1) 96*cfb92d14SAndroid Build Coastguard Worker node._expect(case[1]) 97*cfb92d14SAndroid Build Coastguard Worker 98*cfb92d14SAndroid Build Coastguard Worker 99*cfb92d14SAndroid Build Coastguard Workerif __name__ == '__main__': 100*cfb92d14SAndroid Build Coastguard Worker unittest.main() 101