Matter SDK Coverage Report
Current view: top level - app - GenericEventManagementTestEventTriggerHandler.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 0.0 % 22 0
Test Date: 2025-01-17 19:00:11 Functions: 0.0 % 2 0

            Line data    Source code
       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            0 : CHIP_ERROR GenericEventManagementTestEventTriggerHandler::HandleFillUpEventLoggingBufferEventTriger()
      31              : {
      32              :     /* Create a fake hardware fault list. */
      33            0 :     GeneralFaults<kMaxHardwareFaults> hardwareFaults;
      34            0 :     for (uint8_t hardwareFault = to_underlying(GeneralDiagnostics::HardwareFaultEnum::kUnspecified);
      35            0 :          hardwareFault < kMaxHardwareFaults; hardwareFault++)
      36              :     {
      37            0 :         hardwareFaults.add(hardwareFault);
      38              :     }
      39              : 
      40              :     /* Fill up the critical logging buffer by 10 hardware faults. */
      41            0 :     constexpr uint8_t kHardwareFaultCountForCriticalBuffer = 10;
      42            0 :     for (uint8_t i = 0; i < kHardwareFaultCountForCriticalBuffer; i++)
      43              :     {
      44            0 :         GeneralDiagnosticsServer::Instance().OnHardwareFaultsDetect(hardwareFaults, hardwareFaults);
      45              :     }
      46              : 
      47              :     /* Fill up the info logging buffer. */
      48            0 :     FillUpEventLoggingBufferWithFakeSoftwareFault(CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE);
      49              : 
      50              :     /* Fill up the debug logging buffer. */
      51            0 :     FillUpEventLoggingBufferWithFakeSoftwareFault(CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE);
      52              : 
      53            0 :     return CHIP_NO_ERROR;
      54            0 : }
      55              : 
      56            0 : void GenericEventManagementTestEventTriggerHandler::FillUpEventLoggingBufferWithFakeSoftwareFault(size_t bufferSize)
      57              : {
      58              :     /* Create a fake fault message. */
      59            0 :     constexpr size_t kEncodingOverhead = 0x40;
      60            0 :     const size_t recordSize            = bufferSize - kEncodingOverhead;
      61            0 :     char * recordBuffer                = static_cast<char *>(Platform::MemoryAlloc(recordSize));
      62            0 :     VerifyOrReturn(recordBuffer != nullptr);
      63            0 :     std::unique_ptr<char, decltype(&Platform::MemoryFree)> recordString(recordBuffer, &Platform::MemoryFree);
      64            0 :     memset(recordString.get(), 0x55, recordSize);
      65            0 :     recordString.get()[recordSize - 1] = '\0';
      66              : 
      67              :     /* Fill up the logging buffer by a software fault. */
      68            0 :     TriggerSoftwareFaultEvent(recordString.get());
      69            0 : }
      70              : 
      71              : } // namespace app
      72              : } // namespace chip
        

Generated by: LCOV version 2.0-1