Skip to content

Commit 09ea936

Browse files
authored
Add reading of heap statistics before and after stress test (project-chip#24489)
1 parent 19cb1a5 commit 09ea936

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/python_testing/TC_RR_1_1.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,19 @@ async def test_TC_RR_1_1(self):
7575
skip_user_label_cluster_steps = self.user_params.get("skip_user_label_cluster_steps", False)
7676
# Whether to do the local session ID comparison checks to prove new sessions have not been established.
7777
check_local_session_id_unchanged = self.user_params.get("check_local_session_id_unchanged", False)
78+
# Whether to check heap statistics. Add `--bool-arg check_heap_watermarks:true` to command line to enable
79+
check_heap_watermarks = self.user_params.get("check_heap_watermarks", False)
7880

7981
BEFORE_LABEL = "Before Subscriptions 12345678912"
8082
AFTER_LABEL = "After Subscriptions 123456789123"
8183

8284
# Pre-conditions
8385

86+
# Do a read-out of heap statistics before the test begins
87+
if check_heap_watermarks:
88+
logging.info("Read Heap info before stress test")
89+
high_watermark_before, current_usage_before = await self.read_heap_statistics(dev_ctrl)
90+
8491
# Make sure all certificates are installed with maximal size
8592
dev_ctrl.fabricAdmin.certificateAuthority.maximizeCertChains = True
8693

@@ -406,6 +413,14 @@ async def test_TC_RR_1_1(self):
406413
num_fabrics_to_commission, fabric_unique_clients, group_key_map, groups_cluster_endpoints, indicated_max_groups_per_fabric)
407414
await self.validate_group_table(num_fabrics_to_commission, fabric_unique_clients, group_table_written)
408415

416+
# Read heap watermarks after the test
417+
if check_heap_watermarks:
418+
logging.info("Read Heap info after stress test")
419+
high_watermark_after, current_usage_after = await self.read_heap_statistics(dev_ctrl)
420+
logging.info("=== Heap Usage Diagnostics ===\nHigh watermark: {} (before) / {} (after)\n"
421+
"Current usage: {} (before) / {} (after)".format(high_watermark_before, high_watermark_after,
422+
current_usage_before, current_usage_after))
423+
409424
def random_string(self, length) -> str:
410425
rnd = self._pseudo_random_generator
411426
return "".join([rnd.choice("abcdef0123456789") for _ in range(length)])[:length]
@@ -619,7 +634,7 @@ def build_acl(self, fabric_number, client_by_name, num_controllers_per_fabric):
619634
# - Subjects field: [0x3000_0000_0000_0001, 0x3000_0000_0000_0002, 0x3000_0000_0000_0003, 0x3000_0000_0000_0004]
620635
# - Targets field: [{Cluster: 0xFFF1_FC40, DeviceType: 0xFFF1_FC20}, {Cluster: 0xFFF1_FC41, DeviceType: 0xFFF1_FC21}, {Cluster: 0xFFF1_FC02, DeviceType: 0xFFF1_FC42}]
621636
# . struct
622-
# - Privilege field: View (3)
637+
# - Privilege field: View (1)
623638
# - AuthMode field: CASE (2)
624639
# - Subjects field: [0x4000_0000_0000_0001, 0x4000_0000_0000_0002, 0x4000_0000_0000_0003, 0x4000_0000_0000_0004]
625640
# - Targets field: [{Cluster: 0xFFF1_FC80, DeviceType: 0xFFF1_FC20}, {Cluster: 0xFFF1_FC81, DeviceType: 0xFFF1_FC21}, {Cluster: 0xFFF1_FC82, DeviceType: 0xFFF1_FC22}]
@@ -666,7 +681,7 @@ def build_acl(self, fabric_number, client_by_name, num_controllers_per_fabric):
666681
targets=operate_targets)
667682
acl.append(operate_acl_entry)
668683

669-
# Operate ACL entry
684+
# View ACL entry
670685
view_subjects = [0x4000_0000_0000_0001, 0x4000_0000_0000_0002, 0x4000_0000_0000_0003, 0x4000_0000_0000_0004]
671686
view_targets = [
672687
Clusters.AccessControl.Structs.Target(cluster=0xFFF1_FC80, deviceType=0xFFF1_BC20),
@@ -701,6 +716,25 @@ def build_group_key(self, fabric_index: int, group_key_index: int, keys_per_fabr
701716
epochKey2=self.random_string(16).encode(),
702717
epochStartTime2=(set_id * 4 + 2))
703718

719+
async def read_heap_statistics(self, dev_ctrl):
720+
diagnostics_contents = [
721+
Clusters.SoftwareDiagnostics.Attributes.CurrentHeapHighWatermark,
722+
Clusters.SoftwareDiagnostics.Attributes.CurrentHeapUsed,
723+
]
724+
diagnostics_paths = [(0, attrib) for attrib in diagnostics_contents]
725+
swdiag_info = await dev_ctrl.ReadAttribute(self.dut_node_id, diagnostics_paths)
726+
727+
# Make sure everything came back from the read that we expected
728+
asserts.assert_true(0 in swdiag_info.keys(), "Must have read endpoint 0 data")
729+
asserts.assert_true(Clusters.SoftwareDiagnostics in swdiag_info[0].keys(
730+
), "Must have read Software Diagnostics cluster data")
731+
for attribute in diagnostics_contents:
732+
asserts.assert_true(attribute in swdiag_info[0][Clusters.SoftwareDiagnostics],
733+
"Must have read back attribute %s" % (attribute.__name__))
734+
high_watermark = swdiag_info[0][Clusters.SoftwareDiagnostics][Clusters.SoftwareDiagnostics.Attributes.CurrentHeapHighWatermark]
735+
current_usage = swdiag_info[0][Clusters.SoftwareDiagnostics][Clusters.SoftwareDiagnostics.Attributes.CurrentHeapUsed]
736+
return high_watermark, current_usage
737+
704738

705739
if __name__ == "__main__":
706740
default_matter_test_main(maximize_cert_chains=True, controller_cat_tags=[0x0001_0001])

0 commit comments

Comments
 (0)