[clang-tidy] Fix clang-tidy errors from g3/gsys config [1/2]
Fix clang-tidy errors by applying auto-fixes from using -fix flag.
All errors are seen here: https://paste.googleplex.com/5988927361253376
The remaining errors requiring manual fixes in Part 2 are seen here: https://paste.googleplex.com/5391272864120832
Tested: built from local changes and flashed successfully on machine
Change-Id: I89fe97978aa13170792f366eb40fde74c0ddc7f6
Signed-off-by: David Tang <davtang@google.com>
diff --git a/.clang-tidy-ignore b/.clang-tidy-ignore
new file mode 100644
index 0000000..4cb3081
--- /dev/null
+++ b/.clang-tidy-ignore
@@ -0,0 +1,3 @@
+subprojects/*
+thirdparty/*
+google3/*
diff --git a/ec_util.cpp b/ec_util.cpp
index 96c875f..477104a 100644
--- a/ec_util.cpp
+++ b/ec_util.cpp
@@ -57,15 +57,13 @@
} // namespace
[[nodiscard]] std::span<const uint8_t>
- EcUtilImpl::getResponseBody(std::vector<uint8_t>& response) const
+EcUtilImpl::getResponseBody(std::vector<uint8_t> &response)
{
std::span<const uint8_t> output = response;
- auto& rsp = stdplus::raw::extractRef<RspHeader>(output);
- if (rsp.result != EC_RES_SUCCESS)
- {
- stdplus::print(stderr,
- "Command received a bad response from Hoth {:#x}\n",
- static_cast<uint8_t>(rsp.result));
+ auto &rsp = stdplus::raw::extractRef<RspHeader>(output);
+ if (rsp.result != EC_RES_SUCCESS) {
+ stdplus::print(stderr, "Command received a bad response from Hoth {:#x}\n",
+ static_cast<uint8_t>(rsp.result));
throw ResponseFailure();
}
diff --git a/ec_util.hpp b/ec_util.hpp
index ecb7f0c..93c697f 100644
--- a/ec_util.hpp
+++ b/ec_util.hpp
@@ -46,8 +46,8 @@
bool checkHothPersistentPanicInfo() const;
private:
- [[nodiscard]] std::span<const uint8_t>
- getResponseBody(std::vector<uint8_t>& response) const;
+ [[nodiscard]] static std::span<const uint8_t>
+ getResponseBody(std::vector<uint8_t> &response);
/** @brief Connection to Hoth for sending and receiving host commands */
HostCommand* hostCmd;
diff --git a/firmware_mtd_updater.cpp b/firmware_mtd_updater.cpp
index cbc765a..9b52154 100644
--- a/firmware_mtd_updater.cpp
+++ b/firmware_mtd_updater.cpp
@@ -44,10 +44,11 @@
mtd->flashCopy(sys, firmwareData, updateDevice);
}
-void FirmwareMtdUpdater::spiWrite(uint32_t, std::vector<uint8_t>)
+void FirmwareMtdUpdater::spiWrite([[maybe_unused]] uint32_t address,
+ [[maybe_unused]] std::vector<uint8_t> data)
{
stdplus::print(stderr,
- "SpiWrite method is not applicable to FirmwareMtdUpdater\n");
+ "SpiWrite method is not applicable to FirmwareMtdUpdater\n");
throw FirmwareFailure();
}
diff --git a/firmware_spi_updater.cpp b/firmware_spi_updater.cpp
index 99462f3..c173f35 100644
--- a/firmware_spi_updater.cpp
+++ b/firmware_spi_updater.cpp
@@ -73,7 +73,7 @@
*/
struct SpiEraseTransaction
{
- SpiEraseTransaction(uint8_t addressSize)
+ explicit SpiEraseTransaction(uint8_t addressSize)
{
header.mosiLen = 1 + addressSize;
header.misoLen = eraseMisoLen;
@@ -194,21 +194,19 @@
setSpsPassThoughDisabled = true;
return;
}
- else
- {
- stdplus::print(stderr, "{}: Failed to disable SPS passthrough.\n",
- __func__);
- }
+
+ stdplus::print(stderr, "{}: Failed to disable SPS passthrough.\n",
+ __func__);
}
fwUpdater->resetTarget(EC_TARGET_RESET_OPTION_SET);
didResetTarget = true;
}
FirmwareSpiUpdater::SpiWritePreparer::SpiWritePreparer(
- SpiWritePreparer&& preparer) :
- fwUpdater(preparer.fwUpdater),
- setSpsPassThoughDisabled(preparer.setSpsPassThoughDisabled),
- didResetTarget(preparer.didResetTarget), resetMode(preparer.resetMode)
+ SpiWritePreparer &&preparer) noexcept
+ : fwUpdater(preparer.fwUpdater),
+ setSpsPassThoughDisabled(preparer.setSpsPassThoughDisabled),
+ didResetTarget(preparer.didResetTarget), resetMode(preparer.resetMode)
{
preparer.fwUpdater = nullptr;
preparer.setSpsPassThoughDisabled = false;
@@ -517,19 +515,18 @@
}
}
-void FirmwareSpiUpdater::appendAddress(std::vector<uint8_t>& array,
- uint32_t address)
+void FirmwareSpiUpdater::appendAddress(std::vector<uint8_t> &array,
+ uint32_t address) const
{
- switch (addressSize)
- {
- case 3:
- appendToByteArray(array, big_uint24_t(address));
- break;
- case 4:
- appendToByteArray(array, big_uint32_t(address));
- break;
- default:
- break;
+ switch (addressSize) {
+ case 3:
+ appendToByteArray(array, big_uint24_t(address));
+ break;
+ case 4:
+ appendToByteArray(array, big_uint32_t(address));
+ break;
+ default:
+ break;
}
}
} // namespace internal
diff --git a/firmware_spi_updater.hpp b/firmware_spi_updater.hpp
index 6a0f77c..c5e4b2d 100644
--- a/firmware_spi_updater.hpp
+++ b/firmware_spi_updater.hpp
@@ -79,7 +79,7 @@
{
public:
SpiWritePreparer(FirmwareSpiUpdater* updater, ResetMode mode);
- SpiWritePreparer(SpiWritePreparer&& preparer);
+ SpiWritePreparer(SpiWritePreparer&& preparer) noexcept;
~SpiWritePreparer();
SpiWritePreparer(const SpiWritePreparer&) = delete;
@@ -188,7 +188,7 @@
* @param[in] array - byte array
* @param[in] address - address
*/
- void appendAddress(std::vector<uint8_t>& array, uint32_t address);
+ void appendAddress(std::vector<uint8_t> &array, uint32_t address) const;
/** @brief The actual firmware update operation.
*
diff --git a/host_command.cpp b/host_command.cpp
index 76fe07f..a027dda 100644
--- a/host_command.cpp
+++ b/host_command.cpp
@@ -46,15 +46,14 @@
HostCommandImpl::HostCommandImpl(MessageIntf* msg, boost::asio::io_context* io,
LogCollectorUtil* logCollectorUtil,
- const std::string name, size_t max_retries,
+ const std::string& name, size_t max_retries,
bool allowLegacyVerify,
- const uint32_t uartChannelId) :
- msg(msg), timer(*io), io(io), logCollectorUtil(logCollectorUtil),
- name(name), max_retries(max_retries), allowLegacyVerify(allowLegacyVerify),
- uartChannelId(uartChannelId)
+ const uint32_t uartChannelId)
+ : msg(msg), timer(*io), io(io), logCollectorUtil(logCollectorUtil),
+ name(name), max_retries(max_retries),
+ allowLegacyVerify(allowLegacyVerify), uartChannelId(uartChannelId)
{
- if (uartChannelId != 0)
- {
+ if (uartChannelId != 0) {
fmt::println(stderr, "Triggering UART log collector for {}", name);
collectUartLogsAsync();
}
@@ -197,8 +196,8 @@
// Concatenate the request header and the request into one uint8_t vector to
// be sent to Hoth
- auto const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
- auto const requestPtr = static_cast<const uint8_t*>(request);
+ auto* const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
+ const auto* const requestPtr = static_cast<const uint8_t*>(request);
std::vector<uint8_t> populatedCommand(
requestHeaderPtr, requestHeaderPtr + sizeof(requestHeader));
populatedCommand.insert(populatedCommand.end(), requestPtr,
@@ -218,8 +217,8 @@
// Concatenate the request header and the request into one uint8_t vector to
// be sent to Hoth
- auto const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
- auto const requestPtr = static_cast<const uint8_t*>(request);
+ auto* const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
+ const auto* const requestPtr = static_cast<const uint8_t*>(request);
std::vector<uint8_t> populatedCommand(
requestHeaderPtr, requestHeaderPtr + sizeof(requestHeader));
populatedCommand.insert(populatedCommand.end(), requestPtr,
@@ -228,18 +227,17 @@
return sendCommand(populatedCommand, timeout);
}
-uint64_t HostCommandImpl::sendCommandAsync(const std::vector<uint8_t>&)
-{
- // Not yet implemented
- return 0;
+uint64_t
+HostCommandImpl::sendCommandAsync([[maybe_unused]] const std::vector<uint8_t>& command) {
+ // Not yet implemented
+ return 0;
}
-std::vector<uint8_t> HostCommandImpl::getResponse(uint64_t)
-{
- // Not yet implemented
- std::vector<uint8_t> result;
+std::vector<uint8_t> HostCommandImpl::getResponse([[maybe_unused]] uint64_t callToken) {
+ // Not yet implemented
+ std::vector<uint8_t> result;
- return result;
+ return result;
}
bool HostCommandImpl::communicationFailure() const
@@ -305,9 +303,9 @@
void HostCommandImpl::collectHothLogs()
{
std::vector<uint8_t> snapshotBufferRequest =
- logCollectorUtil->generateSnapshotRequest();
+ google::hoth::internal::LogCollectorUtil::generateSnapshotRequest();
std::vector<uint8_t> snapshotResponse = sendCommand(snapshotBufferRequest);
- if (!logCollectorUtil->isResponseValid(snapshotResponse))
+ if (!google::hoth::internal::LogCollectorUtil::isResponseValid(snapshotResponse))
{
fmt::println(stderr,
"Response invalid- Unable to snapshot hoth buffer!");
@@ -322,11 +320,11 @@
extractionCounter++)
{
std::vector<uint8_t> grabSnapshotRequest =
- logCollectorUtil->generateGrabSnapshotRequest();
+ google::hoth::internal::LogCollectorUtil::generateGrabSnapshotRequest();
std::vector<uint8_t> grabSnapshotResponse =
sendCommand(grabSnapshotRequest);
- if (!logCollectorUtil->isResponseValid(grabSnapshotResponse))
+ if (!google::hoth::internal::LogCollectorUtil::isResponseValid(grabSnapshotResponse))
{
fmt::println(stderr,
"Response invalid- Unable to grab hoth snapshot!");
@@ -335,7 +333,7 @@
grabSnapshotResponse.erase(grabSnapshotResponse.begin(),
grabSnapshotResponse.begin() +
sizeof(RspHeader));
- logCollectorUtil->publishSnapshot(grabSnapshotResponse,
+ google::hoth::internal::LogCollectorUtil::publishSnapshot(grabSnapshotResponse,
PublishType::Stderr);
if (grabSnapshotResponse.size() <
@@ -496,7 +494,7 @@
fmt::println(stderr, "Getting initial offset with status command...");
}
std::vector<uint8_t> offsetRequest =
- logCollectorUtil->generateGetChannelWriteOffsetRequest(uartChannelId);
+ google::hoth::internal::LogCollectorUtil::generateGetChannelWriteOffsetRequest(uartChannelId);
std::vector<uint8_t> offsetResponse;
try
{
@@ -512,7 +510,7 @@
return std::nullopt;
}
- if (!logCollectorUtil->isResponseValid(offsetResponse))
+ if (!google::hoth::internal::LogCollectorUtil::isResponseValid(offsetResponse))
{
fmt::println(stderr,
"Response invalid- Unable to grab write offset for UART "
@@ -534,11 +532,11 @@
{
std::string heartbeatData = fmt::format(
"Collecting Uart logs for {} with offset {}", name, offset);
- logCollectorUtil->heartbeat(heartbeatData);
+ google::hoth::internal::LogCollectorUtil::heartbeat(heartbeatData);
}
std::vector<uint8_t> uartLogsRequest =
- logCollectorUtil->generateCollectUartLogsRequest(uartChannelId, offset);
+ google::hoth::internal::LogCollectorUtil::generateCollectUartLogsRequest(uartChannelId, offset);
std::vector<uint8_t> readResponse =
sendCommand(uartLogsRequest, std::chrono::milliseconds(500));
@@ -578,7 +576,7 @@
readResponse.begin() + sizeof(RspHeader) +
sizeof(ec_channel_read_response));
- logCollectorUtil->publishSnapshot(readResponse, PublishType::File, name,
+ google::hoth::internal::LogCollectorUtil::publishSnapshot(readResponse, PublishType::File, name,
meta);
return nextReadOffset;
}
diff --git a/host_command.hpp b/host_command.hpp
index 2cec09a..c3c552f 100644
--- a/host_command.hpp
+++ b/host_command.hpp
@@ -51,7 +51,7 @@
explicit HostCommandImpl(MessageIntf* msg, boost::asio::io_context* ioc,
LogCollectorUtil* logCollectorUtil,
- std::string name, size_t max_retries = 0,
+ const std::string& name, size_t max_retries = 0,
bool allowLegacyVerify = true,
uint32_t uartChannelId = 0);
diff --git a/hoth.cpp b/hoth.cpp
index 8e79af9..7b5fb9c 100644
--- a/hoth.cpp
+++ b/hoth.cpp
@@ -198,15 +198,21 @@
// param count should be at least 1 for this msg, but here we won't
// guard the case, crypta will drop the message anyway
if (cbkSlotCmd.cryptaHdr.count == 0)
+ {
return false;
+ }
// slotid size, ideally should be 4, again we don't guard it here
if (cbkSlotCmd.cryptaParam.size != 4)
+ {
return false;
+ }
// check if slotid is 2
if (cbkSlotCmd.slotId == 2)
+ {
return true;
+ }
}
}
catch (...)
@@ -219,8 +225,10 @@
static bool isHostForbiddenCommand(std::span<const uint8_t> command)
{
- if (!isCryptaCommand(command))
- return false;
+ if (!isCryptaCommand(command))
+ {
+ return false;
+ }
return isLoadTokensCommand(command) || isCBKSlot2Command(command);
}
diff --git a/hoth.hpp b/hoth.hpp
index bf1cbbb..0a155b9 100644
--- a/hoth.hpp
+++ b/hoth.hpp
@@ -284,7 +284,7 @@
* @param[in] asyncFuture - Pointer to the async thread of interest
* @return status[FirmwareUpdateStatus] - Status of the async thread
*/
- FirmwareUpdateStatus getAsyncStatus(std::future<void>* asyncFuture);
+ static FirmwareUpdateStatus getAsyncStatus(std::future<void>* asyncFuture);
/** @brief Check for any ongoing payload async threads
* If an ongoing payload async thread is found, throw an exception via elog
diff --git a/log_collector_util.cpp b/log_collector_util.cpp
index 664421b..1cf9c79 100644
--- a/log_collector_util.cpp
+++ b/log_collector_util.cpp
@@ -50,7 +50,7 @@
populateReqHeader(EC_CMD_CONSOLE_REQUEST, /*commandVersion*/ 0x00,
requestBuffer.data(), /*requestPayloadSize*/ 0,
&requestHeader);
- auto const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
+ auto *const requestHeaderPtr = reinterpret_cast<uint8_t *>(&requestHeader);
std::vector<uint8_t> populatedCommand(requestHeaderPtr,
requestHeaderPtr + sizeof(ReqHeader));
@@ -73,9 +73,9 @@
static_cast<void*>(&readSnapshotReq),
sizeof(readSnapshotReq), &consoleReadReqHdr);
- auto const consoleReadReqHdrPtr =
+ auto* const consoleReadReqHdrPtr =
reinterpret_cast<uint8_t*>(&consoleReadReqHdr);
- auto const consoleReadReqPtr =
+ const auto* const consoleReadReqPtr =
reinterpret_cast<const uint8_t*>(&readSnapshotReq);
std::vector<uint8_t> populatedCommandConsoleRead(
@@ -169,8 +169,8 @@
fmt::println(stderr, "Error opening the UART log file: {}", filePath);
return;
}
- outputFile << meta << std::endl;
- outputFile << data << std::endl;
+ outputFile << meta << '\n';
+ outputFile << data << '\n';
outputFile.close();
if constexpr (kDebug)
{
@@ -233,26 +233,23 @@
}
std::vector<uint8_t> LogCollectorUtil::generateGetChannelWriteOffsetRequest(
- const uint32_t& channelId) const
+ const uint32_t &channelId)
{
- if constexpr (kDebug)
- {
- fmt::println(stderr,
- "Getting the hoth channel status for offset for {}...",
- channelId);
+ if constexpr (kDebug) {
+ fmt::println(stderr, "Getting the hoth channel status for offset for {}...",
+ channelId);
}
struct ec_channel_status_request request;
request.channel_id = channelId;
struct ReqHeader requestHeader;
- populateReqHeader(EC_CMD_BOARD_SPECIFIC_BASE +
- EC_PRV_CMD_HOTH_CHANNEL_STATUS,
- /*commandVersion*/ 0x00, static_cast<void*>(&request),
- sizeof(request), &requestHeader);
+ populateReqHeader(EC_CMD_BOARD_SPECIFIC_BASE + EC_PRV_CMD_HOTH_CHANNEL_STATUS,
+ /*commandVersion*/ 0x00, static_cast<void *>(&request),
+ sizeof(request), &requestHeader);
- auto const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
- auto const requestPtr = reinterpret_cast<const uint8_t*>(&request);
+ auto *const requestHeaderPtr = reinterpret_cast<uint8_t *>(&requestHeader);
+ const auto *const requestPtr = reinterpret_cast<const uint8_t *>(&request);
std::vector<uint8_t> populatedCommand(
requestHeaderPtr, requestHeaderPtr + sizeof(requestHeader));
populatedCommand.insert(populatedCommand.end(), requestPtr,
@@ -260,8 +257,9 @@
return populatedCommand;
}
-std::vector<uint8_t> LogCollectorUtil::generateCollectUartLogsRequest(
- const uint32_t channelId, const uint32_t readOffset) const
+std::vector<uint8_t>
+LogCollectorUtil::generateCollectUartLogsRequest(const uint32_t channelId,
+ const uint32_t readOffset)
{
struct ec_channel_read_request request = {
.channel_id = channelId,
@@ -272,11 +270,11 @@
struct ReqHeader requestHeader;
populateReqHeader(EC_CMD_BOARD_SPECIFIC_BASE + EC_CMD_HOTH_CHANNEL_READ,
- /*commandVersion*/ 0x00, static_cast<void*>(&request),
- sizeof(request), &requestHeader);
+ /*commandVersion*/ 0x00, static_cast<void *>(&request),
+ sizeof(request), &requestHeader);
- auto const requestHeaderPtr = reinterpret_cast<uint8_t*>(&requestHeader);
- auto const requestPtr = reinterpret_cast<const uint8_t*>(&request);
+ auto *const requestHeaderPtr = reinterpret_cast<uint8_t *>(&requestHeader);
+ const auto *const requestPtr = reinterpret_cast<const uint8_t *>(&request);
std::vector<uint8_t> populatedCommand(
requestHeaderPtr, requestHeaderPtr + sizeof(requestHeader));
populatedCommand.insert(populatedCommand.end(), requestPtr,
@@ -289,7 +287,7 @@
fmt::println(stderr, "{}", message);
}
-int LogCollectorUtil::getAsyncWaitTime()
+int LogCollectorUtil::getAsyncWaitTime() const
{
return this->asyncWaitTime;
}
diff --git a/log_collector_util.hpp b/log_collector_util.hpp
index c705561..510f8e1 100644
--- a/log_collector_util.hpp
+++ b/log_collector_util.hpp
@@ -115,21 +115,21 @@
*
* @return request as a vector of bytes
*/
- std::vector<uint8_t> generateSnapshotRequest();
+ static std::vector<uint8_t> generateSnapshotRequest();
/**
* @brief Generates a request for getting the snapshot of the hoth buffer
*
* @return request as a vector of bytes
*/
- std::vector<uint8_t> generateGrabSnapshotRequest();
+ static std::vector<uint8_t> generateGrabSnapshotRequest();
/**
* @brief Verifies the response header
*
* @return true or false (in terms of validity)
*/
- bool isResponseValid(std::vector<uint8_t> response);
+ static bool isResponseValid(std::vector<uint8_t> response);
/**
* @brief Generates Collect Uart Request
@@ -137,9 +137,8 @@
* @param[in] channelId - Channel Id for Uart
* @param[in] readOffset - Offset from where the buffer is to be read
*/
- std::vector<uint8_t>
- generateCollectUartLogsRequest(uint32_t channelId,
- uint32_t readOffset) const;
+ static std::vector<uint8_t>
+ generateCollectUartLogsRequest(uint32_t channelId, uint32_t readOffset);
/**
* @brief Publishes the snapshot based on publish type
@@ -150,9 +149,10 @@
* @param[in] meta - If any meta data is to be printed in the logs
*
*/
- void publishSnapshot(std::vector<uint8_t> response, PublishType publishType,
- std::string_view filePathSuffix = "",
- std::string_view meta = "");
+ static void publishSnapshot(std::vector<uint8_t> response,
+ PublishType publishType,
+ std::string_view filePathSuffix = "",
+ std::string_view meta = "");
/**
* @brief Generate unique request id
@@ -166,7 +166,7 @@
*
* @return wait time in seconds
*/
- int getAsyncWaitTime();
+ int getAsyncWaitTime() const;
/**
* @brief Current request counter
@@ -180,8 +180,8 @@
*
* @return request bytes for channel write offset
*/
- std::vector<uint8_t>
- generateGetChannelWriteOffsetRequest(const uint32_t& channelId) const;
+ static std::vector<uint8_t>
+ generateGetChannelWriteOffsetRequest(const uint32_t &channelId);
/**
* @brief Writes to file
@@ -190,14 +190,14 @@
* @param[in] name - suffix of the file name (gets attached to prefix -
* "syslog_file")
*/
- void writeToFile(std::string_view data, std::string_view name);
+ static void writeToFile(std::string_view data, std::string_view name);
/**
* @brief Sends a heartbeat once every kHeartBeatLimit when invoked
*
* @param[in] data - Message for the heartbeat
*/
- void heartbeat(std::string_view data);
+ static void heartbeat(std::string_view message);
/**
* @brief Rate Limits the requests to be sent to log collector
diff --git a/main.cpp b/main.cpp
index eb1ed6e..e04e1c8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -119,15 +119,13 @@
return std::string();
}
-uint32_t getUartChannelId(const std::string uartChannelStr)
-{
- uint32_t uartChannelId = 0;
- for (char c : uartChannelStr)
- {
- uartChannelId <<= 8; // or 0x100, shifting 2 hex digits
- uartChannelId += static_cast<uint32_t>(c);
- }
- return uartChannelId;
+uint32_t getUartChannelId(const std::string &uartChannelStr) {
+ uint32_t uartChannelId = 0;
+ for (char c : uartChannelStr) {
+ uartChannelId <<= 8; // or 0x100, shifting 2 hex digits
+ uartChannelId += static_cast<uint32_t>(c);
+ }
+ return uartChannelId;
}
using google::hoth::internal::ResetMode;
@@ -135,13 +133,21 @@
ResetMode parseReset(char* str)
{
if (!str || "needed"s == str)
+ {
return ResetMode::needed;
+ }
if ("never"s == str)
+ {
return ResetMode::never;
+ }
if ("ignore_fail"s == str)
+ {
return ResetMode::ignore;
+ }
if ("needed_active"s == str)
+ {
return ResetMode::needed_active;
+ }
stdplus::print(stderr, "Unknown reset type {}\n", str);
exit(EXIT_FAILURE);
}
diff --git a/message_file.cpp b/message_file.cpp
index 893bc62..723f225 100644
--- a/message_file.cpp
+++ b/message_file.cpp
@@ -89,16 +89,13 @@
throw internal::errnoException("Error reading from Hoth interface");
}
- else if (ret == 0)
+ if (ret == 0)
{
// EOF hit
throw std::runtime_error("Hit EOF while expecting data");
- }
- else // ret > 0
- {
- buf += ret;
- size -= ret;
- }
+ } // ret > 0
+ buf += ret;
+ size -= ret;
};
}
diff --git a/message_hoth_usb.cpp b/message_hoth_usb.cpp
index e1727e0..a0ecaba 100644
--- a/message_hoth_usb.cpp
+++ b/message_hoth_usb.cpp
@@ -76,8 +76,7 @@
class TimeOut : public std::runtime_error
{
public:
- TimeOut(const std::string& msg) : runtime_error(msg)
- {}
+ explicit TimeOut(const std::string &msg) : runtime_error(msg) {}
};
// Helper function to throw exceptions on returning libhoth_usb errors.
@@ -156,7 +155,7 @@
Int ret;
auto term = str.substr(0, str.find(separator));
- auto end = term.data() + term.size();
+ const auto* end = term.data() + term.size();
auto res = std::from_chars(term.data(), end, ret);
if (res.ec != std::errc() || res.ptr != end)
{
@@ -171,7 +170,9 @@
std::string_view usb_id)
{
if (libusb == nullptr)
+ {
throw std::runtime_error("libusb is nullptr");
+ }
auto bus_id = extract_separated_int<uint8_t>(usb_id, '-');
std::vector<uint8_t> port_ids;
do
@@ -274,14 +275,14 @@
}())
{}
-MessageHothUSB::MessageHothUSB(MessageHothUSB&& other) :
- libusb_(nullptr), ctx_(nullptr), dev_(nullptr), libhoth_usb_(nullptr),
- hoth_dev_(nullptr)
+MessageHothUSB::MessageHothUSB(MessageHothUSB &&other) noexcept
+ : libusb_(nullptr), ctx_(nullptr), dev_(nullptr), libhoth_usb_(nullptr),
+ hoth_dev_(nullptr)
{
this->swap(other);
}
-MessageHothUSB& MessageHothUSB::operator=(MessageHothUSB&& other)
+MessageHothUSB &MessageHothUSB::operator=(MessageHothUSB &&other) noexcept
{
MessageHothUSB temp(std::move(other));
this->swap(temp);
@@ -291,11 +292,17 @@
MessageHothUSB::~MessageHothUSB()
{
if (libhoth_usb_ && hoth_dev_)
+ {
libhoth_usb_->close(hoth_dev_);
+ }
if (libusb_ && dev_)
+ {
libusb_->unref_device(dev_);
+ }
if (libusb_ && ctx_)
+ {
libusb_->exit(ctx_);
+ }
}
void MessageHothUSB::send(const uint8_t* buf, size_t size,
diff --git a/message_hoth_usb.hpp b/message_hoth_usb.hpp
index 215efff..bf224ca 100644
--- a/message_hoth_usb.hpp
+++ b/message_hoth_usb.hpp
@@ -28,8 +28,8 @@
LibHothUsbIntf* libhoth_usb);
MessageHothUSB(const MessageHothUSB&) = delete;
MessageHothUSB& operator=(const MessageHothUSB&) = delete;
- MessageHothUSB(MessageHothUSB&&);
- MessageHothUSB& operator=(MessageHothUSB&&);
+ MessageHothUSB(MessageHothUSB&&) noexcept;
+ MessageHothUSB& operator=(MessageHothUSB&&) noexcept;
MessageHothUSB& swap(MessageHothUSB& other)
{
diff --git a/mtd_util.cpp b/mtd_util.cpp
index 2789792..c2a8f3a 100644
--- a/mtd_util.cpp
+++ b/mtd_util.cpp
@@ -121,17 +121,14 @@
throw errnoException(
std::format("Failed to write to mtd device {}", device));
}
- else if (ret == 0)
+ if (ret == 0)
{
sys->close(fd);
throw std::runtime_error(std::format(
"Unexpected EOF while writing to mtd device {}", device));
- }
- else // ret > 0
- {
- count += ret;
- }
+ } // ret > 0
+ count += ret;
}
// Validate written data
@@ -157,25 +154,22 @@
throw errnoException(
std::format("Failed to read from mtd device {}", device));
}
- else if (ret == 0)
+ if (ret == 0)
{
sys->close(fd);
throw std::runtime_error(std::format(
"Unexpected EOF while reading from mtd device {}", device));
- }
- else // ret > 0
+ } // ret > 0
+ int rc = std::memcmp(data.data() + count, readBuffer.data(), ret);
+ if (rc != 0)
{
- int rc = std::memcmp(data.data() + count, readBuffer.data(), ret);
- if (rc != 0)
- {
- sys->close(fd);
+ sys->close(fd);
- throw std::runtime_error(std::format(
- "Written data failed validation at {} bytes", count));
- }
- count += ret;
+ throw std::runtime_error(
+ std::format("Written data failed validation at {} bytes", count));
}
+ count += ret;
}
auto retClose = sys->close(fd);
diff --git a/payload_update.cpp b/payload_update.cpp
index c1f09f6..7b1f4c5 100644
--- a/payload_update.cpp
+++ b/payload_update.cpp
@@ -212,9 +212,12 @@
do
{
if (regionSize <= max_packet_size)
+ {
readSize = regionSize;
- else
+ } else
+ {
readSize = max_packet_size;
+ }
if (!sys->read(*fd, readBuffer.data(), readSize))
{
@@ -401,8 +404,7 @@
throw errnoException(
std::format("Failed to read from file {}", path));
}
- else if (actualReadSize > 0)
- {
+ if (actualReadSize > 0) {
// Decided not to use initializer list to create the span here as
// actualReadSize is ssize_t and we'd need to static_cast
trimAndSend(std::span<uint8_t>(readBuffer.data(), actualReadSize),
diff --git a/test/ec_util_unittest.cpp b/test/ec_util_unittest.cpp
index 37573a1..ba08336 100644
--- a/test/ec_util_unittest.cpp
+++ b/test/ec_util_unittest.cpp
@@ -27,13 +27,7 @@
using namespace sdbusplus::error::xyz::openbmc_project::control::hoth;
using ::testing::_;
-using ::testing::Assign;
-using ::testing::ContainerEq;
-using ::testing::DoAll;
-using ::testing::Invoke;
-using ::testing::Matcher;
using ::testing::Return;
-using ::testing::Throw;
namespace google
{
@@ -44,7 +38,7 @@
namespace
{
-auto static const goodResponseStr = "\x03\xfd\x00\x00\x00\x00\x00\x00"s;
+auto const goodResponseStr = "\x03\xfd\x00\x00\x00\x00\x00\x00"s;
class EcUtilTest : public ::testing::Test
{
@@ -61,8 +55,8 @@
MATCHER_P(dummyMatches, req, "")
{
- const auto arg_req = static_cast<const uint8_t*>(arg);
- return *arg_req == req;
+ const auto *const arg_req = static_cast<const uint8_t *>(arg);
+ return *arg_req == req;
}
class EcUtilStatisticTest : public EcUtilTest
@@ -86,7 +80,9 @@
{
std::vector<uint8_t> rsp(goodResponseStr.begin(), goodResponseStr.end());
for (uint16_t i = 0; i < 256; i++)
- rsp.push_back(0);
+ {
+ rsp.push_back(0);
+ }
EXPECT_CALL(hostCmd, sendCommand(EC_CMD_BOARD_SPECIFIC_BASE +
EC_PRV_CMD_HOTH_GET_STATISTICS,
diff --git a/test/host_command_unittest.cpp b/test/host_command_unittest.cpp
index b055f62..ff719f7 100644
--- a/test/host_command_unittest.cpp
+++ b/test/host_command_unittest.cpp
@@ -283,14 +283,12 @@
HostCommandImpl::isCommandLongRunning(req_buf, true));
}
-auto static const hello_req_str =
- "\x03\xb6\x01\x00\x00\x00\x04\x00\x42\x00\x00\x00"s;
-auto static const hello_rsp_str =
- "\x03\xad\x00\x00\x04\x00\x00\x00\x46\x03\x02\x01"s;
-std::vector<uint8_t> static const hello_req(hello_req_str.begin(),
- hello_req_str.end());
-std::vector<uint8_t> static const hello_rsp(hello_rsp_str.begin(),
- hello_rsp_str.end());
+auto const hello_req_str = "\x03\xb6\x01\x00\x00\x00\x04\x00\x42\x00\x00\x00"s;
+auto const hello_rsp_str = "\x03\xad\x00\x00\x04\x00\x00\x00\x46\x03\x02\x01"s;
+std::vector<uint8_t> const hello_req(hello_req_str.begin(),
+ hello_req_str.end());
+std::vector<uint8_t> const hello_rsp(hello_rsp_str.begin(),
+ hello_rsp_str.end());
class BufError : public std::exception
{
diff --git a/test/hoth_state_unittest.cpp b/test/hoth_state_unittest.cpp
index f772ca3..07ade6b 100644
--- a/test/hoth_state_unittest.cpp
+++ b/test/hoth_state_unittest.cpp
@@ -33,9 +33,6 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-using ::sdbusplus::error::xyz::openbmc_project::control::hoth::state::
- ExpectedInfoNotFound;
-
using ::testing::_;
using ::testing::IsNull;
using ::testing::Return;
@@ -274,7 +271,7 @@
.WillRepeatedly(Return(0));
}
- void updateStatistics(ec_response_statistics* s)
+ static void updateStatistics(ec_response_statistics *s)
{
s->hoth_reset_flags += 0x10;
s->time_since_hoth_boot_us += 0x10;
diff --git a/test/hoth_unittest.cpp b/test/hoth_unittest.cpp
index 7ef52d4..dc315a2 100644
--- a/test/hoth_unittest.cpp
+++ b/test/hoth_unittest.cpp
@@ -55,15 +55,14 @@
}
protected:
- void waitWhileInProgress(std::function<Hoth::FirmwareUpdateStatus()> func)
+ void waitWhileInProgress(const std::function<Hoth::FirmwareUpdateStatus()> &func)
{
- do
- {
+ do {
std::this_thread::sleep_for(loopDelay);
result = func();
loopCount++;
} while (result == Hoth::FirmwareUpdateStatus::InProgress &&
- loopCount < maxLoopCount);
+ loopCount < maxLoopCount);
}
std::condition_variable cv;
@@ -222,15 +221,14 @@
}
protected:
- void waitWhileInProgress(std::function<Hoth::FirmwareUpdateStatus()> func)
+ void waitWhileInProgress(const std::function<Hoth::FirmwareUpdateStatus()> &func)
{
- do
- {
+ do {
std::this_thread::sleep_for(loopDelay);
result = func();
loopCount++;
} while (result == Hoth::FirmwareUpdateStatus::InProgress &&
- loopCount < maxLoopCount);
+ loopCount < maxLoopCount);
}
std::condition_variable cv;
diff --git a/test/log_collector_util_test.cpp b/test/log_collector_util_test.cpp
index 2c1249a..20cc043 100644
--- a/test/log_collector_util_test.cpp
+++ b/test/log_collector_util_test.cpp
@@ -24,9 +24,6 @@
using namespace google::hoth;
using namespace google::hoth::internal;
-using ::testing::_;
-using ::testing::Return;
-
class LogCollectorUtilTest : public ::testing::Test
{
protected:
@@ -44,7 +41,7 @@
std::vector<uint8_t> expectedResponse = {0x03, 0x66, 0x97, 0x00,
0x00, 0x00, 0x00, 0x00};
std::vector<uint8_t> snapshotRequest =
- logCollectorUtil.generateSnapshotRequest();
+ google::hoth::internal::LogCollectorUtil::generateSnapshotRequest();
EXPECT_EQ(expectedResponse, snapshotRequest);
}
@@ -55,7 +52,7 @@
0x00, 0x01, 0x00, 0x00};
std::vector<uint8_t> grabSnapshotRequest =
- logCollectorUtil.generateGrabSnapshotRequest();
+ google::hoth::internal::LogCollectorUtil::generateGrabSnapshotRequest();
EXPECT_EQ(expectedResponse, grabSnapshotRequest);
}
@@ -64,7 +61,8 @@
{
std::vector<uint8_t> validResponse = {0x03, 0xFD, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
- bool status = logCollectorUtil.isResponseValid(validResponse);
+ bool status = google::hoth::internal::LogCollectorUtil::isResponseValid(
+ validResponse);
EXPECT_EQ(true, status);
}
@@ -74,7 +72,8 @@
rspHeader.result = 1; // invalid response code
std::vector<uint8_t> invalidResponse(sizeof(RspHeader));
std::memcpy(invalidResponse.data(), &rspHeader, sizeof(RspHeader));
- bool status = logCollectorUtil.isResponseValid(invalidResponse);
+ bool status = google::hoth::internal::LogCollectorUtil::isResponseValid(
+ invalidResponse);
EXPECT_EQ(false, status);
}
@@ -110,8 +109,8 @@
{
std::vector<uint8_t> expectedRequest = {0x03, 0x53, 0x37, 0x3E, 0x00, 0x00,
0x04, 0x00, 0x43, 0x55, 0x4e, 0x4b};
- std::vector<uint8_t> request =
- logCollectorUtil.generateGetChannelWriteOffsetRequest(0x4b4e5543);
+ std::vector<uint8_t> request = google::hoth::internal::LogCollectorUtil::
+ generateGetChannelWriteOffsetRequest(0x4b4e5543);
EXPECT_EQ(request, expectedRequest);
}
@@ -137,8 +136,8 @@
0x03, 0x97, 0x36, 0x3e, 0x00, 0x00, 0x10, 0x00, 0x43, 0x55, 0x4e, 0x4b,
0x52, 0x44, 0x11, 0x1b, 0x00, 0x04, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00};
uint32_t offset = 0x1b114452;
- std::vector<uint8_t> requestGenerated =
- logCollectorUtil.generateCollectUartLogsRequest(0x4b4e5543, offset);
+ std::vector<uint8_t> requestGenerated = google::hoth::internal::
+ LogCollectorUtil::generateCollectUartLogsRequest(0x4b4e5543, offset);
EXPECT_EQ(expectedRequest, requestGenerated);
}
diff --git a/test/message_reinit_unittest.cpp b/test/message_reinit_unittest.cpp
index cd483ca..7c8d343 100644
--- a/test/message_reinit_unittest.cpp
+++ b/test/message_reinit_unittest.cpp
@@ -37,20 +37,19 @@
init_count++;
}
- void send(const uint8_t* data, size_t, size_t) override
+ void send(const uint8_t* data, size_t /*size*/, size_t /*seek*/) override
{
- if (data == nullptr)
- {
- throw std::runtime_error("Send Failed");
- }
+ if (data == nullptr)
+ {
+ throw std::runtime_error("Send Failed");
+ }
}
- void recv(uint8_t* data, size_t, size_t) override
+ void recv(uint8_t *data, size_t /*size*/, size_t /*seek*/) override
{
- if (data == nullptr)
- {
- throw std::runtime_error("Recv Failed");
- }
+ if (data == nullptr) {
+ throw std::runtime_error("Recv Failed");
+ }
}
};
diff --git a/test/message_usb_unittest.cpp b/test/message_usb_unittest.cpp
index dbac0cc..b857ec3 100644
--- a/test/message_usb_unittest.cpp
+++ b/test/message_usb_unittest.cpp
@@ -121,7 +121,7 @@
class MessageUSBMemberTest : public MessageUSBTest
{
protected:
- MessageUSBMemberTest() : MessageUSBTest()
+ MessageUSBMemberTest()
{
// ed[0] is intentionally a non BULK type transfer endpoint
// to ensure we filter correctly.
@@ -163,8 +163,7 @@
EXPECT_CALL(libusb, release_interface(handle, id[1].bInterfaceNumber))
.WillOnce(Return(0));
- msg =
- std::make_unique<MessageUSB>("1-1.1", &libusb, /*unit_test=*/true);
+ msg = std::make_unique<MessageUSB>("1-1.1", &libusb, /*unit_test=*/true);
}
libusb_device_handle* const handle =
diff --git a/test/mtd_util_unittest.cpp b/test/mtd_util_unittest.cpp
index 623fd85..e60b1dc 100644
--- a/test/mtd_util_unittest.cpp
+++ b/test/mtd_util_unittest.cpp
@@ -43,7 +43,6 @@
using ::testing::Invoke;
using ::testing::MatcherCast;
using ::testing::NotNull;
-using ::testing::Pointee;
using ::testing::Return;
using ::testing::SetErrnoAndReturn;
using ::testing::StrEq;
@@ -55,13 +54,14 @@
std::map<fs::path, std::optional<std::string>> mtdMap;
-std::vector<fs::path> google::hoth::internal::listDir(const fs::path&)
+std::vector<fs::path>
+google::hoth::internal::listDir(const fs::path& /*unused*/)
{
std::vector<fs::path> output;
- for (const auto& p : mtdMap)
- {
- output.push_back(p.first);
+ output.reserve(mtdMap.size());
+ for (const auto& p : mtdMap) {
+ output.push_back(p.first);
}
return output;
@@ -214,7 +214,7 @@
class FakeMtd
{
public:
- FakeMtd(uint32_t flags = 0) : flags(flags)
+ explicit FakeMtd(uint32_t flags = 0) : flags(flags)
{
mtd.type = MTD_NORFLASH;
mtd.flags = MTD_WRITEABLE;
@@ -234,7 +234,7 @@
}
}
- ssize_t write(int, const void* buf, size_t size)
+ ssize_t write(int /*unused*/, const void *buf, size_t size)
{
// Simulate interruption
if (writeIntrRemain > 0 && writeOffset != 0)
@@ -275,7 +275,7 @@
return writeSize;
}
- ssize_t read(int, void* buf, size_t size)
+ ssize_t read(int /*unused*/, void *buf, size_t size)
{
// Simulate interruption
if (readIntrRemain > 0 && readOffset != 0)
diff --git a/test/payload_update_unittest.cpp b/test/payload_update_unittest.cpp
index fec9be2..dc4f9c4 100644
--- a/test/payload_update_unittest.cpp
+++ b/test/payload_update_unittest.cpp
@@ -39,11 +39,8 @@
using namespace sdbusplus::error::xyz::openbmc_project::control::hoth;
using ::testing::_;
-using ::testing::Assign;
using ::testing::ContainerEq;
-using ::testing::DoAll;
using ::testing::Invoke;
-using ::testing::Matcher;
using ::testing::Return;
using ::testing::Throw;
@@ -56,9 +53,9 @@
namespace
{
-auto static const goodResponseStr = "\x03\xfd\x00\x00\x00\x00\x00\x00"s;
-std::vector<uint8_t> static const gooodResponse(goodResponseStr.begin(),
- goodResponseStr.end());
+auto const goodResponseStr = "\x03\xfd\x00\x00\x00\x00\x00\x00"s;
+std::vector<uint8_t> const gooodResponse(goodResponseStr.begin(),
+ goodResponseStr.end());
class PayloadUpdateTest : public ::testing::Test
{
@@ -77,7 +74,7 @@
MATCHER_P(requestMatches, req, "")
{
- const auto arg_req = static_cast<const payload_update_packet*>(arg);
+ const auto* const arg_req = static_cast<const payload_update_packet *>(arg);
return (arg_req->offset == req.offset && arg_req->len == req.len &&
arg_req->type == req.type);
}
@@ -207,7 +204,7 @@
const payload_update_packet expectedReq = {expectedOffset, expectedSize,
PAYLOAD_UPDATE_READ};
- std::vector<uint8_t> makeResponse(std::span<const uint8_t> data)
+ static std::vector<uint8_t> makeResponse(std::span<const uint8_t> data)
{
internal::RspHeader hdr;
auto hdrSpan = stdplus::raw::asSpan<uint8_t>(hdr);
@@ -458,12 +455,12 @@
MATCHER_P(activateRequestMatches, req, "")
{
- const auto arg_req = static_cast<const internal::ActivateRequest*>(arg);
- return (arg_req->header.offset == req.header.offset &&
- arg_req->header.len == req.header.len &&
- arg_req->header.type == req.header.type &&
- arg_req->activate.half == req.activate.half &&
- arg_req->activate.make_persistent == req.activate.make_persistent);
+ const auto*const arg_req = static_cast<const internal::ActivateRequest*>(arg);
+ return (arg_req->header.offset == req.header.offset &&
+ arg_req->header.len == req.header.len &&
+ arg_req->header.type == req.header.type &&
+ arg_req->activate.half == req.activate.half &&
+ arg_req->activate.make_persistent == req.activate.make_persistent);
}
class PayloadActivateTest : public PayloadUpdateTest
@@ -548,8 +545,8 @@
payload_update_confirm_option::Confirm;
uint32_t timeoute_value = 3600;
uint64_t cookie = 0;
- const payload_update_confirm expectedConfirm = {option, 0, 0,
- 0, 3600, cookie};
+ const payload_update_confirm expectedConfirm = {
+ option, {0, 0, 0}, 3600, cookie};
const internal::ConfirmRequest expectedReq = {expectedHeader,
expectedConfirm};
@@ -559,7 +556,8 @@
MATCHER_P(confirmRequestMatches, req, "")
{
- const auto arg_req = static_cast<const internal::ConfirmRequest*>(arg);
+ const auto *const arg_req =
+ static_cast<const internal::ConfirmRequest *>(arg);
return (arg_req->header.offset == req.header.offset &&
arg_req->header.len == req.header.len &&
arg_req->header.type == req.header.type &&
@@ -857,7 +855,7 @@
std::system_error);
} // namespace internal
-static constexpr uint32_t testFlashSize = 32 * 1024;
+constexpr uint32_t testFlashSize = 32 * 1024;
class PayloadChunkAndSendTest : public PayloadSendTest
{
// Needs to be public in order to be used in TEST_P
@@ -876,30 +874,31 @@
{
public:
// Generate all 0xff file
- FakeFile(uint32_t size) : file(size, 0xff)
- {}
+ explicit FakeFile(uint32_t size) : file(size, 0xff) {}
// Generate all 0xff file with random data between the 2 params passed in
FakeFile(uint32_t randStartOffset, uint32_t randEndOffset, uint32_t size) :
file(size, 0xff)
{
std::mt19937 gen(0);
if (randEndOffset > size)
+ {
throw std::runtime_error(
"RandEndOffset cannot be bigger than size of file");
+ }
auto fileIt = file.begin();
std::generate(fileIt + randStartOffset, fileIt + randEndOffset, gen);
}
// Copy the file passed in manually
- FakeFile(const std::vector<uint8_t>& file)
+ explicit FakeFile(const std::vector<uint8_t> &file)
{
this->file = file;
}
- ssize_t read(int, void* buf, size_t size)
+ ssize_t read(int /*unused*/, void *buf, size_t size)
{
auto readSize = std::min(static_cast<off_t>(file.size()) - readOffset,
- static_cast<off_t>(size));
+ static_cast<off_t>(size));
if (readSize < 0)
{
@@ -918,14 +917,13 @@
class FakeFlash
{
public:
- FakeFlash(uint32_t size) : flash(size, 0xff)
- {}
+ explicit FakeFlash(uint32_t size) : flash(size, 0xff) {}
- std::vector<uint8_t> sendCommand(uint16_t, uint8_t, const void* request,
- size_t requestSize)
+ std::vector<uint8_t> sendCommand(uint16_t /*unused*/, uint8_t /*unused*/,
+ const void *request, size_t requestSize)
{
std::span<const uint8_t> reqSpan(
- reinterpret_cast<const uint8_t*>(request), requestSize);
+ reinterpret_cast<const uint8_t *>(request), requestSize);
auto reqHeader = stdplus::raw::extract<payload_update_packet>(reqSpan);
EXPECT_EQ(reqHeader.type, PAYLOAD_UPDATE_CONTINUE);
diff --git a/tools/hoth_dbus.cpp b/tools/hoth_dbus.cpp
index 2871106..b9f4f8f 100644
--- a/tools/hoth_dbus.cpp
+++ b/tools/hoth_dbus.cpp
@@ -59,7 +59,7 @@
{
std::string service{kHothInterface};
std::string object{kHothObject};
- if (hothId != "")
+ if (!hothId.empty())
{
service += ".";
service += hothId;
@@ -107,16 +107,16 @@
{
if (std::chrono::steady_clock::now() > timeout)
{
- std::cerr << "Verify payload timed out." << std::endl;
- return false;
+ std::cerr << "Verify payload timed out." << '\n';
+ return false;
}
std::this_thread::sleep_for(100ms);
status = getVerifyPayloadStatus(hothId);
}
if (status != FirmwareUpdateStatus::Done)
{
- std::cerr << "Verify payload failed." << std::endl;
- return false;
+ std::cerr << "Verify payload failed." << '\n';
+ return false;
}
return true;
}
@@ -137,27 +137,27 @@
callMethodAndRead("SendHostCommand", hothId, bytes, spanReq);
if (bytes.size() < sizeof(PayloadVersionResponse))
{
- std::cerr << "Invalid response." << std::endl;
- return {};
+ std::cerr << "Invalid response." << '\n';
+ return {};
}
auto response = stdplus::raw::copyFrom<PayloadVersionResponse>(bytes);
if (response.header.struct_version != kStructVersion)
{
- std::cerr << "Response structure version not supported: "
- << response.header.struct_version << std::endl;
- return {};
+ std::cerr << "Response structure version not supported: "
+ << response.header.struct_version << '\n';
+ return {};
}
if (response.header.result != 0)
{
- std::cerr << "Failed to get payload version" << std::endl;
- return {};
+ std::cerr << "Failed to get payload version" << '\n';
+ return {};
}
const uint8_t activeHalf = response.status.header.active_half;
const uint8_t regionCount = response.status.header.region_count;
if (regionCount == 0 || regionCount > PAYLOAD_STATUS_MAX_REGION_STATES)
{
- std::cerr << "Payload status region count invalid." << std::endl;
- return {};
+ std::cerr << "Payload status region count invalid." << '\n';
+ return {};
}
std::string versionStrings[PAYLOAD_STATUS_MAX_REGION_STATES];
for (uint8_t i = 0; i < regionCount; i++)
@@ -177,9 +177,9 @@
}
}
std::cerr << "Active half: " << static_cast<unsigned int>(activeHalf)
- << std::endl;
- std::cerr << "Version[0]: " << versionStrings[0] << std::endl;
- std::cerr << "Version[1]: " << versionStrings[1] << std::endl;
+ << '\n';
+ std::cerr << "Version[0]: " << versionStrings[0] << '\n';
+ std::cerr << "Version[1]: " << versionStrings[1] << '\n';
if (type == payload_update::VersionType::kActiveHalf)
{
return versionStrings[activeHalf];
@@ -190,15 +190,14 @@
bool HothDBus::sendPayloadAndVerify(const std::string& hothId,
const std::string& payloadFile)
{
- std::cerr << hothId << ": Sending payload" << std::endl;
+ std::cerr << hothId << ": Sending payload" << '\n';
callMethod("SendPayload", hothId, payloadFile);
auto timeout = std::chrono::steady_clock::now() + 10min;
FirmwareUpdateStatus status = getSendPayloadStatus(hothId);
while (status == FirmwareUpdateStatus::InProgress)
{
- if (std::chrono::steady_clock::now() > timeout)
- {
- std::cerr << "Send payload timed out." << std::endl;
+ if (std::chrono::steady_clock::now() > timeout) {
+ std::cerr << "Send payload timed out." << '\n';
return false;
}
std::this_thread::sleep_for(1s);
@@ -206,7 +205,7 @@
}
if (status != FirmwareUpdateStatus::Done)
{
- std::cerr << "Send payload failed." << std::endl;
+ std::cerr << "Send payload failed." << '\n';
return false;
}
return verifyPayload(hothId);
@@ -215,15 +214,14 @@
bool HothDBus::sendStaticWPPayloadAndVerify(const std::string& hothId,
const std::string& payloadFile)
{
- std::cerr << hothId << ": Erasing & Sending Static & WP" << std::endl;
+ std::cerr << hothId << ": Erasing & Sending Static & WP" << '\n';
callMethod("EraseAndSendStaticWPPayload", hothId, payloadFile);
auto timeout = std::chrono::steady_clock::now() + 10min;
FirmwareUpdateStatus status = getSendPayloadStatus(hothId);
- while (status == FirmwareUpdateStatus::InProgress)
+ while (status == FirmwareUpdateStatus::InProgress)
{
- if (std::chrono::steady_clock::now() > timeout)
- {
- std::cerr << "Send payload timed out." << std::endl;
+ if (std::chrono::steady_clock::now() > timeout) {
+ std::cerr << "Send payload timed out." << '\n';
return false;
}
std::this_thread::sleep_for(1s);
@@ -231,7 +229,7 @@
}
if (status != FirmwareUpdateStatus::Done)
{
- std::cerr << "Send payload failed." << std::endl;
+ std::cerr << "Send payload failed." << '\n';
return false;
}
return verifyPayload(hothId);
@@ -247,7 +245,7 @@
const std::string name(err->name);
const std::string message(err->message);
std::cerr << "Activate payload error. " << name << ": " << message
- << std::endl;
+ << '\n';
return false;
}
return true;
@@ -263,7 +261,7 @@
const std::string name(err->name);
const std::string message(err->message);
std::cerr << "Activate payload error. " << name << ": " << message
- << std::endl;
+ << '\n';
return false;
}
return true;
@@ -276,9 +274,9 @@
int ret = system("ipmitool mc info");
if (ret)
{
- std::cerr << "ipmitool not working. Error code: " << ret << ". Aborted."
- << std::endl;
- return false;
+ std::cerr << "ipmitool not working. Error code: " << ret << ". Aborted."
+ << '\n';
+ return false;
}
sdbusplus::message::message msg = callMethod("Confirm", hothId);
if (msg.is_method_error())
@@ -287,7 +285,7 @@
const std::string name(err->name);
const std::string message(err->message);
std::cerr << "Confirm payload error. " << name << ": " << message
- << std::endl;
+ << '\n';
return false;
}
return true;
@@ -297,11 +295,11 @@
{
uint32_t toEraseSize;
callMethodAndRead("GetPayloadSize", hothId, toEraseSize);
- std::cerr << hothId << ": Erasing staging area" << std::endl;
+ std::cerr << hothId << ": Erasing staging area" << '\n';
if (toEraseSize == 0 || (toEraseSize % kSectorSizeBytes) != 0)
{
- std::cerr << "Invalid staging area size" << std::endl;
- return false;
+ std::cerr << "Invalid staging area size" << '\n';
+ return false;
}
uint32_t offset = 0;
while (toEraseSize >= kEraseChunkSizeBytes)
@@ -333,11 +331,11 @@
req.header.checksum = ~checksumNegated + 1;
if (option == EC_TARGET_RESET_OPTION_SET)
{
- std::cerr << hothId << ": Put target in reset" << std::endl;
+ std::cerr << hothId << ": Put target in reset" << '\n';
}
else
{
- std::cerr << hothId << ": Release target from reset" << std::endl;
+ std::cerr << hothId << ": Release target from reset" << '\n';
}
std::vector<uint8_t> bytes;
callMethodAndRead("SendHostCommand", hothId, bytes, spanReq);
@@ -346,12 +344,12 @@
if (response.struct_version != kStructVersion)
{
std::cerr << "Response structure version not supported: "
- << response.struct_version << std::endl;
+ << response.struct_version << '\n';
return false;
}
if (response.result != 0)
{
- std::cerr << "Failed to issue reset command" << std::endl;
+ std::cerr << "Failed to issue reset command" << '\n';
return false;
}
@@ -370,13 +368,13 @@
{
req.command = EC_CMD_BOARD_SPECIFIC_BASE |
EC_PRV_CMD_HOTH_SPS_PASSTHROUGH_ENABLE;
- std::cerr << hothId << ": Enable SPS passthrough" << std::endl;
+ std::cerr << hothId << ": Enable SPS passthrough" << '\n';
}
else
{
req.command = EC_CMD_BOARD_SPECIFIC_BASE |
EC_PRV_CMD_HOTH_SPS_PASSTHROUGH_DISABLE;
- std::cerr << hothId << ": Disable SPS passthrough" << std::endl;
+ std::cerr << hothId << ": Disable SPS passthrough" << '\n';
}
using google::hoth::internal::calculateChecksum;
auto spanReq = stdplus::raw::asSpan<uint8_t>(req);
@@ -388,12 +386,12 @@
if (response.struct_version != kStructVersion)
{
std::cerr << "Response structure version not supported: "
- << response.struct_version << std::endl;
+ << response.struct_version << '\n';
return false;
}
if (response.result != 0)
{
- std::cerr << "Failed to issue SPS command" << std::endl;
+ std::cerr << "Failed to issue SPS command" << '\n';
return false;
}
@@ -421,13 +419,12 @@
if (header.struct_version != kStructVersion)
{
std::cerr << "Response structure version not supported: "
- << header.struct_version << std::endl;
+ << header.struct_version << '\n';
return std::nullopt;
}
if (header.result != 0)
{
- std::cerr << "Failed to issue SPS get passthrough status command"
- << std::endl;
+ std::cerr << "Failed to issue SPS get passthrough status command" << '\n';
return std::nullopt;
}
@@ -457,7 +454,7 @@
using google::hoth::internal::calculateChecksum;
uint8_t checksumNegated = calculateChecksum(spanReq);
req.header.checksum = ~checksumNegated + 1;
- std::cerr << ": Expect confirm payload" << std::endl;
+ std::cerr << ": Expect confirm payload" << '\n';
std::vector<uint8_t> bytes;
callMethodAndRead("SendHostCommand", "", bytes, spanReq);
@@ -467,30 +464,30 @@
if (header.struct_version != kStructVersion)
{
std::cerr << "Response structure version not supported: "
- << header.struct_version << std::endl;
+ << header.struct_version << '\n';
return false;
}
if (header.result == google::hoth::internal::EC_RES_INVALID_PARAM ||
header.result == google::hoth::internal::EC_RES_ACCESS_DENIED)
{
std::cerr << "Ignoring expected payload confirm issue:" << header.result
- << std::endl;
+ << '\n';
return true;
}
if (header.result != google::hoth::internal::EC_RES_SUCCESS)
{
std::cerr << "Failed to enable payload confirm: " << header.result
- << header.result << std::endl;
+ << header.result << '\n';
return false;
}
auto confirmResponse =
stdplus::raw::copyFrom<payload_update_confirm_response>(response);
payload_update_confirm_timeout_values& val = confirmResponse.timeout_values;
using boost::endian::little_to_native;
- std::cerr << " min:" << little_to_native(val.min) << std::endl;
- std::cerr << " max:" << little_to_native(val.max) << std::endl;
- std::cerr << " default:" << little_to_native(val.default_val) << std::endl;
- std::cerr << " current:" << little_to_native(val.current) << std::endl;
+ std::cerr << " min:" << little_to_native(val.min) << '\n';
+ std::cerr << " max:" << little_to_native(val.max) << '\n';
+ std::cerr << " default:" << little_to_native(val.default_val) << '\n';
+ std::cerr << " current:" << little_to_native(val.current) << '\n';
return true;
}
diff --git a/tools/hoth_updater_cli.cpp b/tools/hoth_updater_cli.cpp
index 073b72c..d97830d 100644
--- a/tools/hoth_updater_cli.cpp
+++ b/tools/hoth_updater_cli.cpp
@@ -54,7 +54,7 @@
std::string getHothService(std::string_view hoth_id)
{
std::string service = "xyz.openbmc_project.Control.Hoth";
- if (hoth_id != "" && hoth_id != "bmc")
+ if (!hoth_id.empty() && hoth_id != "bmc")
{
service += ".";
service += hoth_id;
@@ -65,7 +65,7 @@
std::string getHothObject(std::string_view hoth_id)
{
std::string object = "/xyz/openbmc_project/Control/Hoth";
- if (hoth_id != "" && hoth_id != "bmc")
+ if (!hoth_id.empty() && hoth_id != "bmc")
{
object += "/";
object += hoth_id;
@@ -168,10 +168,10 @@
}
catch (const std::exception& ex)
{
- std::cout << "Exception caught: " << ex.what() << std::endl;
- std::cout << "Will retry in " << kRetryDelay.count() << " seconds"
- << std::endl;
- std::this_thread::sleep_for(kRetryDelay);
+ std::cout << "Exception caught: " << ex.what() << '\n';
+ std::cout << "Will retry in " << kRetryDelay.count() << " seconds"
+ << '\n';
+ std::this_thread::sleep_for(kRetryDelay);
}
}
throw std::runtime_error("Retry attempt limit exhausted.");
@@ -279,7 +279,9 @@
{
std::size_t delim_pos = s.find_first_of(delim, idx);
if (delim_pos == std::string::npos)
+ {
break;
+ }
ret.emplace_back(s.substr(idx, delim_pos - idx));
idx = delim_pos + 1;
}
diff --git a/tools/hoth_updater_cli.hpp b/tools/hoth_updater_cli.hpp
index 289134c..71aa5de 100644
--- a/tools/hoth_updater_cli.hpp
+++ b/tools/hoth_updater_cli.hpp
@@ -76,8 +76,9 @@
public:
virtual ~HothUpdaterCLI()
{}
- void updateFirmware(sdbusplus::bus::bus& bus, std::string_view hoth_id,
- std::span<const uint8_t> image);
+ static void updateFirmware(sdbusplus::bus::bus &bus,
+ std::string_view hoth_id,
+ std::span<const uint8_t> image);
void doUpdate(const Args& args);
void doActivationCheck(const Args& args);
void doFirmwareVersion(const Args& args);
diff --git a/tools/hoth_updater_main.cpp b/tools/hoth_updater_main.cpp
index 77bd22d..742c9d7 100644
--- a/tools/hoth_updater_main.cpp
+++ b/tools/hoth_updater_main.cpp
@@ -26,7 +26,7 @@
}
catch (std::exception& ex)
{
- std::cerr << ex.what() << std::endl;
+ std::cerr << ex.what() << '\n';
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
diff --git a/tools/payload_update_cli.cpp b/tools/payload_update_cli.cpp
index 1216bdb..6db71c6 100644
--- a/tools/payload_update_cli.cpp
+++ b/tools/payload_update_cli.cpp
@@ -41,23 +41,23 @@
}
catch (const std::exception& e)
{
- std::cerr << "Failed to get SPS passthrough status: "
- << e.what() << std::endl;
+ std::cerr << "Failed to get SPS passthrough status: " << e.what()
+ << '\n';
}
if (!res && args.reset == ResetMode::kIgnore)
{
std::cerr << "Ignoring failed SPS passthrough status command"
- << std::endl;
+ << '\n';
}
else if (res.value_or(true))
{
std::cerr << "Target did not report SPS passthrough disabled. "
- "Attempting reset"
- << std::endl;
+ "Attempting reset"
+ << '\n';
if (!dbus->setTargetResetOption(args.hothId,
EC_TARGET_RESET_OPTION_SET))
{
- std::cerr << "Failed to put target into reset" << std::endl;
+ std::cerr << "Failed to put target into reset" << '\n';
return false;
}
didReset = true;
@@ -65,7 +65,7 @@
}
if (args.spsPassthrough && !dbus->setSpsPassthrough(args.hothId, false))
{
- std::cerr << "Failed to disable SPS passthrough" << std::endl;
+ std::cerr << "Failed to disable SPS passthrough" << '\n';
return false;
}
}
@@ -75,7 +75,7 @@
args.payloadFilename))
{
std::cerr << "Failed to send payload (STATIC & WP) and verify"
- << std::endl;
+ << '\n';
return false;
}
}
@@ -83,24 +83,24 @@
{
if (!dbus->eraseStagingArea(args.hothId))
{
- std::cerr << "Failed to erase staging area" << std::endl;
+ std::cerr << "Failed to erase staging area" << '\n';
return false;
}
if (!dbus->sendPayloadAndVerify(args.hothId, args.payloadFilename))
{
- std::cerr << "Failed to send payload and verify" << std::endl;
+ std::cerr << "Failed to send payload and verify" << '\n';
return false;
}
}
if (!dbus->activatePayload(args.hothId))
{
- std::cerr << "Faild to activate payload" << std::endl;
+ std::cerr << "Faild to activate payload" << '\n';
return false;
}
if (args.hothId.empty() && !dbus->expectConfirmPayload())
{
- std::cerr << "Failed to enable payload confirm" << std::endl;
+ std::cerr << "Failed to enable payload confirm" << '\n';
return false;
}
@@ -108,7 +108,7 @@
{
if (args.spsPassthrough && !dbus->setSpsPassthrough(args.hothId, true))
{
- std::cerr << "Failed to enable SPS passthrough" << std::endl;
+ std::cerr << "Failed to enable SPS passthrough" << '\n';
return false;
}
if (didReset)
@@ -116,7 +116,7 @@
if (!dbus->setTargetResetOption(args.hothId,
EC_TARGET_RESET_OPTION_RELEASE))
{
- std::cerr << "Failed to release target from reset" << std::endl;
+ std::cerr << "Failed to release target from reset" << '\n';
return false;
}
}
@@ -140,8 +140,8 @@
dbus->getPayloadVersion(args.hothId, args.versionType);
if (version != std::nullopt)
{
- std::cout << *version << std::endl;
- return true;
+ std::cout << *version << '\n';
+ return true;
}
return false;
}
diff --git a/tools/payload_update_main.cpp b/tools/payload_update_main.cpp
index 679d7a9..2960a19 100644
--- a/tools/payload_update_main.cpp
+++ b/tools/payload_update_main.cpp
@@ -32,7 +32,7 @@
}
if (!cli.execute())
{
- std::cerr << argv[0] << ": Failed to execute command!" << std::endl;
+ std::cerr << argv[0] << ": Failed to execute command!" << '\n';
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
diff --git a/tools/test/fake_bus.cpp b/tools/test/fake_bus.cpp
index a4bf342..1c9463b 100644
--- a/tools/test/fake_bus.cpp
+++ b/tools/test/fake_bus.cpp
@@ -40,11 +40,11 @@
}
if (options.injectPayloadFail)
{
- std::cout << "Send payload failed." << std::endl;
+ std::cout << "Send payload failed." << '\n';
return false;
}
nextHalfVersion = options.newVersion;
- std::cout << "Payload sent." << std::endl;
+ std::cout << "Payload sent." << '\n';
return verifyPayload();
}
@@ -57,11 +57,11 @@
}
if (options.injectPayloadFail)
{
- std::cout << "Send payload failed." << std::endl;
+ std::cout << "Send payload failed." << '\n';
return false;
}
nextHalfVersion = options.newVersion;
- std::cout << "Payload sent." << std::endl;
+ std::cout << "Payload sent." << '\n';
return verifyPayload();
}
@@ -69,7 +69,7 @@
{
if (options.injectActivateFail)
{
- std::cout << "Activate payload failed." << std::endl;
+ std::cout << "Activate payload failed." << '\n';
return false;
}
return true;
@@ -79,7 +79,7 @@
{
if (options.injectDeactivateFail)
{
- std::cout << "Deactivate payload failed." << std::endl;
+ std::cout << "Deactivate payload failed." << '\n';
return false;
}
return true;
@@ -98,10 +98,10 @@
}
if (options.injectInvalidAreaSize)
{
- std::cout << "Invalid staging area size" << std::endl;
+ std::cout << "Invalid staging area size" << '\n';
return false;
}
- std::cout << "Erased." << std::endl;
+ std::cout << "Erased." << '\n';
return true;
}
@@ -129,12 +129,12 @@
{
if (options.injectVersionFail)
{
- std::cout << "Failed to get payload version" << std::endl;
+ std::cout << "Failed to get payload version" << '\n';
return {};
}
- std::cerr << "Active half: 0" << std::endl;
- std::cerr << "Version[0]: " << fake_bus::kActiveHalfVersion << std::endl;
- std::cerr << "Version[1]: " << nextHalfVersion << std::endl;
+ std::cerr << "Active half: 0" << '\n';
+ std::cerr << "Version[0]: " << fake_bus::kActiveHalfVersion << '\n';
+ std::cerr << "Version[1]: " << nextHalfVersion << '\n';
if (type == payload_update::VersionType::kActiveHalf)
{
return fake_bus::kActiveHalfVersion;
@@ -142,14 +142,12 @@
return nextHalfVersion;
}
-bool FakeBus::verifyPayload()
-{
- if (options.injectVerifyPayloadFail)
- {
- std::cout << "Verify payload failed." << std::endl;
- return false;
- }
- return true;
+bool FakeBus::verifyPayload() const {
+ if (options.injectVerifyPayloadFail) {
+ std::cout << "Verify payload failed." << '\n';
+ return false;
+ }
+ return true;
}
bool FakeBus::setSpsPassthrough(const std::string& /*hothId*/,
@@ -157,7 +155,7 @@
{
if (options.injectSpsPassthroughFail)
{
- std::cout << "Failed to set SPS passthrough mode" << std::endl;
+ std::cout << "Failed to set SPS passthrough mode" << '\n';
return false;
}
return true;
diff --git a/tools/test/fake_bus.hpp b/tools/test/fake_bus.hpp
index d5b084e..885bd24 100644
--- a/tools/test/fake_bus.hpp
+++ b/tools/test/fake_bus.hpp
@@ -76,7 +76,7 @@
}
private:
- bool verifyPayload();
+ bool verifyPayload() const;
fake_bus::Options options;
bool resetHeld = false;
std::string activeHalfVersion = fake_bus::kActiveHalfVersion;
diff --git a/tools/test/hoth_updater_cli_test.cpp b/tools/test/hoth_updater_cli_test.cpp
index 5de8c14..253f8ca 100644
--- a/tools/test/hoth_updater_cli_test.cpp
+++ b/tools/test/hoth_updater_cli_test.cpp
@@ -21,8 +21,6 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-namespace fs = ::std::filesystem;
-
namespace google::hoth::tools
{
namespace
diff --git a/tools/test/payload_update_cli_test.cpp b/tools/test/payload_update_cli_test.cpp
index 97d10eb..79982cf 100644
--- a/tools/test/payload_update_cli_test.cpp
+++ b/tools/test/payload_update_cli_test.cpp
@@ -31,7 +31,7 @@
options.resetRequired = true;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -50,7 +50,7 @@
options.resetRequired = true;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -70,7 +70,7 @@
options.resetRequired = true;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -89,7 +89,7 @@
fake_bus::Options options;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -110,7 +110,7 @@
options.injectInvalidAreaSize = true;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -131,7 +131,7 @@
options.injectPayloadFail = true;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -151,8 +151,8 @@
options.newVersion = "3.0.0.0";
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
- auto localBus = bus.get();
+ auto *localParser = parser.get();
+ auto *localBus = bus.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
@@ -179,7 +179,7 @@
options.injectSpsPassthroughFail = true;
auto parser = std::make_unique<FakeParser>();
auto bus = std::make_unique<FakeBus>(options);
- auto localParser = parser.get();
+ auto *localParser = parser.get();
auto cli =
std::make_unique<PayloadUpdateCLI>(std::move(parser), std::move(bus));
Args args;
diff --git a/usb_reset/main.cpp b/usb_reset/main.cpp
index a9bcd68..e14129d 100644
--- a/usb_reset/main.cpp
+++ b/usb_reset/main.cpp
@@ -61,16 +61,14 @@
void resetUSBHub(int i2cBus, int i2cAddr)
{
- std::cerr << "resetting i2c device: " << i2cBus << ", " << i2cAddr
- << std::endl;
+ std::cerr << "resetting i2c device: " << i2cBus << ", " << i2cAddr << '\n';
std::filesystem::path devpath = "/dev/i2c-" + std::to_string(i2cBus);
int fd = ::open(devpath.c_str(), std::ios_base::in | std::ios_base::out);
- if (fd < 0)
- {
+ if (fd < 0) {
std::cerr << "fail to open i2c device: " << i2cBus << ", " << i2cAddr
- << std::endl;
+ << '\n';
return;
}
@@ -91,7 +89,7 @@
{
if (i > 0)
{
- std::cerr << "retry the reset command" << std::endl;
+ std::cerr << "retry the reset command" << '\n';
}
res = i2c_smbus_write_byte_data(fd, 0x01, 0x00);
if (res < 0)
@@ -134,42 +132,42 @@
::close(fd);
}
-void handler(std::shared_ptr<sdbusplus::asio::connection> bus)
+void handler(const std::shared_ptr<sdbusplus::asio::connection> &bus)
{
auto getter = std::make_shared<GetSensorConfiguration>(
- bus, [&bus](const ManagedObjectType& configurations) {
- if (!readingStateGood(PowerState::on))
- {
- return;
- }
+ bus, [](const ManagedObjectType &configurations)
+ {
+ if (!readingStateGood(PowerState::on))
+ {
+ return;
+ }
- for (const auto& [path, configData] : configurations)
+ for (const auto &[path, configData] : configurations)
+ {
+ auto find = configData.find(configInterfaceName(daemonType));
+ if (find == configData.end())
{
- auto find = configData.find(configInterfaceName(daemonType));
- if (find == configData.end())
- {
- continue;
- }
- const auto& config = find->second;
- auto i2cBus = extractBusNumber(path, config);
- auto i2cAddr = extractAddress(path, config);
-
- if (!i2cBus || !i2cAddr)
- {
- std::cerr << "failed to find i2c bus info: continue"
- << std::endl;
- continue;
- }
- auto initiated = initSet.find({*i2cBus, *i2cAddr});
- if (initiated != initSet.end())
- {
- continue;
- }
- resetUSBHub(*i2cBus, *i2cAddr);
- initSet.emplace(*i2cBus, *i2cAddr);
+ continue;
}
- });
+ const auto &config = find->second;
+ auto i2cBus = extractBusNumber(path, config);
+ auto i2cAddr = extractAddress(path, config);
+
+ if (!i2cBus || !i2cAddr)
+ {
+ std::cerr << "failed to find i2c bus info: continue" << '\n';
+ continue;
+ }
+ auto initiated = initSet.find({*i2cBus, *i2cAddr});
+ if (initiated != initSet.end())
+ {
+ continue;
+ }
+ resetUSBHub(*i2cBus, *i2cAddr);
+ initSet.emplace(*i2cBus, *i2cAddr);
+ }
+ });
getter->getConfiguration(std::vector<std::string>{daemonType});
}
diff --git a/usb_reset/utils.cpp b/usb_reset/utils.cpp
index f25c7d9..28efec6 100644
--- a/usb_reset/utils.cpp
+++ b/usb_reset/utils.cpp
@@ -31,8 +31,6 @@
#include <variant>
#include <vector>
-namespace fs = std::filesystem;
-
static bool powerStatusOn = false;
static bool biosHasPost = false;
static bool chassisStatusOn = false;
@@ -43,7 +41,7 @@
std::list<PowerCallbackEntry::callback_t> PowerCallbackEntry::list;
-bool isPowerOn(void)
+bool isPowerOn()
{
if (!powerMatch)
{
@@ -52,7 +50,7 @@
return powerStatusOn;
}
-bool hasBiosPost(void)
+bool hasBiosPost()
{
if (!postMatch)
{
@@ -61,8 +59,7 @@
return biosHasPost;
}
-bool isChassisOn(void)
-{
+bool isChassisOn() {
if (!chassisMatch)
{
throw std::runtime_error("Chassis On Match Not Created");
diff --git a/usb_util.cpp b/usb_util.cpp
index 0299234..0c435c9 100644
--- a/usb_util.cpp
+++ b/usb_util.cpp
@@ -33,7 +33,7 @@
Int ret;
auto term = str.substr(0, str.find(separator));
- auto end = term.data() + term.size();
+ const auto *end = term.data() + term.size();
auto res = std::from_chars(term.data(), end, ret);
if (static_cast<bool>(res.ec) || res.ptr != end)
{