Skip to content

Commit e7f6d0e

Browse files
authored
Improve python test for TC_DGSW_2_3 (project-chip#36969)
1 parent 354e43d commit e7f6d0e

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/python_testing/TC_DGSW_2_1.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def is_valid_uint64_value(value):
5050
def is_valid_uint32_value(value):
5151
return isinstance(value, int) and 0 <= value <= 0xFFFFFFFF
5252

53+
@staticmethod
54+
def is_valid_str_value(value):
55+
return isinstance(value, str) and len(value) > 0
56+
5357
async def read_dgsw_attribute_expect_success(self, endpoint, attribute):
5458
cluster = Clusters.Objects.SoftwareDiagnostics
5559
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):
8488

8589
# STEP 2: TH reads from the DUT the ThreadMetrics attribute
8690
self.step(2)
87-
if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.ThreadMetrics.attribute_id in attribute_list):
91+
if self.pics_guard(attributes.ThreadMetrics.attribute_id in attribute_list):
8892
thread_metrics_list = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.ThreadMetrics)
89-
# the Id field is mandatory
90-
asserts.assert_true(self.is_valid_uint64_value(thread_metrics_list[0].id), "Id field should be a uint64 type")
91-
if thread_metrics_list[0].name is not None:
92-
asserts.assert_true(thread_metrics_list[0].name, str, "Name field should be a string type")
93-
if thread_metrics_list[0].stackFreeCurrent is not None:
94-
asserts.assert_true(self.is_valid_uint32_value(
95-
thread_metrics_list[0].stackFreeCurrent), "StackFreeCurrent field should be a uint32 type")
96-
if thread_metrics_list[0].stackFreeMinimum is not None:
97-
asserts.assert_true(self.is_valid_uint32_value(
98-
thread_metrics_list[0].stackFreeMinimum), "StackFreeMinimum field should be a uint32 type")
99-
if thread_metrics_list[0].stackSize is not None:
100-
asserts.assert_true(self.is_valid_uint32_value(
101-
thread_metrics_list[0].stackSize), "StackSize field should be a uint32s type")
93+
94+
# Validate each element in the thread_metrics_list
95+
for metric in thread_metrics_list:
96+
# The Id field is mandatory
97+
asserts.assert_true(self.is_valid_uint64_value(metric.id), "Id field should be a uint64 type")
98+
99+
# Validate the optional Name field
100+
if metric.name is not None:
101+
asserts.assert_true(self.is_valid_str_value(metric.name), "Name field should be a string type")
102+
103+
# Validate the optional StackFreeCurrent field
104+
if metric.stackFreeCurrent is not None:
105+
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeCurrent),
106+
"StackFreeCurrent field should be a uint32 type")
107+
108+
# Validate the optional StackFreeMinimum field
109+
if metric.stackFreeMinimum is not None:
110+
asserts.assert_true(self.is_valid_uint32_value(metric.stackFreeMinimum),
111+
"StackFreeMinimum field should be a uint32 type")
112+
113+
# Validate the optional StackSize field
114+
if metric.stackSize is not None:
115+
asserts.assert_true(self.is_valid_uint32_value(metric.stackSize), "StackSize field should be a uint32 type")
102116

103117
# STEP 3: TH reads from the DUT the CurrentHeapFree attribute
104118
self.step(3)
105-
if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapFree.attribute_id in attribute_list):
119+
if self.pics_guard(attributes.CurrentHeapFree.attribute_id in attribute_list):
106120
current_heap_free_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapFree)
107121
asserts.assert_true(self.is_valid_uint64_value(current_heap_free_attr), "CurrentHeapFree field should be a uint64 type")
108122

109123
# STEP 4: TH reads from the DUT the CurrentHeapUsed attribute
110124
self.step(4)
111-
if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapUsed.attribute_id in attribute_list):
125+
if self.pics_guard(attributes.CurrentHeapUsed.attribute_id in attribute_list):
112126
current_heap_used_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapUsed)
113127
asserts.assert_true(self.is_valid_uint64_value(current_heap_used_attr), "CurrentHeapUsed field should be a uint64 type")
114128

115129
# STEP 5: TH reads from the DUT the CurrentHeapHighWatermark attribute
116130
self.step(5)
117-
if self.pics_guard(Clusters.SoftwareDiagnostics.Attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
131+
if self.pics_guard(attributes.CurrentHeapHighWatermark.attribute_id in attribute_list):
118132
current_heap_high_watermark_attr = await self.read_dgsw_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentHeapHighWatermark)
119133
asserts.assert_true(self.is_valid_uint64_value(current_heap_high_watermark_attr),
120134
"CurrentHeapHighWatermark field should be a uint64 type")

0 commit comments

Comments
 (0)