@@ -50,6 +50,10 @@ def is_valid_uint64_value(value):
50
50
def is_valid_uint32_value (value ):
51
51
return isinstance (value , int ) and 0 <= value <= 0xFFFFFFFF
52
52
53
+ @staticmethod
54
+ def is_valid_str_value (value ):
55
+ return isinstance (value , str ) and len (value ) > 0
56
+
53
57
async def read_dgsw_attribute_expect_success (self , endpoint , attribute ):
54
58
cluster = Clusters .Objects .SoftwareDiagnostics
55
59
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):
84
88
85
89
# STEP 2: TH reads from the DUT the ThreadMetrics attribute
86
90
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 ):
88
92
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" )
102
116
103
117
# STEP 3: TH reads from the DUT the CurrentHeapFree attribute
104
118
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 ):
106
120
current_heap_free_attr = await self .read_dgsw_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentHeapFree )
107
121
asserts .assert_true (self .is_valid_uint64_value (current_heap_free_attr ), "CurrentHeapFree field should be a uint64 type" )
108
122
109
123
# STEP 4: TH reads from the DUT the CurrentHeapUsed attribute
110
124
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 ):
112
126
current_heap_used_attr = await self .read_dgsw_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentHeapUsed )
113
127
asserts .assert_true (self .is_valid_uint64_value (current_heap_used_attr ), "CurrentHeapUsed field should be a uint64 type" )
114
128
115
129
# STEP 5: TH reads from the DUT the CurrentHeapHighWatermark attribute
116
130
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 ):
118
132
current_heap_high_watermark_attr = await self .read_dgsw_attribute_expect_success (endpoint = endpoint , attribute = attributes .CurrentHeapHighWatermark )
119
133
asserts .assert_true (self .is_valid_uint64_value (current_heap_high_watermark_attr ),
120
134
"CurrentHeapHighWatermark field should be a uint64 type" )
0 commit comments