Skip to content

Commit

Permalink
Improve python test for TC_DGSW_2_3 (#36969)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored Jan 7, 2025
1 parent 354e43d commit e7f6d0e
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/python_testing/TC_DGSW_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e7f6d0e

Please sign in to comment.