Skip to content

Commit

Permalink
Merge e0fc837 into 2d62ad1
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple authored Nov 7, 2023
2 parents 2d62ad1 + e0fc837 commit 4741256
Show file tree
Hide file tree
Showing 25 changed files with 1,894 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
# target versions instead?
run: |
mkdir -p /tmp/darwin/framework-tests
../../../out/debug/chip-all-clusters-app --interface-id -1 > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
../../../out/debug/chip-all-clusters-app --interface-id -1 --end_user_support_log /tmp/endusersupportlog.txt --network_diagnostics_log /tmp/networkdiagnosticslog.txt --crash_log /tmp/crashlog.txt > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
../../../out/debug/chip-all-clusters-app --interface-id -1 --dac_provider ../../../credentials/development/commissioner_dut/struct_cd_origin_pid_vid_correct/test_case_vector.json --product-id 32768 --discriminator 3839 --secured-device-port 5539 --KVS /tmp/chip-all-clusters-app-kvs2 > >(tee /tmp/darwin/framework-tests/all-cluster-app-origin-vid.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-origin-vid-err.log >&2) &
# Disable BLE because the app does not have the permission to use
# it and that may crash the CI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,13 @@ server cluster DiagnosticLogs = 50 {
optional char_string<32> transferFileDesignator = 2;
}

response struct RetrieveLogsResponse = 1 {
StatusEnum status = 0;
LONG_OCTET_STRING logContent = 1;
optional epoch_us UTCTimeStamp = 2;
optional systime_us timeSinceBoot = 3;
}

command RetrieveLogsRequest(RetrieveLogsRequestRequest): RetrieveLogsResponse = 0;
}

Expand Down Expand Up @@ -5386,10 +5393,15 @@ endpoint 0 {
}

server cluster DiagnosticLogs {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 1;

handle command RetrieveLogsRequest;
handle command RetrieveLogsResponse;
}

server cluster GeneralDiagnostics {
Expand Down
77 changes: 75 additions & 2 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -2643,9 +2643,81 @@
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "RetrieveLogsResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
Expand Down Expand Up @@ -14856,7 +14928,7 @@
"code": 3,
"mfgCode": null,
"side": "server",
"type": "temperature",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
Expand Down Expand Up @@ -21901,5 +21973,6 @@
"endpointId": 65534,
"networkId": 0
}
]
],
"log": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

#pragma once

#include <app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h>
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>

#include <fstream>

namespace chip {
namespace app {
namespace Clusters {
namespace DiagnosticLogs {

/**
* The application delegate to statically define the options.
*/

class LogProvider : public LogProviderDelegate
{
static LogSessionHandle sLogSessionHandle;
static LogProvider sInstance;

public:
LogSessionHandle StartLogCollection(IntentEnum logType);

uint64_t GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF);

void EndLogCollection(LogSessionHandle logSessionHandle);

uint64_t GetTotalNumberOfBytesConsumed(LogSessionHandle logSessionHandle);

void SetEndUserSupportLogFileDesignator(const char * logFileName);

void SetNetworkDiagnosticsLogFileDesignator(const char * logFileName);

void SetCrashLogFileDesignator(const char * logFileName);

LogProvider(){};

~LogProvider(){};

static inline LogProvider & getLogProvider() { return sInstance; }

private:
const char * GetLogFilePath(IntentEnum logType);

char mEndUserSupportLogFileDesignator[kLogFileDesignatorMaxLen];
char mNetworkDiagnosticsLogFileDesignator[kLogFileDesignatorMaxLen];
char mCrashLogFileDesignator[kLogFileDesignatorMaxLen];

std::ifstream mFileStream;

LogSessionHandle mLogSessionHandle;

uint64_t mTotalNumberOfBytesConsumed;
};

} // namespace DiagnosticLogs
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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 "diagnostic-logs-provider-delegate-impl.h"
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h>
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>

using namespace chip;
using namespace chip::app::Clusters::DiagnosticLogs;

constexpr uint16_t kChunkSizeZero = 0;

LogProvider LogProvider::sInstance;

LogSessionHandle LogProvider::sLogSessionHandle;

LogSessionHandle LogProvider::StartLogCollection(IntentEnum logType)
{

mTotalNumberOfBytesConsumed = 0;

// Open the file of type
const char * fileName = GetLogFilePath(logType);
if (fileName != nullptr)
{
mFileStream.open(fileName, std::ios_base::binary | std::ios_base::in);
if (!mFileStream.good())
{
ChipLogError(BDX, "Failed to open the log file");
return kInvalidLogSessionHandle;
}
sLogSessionHandle++;
mLogSessionHandle = sLogSessionHandle;
}
else
{
mLogSessionHandle = kInvalidLogSessionHandle;
}
return mLogSessionHandle;
}

uint64_t LogProvider::GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF)
{
if (logSessionHandle != mLogSessionHandle && outBuffer.size() == 0)
{
return kChunkSizeZero;
}

if (!mFileStream.is_open())
{
ChipLogError(BDX, "File is not open");
return kChunkSizeZero;
}

mFileStream.seekg(static_cast<long long>(mTotalNumberOfBytesConsumed));
mFileStream.read(reinterpret_cast<char *>(outBuffer.data()), kLogContentMaxSize);

if (!(mFileStream.good() || mFileStream.eof()))
{
ChipLogError(BDX, "Failed to read the log file");
mFileStream.close();
return kChunkSizeZero;
}

uint64_t bytesRead = static_cast<uint64_t>(mFileStream.gcount());
outIsEOF = (mFileStream.peek() == EOF);

mTotalNumberOfBytesConsumed += bytesRead;
return bytesRead;
}

void LogProvider::EndLogCollection(LogSessionHandle logSessionHandle)
{
if (logSessionHandle == mLogSessionHandle && mFileStream.is_open())
{
mFileStream.close();
}
}

uint64_t LogProvider::GetTotalNumberOfBytesConsumed(LogSessionHandle logSessionHandle)
{
if (logSessionHandle == mLogSessionHandle)
{
return mTotalNumberOfBytesConsumed;
}
return kChunkSizeZero;
}

const char * LogProvider::GetLogFilePath(IntentEnum logType)
{
switch (logType)
{
case IntentEnum::kEndUserSupport:
return mEndUserSupportLogFileDesignator;
case IntentEnum::kNetworkDiag:
return mNetworkDiagnosticsLogFileDesignator;
case IntentEnum::kCrashLogs:
return mCrashLogFileDesignator;
default:
return nullptr;
}
}

void LogProvider::SetEndUserSupportLogFileDesignator(const char * logFileName)
{
strncpy(mEndUserSupportLogFileDesignator, logFileName, strlen(logFileName));
}

void LogProvider::SetNetworkDiagnosticsLogFileDesignator(const char * logFileName)
{
strncpy(mNetworkDiagnosticsLogFileDesignator, logFileName, strlen(logFileName));
}

void LogProvider::SetCrashLogFileDesignator(const char * logFileName)
{
strncpy(mCrashLogFileDesignator, logFileName, strlen(logFileName));
}
Loading

0 comments on commit 4741256

Please sign in to comment.