Skip to content

Commit

Permalink
Add a lint for use of PRI*64 macros. (#30541)
Browse files Browse the repository at this point in the history
These are not supported on all libcs.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jan 20, 2024
1 parent 3e197b0 commit 1852633
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 59 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ jobs:
run: |
git grep -n "PRI.16" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)third_party/lwip/repo/lwip/src/include/lwip/arch.h' && exit 1 || exit 0
# git grep exits with 0 if it finds a match, but we want
# to fail (exit nonzero) on match. And we want to exclude this file,
# to avoid our grep regexp matching itself.
- name: Check for use of PRI*64, which are not supported on some libcs.
if: always()
run: |
# TODO: MessageDefHelper should ideally not be excluded here.
# TODO: chip_im_initiatore should ideally not be excluded here.
# TODO: TLVDebug should ideally not be excluded here.
# TODO: protocol_decoder.cpp should ideally not be excluded here.
# TODO: PersistentStorageMacros.h should ideally not be excluded here.
git grep -n "PRI.64" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)examples/chip-tool' ':(exclude)examples/tv-casting-app' ':(exclude)src/app/MessageDef/MessageDefHelper.cpp' ':(exclude)src/app/tests/integration/chip_im_initiator.cpp' ':(exclude)src/lib/core/TLVDebug.cpp' ':(exclude)src/lib/dnssd/tests/TestTxtFields.cpp' ':(exclude)src/lib/format/protocol_decoder.cpp' ':(exclude)src/lib/support/PersistentStorageMacros.h' ':(exclude)src/messaging/tests/echo/echo_requester.cpp' ':(exclude)src/platform/Linux' ':(exclude)src/platform/Ameba' ':(exclude)src/platform/ESP32' ':(exclude)src/platform/webos' ':(exclude)zzz_generated/chip-tool' ':(exclude)src/tools/chip-cert/Cmd_PrintCert.cpp' && exit 1 || exit 0
# git grep exits with 0 if it finds a match, but we want
# to fail (exit nonzero) on match. And we want to exclude this file,
# to avoid our grep regexp matching itself.
Expand Down
13 changes: 7 additions & 6 deletions examples/shell/shell_common/cmd_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,18 @@ static bool PrintServerSession(void * context, SessionHandle & session)
case Session::SessionType::kSecure: {
SecureSession * secureSession = session->AsSecureSession();
SecureSession::Type secureSessionType = secureSession->GetSecureSessionType();
streamer_printf(
streamer_get(), "session type=SECURE %s id=0x%04x peerSessionId=0x%04x peerNodeId=0x%016" PRIx64 " fabricIdx=%d\r\n",
secureSessionType == SecureSession::Type::kCASE ? "CASE" : "PASE", secureSession->GetLocalSessionId(),
secureSession->AsSecureSession()->GetPeerSessionId(), secureSession->GetPeerNodeId(), secureSession->GetFabricIndex());
streamer_printf(streamer_get(),
"session type=SECURE %s id=0x%04x peerSessionId=0x%04x peerNodeId=0x" ChipLogFormatX64 " fabricIdx=%d\r\n",
secureSessionType == SecureSession::Type::kCASE ? "CASE" : "PASE", secureSession->GetLocalSessionId(),
secureSession->AsSecureSession()->GetPeerSessionId(), ChipLogValueX64(secureSession->GetPeerNodeId()),
secureSession->GetFabricIndex());
break;
}

case Session::SessionType::kUnauthenticated: {
UnauthenticatedSession * unsecuredSession = session->AsUnauthenticatedSession();
streamer_printf(streamer_get(), "session type=UNSECURED id=0x0000 peerNodeId=0x%016" PRIx64 "\r\n",
unsecuredSession->GetPeerNodeId());
streamer_printf(streamer_get(), "session type=UNSECURED id=0x0000 peerNodeId=0x" ChipLogFormatX64 "\r\n",
ChipLogValueX64(unsecuredSession->GetPeerNodeId()));
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/AttributePathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CHIP_ERROR AttributePathIB::Parser::PrettyPrint() const
{
NodeId node;
reader.Get(node);
PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node);
PRETTY_PRINT("\tNode = 0x" ChipLogFormatX64 ",", ChipLogValueX64(node));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/ClusterPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CHIP_ERROR ClusterPathIB::Parser::PrettyPrint() const
{
NodeId node;
reader.Get(node);
PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node);
PRETTY_PRINT("\tNode = 0x" ChipLogFormatX64 ",", ChipLogValueX64(node));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand Down
12 changes: 6 additions & 6 deletions src/app/MessageDef/EventDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CHIP_ERROR EventDataIB::Parser::PrettyPrint() const
{
EventNumber number;
ReturnErrorOnFailure(reader.Get(number));
PRETTY_PRINT("\tEventNumber = 0x%" PRIx64 ",", number);
PRETTY_PRINT("\tEventNumber = 0x" ChipLogFormatX64 ",", ChipLogValueX64(number));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand All @@ -81,7 +81,7 @@ CHIP_ERROR EventDataIB::Parser::PrettyPrint() const
{
uint64_t value;
ReturnErrorOnFailure(reader.Get(value));
PRETTY_PRINT("\tPriorityLevel = 0x%" PRIx64 ",", value);
PRETTY_PRINT("\tPriorityLevel = 0x" ChipLogFormatX64 ",", ChipLogValueX64(value));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand All @@ -92,7 +92,7 @@ CHIP_ERROR EventDataIB::Parser::PrettyPrint() const
{
uint64_t value;
ReturnErrorOnFailure(reader.Get(value));
PRETTY_PRINT("\tEpochTimestamp = 0x%" PRIx64 ",", value);
PRETTY_PRINT("\tEpochTimestamp = 0x" ChipLogFormatX64 ",", ChipLogValueX64(value));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand All @@ -104,7 +104,7 @@ CHIP_ERROR EventDataIB::Parser::PrettyPrint() const
{
uint64_t value;
ReturnErrorOnFailure(reader.Get(value));
PRETTY_PRINT("\tSystemTimestamp = 0x%" PRIx64 ",", value);
PRETTY_PRINT("\tSystemTimestamp = 0x" ChipLogFormatX64 ",", ChipLogValueX64(value));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand All @@ -115,7 +115,7 @@ CHIP_ERROR EventDataIB::Parser::PrettyPrint() const
{
uint64_t value;
ReturnErrorOnFailure(reader.Get(value));
PRETTY_PRINT("\tDeltaEpochTimestampstamp= 0x%" PRIx64 ",", value);
PRETTY_PRINT("\tDeltaEpochTimestampstamp= 0x" ChipLogFormatX64 ",", ChipLogValueX64(value));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand All @@ -126,7 +126,7 @@ CHIP_ERROR EventDataIB::Parser::PrettyPrint() const
{
uint64_t value;
ReturnErrorOnFailure(reader.Get(value));
PRETTY_PRINT("\tDeltaSystemTimestamp = 0x%" PRIx64 ",", value);
PRETTY_PRINT("\tDeltaSystemTimestamp = 0x" ChipLogFormatX64 ",", ChipLogValueX64(value));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/EventFilterIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CHIP_ERROR EventFilterIB::Parser::PrettyPrint() const
{
NodeId node;
ReturnErrorOnFailure(reader.Get(node));
PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node);
PRETTY_PRINT("\tNode = 0x" ChipLogFormatX64 ",", ChipLogValueX64(node));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand All @@ -66,7 +66,7 @@ CHIP_ERROR EventFilterIB::Parser::PrettyPrint() const
{
uint64_t eventMin;
ReturnErrorOnFailure(reader.Get(eventMin));
PRETTY_PRINT("\tEventMin = 0x%" PRIx64 ",", eventMin);
PRETTY_PRINT("\tEventMin = 0x" ChipLogFormatX64 ",", ChipLogValueX64(eventMin));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/EventPathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CHIP_ERROR EventPathIB::Parser::PrettyPrint() const
{
NodeId node;
reader.Get(node);
PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node);
PRETTY_PRINT("\tNode = 0x" ChipLogFormatX64 ",", ChipLogValueX64(node));
}
#endif // CHIP_DETAIL_LOGGING
break;
Expand Down
4 changes: 4 additions & 0 deletions src/app/MessageDef/MessageDefHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLa

ReturnErrorOnFailure(aReader.Get(value_s64));

// TODO: Figure out how to not use PRId64 here, since it's not supported
// on all libcs.
PRETTY_PRINT_SAMELINE("%" PRId64 ", ", value_s64);
break;
}
Expand All @@ -147,6 +149,8 @@ CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLa

ReturnErrorOnFailure(aReader.Get(value_u64));

// TODO: Figure out how to not use PRIu64 here, since it's not supported
// on all libcs.
PRETTY_PRINT_SAMELINE("%" PRIu64 ", ", value_u64);
break;
}
Expand Down
6 changes: 4 additions & 2 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3144,8 +3144,10 @@ bool DoorLockServer::sendRemoteLockUserChange(chip::EndpointId endpointId, LockD
}
ChipLogProgress(Zcl,
"[RemoteLockUserChange] Sent lock user change event "
"[endpointId=%d,eventNumber=%" PRIu64 ",dataType=%u,operation=%u,nodeId=%" PRIu64 ",fabricIndex=%d]",
endpointId, eventNumber, to_underlying(dataType), to_underlying(operation), nodeId, fabricIndex);
"[endpointId=%d,eventNumber=0x" ChipLogFormatX64 ",dataType=%u,operation=%u,nodeId=0x" ChipLogFormatX64
",fabricIndex=%d]",
endpointId, ChipLogValueX64(eventNumber), to_underlying(dataType), to_underlying(operation),
ChipLogValueX64(nodeId), fabricIndex);
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ CHIP_ERROR Engine::BuildSingleReportDataAttributeReportIBs(ReportDataMessage::Bu
ConcreteAttributePath readPath;

ChipLogDetail(DataManagement,
"Building Reports for ReadHandler with LastReportGeneration = %" PRIu64 " DirtyGeneration = %" PRIu64,
apReadHandler->mPreviousReportsBeginGeneration, apReadHandler->mDirtyGeneration);
"Building Reports for ReadHandler with LastReportGeneration = 0x" ChipLogFormatX64
" DirtyGeneration = 0x" ChipLogFormatX64,
ChipLogValueX64(apReadHandler->mPreviousReportsBeginGeneration),
ChipLogValueX64(apReadHandler->mDirtyGeneration));

// This ReadHandler is not generating reports, so we reset the iterator for a clean start.
if (!apReadHandler->IsReporting())
Expand Down
6 changes: 3 additions & 3 deletions src/app/reporting/ReportSchedulerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ void ReportSchedulerImpl::OnSubscriptionEstablished(ReadHandler * aReadHandler)
newNode = mNodesPool.CreateObject(aReadHandler, this, now);

ChipLogProgress(DataManagement,
"Registered a ReadHandler that will schedule a report between system Timestamp: %" PRIu64
" and system Timestamp %" PRIu64 ".",
newNode->GetMinTimestamp().count(), newNode->GetMaxTimestamp().count());
"Registered a ReadHandler that will schedule a report between system Timestamp: 0x" ChipLogFormatX64
" and system Timestamp 0x" ChipLogFormatX64 ".",
ChipLogValueX64(newNode->GetMinTimestamp().count()), ChipLogValueX64(newNode->GetMaxTimestamp().count()));
}

/// @brief When a ReadHandler becomes reportable, schedule, recalculate and reschedule the report.
Expand Down
4 changes: 2 additions & 2 deletions src/app/reporting/SynchronizedReportSchedulerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ void SynchronizedReportSchedulerImpl::TimerFired()
if (node->IsReportableNow(now))
{
node->SetEngineRunScheduled(true);
ChipLogProgress(DataManagement, "Handler: %p with min: %" PRIu64 " and max: %" PRIu64 "", (node),
node->GetMinTimestamp().count(), node->GetMaxTimestamp().count());
ChipLogProgress(DataManagement, "Handler: %p with min: 0x" ChipLogFormatX64 " and max: 0x" ChipLogFormatX64 "", (node),
ChipLogValueX64(node->GetMinTimestamp().count()), ChipLogValueX64(node->GetMaxTimestamp().count()));
}

return Loop::Continue;
Expand Down
Loading

0 comments on commit 1852633

Please sign in to comment.