mirror of
https://github.com/espressif/openthread.git
synced 2026-09-06 09:10:04 +00:00
[tests] add test for dataset updater (#6227)
This commit is contained in:
@@ -45,6 +45,7 @@ CHANNEL_MANAGER ?= 1
|
||||
CHANNEL_MONITOR ?= 1
|
||||
CHILD_SUPERVISION ?= 1
|
||||
DAEMON ?= 0
|
||||
DATASET_UPDATER ?= 1
|
||||
DHCP6_CLIENT ?= 1
|
||||
DHCP6_SERVER ?= 1
|
||||
DIAGNOSTIC ?= 1
|
||||
|
||||
@@ -157,6 +157,7 @@ EXTRA_DIST = \
|
||||
test_coap_block.py \
|
||||
test_common.py \
|
||||
test_crypto.py \
|
||||
test_dataset_updater.py \
|
||||
test_diag.py \
|
||||
test_dnssd.py \
|
||||
test_ipv6.py \
|
||||
@@ -211,6 +212,7 @@ check_SCRIPTS = \
|
||||
test_coap_block.py \
|
||||
test_common.py \
|
||||
test_crypto.py \
|
||||
test_dataset_updater.py \
|
||||
test_diag.py \
|
||||
test_dnssd.py \
|
||||
test_ipv6.py \
|
||||
|
||||
@@ -1882,6 +1882,23 @@ class NodeImpl:
|
||||
self.send_command('dataset commit pending')
|
||||
self._expect_done()
|
||||
|
||||
def start_dataset_updater(self, panid=None, channel=None):
|
||||
self.send_command('dataset clear')
|
||||
self._expect_done()
|
||||
|
||||
if panid is not None:
|
||||
cmd = 'dataset panid %d' % panid
|
||||
self.send_command(cmd)
|
||||
self._expect_done()
|
||||
|
||||
if channel is not None:
|
||||
cmd = 'dataset channel %d' % channel
|
||||
self.send_command(cmd)
|
||||
self._expect_done()
|
||||
|
||||
self.send_command('dataset updater start')
|
||||
self._expect_done()
|
||||
|
||||
def announce_begin(self, mask, count, period, ipaddr):
|
||||
cmd = 'commissioner announce %d %d %d %s' % (
|
||||
mask,
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2021, 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.
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
import config
|
||||
import thread_cert
|
||||
|
||||
LEADER = 1
|
||||
ROUTER = 2
|
||||
MED = 3
|
||||
SED = 4
|
||||
|
||||
|
||||
class TestDatasetUpdater(thread_cert.TestCase):
|
||||
SUPPORT_NCP = False
|
||||
USE_MESSAGE_FACTORY = False
|
||||
|
||||
TOPOLOGY = {
|
||||
LEADER: {
|
||||
'mode': 'rdn',
|
||||
'channel': 11,
|
||||
'panid': 0xface,
|
||||
},
|
||||
ROUTER: {
|
||||
'mode': 'rdn',
|
||||
'channel': 11,
|
||||
'panid': 0xface,
|
||||
'router_selection_jitter': 1,
|
||||
},
|
||||
MED: {
|
||||
'mode': 'rn',
|
||||
'channel': 11,
|
||||
'panid': 0xface,
|
||||
'allowlist': [ROUTER],
|
||||
},
|
||||
SED: {
|
||||
'mode': '-',
|
||||
'channel': 11,
|
||||
'panid': 0xface,
|
||||
'timeout': config.DEFAULT_CHILD_TIMEOUT,
|
||||
'allowlist': [ROUTER],
|
||||
},
|
||||
}
|
||||
|
||||
def test(self):
|
||||
self.nodes[LEADER].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
|
||||
|
||||
self.nodes[ROUTER].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[ROUTER].get_state(), 'router')
|
||||
|
||||
self.nodes[MED].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[MED].get_state(), 'child')
|
||||
|
||||
self.nodes[SED].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[SED].get_state(), 'child')
|
||||
|
||||
self.verify_state(11)
|
||||
|
||||
# update initiated by LEADER
|
||||
self.nodes[LEADER].start_dataset_updater(channel=12)
|
||||
self.simulator.go(120)
|
||||
self.verify_state(12)
|
||||
|
||||
# update initiated by ROUTER
|
||||
self.nodes[ROUTER].start_dataset_updater(channel=13)
|
||||
self.simulator.go(120)
|
||||
self.verify_state(13)
|
||||
|
||||
# update initiated by LEADER overridden by ROUTER
|
||||
self.nodes[LEADER].start_dataset_updater(channel=14)
|
||||
self.simulator.go(20)
|
||||
self.nodes[ROUTER].start_dataset_updater(channel=15)
|
||||
self.simulator.go(120)
|
||||
self.verify_state(15)
|
||||
|
||||
# update initiated by ROUTER overridden by LEADER
|
||||
self.nodes[ROUTER].start_dataset_updater(channel=16)
|
||||
self.simulator.go(10)
|
||||
self.nodes[LEADER].start_dataset_updater(channel=17)
|
||||
self.simulator.go(120)
|
||||
self.verify_state(17)
|
||||
|
||||
def verify_state(self, channel):
|
||||
self.assertEqual(self.nodes[LEADER].get_channel(), channel)
|
||||
self.assertEqual(self.nodes[ROUTER].get_channel(), channel)
|
||||
self.assertEqual(self.nodes[MED].get_channel(), channel)
|
||||
self.assertEqual(self.nodes[SED].get_channel(), channel)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user