Skip to content

Commit 4302648

Browse files
ericzijian1994hare-siterwellrestyled-commits
authored andcommitted
Added method in python runner to get eventNumber for TC-SMOKECO tests (#28704)
* Add method to get last event number in python * Update TC-SMOKECO tests * Retain event number when reading events * Improve the method of get event number * Restyled by autopep8 * Add variable checking * Update name --------- Co-authored-by: Hare <[email protected]> Co-authored-by: Restyled.io <[email protected]>
1 parent 84a7591 commit 4302648

File tree

9 files changed

+78
-57
lines changed

9 files changed

+78
-57
lines changed

examples/chip-tool/commands/common/RemoteDataModelLogger.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <lib/support/SafeInt.h>
2222
#include <lib/support/jsontlv/TlvJson.h>
2323

24+
constexpr const char * kEventNumberKey = "eventNumber";
2425
constexpr const char * kDataVersionKey = "dataVersion";
2526
constexpr const char * kClusterIdKey = "clusterId";
2627
constexpr const char * kEndpointIdKey = "endpointId";
@@ -129,9 +130,10 @@ CHIP_ERROR LogEventAsJSON(const chip::app::EventHeader & header, chip::TLV::TLVR
129130
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);
130131

131132
Json::Value value;
132-
value[kClusterIdKey] = header.mPath.mClusterId;
133-
value[kEndpointIdKey] = header.mPath.mEndpointId;
134-
value[kEventIdKey] = header.mPath.mEventId;
133+
value[kClusterIdKey] = header.mPath.mClusterId;
134+
value[kEndpointIdKey] = header.mPath.mEndpointId;
135+
value[kEventIdKey] = header.mPath.mEventId;
136+
value[kEventNumberKey] = header.mEventNumber;
135137

136138
chip::TLV::TLVReader reader;
137139
reader.Init(*data);

examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
_CLUSTER_ERROR = 'clusterError'
3636
_VALUE = 'value'
3737
_DATA_VERSION = 'dataVersion'
38+
_EVENT_NUMBER = 'eventNumber'
3839

3940
# FabricIndex is a special case where the field is added as a struct field by the SDK
4041
# if needed but is not part of the XML definition of the struct.
@@ -89,7 +90,7 @@ def __translate_names(self, payloads):
8990
elif key == _EVENT_ID:
9091
key = _EVENT
9192
value = specs.get_event_name(payload[_CLUSTER_ID], value)
92-
elif key == _VALUE or key == _ERROR or key == _CLUSTER_ERROR or key == _DATA_VERSION:
93+
elif key == _VALUE or key == _ERROR or key == _CLUSTER_ERROR or key == _DATA_VERSION or key == _EVENT_NUMBER:
9394
pass
9495
else:
9596
# Raise an error since the other fields probably needs to be translated too.

scripts/py_matter_yamltests/matter_yamltests/parser.py

+4
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ def wait_for(self):
688688
def event_number(self):
689689
return self._test.event_number
690690

691+
@event_number.setter
692+
def event_number(self, value):
693+
self._test.event_number = value
694+
691695
@property
692696
def pics(self):
693697
return self._test.pics

scripts/py_matter_yamltests/matter_yamltests/runner.py

+15
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ def run(self, config: TestRunnerConfig) -> bool:
124124
class TestRunner(TestRunnerBase):
125125
"""
126126
TestRunner is a default runner implementation.
127+
128+
last_event_number: The latest event number value after the readEvent command.
127129
"""
130+
131+
last_event_number: int = 0
132+
128133
async def start(self):
129134
return
130135

@@ -175,6 +180,9 @@ async def _run(self, parser: TestParser, config: TestRunnerConfig):
175180

176181
test_duration = 0
177182
for idx, request in enumerate(parser.tests):
183+
if request.is_event and request.event_number == 'newEventsOnly':
184+
request.event_number = self.last_event_number + 1
185+
178186
if not request.is_pics_enabled:
179187
hooks.step_skipped(request.label, request.pics)
180188
continue
@@ -199,6 +207,13 @@ async def _run(self, parser: TestParser, config: TestRunnerConfig):
199207
duration = round((time.time() - start) * 1000, 2)
200208
test_duration += duration
201209

210+
if request.is_event:
211+
last_event = responses[-1]
212+
if isinstance(last_event, dict):
213+
received_event_number = last_event.get('eventNumber')
214+
if isinstance(received_event_number, int) and self.last_event_number < received_event_number:
215+
self.last_event_number = received_event_number
216+
202217
logger = request.post_process_response(responses)
203218

204219
if logger.is_failure():

scripts/tests/chiptest/__init__.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,16 @@ def _GetInDevelopmentTests() -> Set[str]:
135135
"Test_TC_PSCFG_1_1.yaml", # Power source configuration cluster is deprecated and removed from all-clusters
136136
"Test_TC_PSCFG_2_1.yaml", # Power source configuration cluster is deprecated and removed from all-clusters
137137
"Test_TC_PSCFG_2_2.yaml", # Power source configuration cluster is deprecated and removed from all-clusters
138-
"Test_TC_SMOKECO_2_6.yaml", # chip-repl does not support local timeout (07/20/2023) and test assumes
139-
# TestEventTriggersEnabled is true, which it's not in CI. Also, test
140-
# has wrong key for eventNumber: because using the right key leads to
141-
# codegen that does not compile.
142138
"Test_TC_SMOKECO_2_2.yaml", # chip-repl does not support local timeout (07/20/2023) and test assumes
143-
# TestEventTriggersEnabled is true, which it's not in CI. Also, test
144-
# has wrong key for eventNumber: because using the right key leads to
145-
# codegen that does not compile.
139+
# TestEventTriggersEnabled is true, which it's not in CI.
146140
"Test_TC_SMOKECO_2_3.yaml", # chip-repl does not support local timeout (07/20/2023) and test assumes
147-
# TestEventTriggersEnabled is true, which it's not in CI. Also, test
148-
# has wrong key for eventNumber: because using the right key leads to
149-
# codegen that does not compile.
141+
# TestEventTriggersEnabled is true, which it's not in CI.
150142
"Test_TC_SMOKECO_2_4.yaml", # chip-repl does not support local timeout (07/20/2023) and test assumes
151-
# TestEventTriggersEnabled is true, which it's not in CI. Also, test
152-
# has wrong key for eventNumber: because using the right key leads to
153-
# codegen that does not compile.
154-
"Test_TC_SMOKECO_2_5.yaml", # chip-repl does not support local timeout (07/20/2023) and test uses unknown
155-
# keepSubscriptions key in the YAML. Also, test has wrong key for eventNumber:
156-
# because using the right key leads to codegen that does not compile.
143+
# TestEventTriggersEnabled is true, which it's not in CI.
144+
"Test_TC_SMOKECO_2_5.yaml", # chip-repl does not support local timeout (07/20/2023) and test assumes
145+
# TestEventTriggersEnabled is true, which it's not in CI.
146+
"Test_TC_SMOKECO_2_6.yaml", # chip-repl does not support local timeout (07/20/2023) and test assumes
147+
# TestEventTriggersEnabled is true, which it's not in CI.
157148
}
158149

159150

src/app/tests/suites/certification/Test_TC_SMOKECO_2_2.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ config:
3636
TEST_EVENT_TRIGGER_SMOKE_ALARM_CLEAR:
3737
type: int64u
3838
defaultValue: "0xffffffff000000a0"
39-
EVENT_NUMBER:
40-
type: int64u
41-
defaultValue: 0
4239

4340
tests:
4441
- label: "Step 1: Commission DUT to TH"
@@ -69,6 +66,11 @@ tests:
6966
constraints:
7067
type: enum8
7168

69+
- label: "TH gets last event number from DUT"
70+
PICS: SMOKECO.S.E0a
71+
command: "readEvent"
72+
event: "AllClear"
73+
7274
- label:
7375
"Step 4: TH reads TestEventTriggersEnabled attribute from General
7476
Diagnostics Cluster"
@@ -121,7 +123,7 @@ tests:
121123
PICS: SMOKECO.S.E00
122124
command: "readEvent"
123125
event: "SmokeAlarm"
124-
EVENT_NUMBER: EVENT_NUMBER + 1
126+
eventNumber: "newEventsOnly"
125127
response:
126128
value: { AlarmSeverityLevel: 1 }
127129

@@ -201,7 +203,7 @@ tests:
201203
PICS: SMOKECO.S.E00
202204
command: "readEvent"
203205
event: "SmokeAlarm"
204-
EVENT_NUMBER: EVENT_NUMBER + 2
206+
eventNumber: "newEventsOnly"
205207
response:
206208
value: { AlarmSeverityLevel: 2 }
207209

@@ -246,6 +248,6 @@ tests:
246248
PICS: SMOKECO.S.E0a
247249
command: "readEvent"
248250
event: "AllClear"
249-
EVENT_NUMBER: EVENT_NUMBER + 3
251+
eventNumber: "newEventsOnly"
250252
response:
251253
value: {}

src/app/tests/suites/certification/Test_TC_SMOKECO_2_3.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ config:
3535
TEST_EVENT_TRIGGER_CO_ALARM_CLEAR:
3636
type: int64u
3737
defaultValue: "0xffffffff000000a1"
38-
EVENT_NUMBER:
39-
type: int64u
40-
defaultValue: 0
4138

4239
tests:
4340
- label: "Step 1: Commission DUT to TH"
@@ -68,6 +65,11 @@ tests:
6865
constraints:
6966
type: enum8
7067

68+
- label: "TH gets last event number from DUT"
69+
PICS: SMOKECO.S.E0a
70+
command: "readEvent"
71+
event: "AllClear"
72+
7173
- label:
7274
"Step 4: TH reads TestEventTriggersEnabled attribute from General
7375
Diagnostics Cluster"
@@ -120,7 +122,7 @@ tests:
120122
PICS: SMOKECO.S.E01
121123
command: "readEvent"
122124
event: "COAlarm"
123-
EVENT_NUMBER: EVENT_NUMBER + 1
125+
eventNumber: "newEventsOnly"
124126
response:
125127
value: { AlarmSeverityLevel: 1 }
126128

@@ -200,7 +202,7 @@ tests:
200202
PICS: SMOKECO.S.E01
201203
command: "readEvent"
202204
event: "COAlarm"
203-
EVENT_NUMBER: EVENT_NUMBER + 2
205+
eventNumber: "newEventsOnly"
204206
response:
205207
value: { AlarmSeverityLevel: 2 }
206208

@@ -245,6 +247,6 @@ tests:
245247
PICS: SMOKECO.S.E0a
246248
command: "readEvent"
247249
event: "AllClear"
248-
EVENT_NUMBER: EVENT_NUMBER + 3
250+
eventNumber: "newEventsOnly"
249251
response:
250252
value: {}

src/app/tests/suites/certification/Test_TC_SMOKECO_2_4.yaml

+16-14
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ config:
4848
TEST_EVENT_TRIGGER_END_OF_SERVICE_ALERT_CLEAR:
4949
type: int64u
5050
defaultValue: "0xffffffff000000aa"
51-
EVENT_NUMBER:
52-
type: int64u
53-
defaultValue: 0
5451

5552
tests:
5653
- label: "Step 1: Commission DUT to TH"
@@ -81,6 +78,11 @@ tests:
8178
constraints:
8279
type: enum8
8380

81+
- label: "TH gets last event number from DUT"
82+
PICS: SMOKECO.S.E0a
83+
command: "readEvent"
84+
event: "AllClear"
85+
8486
- label:
8587
"Step 4: TH reads TestEventTriggersEnabled attribute from General
8688
Diagnostics Cluster"
@@ -133,7 +135,7 @@ tests:
133135
PICS: SMOKECO.S.E02
134136
command: "readEvent"
135137
event: "LowBattery"
136-
EVENT_NUMBER: EVENT_NUMBER + 1
138+
eventNumber: "newEventsOnly"
137139
response:
138140
value: { AlarmSeverityLevel: 1 }
139141

@@ -178,7 +180,7 @@ tests:
178180
PICS: SMOKECO.S.E02
179181
command: "readEvent"
180182
event: "LowBattery"
181-
EVENT_NUMBER: EVENT_NUMBER + 2
183+
eventNumber: "newEventsOnly"
182184
response:
183185
value: { AlarmSeverityLevel: 2 }
184186

@@ -223,7 +225,7 @@ tests:
223225
PICS: SMOKECO.S.E0a
224226
command: "readEvent"
225227
event: "AllClear"
226-
EVENT_NUMBER: EVENT_NUMBER + 3
228+
eventNumber: "newEventsOnly"
227229
response:
228230
value: {}
229231

@@ -279,7 +281,7 @@ tests:
279281
PICS: SMOKECO.S.E03
280282
command: "readEvent"
281283
event: "HardwareFault"
282-
EVENT_NUMBER: EVENT_NUMBER + 4
284+
eventNumber: "newEventsOnly"
283285
response:
284286
value: {}
285287

@@ -325,7 +327,7 @@ tests:
325327
PICS: SMOKECO.S.E0a
326328
command: "readEvent"
327329
event: "AllClear"
328-
EVENT_NUMBER: EVENT_NUMBER + 5
330+
eventNumber: "newEventsOnly"
329331
response:
330332
value: {}
331333

@@ -381,7 +383,7 @@ tests:
381383
PICS: SMOKECO.S.E04
382384
command: "readEvent"
383385
event: "EndOfService"
384-
EVENT_NUMBER: EVENT_NUMBER + 6
386+
eventNumber: "newEventsOnly"
385387
response:
386388
value: {}
387389

@@ -427,7 +429,7 @@ tests:
427429
PICS: SMOKECO.S.E0a
428430
command: "readEvent"
429431
event: "AllClear"
430-
EVENT_NUMBER: EVENT_NUMBER + 7
432+
eventNumber: "newEventsOnly"
431433
response:
432434
value: {}
433435

@@ -499,7 +501,7 @@ tests:
499501
PICS: SMOKECO.S.E05
500502
command: "readEvent"
501503
event: "SelfTestComplete"
502-
EVENT_NUMBER: EVENT_NUMBER + 8
504+
eventNumber: "newEventsOnly"
503505
response:
504506
value: {}
505507

@@ -516,7 +518,7 @@ tests:
516518
PICS: SMOKECO.S.E0a
517519
command: "readEvent"
518520
event: "AllClear"
519-
EVENT_NUMBER: EVENT_NUMBER + 9
521+
eventNumber: "newEventsOnly"
520522
response:
521523
value: {}
522524

@@ -561,7 +563,7 @@ tests:
561563
PICS: SMOKECO.S.E05
562564
command: "readEvent"
563565
event: "SelfTestComplete"
564-
EVENT_NUMBER: EVENT_NUMBER + 10
566+
eventNumber: "newEventsOnly"
565567
response:
566568
value: {}
567569

@@ -578,6 +580,6 @@ tests:
578580
PICS: SMOKECO.S.E0a
579581
command: "readEvent"
580582
event: "AllClear"
581-
EVENT_NUMBER: EVENT_NUMBER + 11
583+
eventNumber: "newEventsOnly"
582584
response:
583585
value: {}

0 commit comments

Comments
 (0)