Skip to content

Commit fa4d1cf

Browse files
committed
python_testing: generate controller's nodeid and shutdown subscription
* implementation of generate_random_node_id with exculdes values, the method add possibilty to run multiple test cases within one test session (the controllers' nodeid is the same for new controller in different test cases) * ACE-1.2 script update: shutdown scubscriptions Signed-off-by: Michał Szablowski <michal.szablowski@nordicsemi.no>
1 parent 6e31453 commit fa4d1cf

6 files changed

+52
-13
lines changed

src/python_testing/TC_ACE_1_2.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from chip.clusters.Attribute import EventReadResult, SubscriptionTransaction, TypedAttributePath
3131
from chip.exceptions import ChipStackError
3232
from chip.interaction_model import Status
33-
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
33+
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, generate_random_nodeid
3434
from mobly import asserts
3535

3636

@@ -87,8 +87,16 @@ def __init__(self, *args):
8787
self.breadcrumb = 1
8888
self.breadcrumb_queue = queue.Queue()
8989
self.subscription_breadcrumb = None
90+
self.subscriptions = []
9091
super().__init__(*args)
9192

93+
94+
def teardown_class(self):
95+
for subscription in self.subscriptions:
96+
subscription.Shutdown()
97+
if self.subscription_breadcrumb is not None:
98+
self.subscription_breadcrumb.Shutdown()
99+
92100
async def write_acl(self, acl):
93101
# This returns an attribute status
94102
result = await self.default_controller.WriteAttribute(self.dut_node_id, [(0, Clusters.AccessControl.Attributes.Acl(acl))])
@@ -97,6 +105,9 @@ async def write_acl(self, acl):
97105
async def steps_subscribe_breadcrumb(self, print_steps: bool):
98106
if print_steps:
99107
self.print_step(3, "TH2 subscribes to the Breadcrumb attribute")
108+
if isinstance(self.subscription_breadcrumb, Clusters.Attribute.SubscriptionTransaction):
109+
self.subscription_breadcrumb.Shutdown()
110+
100111
self.subscription_breadcrumb = await self.TH2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.GeneralCommissioning.Attributes.Breadcrumb)], reportInterval=(1, 5), keepSubscriptions=False, autoResubscribe=False)
101112
breadcrumb_cb = AttributeChangeCallback(Clusters.GeneralCommissioning.Attributes.Breadcrumb, self.breadcrumb_queue)
102113
self.subscription_breadcrumb.SetAttributeUpdateCallback(breadcrumb_cb)
@@ -136,7 +147,7 @@ async def test_TC_ACE_1_2(self):
136147
fabric_admin = self.certificate_authority_manager.activeCaList[0].adminList[0]
137148

138149
TH1_nodeid = self.matter_test_config.controller_node_id
139-
TH2_nodeid = self.matter_test_config.controller_node_id + 1
150+
TH2_nodeid = generate_random_nodeid(excluded_nodeid={TH1_nodeid})
140151

141152
self.TH2 = fabric_admin.NewController(nodeId=TH2_nodeid,
142153
paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path))
@@ -157,13 +168,15 @@ async def test_TC_ACE_1_2(self):
157168
acl_queue = queue.Queue()
158169
acl_cb = AttributeChangeCallback(Clusters.AccessControl.Attributes.Acl, acl_queue)
159170
subscription_acl.SetAttributeUpdateCallback(acl_cb)
171+
self.subscriptions.append(subscription_acl)
160172

161173
self.print_step(5, "TH2 subscribes to the AccessControlEntryChanged event")
162174
urgent = 1
163175
subscription_ace = await self.TH2.ReadEvent(nodeid=self.dut_node_id, events=[(0, Clusters.AccessControl.Events.AccessControlEntryChanged, urgent)], reportInterval=(1, 5), fabricFiltered=False, keepSubscriptions=True, autoResubscribe=False)
164176
ace_queue = queue.Queue()
165177
ace_cb = EventChangeCallback(Clusters.AccessControl.Events.AccessControlEntryChanged, ace_queue)
166178
subscription_ace.SetEventUpdateCallback(ace_cb)
179+
self.subscriptions.append(subscription_ace)
167180

168181
self.print_step(6, "TH1 writes ACL attribute")
169182
acl = Clusters.AccessControl.Structs.AccessControlEntryStruct(

src/python_testing/TC_ACE_1_3.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import chip.clusters as Clusters
2828
from chip.interaction_model import Status
29-
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
29+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main, generate_random_nodeid
3030
from mobly import asserts
3131

3232

@@ -137,9 +137,24 @@ async def test_TC_ACE_1_3(self):
137137
fabric_admin = self.certificate_authority_manager.activeCaList[0].adminList[0]
138138

139139
TH0_nodeid = self.matter_test_config.controller_node_id
140-
TH1_nodeid = self.matter_test_config.controller_node_id + 1
141-
TH2_nodeid = self.matter_test_config.controller_node_id + 2
142-
TH3_nodeid = self.matter_test_config.controller_node_id + 3
140+
TH1_nodeid = generate_random_nodeid(
141+
excluded_nodeid={
142+
TH0_nodeid
143+
}
144+
)
145+
TH2_nodeid = generate_random_nodeid(
146+
excluded_nodeid={
147+
TH0_nodeid,
148+
TH1_nodeid
149+
}
150+
)
151+
TH3_nodeid = generate_random_nodeid(
152+
excluded_nodeid={
153+
TH0_nodeid,
154+
TH1_nodeid,
155+
TH2_nodeid
156+
}
157+
)
143158

144159
TH1 = fabric_admin.NewController(nodeId=TH1_nodeid,
145160
paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path),

src/python_testing/TC_ACE_1_5.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import chip.clusters as Clusters
2828
from chip import ChipDeviceCtrl
2929
from chip.interaction_model import Status
30-
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
30+
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, generate_random_nodeid
3131
from mobly import asserts
3232

3333

@@ -53,7 +53,7 @@ async def test_TC_ACE_1_5(self):
5353
new_fabric_admin = new_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.matter_test_config.fabric_id + 1)
5454

5555
TH1_nodeid = self.matter_test_config.controller_node_id
56-
TH2_nodeid = self.matter_test_config.controller_node_id + 2
56+
TH2_nodeid = generate_random_nodeid(excluded_nodeid={TH1_nodeid})
5757

5858
self.th2 = new_fabric_admin.NewController(nodeId=TH2_nodeid,
5959
paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path))

src/python_testing/TC_AccessChecker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from chip.tlv import uint
1717
from global_attribute_ids import GlobalAttributeIds
1818
from matter_testing_support import (AttributePathLocation, ClusterPathLocation, MatterBaseTest, TestStep, async_test_body,
19-
default_matter_test_main)
19+
default_matter_test_main, generate_random_nodeid)
2020
from spec_parsing_support import XmlCluster, build_xml_clusters
2121

2222

@@ -66,7 +66,7 @@ async def setup_class(self):
6666
self._record_errors()
6767
# We need to run this test from two controllers so we can test access to the ACL cluster while retaining access to the ACL cluster
6868
fabric_admin = self.certificate_authority_manager.activeCaList[0].adminList[0]
69-
self.TH2_nodeid = self.matter_test_config.controller_node_id + 1
69+
self.TH2_nodeid = generate_random_nodeid(excluded_nodeid={self.matter_test_config.controller_node_id})
7070
self.TH2 = fabric_admin.NewController(nodeId=self.TH2_nodeid)
7171

7272
# Both the tests in this suite are potentially long-running if there are a large number of attributes on the DUT

src/python_testing/TC_IDM_4_2.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from chip.clusters.Attribute import AttributePath, TypedAttributePath
2525
from chip.exceptions import ChipStackError
2626
from chip.interaction_model import Status
27-
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
27+
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, generate_random_nodeid
2828
from mobly import asserts
2929

3030
'''
@@ -134,7 +134,11 @@ async def test_TC_IDM_4_2(self):
134134
# Subscriber/client with limited access to the DUT
135135
# Will validate error status codes
136136
fabric_admin = self.certificate_authority_manager.activeCaList[0].adminList[0]
137-
CR2_nodeid = self.matter_test_config.controller_node_id + 1
137+
CR2_nodeid = generate_random_nodeid(
138+
excluded_nodeid={
139+
self.matter_test_config.controller_node_id
140+
}
141+
)
138142
CR2: ChipDeviceController = fabric_admin.NewController(
139143
nodeId=CR2_nodeid,
140144
paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path),

src/python_testing/matter_testing_support.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,13 @@ def parse_matter_test_args(argv: Optional[List[str]] = None) -> MatterTestConfig
14931493
return convert_args_to_matter_config(parser.parse_known_args(argv)[0])
14941494

14951495

1496+
def generate_random_nodeid(excluded_nodeid: typing.Optional[typing.Set] = set()) -> int:
1497+
"Generate random complainat nodeid, excluding a set of provided nodeids."
1498+
nodeid = random.randint(1, 0xFFFF_FFEF_FFFF_FFFF)
1499+
if nodeid in excluded_nodeid:
1500+
return generate_random_nodeid(excluded_nodeid)
1501+
return nodeid
1502+
14961503
def async_test_body(body):
14971504
"""Decorator required to be applied whenever a `test_*` method is `async def`.
14981505
@@ -1697,7 +1704,7 @@ def run_tests_no_exit(test_class: MatterBaseTest, matter_test_config: MatterTest
16971704

16981705
try:
16991706
runner.run()
1700-
ok = runner.results.is_all_pass and ok
1707+
ok = runner.results.is_all_pass and ok
17011708
except TimeoutError:
17021709
ok = False
17031710
except signals.TestAbortAll:

0 commit comments

Comments
 (0)