From e7f6d0eb303946f4272da2a01e1262b4dd1d594d Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 7 Jan 2025 09:39:28 -0800 Subject: [PATCH] Improve python test for TC_DGSW_2_3 (#36969) --- src/python_testing/TC_DGSW_2_1.py | 48 ++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/python_testing/TC_DGSW_2_1.py b/src/python_testing/TC_DGSW_2_1.py index efc2df95fb24b4..6fd13293e0543e 100644 --- a/src/python_testing/TC_DGSW_2_1.py +++ b/src/python_testing/TC_DGSW_2_1.py @@ -50,6 +50,10 @@ def is_valid_uint64_value(value): def is_valid_uint32_value(value): return isinstance(value, int) and 0 <= value <= 0xFFFFFFFF + @staticmethod + def is_valid_str_value(value): + return isinstance(value, str) and len(value) > 0 + async def read_dgsw_attribute_expect_success(self, endpoint, attribute): cluster = Clusters.Objects.SoftwareDiagnostics return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) @@ -84,37 +88,47 @@ async def test_TC_DGSW_2_1(self): # STEP 2: TH reads from the DUT the ThreadMetrics attribute self.step(2) - if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.ThreadMetrics.attribute_id in attribute_list): + if self.pics_guard(attributes.ThreadMetrics.attribute_id in attribute_list): thread_metrics_list = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.ThreadMetrics) - # the Id field is mandatory - asserts.assert_true(self.is_valid_uint64_value(thread_metrics_list[0].id), "Id field should be a uint64 type") - if thread_metrics_list[0].name is not None: - asserts.assert_true(thread_metrics_list[0].name, str, "Name field should be a string type") - if thread_metrics_list[0].stackFreeCurrent is not None: - asserts.assert_true(self.is_valid_uint32_value( - thread_metrics_list[0].stackFreeCurrent), "StackFreeCurrent field should be a uint32 type") - if thread_metrics_list[0].stackFreeMinimum is not None: - asserts.assert_true(self.is_valid_uint32_value( - thread_metrics_list[0].stackFreeMinimum), "StackFreeMinimum field should be a uint32 type") - if thread_metrics_list[0].stackSize is not None: - asserts.assert_true(self.is_valid_uint32_value( - thread_metrics_list[0].stackSize), "StackSize field should be a uint32s type") + + # Validate each element in the thread_metrics_list + for metric in thread_metrics_list: + # The Id field is mandatory + asserts.assert_true(self.is_valid_uint64_value(metric.id), "Id field should be a uint64 type") + + # Validate the optional Name field + if metric.name is not None: + asserts.assert_true(self.is_valid_str_value(metric.name), "Name field should be a string type") + + # Validate the optional StackFreeCurrent field + if metric.stackFreeCurrent is not None: + asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeCurrent), + "StackFreeCurrent field should be a uint32 type") + + # Validate the optional StackFreeMinimum field + if metric.stackFreeMinimum is not None: + asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeMinimum), + "StackFreeMinimum field should be a uint32 type") + + # Validate the optional StackSize field + if metric.stackSize is not None: + asserts.assert_true(self.is_valid_uint32_value(metric.stackSize), "StackSize field should be a uint32 type") # STEP 3: TH reads from the DUT the CurrentHeapFree attribute self.step(3) - if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapFree.attribute_id in attribute_list): + if self.pics_guard(attributes.CurrentHeapFree.attribute_id in attribute_list): current_heap_free_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapFree) asserts.assert_true(self.is_valid_uint64_value(current_heap_free_attr), "CurrentHeapFree field should be a uint64 type") # STEP 4: TH reads from the DUT the CurrentHeapUsed attribute self.step(4) - if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapUsed.attribute_id in attribute_list): + if self.pics_guard(attributes.CurrentHeapUsed.attribute_id in attribute_list): current_heap_used_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed) asserts.assert_true(self.is_valid_uint64_value(current_heap_used_attr), "CurrentHeapUsed field should be a uint64 type") # STEP 5: TH reads from the DUT the CurrentHeapHighWatermark attribute self.step(5) - if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapHighWatermark.attribute_id in attribute_list): + if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list): current_heap_high_watermark_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark) asserts.assert_true(self.is_valid_uint64_value(current_heap_high_watermark_attr), "CurrentHeapHighWatermark field should be a uint64 type")