Skip to content

Commit c24df40

Browse files
tcarmelveilleuxArekBalysNordic
authored andcommitted
[nrf fromtree] Make TestEventTrigger delegate testable and extensible (#31724)
* Make TestEventTrigger delegate testable and extensible - Make TestEventTriggerDelegate base class manage multiple sub-handlers. - Add unit tests for TestEventTriggerDelegate - Introduce an interface for generic TestEventTrigger handlers - Add Clear() method to Intrusive list to remove everything. - Document the fact that `emberAfHandleEventTrigger` should NOT be used - Update all examples as needed. - Renumber OTA and SmokeCO testevent trigger prefix to match new Matter 1.3 standard (first 16 bits == cluster ID being tested). - Clean-up dead code - Register OTA test event handler as intended. - Add TODOs for platforms to clean-up TestEventTriggerDelegate registration. - Updated BOOLCFG tests to use `--hex-arg` for PIXIT since `--int-arg` is too confusing with complex keys. Issue #31723 Testing done: - EEVSE Python tests using event triggers pass - SMOKECO YAML tests using event triggers pass - BOOLCFG Python tests using event triggers pass - TC_TestEventTrigger passes - New unit tests pass * Fix merge issue * Restyled by clang-format * Fix uninitialized variable access * Fix Ameba/Silabs build * Fix CopyString bound * More fixes of Ameba/Silabs build --------- Co-authored-by: Restyled.io <commits@restyled.io> Cherry-picked from: 4cd1825
1 parent 49b5f80 commit c24df40

File tree

67 files changed

+3900
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3900
-357
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <app/clusters/boolean-state-configuration-server/BooleanStateConfigurationTestEventTriggerHandler.h>
19+
#include <app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.h>
20+
21+
#include <platform/CHIPDeviceLayer.h>
22+
23+
using namespace chip;
24+
using namespace chip::app::Clusters::BooleanStateConfiguration;
25+
using namespace chip::DeviceLayer;
26+
27+
bool HandleBooleanStateConfigurationTestEventTrigger(uint64_t eventTrigger)
28+
{
29+
BooleanStateConfigurationTrigger trigger = static_cast<BooleanStateConfigurationTrigger>(eventTrigger);
30+
31+
switch (trigger)
32+
{
33+
case BooleanStateConfigurationTrigger::kSensorTrigger:
34+
ChipLogProgress(Support, "[BooleanStateConfiguration-Test-Event] => Trigger sensor");
35+
SetAllEnabledAlarmsActive(1);
36+
break;
37+
38+
case BooleanStateConfigurationTrigger::kSensorUntrigger:
39+
ChipLogProgress(Support, "[BooleanStateConfiguration-Test-Event] => Untrigger sensor");
40+
ClearAllAlarms(1);
41+
break;
42+
43+
default:
44+
45+
return false;
46+
}
47+
48+
return true;
49+
}

examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include <app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerDelegate.h>
18+
#include <app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerHandler.h>
1919
#include <app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h>
2020

2121
#include <platform/CHIPDeviceLayer.h>

examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
#include "SmokeCOAlarmManager.h"
19-
#include <app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerDelegate.h>
19+
#include <app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerHandler.h>
2020
#include <lib/support/TypeTraits.h>
2121

2222
using namespace chip;

examples/all-clusters-app/ameba/main/chipinterface.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ static void InitServer(intptr_t context)
140140
static chip::CommonCaseDeviceServerInitParams initParams;
141141

142142
#if CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER
143-
static AmebaTestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
144-
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
143+
// TODO(#31723): Show to customers that they can do `Server::GetInstance().GetTestEventTriggerDelegate().AddHandler(xxx)`
144+
// to add custom handlers during their app init, after InitServer.
145+
static AmebaTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
146+
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
145147
#endif
146148

147149
initParams.InitializeStaticResourcesBeforeServerInit();

examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <stdbool.h>
2323
#include <stdint.h>
2424

25-
bool emberAfHandleEventTrigger(uint64_t eventTrigger);
26-
2725
class SmokeCoAlarmManager
2826
{
2927
public:

examples/all-clusters-app/nrfconnect/main/AppTask.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
#include <app/server/OnboardingCodesUtil.h>
2828
#include <app/server/Server.h>
2929

30+
#include <app/TestEventTriggerDelegate.h>
3031
#include <app/clusters/identify-server/identify-server.h>
31-
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
32+
#include <app/clusters/ota-requestor/OTATestEventTriggerHandler.h>
3233
#include <app/util/attribute-storage.h>
3334

3435
#include <credentials/DeviceAttestationCredsProvider.h>
@@ -204,9 +205,12 @@ CHIP_ERROR AppTask::Init()
204205
#endif
205206

206207
static CommonCaseDeviceServerInitParams initParams;
207-
static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
208+
static SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
209+
static OTATestEventTriggerHandler sOtaTestEventTriggerHandler{};
210+
VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR);
211+
VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR);
208212
(void) initParams.InitializeStaticResourcesBeforeServerInit();
209-
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
213+
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
210214
ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));
211215
AppFabricTableDelegate::Init();
212216

0 commit comments

Comments
 (0)