Skip to content

Commit 1186767

Browse files
carol-applepull[bot]
authored andcommitted
Log BDX messages (#11510)
* Log BDX messages * Create a new macro ChipLogAutomation - This macro is to be used only for test validation purpose * Remove private struct members from BdxMessage types - Pass in the message type directly during logging
1 parent 3518f5d commit 1186767

File tree

10 files changed

+253
-16
lines changed

10 files changed

+253
-16
lines changed

src/lib/core/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ buildconfig_header("chip_buildconfig") {
4646
"CHIP_ERROR_LOGGING=${chip_error_logging}",
4747
"CHIP_PROGRESS_LOGGING=${chip_progress_logging}",
4848
"CHIP_DETAIL_LOGGING=${chip_detail_logging}",
49+
"CHIP_AUTOMATION_LOGGING=${chip_automation_logging}",
4950
"CHIP_CONFIG_SHORT_ERROR_STR=${chip_config_short_error_str}",
5051
"CHIP_CONFIG_ENABLE_ARG_PARSER=${chip_config_enable_arg_parser}",
5152
"CHIP_TARGET_STYLE_UNIX=${chip_target_style_unix}",

src/lib/core/CHIPConfig.h

+12
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,18 @@
18321832
#define CHIP_DETAIL_LOGGING 1
18331833
#endif // CHIP_DETAIL_LOGGING
18341834

1835+
/**
1836+
* @def CHIP_AUTOMATION_LOGGING
1837+
*
1838+
* @brief
1839+
* If asserted (1), enable logging of all messages in the
1840+
* chip::Logging::kLogCategory_Automation category.
1841+
*
1842+
*/
1843+
#ifndef CHIP_AUTOMATION_LOGGING
1844+
#define CHIP_AUTOMATION_LOGGING 1
1845+
#endif // CHIP_AUTOMATION_LOGGING
1846+
18351847
/**
18361848
* CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE
18371849
*

src/lib/core/core.gni

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ declare_args() {
3030
# Enable detail logging.
3131
chip_detail_logging = chip_logging
3232

33+
# Enable automation logging.
34+
chip_automation_logging = chip_logging
35+
3336
# Enable short error strings.
3437
chip_config_short_error_str = false
3538

src/lib/support/logging/CHIPLogging.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static const char ModuleNames[] = "-\0\0" // None
9595
"IM\0" // InteractionModel
9696
"TST" // Test
9797
"ODP" // OperationalDeviceProxy
98+
"ATM" // Automation
9899
;
99100

100101
#define ModuleNamesCount ((sizeof(ModuleNames) - 1) / chip::Logging::kMaxModuleNameLen)

src/lib/support/logging/CHIPLogging.h

+25-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* - #CHIP_ERROR_LOGGING
3030
* - #CHIP_PROGRESS_LOGGING
3131
* - #CHIP_DETAIL_LOGGING
32+
* - #CHIP_AUTOMATION_LOGGING
3233
*
3334
*/
3435

@@ -62,6 +63,7 @@
6263
* - #CHIP_ERROR_LOGGING
6364
* - #CHIP_PROGRESS_LOGGING
6465
* - #CHIP_DETAIL_LOGGING
66+
* - #CHIP_AUTOMATION_LOGGING
6567
*
6668
*/
6769

@@ -174,11 +176,32 @@ void SetLogFilter(uint8_t category);
174176
#define ChipLogByteSpan(MOD, DATA) ((void) 0)
175177
#endif
176178

177-
#if CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING || CHIP_DETAIL_LOGGING
179+
#ifndef CHIP_AUTOMATION_LOGGING
180+
#define CHIP_AUTOMATION_LOGGING 1
181+
#endif
182+
183+
#if CHIP_AUTOMATION_LOGGING
184+
/**
185+
* @def ChipLogAutomation(MSG, ...)
186+
*
187+
* @brief
188+
* Log a chip message for the specified module in the 'Automation'
189+
* category.
190+
*
191+
*/
192+
#ifndef ChipLogAutomation
193+
#define ChipLogAutomation(MSG, ...) \
194+
chip::Logging::Log(chip::Logging::kLogModule_Automation, chip::Logging::kLogCategory_Automation, MSG, ##__VA_ARGS__)
195+
#endif
196+
#else
197+
#define ChipLogAutomation(MOD, MSG, ...) ((void) 0)
198+
#endif
199+
200+
#if CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING || CHIP_DETAIL_LOGGING || CHIP_AUTOMATION_LOGGING
178201
#define _CHIP_USE_LOGGING 1
179202
#else
180203
#define _CHIP_USE_LOGGING 0
181-
#endif /* CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING || CHIP_DETAIL_LOGGING */
204+
#endif /* CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING || CHIP_DETAIL_LOGGING || CHIP_AUTOMATION_LOGGING */
182205

183206
#if _CHIP_USE_LOGGING
184207

src/lib/support/logging/Constants.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum LogModule
5757
kLogModule_InteractionModel,
5858
kLogModule_Test,
5959
kLogModule_OperationalDeviceProxy,
60+
kLogModule_Automation,
6061

6162
kLogModule_Max
6263
};
@@ -125,7 +126,16 @@ enum LogCategory
125126
*/
126127
kLogCategory_Detail = 3,
127128

128-
kLogCategory_Max = kLogCategory_Detail
129+
/*!<
130+
* Indicates a category of log message that describes automation
131+
* information about an event or the state of the system.
132+
*
133+
* Such messages can be used by automation for test validation.
134+
*
135+
*/
136+
kLogCategory_Automation = 4,
137+
138+
kLogCategory_Max = kLogCategory_Automation
129139
};
130140

131141
} // namespace Logging

src/platform/qpg/args.gni

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ chip_inet_config_enable_tcp_endpoint = false
3131
# Size opt's
3232
#chip_progress_logging = false
3333
chip_detail_logging = false
34+
chip_automation_logging = false
3435

3536
# Use -Os
3637
is_debug = false

src/protocols/bdx/BdxMessages.cpp

+104-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#include <utility>
3232

3333
namespace {
34-
constexpr uint8_t kVersionMask = 0x0F;
34+
constexpr uint8_t kVersionMask = 0x0F;
35+
constexpr uint8_t kMaxFileDesignatorLen = 32;
3536
} // namespace
3637

3738
using namespace chip;
@@ -99,17 +100,16 @@ CHIP_ERROR TransferInit::Parse(System::PacketBufferHandle aBuffer)
99100
uint32_t tmpUint32Value = 0; // Used for reading non-wide length and offset fields
100101
uint8_t * bufStart = aBuffer->Start();
101102
Reader bufReader(bufStart, aBuffer->DataLength());
102-
BitFlags<RangeControlFlags> rangeCtlFlags;
103103

104-
SuccessOrExit(bufReader.Read8(&proposedTransferCtl).Read8(rangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
104+
SuccessOrExit(bufReader.Read8(&proposedTransferCtl).Read8(mRangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
105105

106106
Version = proposedTransferCtl & kVersionMask;
107107
TransferCtlOptions.SetRaw(static_cast<uint8_t>(proposedTransferCtl & ~kVersionMask));
108108

109109
StartOffset = 0;
110-
if (rangeCtlFlags.Has(RangeControlFlags::kStartOffset))
110+
if (mRangeCtlFlags.Has(RangeControlFlags::kStartOffset))
111111
{
112-
if (rangeCtlFlags.Has(RangeControlFlags::kWiderange))
112+
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
113113
{
114114
SuccessOrExit(bufReader.Read64(&StartOffset).StatusCode());
115115
}
@@ -121,9 +121,9 @@ CHIP_ERROR TransferInit::Parse(System::PacketBufferHandle aBuffer)
121121
}
122122

123123
MaxLength = 0;
124-
if (rangeCtlFlags.Has(RangeControlFlags::kDefLen))
124+
if (mRangeCtlFlags.Has(RangeControlFlags::kDefLen))
125125
{
126-
if (rangeCtlFlags.Has(RangeControlFlags::kWiderange))
126+
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
127127
{
128128
SuccessOrExit(bufReader.Read64(&MaxLength).StatusCode());
129129
}
@@ -166,6 +166,34 @@ size_t TransferInit::MessageSize() const
166166
return WriteToBuffer(emptyBuf).Needed();
167167
}
168168

169+
#if CHIP_AUTOMATION_LOGGING
170+
void TransferInit::LogMessage(bdx::MessageType messageType) const
171+
{
172+
char fd[kMaxFileDesignatorLen];
173+
snprintf(fd, sizeof(fd), "%s", FileDesignator);
174+
175+
switch (messageType)
176+
{
177+
case MessageType::SendInit:
178+
ChipLogAutomation("SendInit");
179+
break;
180+
case MessageType::ReceiveInit:
181+
ChipLogAutomation("ReceiveInit");
182+
break;
183+
default:
184+
break;
185+
}
186+
187+
ChipLogAutomation(" Proposed Transfer Control: 0x%X", static_cast<unsigned>(TransferCtlOptions.Raw() | Version));
188+
ChipLogAutomation(" Range Control: 0x%X", static_cast<unsigned>(mRangeCtlFlags.Raw()));
189+
ChipLogAutomation(" Proposed Max Block Size: %" PRIu16, MaxBlockSize);
190+
ChipLogAutomation(" Start Offset: 0x" ChipLogFormatX64, ChipLogValueX64(StartOffset));
191+
ChipLogAutomation(" Proposed Max Length: 0x" ChipLogFormatX64, ChipLogValueX64(MaxLength));
192+
ChipLogAutomation(" File Designator Length: %" PRIu16, FileDesLength);
193+
ChipLogAutomation(" File Designator: %s", fd);
194+
}
195+
#endif // CHIP_AUTOMATION_LOGGING
196+
169197
bool TransferInit::operator==(const TransferInit & another) const
170198
{
171199
if ((MetadataLength != another.MetadataLength) || (FileDesLength != another.FileDesLength))
@@ -246,6 +274,16 @@ size_t SendAccept::MessageSize() const
246274
return WriteToBuffer(emptyBuf).Needed();
247275
}
248276

277+
#if CHIP_AUTOMATION_LOGGING
278+
void SendAccept::LogMessage(bdx::MessageType messageType) const
279+
{
280+
(void) messageType;
281+
ChipLogAutomation("SendAccept");
282+
ChipLogAutomation(" Transfer Control: 0x%X", static_cast<unsigned>(TransferCtlFlags.Raw() | Version));
283+
ChipLogAutomation(" Max Block Size: %" PRIu16, MaxBlockSize);
284+
}
285+
#endif // CHIP_AUTOMATION_LOGGING
286+
249287
bool SendAccept::operator==(const SendAccept & another) const
250288
{
251289
if (MetadataLength != another.MetadataLength)
@@ -317,19 +355,18 @@ CHIP_ERROR ReceiveAccept::Parse(System::PacketBufferHandle aBuffer)
317355
uint32_t tmpUint32Value = 0; // Used for reading non-wide length and offset fields
318356
uint8_t * bufStart = aBuffer->Start();
319357
Reader bufReader(bufStart, aBuffer->DataLength());
320-
BitFlags<RangeControlFlags> rangeCtlFlags;
321358

322-
SuccessOrExit(bufReader.Read8(&transferCtl).Read8(rangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
359+
SuccessOrExit(bufReader.Read8(&transferCtl).Read8(mRangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
323360

324361
Version = transferCtl & kVersionMask;
325362

326363
// Only one of these values should be set. It is up to the caller to verify this.
327364
TransferCtlFlags.SetRaw(static_cast<uint8_t>(transferCtl & ~kVersionMask));
328365

329366
StartOffset = 0;
330-
if (rangeCtlFlags.Has(RangeControlFlags::kStartOffset))
367+
if (mRangeCtlFlags.Has(RangeControlFlags::kStartOffset))
331368
{
332-
if (rangeCtlFlags.Has(RangeControlFlags::kWiderange))
369+
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
333370
{
334371
SuccessOrExit(bufReader.Read64(&StartOffset).StatusCode());
335372
}
@@ -341,9 +378,9 @@ CHIP_ERROR ReceiveAccept::Parse(System::PacketBufferHandle aBuffer)
341378
}
342379

343380
Length = 0;
344-
if (rangeCtlFlags.Has(RangeControlFlags::kDefLen))
381+
if (mRangeCtlFlags.Has(RangeControlFlags::kDefLen))
345382
{
346-
if (rangeCtlFlags.Has(RangeControlFlags::kWiderange))
383+
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
347384
{
348385
SuccessOrExit(bufReader.Read64(&Length).StatusCode());
349386
}
@@ -380,6 +417,18 @@ size_t ReceiveAccept::MessageSize() const
380417
return WriteToBuffer(emptyBuf).Needed();
381418
}
382419

420+
#if CHIP_AUTOMATION_LOGGING
421+
void ReceiveAccept::LogMessage(bdx::MessageType messageType) const
422+
{
423+
(void) messageType;
424+
ChipLogAutomation("ReceiveAccept");
425+
ChipLogAutomation(" Transfer Control: 0x%X", TransferCtlFlags.Raw() | Version);
426+
ChipLogAutomation(" Range Control: 0x%X", mRangeCtlFlags.Raw());
427+
ChipLogAutomation(" Max Block Size: %" PRIu16, MaxBlockSize);
428+
ChipLogAutomation(" Length: 0x" ChipLogFormatX64, ChipLogValueX64(Length));
429+
}
430+
#endif // CHIP_AUTOMATION_LOGGING
431+
383432
bool ReceiveAccept::operator==(const ReceiveAccept & another) const
384433
{
385434
if (MetadataLength != another.MetadataLength)
@@ -423,6 +472,28 @@ bool CounterMessage::operator==(const CounterMessage & another) const
423472
return (BlockCounter == another.BlockCounter);
424473
}
425474

475+
#if CHIP_AUTOMATION_LOGGING
476+
void CounterMessage::LogMessage(bdx::MessageType messageType) const
477+
{
478+
switch (messageType)
479+
{
480+
case MessageType::BlockQuery:
481+
ChipLogAutomation("BlockQuery");
482+
break;
483+
case MessageType::BlockAck:
484+
ChipLogAutomation("BlockAck");
485+
break;
486+
case MessageType::BlockAckEOF:
487+
ChipLogAutomation("BlockAckEOF");
488+
break;
489+
default:
490+
break;
491+
}
492+
493+
ChipLogAutomation(" Block Counter: %" PRIu32, BlockCounter);
494+
}
495+
#endif // CHIP_AUTOMATION_LOGGING
496+
426497
// WARNING: this function should never return early, since MessageSize() relies on it to calculate
427498
// the size of the message (even if the message is incomplete or filled out incorrectly).
428499
Encoding::LittleEndian::BufferWriter & DataBlock::WriteToBuffer(Encoding::LittleEndian::BufferWriter & aBuffer) const
@@ -469,6 +540,26 @@ size_t DataBlock::MessageSize() const
469540
return WriteToBuffer(emptyBuf).Needed();
470541
}
471542

543+
#if CHIP_AUTOMATION_LOGGING
544+
void DataBlock::LogMessage(bdx::MessageType messageType) const
545+
{
546+
switch (messageType)
547+
{
548+
case MessageType::Block:
549+
ChipLogAutomation("Block");
550+
break;
551+
case MessageType::BlockEOF:
552+
ChipLogAutomation("BlockEOF");
553+
break;
554+
default:
555+
break;
556+
}
557+
558+
ChipLogAutomation(" Block Counter: %" PRIu32, BlockCounter);
559+
ChipLogAutomation(" Data Length: %zu", DataLength);
560+
}
561+
#endif // CHIP_AUTOMATION_LOGGING
562+
472563
bool DataBlock::operator==(const DataBlock & another) const
473564
{
474565
if (DataLength != another.DataLength)

0 commit comments

Comments
 (0)