1#!/usr/bin/env python3 2# 3# Copyright (c) 2021, 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 29from cli import verify 30import cli 31 32import sys 33 34print(sys.version) 35 36# ----------------------------------------------------------------------------------------------------------------------- 37# Test description: simple CLI get and set commands 38 39test_name = __file__[:-3] if __file__.endswith('.py') else __file__ 40print('-' * 120) 41print('Starting \'{}\''.format(test_name)) 42 43# ----------------------------------------------------------------------------------------------------------------------- 44# Creating `Nodes` instances 45 46node = cli.Node() 47 48# ----------------------------------------------------------------------------------------------------------------------- 49# Test implementation 50 51node.set_channel(21) 52verify(node.get_channel() == '21') 53 54ext_addr = '1122334455667788' 55node.set_ext_addr(ext_addr) 56verify(node.get_ext_addr() == ext_addr) 57 58ext_panid = '1020031510006016' 59node.set_ext_panid(ext_panid) 60verify(node.get_ext_panid() == ext_panid) 61 62key = '0123456789abcdeffecdba9876543210' 63node.set_network_key(key) 64verify(node.get_network_key() == key) 65 66panid = '0xabba' 67node.set_panid(panid) 68verify(node.get_panid() == panid) 69 70mode = 'rd' 71node.set_mode(mode) 72verify(node.get_mode() == mode) 73 74threshold = '1' 75node.set_router_upgrade_threshold(threshold) 76verify(node.get_router_upgrade_threshold() == threshold) 77 78jitter = '100' 79node.set_router_selection_jitter(jitter) 80verify(node.get_router_selection_jitter() == jitter) 81 82verify(node.get_interface_state() == 'down') 83verify(node.get_state() == 'disabled') 84 85# ----------------------------------------------------------------------------------------------------------------------- 86# Test finished 87 88cli.Node.finalize_all_nodes() 89 90print('\'{}\' passed.'.format(test_name)) 91