forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTC_IDM_4_2.py
611 lines (495 loc) · 27.5 KB
/
TC_IDM_4_2.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#
# Copyright (c) 2023 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import copy
import logging
import time
import queue
import chip.clusters as Clusters
from chip.clusters import ClusterObjects as ClusterObjects
from chip.ChipDeviceCtrl import ChipDeviceController
from chip.clusters.Attribute import AttributePath, TypedAttributePath, SubscriptionTransaction
from chip.exceptions import ChipStackError
from chip.interaction_model import Status
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
from mobly import asserts
'''
Category:
Functional
Description:
Validates Interaction Data Model (IDM), specifically subscription responses. Some example of tests run:
- Subscriptions with varying MaxIntervalCeiling
- Checks for `InvalidAction` results when subscribing to clusters and attributes without access rights
- Checks that subscription is not established for invalid MinIntervalFloor
- Validates that only correctly filtered data is received when a subscription is established
Full test plan link for details:
https://github.com/CHIP-Specifications/chip-test-plans/blob/master/src/interactiondatamodel.adoc#tc-idm-4-2-subscription-response-messages-from-dut-test-cases-dut_server
'''
class AttributeChangeCallback:
def __init__(self, expected_attribute: ClusterObjects.ClusterAttributeDescriptor, output: queue.Queue):
self._output = output
self._expected_attribute = expected_attribute
self.callback_trigger_time_ms = 0;
def __call__(self, path: TypedAttributePath, transaction: SubscriptionTransaction):
if path.AttributeType == self._expected_attribute:
current_time = time.time()
q = (path, transaction)
logging.info(f'Got subscription report for {path.AttributeType} at {current_time}')
print(f"@@_end: {current_time}")
self._output.put(q)
self.callback_trigger_time_ms = current_time
class TC_IDM_4_2(MatterBaseTest):
ROOT_NODE_ENDPOINT_ID = 0
async def write_acl(self, ctrl, acl, ep=ROOT_NODE_ENDPOINT_ID):
result = await ctrl.WriteAttribute(self.dut_node_id, [(ep, Clusters.AccessControl.Attributes.Acl(acl))])
asserts.assert_equal(result[ep].Status, Status.Success, "ACL write failed")
async def get_descriptor_server_list(self, ctrl, ep=ROOT_NODE_ENDPOINT_ID):
return await self.read_single_attribute_check_success(
endpoint=ep,
dev_ctrl=ctrl,
cluster=Clusters.Descriptor,
attribute=Clusters.Descriptor.Attributes.ServerList
)
async def get_idle_mode_duration_sec(self, ctrl, ep=ROOT_NODE_ENDPOINT_ID):
return await self.read_single_attribute_check_success(
endpoint=ep,
dev_ctrl=ctrl,
cluster=Clusters.IcdManagement,
attribute=Clusters.IcdManagement.Attributes.IdleModeDuration
)
def get_attribute_value_wait(self, sub, typed_attr_path):
start_time = time.time()
timeout = 10
increment = 0.1
loop = True
attribute_value = None
while loop:
# Get the attribute value
attribute_value = sub.GetAttribute(typed_attr_path)
# Check if the value is not an empty string
if attribute_value != "":
loop = False # Exit the loop
else:
# Check if the timeout has been reached
if time.time() - start_time > timeout:
error_msg = f"Timeout: Value for '{typed_attr_path.AttributeName}' attribute not found within {timeout} seconds."
raise TimeoutError(error_msg)
else:
time.sleep(increment)
return attribute_value
@staticmethod
def verify_attribute_exists(sub, cluster, attribute, ep=ROOT_NODE_ENDPOINT_ID):
sub_attrs = sub
if isinstance(sub, Clusters.Attribute.SubscriptionTransaction):
sub_attrs = sub.GetAttributes()
asserts.assert_true(ep in sub_attrs, "Must have read endpoint %s data" % ep)
asserts.assert_true(cluster in sub_attrs[ep], "Must have read %s cluster data" % cluster.__name__)
asserts.assert_true(attribute in sub_attrs[ep][cluster],
"Must have read back attribute %s" % attribute.__name__)
@staticmethod
def get_typed_attribute_path(attribute, ep=ROOT_NODE_ENDPOINT_ID):
return TypedAttributePath(
Path=AttributePath(
EndpointId=ep,
Attribute=attribute
)
)
async def get_dut_acl(self, ep=ROOT_NODE_ENDPOINT_ID):
sub = await self.default_controller.ReadAttribute(
nodeid=self.dut_node_id,
attributes=[(ep, Clusters.AccessControl.Attributes.Acl)],
keepSubscriptions=False,
fabricFiltered=True
)
acl_list = sub[ep][Clusters.AccessControl][Clusters.AccessControl.Attributes.Acl]
return acl_list
async def add_ace_to_dut_acl(self, ctrl, ace):
dut_acl_original = await self.get_dut_acl()
dut_acl = copy.deepcopy(dut_acl_original)
dut_acl.append(ace)
await self.write_acl(ctrl=ctrl, acl=dut_acl)
@staticmethod
def is_valid_uint32_value(var):
return isinstance(var, int) and 0 <= var <= 0xFFFFFFFF
@staticmethod
def is_valid_uint16_value(var):
return isinstance(var, int) and 0 <= var <= 0xFFFF
@async_test_body
async def test_TC_IDM_4_2(self):
# Test setup
cluster_rev_attr = Clusters.BasicInformation.Attributes.ClusterRevision
cluster_rev_attr_typed_path = self.get_typed_attribute_path(cluster_rev_attr)
node_label_attr = Clusters.BasicInformation.Attributes.NodeLabel
node_label_attr_path = [(0, node_label_attr)]
node_label_attr_typed_path = self.get_typed_attribute_path(node_label_attr)
SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC = 0
INVALID_ACTION_ERROR_CODE = 0x580
# Controller 1 setup
# Subscriber/client with admin access to the DUT
# Will write ACL for controller 2 and validate success/error codes
CR1: ChipDeviceController = self.default_controller
# Controller 2 setup
# Subscriber/client with limited access to the DUT
# Will validate error status codes
fabric_admin = self.certificate_authority_manager.activeCaList[0].adminList[0]
CR2_nodeid = self.matter_test_config.controller_node_id + 1
CR2: ChipDeviceController = fabric_admin.NewController(
nodeId=CR2_nodeid,
paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path),
)
# *** Step 0 ***
self.print_step("0", "CR1 reads the Descriptor cluster ServerList attribute from EP0")
ep0_servers = await self.get_descriptor_server_list(CR1)
# Check if ep0_servers contains the ICD Management cluster ID (0x0046)
if Clusters.IcdManagement.id in ep0_servers:
# Read the IdleModeDuration attribute value from the DUT
logging.info(
"CR1 reads from the DUT the IdleModeDuration attribute and sets SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC = IdleModeDuration")
idleModeDuration = await self.get_idle_mode_duration_sec(CR1)
SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC = idleModeDuration
min_interval_floor_sec = 0
else:
# Defaulting SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC to 60 minutes
SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC = 60 * 60
min_interval_floor_sec = 3
logging.info(
f"Set SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC to {SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC} seconds")
# *** Step 1 ***
self.print_step(1, "CR1 sends a subscription message to the DUT with MaxIntervalCeiling set to a value greater than SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC. DUT sends a report data action to the TH. CR1 sends a success status response to the DUT. DUT sends a Subscribe Response Message to the CR1 to activate the subscription.")
max_interval_ceiling_sec = SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC + 5
asserts.assert_greater(max_interval_ceiling_sec, min_interval_floor_sec,
"MaxIntervalCeiling must be greater than MinIntervalFloor")
# Subscribe to attribute
sub_cr1_step1 = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=node_label_attr_path,
reportInterval=(min_interval_floor_sec, max_interval_ceiling_sec),
keepSubscriptions=False
)
# Verify attribute came back
self.verify_attribute_exists(
sub=sub_cr1_step1,
cluster=Clusters.BasicInformation,
attribute=node_label_attr
)
# Verify subscriptionId is of uint32 type
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step1.subscriptionId), "subscriptionId is not of uint32 type.")
# Verify MaxInterval is of uint32 type
sub_cr1_step1_intervals = sub_cr1_step1.GetReportingIntervalsSeconds()
sub_cr1_step1_min_interval_floor_sec, sub_cr1_step1_max_interval_ceiling_sec = sub_cr1_step1_intervals
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step1_max_interval_ceiling_sec),
"MaxInterval is not of uint32 type.")
# Verify MaxInterval is less than or equal to SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC
asserts.assert_less_equal(sub_cr1_step1_max_interval_ceiling_sec, max_interval_ceiling_sec,
"MaxInterval is not less than or equal to SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC")
sub_cr1_step1.Shutdown()
# *** Step 2 ***
self.print_step(2, "CR1 sends a subscription message to the DUT with MaxIntervalCeiling set to a value less than SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC. DUT sends a report data action to the CR1. CR1 sends a success status response to the DUT. DUT sends a Subscribe Response Message to the CR1 to activate the subscription.")
min_interval_floor_sec = 1
max_interval_ceiling_sec = max(2, SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC - 5)
asserts.assert_greater(max_interval_ceiling_sec, min_interval_floor_sec,
"MaxIntervalCeiling must be greater than MinIntervalFloor")
# Subscribe to attribute
sub_cr1_step2 = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=node_label_attr_path,
reportInterval=(min_interval_floor_sec, max_interval_ceiling_sec),
keepSubscriptions=False
)
# Verify attribute came back
self.verify_attribute_exists(
sub=sub_cr1_step2,
cluster=Clusters.BasicInformation,
attribute=node_label_attr
)
# Verify subscriptionId is of uint32 type
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step2.subscriptionId), "subscriptionId is not of uint32 type.")
# Verify MaxInterval is of uint32 type
sub_cr1_step2_intervals = sub_cr1_step2.GetReportingIntervalsSeconds()
sub_cr1_step2_min_interval_floor_sec, sub_cr1_step2_max_interval_ceiling_sec = sub_cr1_step2_intervals
asserts.assert_true(self.is_valid_uint32_value(sub_cr1_step2_max_interval_ceiling_sec),
"MaxInterval is not of uint32 type.")
# Verify MaxInterval is less than or equal to MaxIntervalCeiling
asserts.assert_less_equal(sub_cr1_step2_max_interval_ceiling_sec, SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC,
"MaxInterval is not less than or equal to SUBSCRIPTION_MAX_INTERVAL_PUBLISHER_LIMIT_SEC")
sub_cr1_step2.Shutdown()
# *** Step 3 ***
self.print_step(3, "Setup CR2 such that it does not have access to a specific cluster. CR2 sends a subscription message to subscribe to an attribute on that cluster for which it does not have access.")
# Limited ACE for controller 2 with single cluster access
CR2_limited_ace = Clusters.AccessControl.Structs.AccessControlEntryStruct(
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView,
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(cluster=Clusters.BasicInformation.id)],
subjects=[CR2_nodeid])
self.add_ace_to_dut_acl(CR1, CR2_limited_ace)
# Controller 2 tries to subscribe an attribute from a cluster
# it doesn't have access to
# "INVALID_ACTION" status response expected
try:
await CR2.ReadAttribute(
nodeid=self.dut_node_id,
# Attribute from a cluster controller 2 has no access to
attributes=[(0, Clusters.AccessControl.Attributes.Acl)],
keepSubscriptions=False,
reportInterval=[3, 3],
autoResubscribe=False
)
asserts.fail("Expected exception not thrown")
except ChipStackError as e:
# Verify that the DUT returns an "INVALID_ACTION" status response
asserts.assert_equal(e.err, INVALID_ACTION_ERROR_CODE,
"Incorrect error response for subscription to unallowed cluster")
# *** Step 4 ***
self.print_step(4, "Setup CR2 such that it does not have access to all attributes on a specific cluster and endpoint. CR2 sends a subscription request to subscribe to all attributes for which it does not have access.")
# Limited ACE for controller 2 with single cluster access and specific endpoint
CR2_limited_ace = Clusters.AccessControl.Structs.AccessControlEntryStruct(
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView,
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(
endpoint=1,
cluster=Clusters.BasicInformation.id)],
subjects=[CR2_nodeid])
self.add_ace_to_dut_acl(CR1, CR2_limited_ace)
# Controller 2 tries to subscribe to all attributes from a cluster
# it doesn't have access to
# "INVALID_ACTION" status response expected
try:
await CR2.ReadAttribute(
nodeid=self.dut_node_id,
# Cluster controller 2 has no access to
attributes=[(0, Clusters.BasicInformation)],
keepSubscriptions=False,
reportInterval=[3, 3],
autoResubscribe=False
)
raise ValueError("Expected exception not thrown")
except ChipStackError as e:
# Verify that the DUT returns an "INVALID_ACTION" status response
asserts.assert_equal(e.err, INVALID_ACTION_ERROR_CODE,
"Incorrect error response for subscription to unallowed cluster")
# *** Step 5 ***
self.print_step(5, "Setup CR2 such that it does not have access to an Endpoint. CR2 sends a subscription request to subscribe to all attributes on all clusters on a specific Endpoint for which it does not have access.")
# Limited ACE for controller 2 with endpoint 1 access only to all clusters and all attributes
CR2_limited_ace = Clusters.AccessControl.Structs.AccessControlEntryStruct(
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView,
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=1)],
subjects=[CR2_nodeid])
self.add_ace_to_dut_acl(CR1, CR2_limited_ace)
# Controller 2 tries to subscribe to all attributes from all clusters
# on an endpoint it doesn't have access to
# "INVALID_ACTION" status response expected
try:
await CR2.ReadAttribute(
nodeid=self.dut_node_id,
# Endpoint controller 2 has no access to
attributes=[(0)],
keepSubscriptions=False,
reportInterval=[3, 3],
autoResubscribe=False
)
raise ValueError("Expected exception not thrown")
except ChipStackError as e:
# Verify that the DUT returns an "INVALID_ACTION" status response
asserts.assert_equal(e.err, INVALID_ACTION_ERROR_CODE,
"Incorrect error response for subscription to unallowed endpoint")
# *** Step 6 ***
self.print_step(6, "Setup CR2 such that it does not have access to the Node. CR2 sends a subscription request to subscribe to all attributes on all clusters on all endpoints on a Node for which it does not have access.")
# Skip setting an ACE for controller 2 so
# the DUT node rejects subscribing to it
# Write original DUT ACL into DUT
dut_acl_original = await self.get_dut_acl()
await self.write_acl(ctrl=CR1, acl=dut_acl_original)
# Controller 2 tries to subscribe to all attributes from all clusters
# from all endpoints on a node it doesn't have access to
# "INVALID_ACTION" status response expected
try:
await CR2.ReadAttribute(
# Node controller 2 has no access to
nodeid=self.dut_node_id,
attributes=[],
keepSubscriptions=False,
reportInterval=[3, 3],
autoResubscribe=False
)
raise ValueError("Expected exception not thrown")
except ChipStackError as e:
# Verify that the DUT returns an "INVALID_ACTION" status response
asserts.assert_equal(e.err, INVALID_ACTION_ERROR_CODE,
"Incorrect error response for subscription to unallowed node")
# *** Step 7 ***
self.print_step(7, "CR1 sends a subscription request action for an attribute with an empty DataVersionFilters field. DUT sends a report data action with the data of the attribute along with the data version. Tear down the subscription for that attribute. Start another subscription with the DataVersionFilter field set to the data version received above.")
# Subscribe to attribute with empty dataVersionFilters
sub_cr1_empty_dvf = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=node_label_attr_path,
keepSubscriptions=False
)
# Verify DataVersion attribute came back
self.verify_attribute_exists(
sub=sub_cr1_empty_dvf,
cluster=Clusters.BasicInformation,
attribute=Clusters.Attribute.DataVersion
)
# Get DataVersion
data_version = sub_cr1_empty_dvf[0][Clusters.BasicInformation][Clusters.Attribute.DataVersion]
data_version_filter = [(0, Clusters.BasicInformation, data_version)]
# Subscribe to attribute with provided DataVersion
sub_cr1_step8 = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=node_label_attr_path,
reportInterval=(10, 20),
keepSubscriptions=False,
dataVersionFilters=data_version_filter
)
# Verify that the subscription is activated between CR1 and DUT
asserts.assert_true(sub_cr1_step8.subscriptionId, "Subscription not activated")
sub_cr1_step8.Shutdown()
# *** Step 8 ***
self.print_step(8, "CR1 sends a subscription request action for an attribute and sets the MinIntervalFloor to min_interval_floor_s and MaxIntervalCeiling to 10. Activate the Subscription between CR1 and DUT and record the time when the priming ReportDataMessage is received as t_report. Save the returned MaxInterval from the SubscribeResponseMessage as max_interval_s.")
# Subscribe to attribute
min_interval_floor_sec = 3
max_interval_ceiling_sec = 10
sub_cr1_update_value = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=node_label_attr_path,
reportInterval=(min_interval_floor_sec, max_interval_ceiling_sec),
keepSubscriptions=False
)
# Record the time when the priming ReportDataMessage is received
t_report_sec = time.time()
print(f"@@_begin: {t_report_sec}")
# Saving the returned MaxInterval from the SubscribeResponseMessage
sub_cr1_step8_intervals = sub_cr1_step8.GetReportingIntervalsSeconds()
min_interval_sec, max_interval_sec = sub_cr1_step8_intervals
# Get subscription timeout
subscription_timeout = sub_cr1_update_value.GetSubscriptionTimeoutMs()
print(f"subscription_timeout: {subscription_timeout}")
# Set Attribute Update Callb
nodel_label_queue = queue.Queue()
node_label_update_cb = AttributeChangeCallback(node_label_attr, nodel_label_queue)
sub_cr1_update_value.SetAttributeUpdateCallback(node_label_update_cb)
# Modify attribute value
new_node_label_write = "NewNodeLabel_011235813"
await CR1.WriteAttribute(
self.dut_node_id,
[(0, node_label_attr(value=new_node_label_write))]
)
# write time - sub time -> bigger than floor and less than sub timeout
# Wait MinIntervalFloor seconds before reading updated attribute value
# new_node_label_read = self.get_attribute_value_wait(sub_cr1_update_value, node_label_attr_typed_path)
# Verify new attribute value after MinIntervalFloor time, deprecated
# asserts.assert_equal(new_node_label_read, new_node_label_write, "Attribute value not updated after write operation.")
sub_cr1_update_value.Shutdown()
# *** Step 9 ***
# *** Step 10 ***
self.print_step(
10, "CR1 sends a subscription request action for an attribute and set the MinIntervalFloor value to be greater than MaxIntervalCeiling.")
# Subscribe to attribute with invalid reportInterval arguments, expect and exception
sub_cr1_invalid_intervals = None
try:
sub_cr1_invalid_intervals = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=node_label_attr_path,
reportInterval=(20, 10),
keepSubscriptions=False
)
except ChipStackError:
# Verify no subscription is established
with asserts.assert_raises(AttributeError):
sub_cr1_invalid_intervals.subscriptionId
except Exception:
asserts.fail("Expected exception was not thrown")
# *** Step 11 ***
self.print_step(
11, "CR1 sends a subscription request to subscribe to a specific global attribute from all clusters on all endpoints.")
# Omitting endpoint to indicate endpoint wildcard
cluster_rev_attr_path = [(cluster_rev_attr)]
# Subscribe to global attribute
sub_cr1_step11 = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=cluster_rev_attr_path,
reportInterval=(3, 3),
keepSubscriptions=False
)
# Verify that the subscription is activated between CR1 and DUT
asserts.assert_true(sub_cr1_step11.subscriptionId, "Subscription not activated")
# Verify attribute came back
self.verify_attribute_exists(
sub=sub_cr1_step11,
cluster=Clusters.BasicInformation,
attribute=cluster_rev_attr
)
# Verify DUT sends back the attribute values for the global attribute
cluster_revision_attr_value = sub_cr1_step11.GetAttribute(cluster_rev_attr_typed_path)
# Verify ClusterRevision is of uint16 type
asserts.assert_true(self.is_valid_uint16_value(cluster_revision_attr_value), "ClusterRevision is not of uint16 type.")
# Verify valid ClusterRevision value
asserts.assert_greater_equal(cluster_revision_attr_value, 0, "Invalid ClusterRevision value.")
sub_cr1_step11.Shutdown()
# *** Step 12 ***
self.print_step(12, "CR1 sends a subscription request to subscribe to a global attribute on an endpoint on all clusters.")
# Specifying single endpoint 0
requested_ep = 0
cluster_rev_attr_path = [(requested_ep, cluster_rev_attr)]
# Subscribe to global attribute
sub_cr1_step12 = await CR1.ReadAttribute(
nodeid=self.dut_node_id,
attributes=cluster_rev_attr_path,
reportInterval=(3, 3),
keepSubscriptions=False
)
# Verify that the subscription is activated between CR1 and DUT
asserts.assert_true(sub_cr1_step12.subscriptionId, "Subscription not activated")
# Verify attribute came back
self.verify_attribute_exists(
sub=sub_cr1_step12,
cluster=Clusters.BasicInformation,
attribute=cluster_rev_attr
)
# Verify no data from other endpoints is sent back
attributes = sub_cr1_step12.GetAttributes()
ep_keys = list(attributes.keys())
asserts.assert_true(len(ep_keys) == 1, "More than one endpoint returned, exactly 1 was expected")
# Verify DUT sends back the attribute values for the global attribute
cluster_rev_attr_typed_path = self.get_typed_attribute_path(cluster_rev_attr)
cluster_revision_attr_value = sub_cr1_step12.GetAttribute(cluster_rev_attr_typed_path)
# Verify ClusterRevision is of uint16 type
asserts.assert_true(self.is_valid_uint16_value(cluster_revision_attr_value), "ClusterRevision is not of uint16 type.")
sub_cr1_step12.Shutdown()
# *** Step 13 ***
self.print_step(13, "CR1 sends a subscription request to the DUT with both AttributeRequests and EventRequests as empty.")
# Attempt a subscription with both AttributeRequests and EventRequests as empty
sub_cr1_step13 = None
try:
sub_cr1_step13 = await CR1.Read(
nodeid=self.dut_node_id,
attributes=[],
events=[],
reportInterval=(3, 3)
)
raise ValueError("Expected exception not thrown")
except ChipStackError as e:
# Verify that the DUT sends back a Status Response Action with the INVALID_ACTION Status Code
asserts.assert_equal(e.err, INVALID_ACTION_ERROR_CODE,
"Incorrect error response for subscription with empty AttributeRequests and EventRequests")
# Verify no subscription is established
with asserts.assert_raises(AttributeError):
sub_cr1_step13.subscriptionId
except Exception:
asserts.fail("Expected exception was not thrown")
if __name__ == "__main__":
default_matter_test_main()