Skip to content

Commit 292665e

Browse files
authored
Wait (block) for the SoftwareFault event instead of asleep (#37085)
1 parent 9b8fffe commit 292665e

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

src/python_testing/TC_DGSW_2_2.py

+42-34
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@
4141
# === END CI TEST ARGUMENTS ===
4242
#
4343

44-
import asyncio
45-
4644
import chip.clusters as Clusters
47-
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
45+
from chip.testing.matter_testing import EventChangeCallback, MatterBaseTest, TestStep, async_test_body, default_matter_test_main
4846
from mobly import asserts
4947

5048

@@ -61,10 +59,33 @@ def is_valid_octet_string(value):
6159
async def send_software_fault_test_event_trigger(self):
6260
await self.send_test_event_triggers(eventTrigger=0x0034000000000000)
6361

64-
async def read_software_fault_events(self, endpoint):
65-
event_path = [(endpoint, Clusters.SoftwareDiagnostics.Events.SoftwareFault, 1)]
66-
events = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path)
67-
return events
62+
def validate_soft_fault_event_data(self, event_data):
63+
"""
64+
Validates the SoftFault event data according to the test plan and specification.
65+
66+
This method checks:
67+
- `Id` field: Must be of type uint64
68+
- `Name` field: Vendor-specific string
69+
- `FaultRecording` field: Vendor-specific payload in octet string format (bytes/bytearray)
70+
"""
71+
72+
# Validate 'Id' field: Ensure it is a uint64 type
73+
asserts.assert_true(
74+
self.is_valid_uint64_value(event_data.id),
75+
"The 'Id' field must be a uint64 type"
76+
)
77+
78+
# Validate 'Name' field: Ensure it is a string
79+
asserts.assert_true(
80+
isinstance(event_data.name, str),
81+
"The 'Name' field must be a string type"
82+
)
83+
84+
# Validate 'FaultRecording' field: Ensure it is an octet string (bytes or bytearray)
85+
asserts.assert_true(
86+
self.is_valid_octet_string(event_data.faultRecording),
87+
"The 'FaultRecording' field must be an octet string (bytes or bytearray)"
88+
)
6889

6990
def desc_TC_DGSW_2_2(self) -> str:
7091
"""Returns a description of this test"""
@@ -88,40 +109,27 @@ async def test_TC_DGSW_2_2(self):
88109
# STEP 1: Commission DUT (already done)
89110
self.step(1)
90111

112+
# Create and start an EventChangeCallback to subscribe for events
113+
events_callback = EventChangeCallback(Clusters.SoftwareDiagnostics)
114+
await events_callback.start(
115+
self.default_controller, # The controller
116+
self.dut_node_id, # DUT's node id
117+
endpoint # The endpoint on which we expect Wi-Fi events
118+
)
119+
91120
# STEP 2: DUT sends an event report to TH. TH reads a list of SoftwareFault structs from DUT.
92121
self.step(2)
93122

94123
# Trigger a SoftwareFault event on the DUT
95124
await self.send_software_fault_test_event_trigger()
96125

97-
# Allow some time for the event to be processed
98-
await asyncio.sleep(1)
99-
100-
# Read the SoftwareFault events
101-
software_fault_events = await self.read_software_fault_events(endpoint)
102-
103-
# There should be at least one SoftwareFault event for this test to be valid.
104-
asserts.assert_true(len(software_fault_events) > 0, "No SoftwareFault events received from the DUT.")
105-
106-
# For each event, verify the data type requirements
107-
for event_data in software_fault_events:
108-
# According to the test plan and specification:
109-
# - Id is mandatory, uint64
110-
# - Name is vendor-specific string
111-
# - FaultRecording is vendor-specific payload in octstr format
112-
113-
# Validate Id
114-
asserts.assert_true(self.is_valid_uint64_value(event_data.Data.id),
115-
"Id field should be a uint64 type")
116-
117-
# Validate Name (string) - assuming event_data.Name is a string
118-
asserts.assert_true(isinstance(event_data.Data.name, str),
119-
"Name field should be a string type")
126+
# Wait (block) for the SoftwareFault event to arrive
127+
event_data = events_callback.wait_for_event_report(
128+
Clusters.SoftwareDiagnostics.Events.SoftwareFault
129+
)
120130

121-
# Validate FaultRecording (octet_string)
122-
# Assuming event_data.FaultRecording is bytes or bytearray
123-
asserts.assert_true(self.is_valid_octet_string(event_data.Data.faultRecording),
124-
"FaultRecording field should be an octet string (bytes/bytearray)")
131+
# Validate the SoftwareFault event fields
132+
self.validate_soft_fault_event_data(event_data)
125133

126134

127135
if __name__ == "__main__":

0 commit comments

Comments
 (0)