Skip to content

Commit

Permalink
[nrf fromtree] Make TestEventTrigger delegate testable and extensible…
Browse files Browse the repository at this point in the history
… (#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 <[email protected]>

Cherry-picked from: 4cd1825
  • Loading branch information
tcarmelveilleux authored and ArekBalysNordic committed Mar 26, 2024
1 parent f2dfb17 commit 70be330
Show file tree
Hide file tree
Showing 67 changed files with 3,903 additions and 357 deletions.
49 changes: 49 additions & 0 deletions examples/all-clusters-app/all-clusters-common/src/boolcfg-stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <app/clusters/boolean-state-configuration-server/BooleanStateConfigurationTestEventTriggerHandler.h>
#include <app/clusters/boolean-state-configuration-server/boolean-state-configuration-server.h>

#include <platform/CHIPDeviceLayer.h>

using namespace chip;
using namespace chip::app::Clusters::BooleanStateConfiguration;
using namespace chip::DeviceLayer;

bool HandleBooleanStateConfigurationTestEventTrigger(uint64_t eventTrigger)
{
BooleanStateConfigurationTrigger trigger = static_cast<BooleanStateConfigurationTrigger>(eventTrigger);

switch (trigger)
{
case BooleanStateConfigurationTrigger::kSensorTrigger:
ChipLogProgress(Support, "[BooleanStateConfiguration-Test-Event] => Trigger sensor");
SetAllEnabledAlarmsActive(1);
break;

case BooleanStateConfigurationTrigger::kSensorUntrigger:
ChipLogProgress(Support, "[BooleanStateConfiguration-Test-Event] => Untrigger sensor");
ClearAllAlarms(1);
break;

default:

return false;
}

return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

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

#include <platform/CHIPDeviceLayer.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

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

using namespace chip;
Expand Down
6 changes: 4 additions & 2 deletions examples/all-clusters-app/ameba/main/chipinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ static void InitServer(intptr_t context)
static chip::CommonCaseDeviceServerInitParams initParams;

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

initParams.InitializeStaticResourcesBeforeServerInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <stdbool.h>
#include <stdint.h>

bool emberAfHandleEventTrigger(uint64_t eventTrigger);

class SmokeCoAlarmManager
{
public:
Expand Down
10 changes: 7 additions & 3 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>

#include <app/TestEventTriggerDelegate.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
#include <app/clusters/ota-requestor/OTATestEventTriggerHandler.h>
#include <app/util/attribute-storage.h>

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

static CommonCaseDeviceServerInitParams initParams;
static OTATestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) };
static SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
static OTATestEventTriggerHandler sOtaTestEventTriggerHandler{};
VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR);
VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR);
(void) initParams.InitializeStaticResourcesBeforeServerInit();
initParams.testEventTriggerDelegate = &testEventTriggerDelegate;
initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate;
ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams));
AppFabricTableDelegate::Init();

Expand Down
Loading

0 comments on commit 70be330

Please sign in to comment.