Skip to content

Commit 0c4287b

Browse files
authored
[Infineon] Add a test trigger for CYW30739 to fill up event logging buffers. (project-chip#33382)
* [Infineon] Add a test trigger for CYW30739 to fill up event logging buffers. * Implement the TestEventTriggerDelegate class to provide a vendor trigger kFillUpEventLoggingBuffer as 0xffffffff00000000 (-4294967296) to fill up event logging buffers with HardwareFaultChange and SoftwareFault events. * Implement the OnSoftwareFaultEventHandler method to build and log a SoftwareFault event. * Fix string literals and the vendor event trigger value. Change the vendor trigger kFillUpEventLoggingBuffer from 0xffffffff00000000 (-4294967296) to 0xffffffff13880000 (-3967287296). * Move common trigger logics to GenericEventManagementTestEventTriggerHandler class.
1 parent 63f4b79 commit 0c4287b

10 files changed

+298
-0
lines changed

examples/platform/infineon/cyw30739/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import("${cyw30739_sdk_build_root}/cyw30739_sdk.gni")
2020

2121
static_library("platform") {
2222
sources = [
23+
"EventManagementTestEventTriggerHandler.h",
2324
"LEDWidget.h",
2425
"OTAConfig.h",
26+
"SoftwareDiagnostics.h",
2527
"main.cpp",
2628
]
2729

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "EventManagementTestEventTriggerHandler.h"
20+
21+
#include "SoftwareDiagnostics.h"
22+
23+
namespace chip {
24+
namespace DeviceLayer {
25+
namespace Infineon {
26+
namespace CYW30739 {
27+
28+
CHIP_ERROR EventManagementTestEventTriggerHandler::HandleEventTrigger(uint64_t eventTrigger)
29+
{
30+
switch (eventTrigger)
31+
{
32+
case kFillUpEventLoggingBuffer:
33+
return HandleFillUpEventLoggingBufferEventTriger();
34+
default:
35+
return CHIP_ERROR_INVALID_ARGUMENT;
36+
}
37+
}
38+
39+
void EventManagementTestEventTriggerHandler::TriggerSoftwareFaultEvent(const char * faultRecordString)
40+
{
41+
OnSoftwareFaultEventHandler(faultRecordString);
42+
}
43+
44+
} // namespace CYW30739
45+
} // namespace Infineon
46+
} // namespace DeviceLayer
47+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/GenericEventManagementTestEventTriggerHandler.h>
22+
23+
namespace chip {
24+
namespace DeviceLayer {
25+
namespace Infineon {
26+
namespace CYW30739 {
27+
28+
class EventManagementTestEventTriggerHandler : public app::GenericEventManagementTestEventTriggerHandler
29+
{
30+
public:
31+
static constexpr uint64_t kFillUpEventLoggingBuffer = 0xffff'ffff'1388'0000;
32+
33+
CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override;
34+
35+
private:
36+
virtual void TriggerSoftwareFaultEvent(const char * faultRecordString) override;
37+
};
38+
39+
} // namespace CYW30739
40+
} // namespace Infineon
41+
} // namespace DeviceLayer
42+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "SoftwareDiagnostics.h"
20+
21+
#include <app/clusters/software-diagnostics-server/software-diagnostics-server.h>
22+
#include <app/util/config.h>
23+
#include <platform/CHIPDeviceLayer.h>
24+
25+
namespace chip {
26+
namespace DeviceLayer {
27+
namespace Infineon {
28+
namespace CYW30739 {
29+
30+
using namespace chip::app::Clusters;
31+
32+
void OnSoftwareFaultEventHandler(const char * faultRecordString)
33+
{
34+
#ifdef MATTER_DM_PLUGIN_SOFTWARE_DIAGNOSTICS_SERVER
35+
SoftwareDiagnostics::Events::SoftwareFault::Type softwareFault;
36+
37+
/* Unable to access thread ID in the application layer. */
38+
softwareFault.id = 0;
39+
40+
if (DeviceLayer::PlatformMgrImpl().IsCurrentTask())
41+
{
42+
softwareFault.name.SetValue("Matter"_span);
43+
}
44+
else if (DeviceLayer::ThreadStackMgrImpl().IsCurrentTask())
45+
{
46+
softwareFault.name.SetValue("Thread"_span);
47+
}
48+
else
49+
{
50+
softwareFault.name.SetValue("App"_span);
51+
}
52+
53+
softwareFault.faultRecording.SetValue(ByteSpan(Uint8::from_const_char(faultRecordString), strlen(faultRecordString)));
54+
55+
SoftwareDiagnosticsServer::Instance().OnSoftwareFaultDetect(softwareFault);
56+
#endif // MATTER_DM_PLUGIN_SOFTWARE_DIAGNOSTICS_SERVER
57+
}
58+
59+
} // namespace CYW30739
60+
} // namespace Infineon
61+
} // namespace DeviceLayer
62+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace chip {
20+
namespace DeviceLayer {
21+
namespace Infineon {
22+
namespace CYW30739 {
23+
24+
void OnSoftwareFaultEventHandler(const char * faultRecordString);
25+
26+
} // namespace CYW30739
27+
} // namespace Infineon
28+
} // namespace DeviceLayer
29+
} // namespace chip

examples/platform/infineon/cyw30739/cyw30739_example.gni

+2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ template("cyw30739_example") {
2424

2525
static_library(target_name) {
2626
sources = [
27+
"${cyw30739_example_dir}/EventManagementTestEventTriggerHandler.cpp",
2728
"${cyw30739_example_dir}/LEDWidget.cpp",
2829
"${cyw30739_example_dir}/OTAConfig.cpp",
30+
"${cyw30739_example_dir}/SoftwareDiagnostics.cpp",
2931
"${cyw30739_example_dir}/matter_config.cpp",
3032
]
3133

examples/platform/infineon/cyw30739/matter_config.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "matter_config.h"
2121
#include "AppTask.h"
22+
#include "EventManagementTestEventTriggerHandler.h"
2223
#ifdef BOARD_ENABLE_DISPLAY
2324
#include "GUI.h"
2425
#endif
@@ -208,8 +209,10 @@ void CYW30739MatterConfig::InitApp(void)
208209
/* Start CHIP datamodel server */
209210
static chip::SimpleTestEventTriggerDelegate sTestEventTriggerDelegate{};
210211
static chip::OTATestEventTriggerHandler sOtaTestEventTriggerHandler{};
212+
static Infineon::CYW30739::EventManagementTestEventTriggerHandler sEventManagementTestEventTriggerHandler{};
211213
VerifyOrDie(sTestEventTriggerDelegate.Init(chip::ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR);
212214
VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR);
215+
VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sEventManagementTestEventTriggerHandler) == CHIP_NO_ERROR);
213216
// Create initParams with SDK example defaults here
214217
static chip::CommonCaseDeviceServerInitParams initParams;
215218
(void) initParams.InitializeStaticResourcesBeforeServerInit();

src/app/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ static_library("app") {
325325
"EventManagement.h",
326326
"FailSafeContext.cpp",
327327
"FailSafeContext.h",
328+
"GenericEventManagementTestEventTriggerHandler.cpp",
329+
"GenericEventManagementTestEventTriggerHandler.h",
328330
"OTAUserConsentCommon.h",
329331
"ReadHandler.cpp",
330332
"SafeAttributePersistenceProvider.h",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "GenericEventManagementTestEventTriggerHandler.h"
20+
21+
#include <app/clusters/general-diagnostics-server/general-diagnostics-server.h>
22+
#include <platform/GeneralFaults.h>
23+
24+
namespace chip {
25+
namespace app {
26+
27+
using namespace chip::DeviceLayer;
28+
using namespace chip::app::Clusters;
29+
30+
CHIP_ERROR GenericEventManagementTestEventTriggerHandler::HandleFillUpEventLoggingBufferEventTriger()
31+
{
32+
/* Create a fake hardware fault list. */
33+
GeneralFaults<kMaxHardwareFaults> hardwareFaults;
34+
for (uint8_t hardwareFault = to_underlying(GeneralDiagnostics::HardwareFaultEnum::kUnspecified);
35+
hardwareFault < kMaxHardwareFaults; hardwareFault++)
36+
{
37+
hardwareFaults.add(hardwareFault);
38+
}
39+
40+
/* Fill up the critical logging buffer by 10 hardware faults. */
41+
constexpr uint8_t kHardwareFaultCountForCriticalBuffer = 10;
42+
for (uint8_t i = 0; i < kHardwareFaultCountForCriticalBuffer; i++)
43+
{
44+
GeneralDiagnosticsServer::Instance().OnHardwareFaultsDetect(hardwareFaults, hardwareFaults);
45+
}
46+
47+
/* Fill up the info logging buffer. */
48+
FillUpEventLoggingBufferWithFakeSoftwareFault(CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE);
49+
50+
/* Fill up the debug logging buffer. */
51+
FillUpEventLoggingBufferWithFakeSoftwareFault(CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE);
52+
53+
return CHIP_NO_ERROR;
54+
}
55+
56+
void GenericEventManagementTestEventTriggerHandler::FillUpEventLoggingBufferWithFakeSoftwareFault(size_t bufferSize)
57+
{
58+
/* Create a fake fault message. */
59+
constexpr size_t kEncodingOverhead = 0x40;
60+
const size_t recordSize = bufferSize - kEncodingOverhead;
61+
char * recordBuffer = static_cast<char *>(Platform::MemoryAlloc(recordSize));
62+
VerifyOrReturn(recordBuffer != nullptr);
63+
std::unique_ptr<char, decltype(&Platform::MemoryFree)> recordString(recordBuffer, &Platform::MemoryFree);
64+
memset(recordString.get(), 0x55, recordSize);
65+
recordString.get()[recordSize - 1] = '\0';
66+
67+
/* Fill up the logging buffer by a software fault. */
68+
TriggerSoftwareFaultEvent(recordString.get());
69+
}
70+
71+
} // namespace app
72+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/TestEventTriggerDelegate.h>
22+
23+
namespace chip {
24+
namespace app {
25+
26+
class GenericEventManagementTestEventTriggerHandler : public TestEventTriggerHandler
27+
{
28+
protected:
29+
CHIP_ERROR HandleFillUpEventLoggingBufferEventTriger();
30+
31+
private:
32+
void FillUpEventLoggingBufferWithFakeSoftwareFault(size_t bufferSize);
33+
virtual void TriggerSoftwareFaultEvent(const char * faultRecordString) = 0;
34+
};
35+
36+
} // namespace app
37+
} // namespace chip

0 commit comments

Comments
 (0)