41
41
# === END CI TEST ARGUMENTS ===
42
42
#
43
43
44
- import asyncio
45
-
46
44
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
48
46
from mobly import asserts
49
47
50
48
@@ -61,10 +59,33 @@ def is_valid_octet_string(value):
61
59
async def send_software_fault_test_event_trigger (self ):
62
60
await self .send_test_event_triggers (eventTrigger = 0x0034000000000000 )
63
61
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
+ )
68
89
69
90
def desc_TC_DGSW_2_2 (self ) -> str :
70
91
"""Returns a description of this test"""
@@ -88,40 +109,27 @@ async def test_TC_DGSW_2_2(self):
88
109
# STEP 1: Commission DUT (already done)
89
110
self .step (1 )
90
111
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
+
91
120
# STEP 2: DUT sends an event report to TH. TH reads a list of SoftwareFault structs from DUT.
92
121
self .step (2 )
93
122
94
123
# Trigger a SoftwareFault event on the DUT
95
124
await self .send_software_fault_test_event_trigger ()
96
125
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
+ )
120
130
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 )
125
133
126
134
127
135
if __name__ == "__main__" :
0 commit comments