1#!/usr/bin/env python3 2# 3# Copyright (c) 2018, 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 30import time 31import unittest 32 33import thread_cert 34 35 36class TestDiag(thread_cert.TestCase): 37 SUPPORT_NCP = False 38 39 TOPOLOGY = {1: None} 40 41 def test(self): 42 node = self.nodes[1] 43 44 cases = [ 45 ('diag', 'diagnostics mode is disabled\r\n'), 46 ('diag send 10 100', 'Error 13: InvalidState\r\n'), 47 ('diag start', 'Done\r\n'), 48 ('diag invalid test\n', 'diag feature \'invalid\' is not supported'), 49 ('diag', 'diagnostics mode is enabled\r\n'), 50 ('diag channel 10', 'Error 7: InvalidArgs\r\n'), 51 ('diag channel 11', 'Done\r\n'), 52 ('diag channel', '11\r\n'), 53 ('diag power -10', 'Done\r\n'), 54 ('diag power', '-10\r\n'), 55 ( 56 'diag stats', 57 'received packets: 0\r\n' 58 'sent success packets: 0\r\n' 59 'sent error cca packets: 0\r\n' 60 'sent error abort packets: 0\r\n' 61 'sent error invalid state packets: 0\r\n' 62 'sent error others packets: 0\r\n' 63 'first received packet: rssi=0, lqi=0\r\n' 64 'last received packet: rssi=0, lqi=0\r\n', 65 ), 66 ('diag send 20 100', 'Done\r\n'), 67 (' diag \t send \t 20\t100', 'Done\r\n'), 68 ('diag repeat 100 100', 'Done\r\n'), 69 ('diag repeat stop', 'Done\r\n'), 70 ('diag stop', 'Done\r\n'), 71 ('diag', 'diagnostics mode is disabled\r\n'), 72 ( 73 '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', 74 'Error 7: InvalidArgs\r\n', 75 ), 76 ] 77 78 for case in cases: 79 node.send_command(case[0]) 80 self.simulator.go(1) 81 if type(self.simulator).__name__ == 'VirtualTime': 82 time.sleep(0.1) 83 node._expect(case[1]) 84 85 86if __name__ == '__main__': 87 unittest.main() 88