[clang-tidy] Fix clang-tidy errors
Fix the following clang-tidy errors:
readability-avoid-const-params-in-decls
readability-static-accessed-through-instance
modernize-avoid-bind
cert-msc30-c
cert-msc50-cpp
cert-err34-c
performance-faster-string-find
Google-Bug-Id: 375054631
Change-Id: Ie1cff74d9e887e0f1df20288623639e437d50ac8
Signed-off-by: David Tang <davtang@google.com>
diff --git a/firmware_spi_updater.hpp b/firmware_spi_updater.hpp
index 107cf70..6a0f77c 100644
--- a/firmware_spi_updater.hpp
+++ b/firmware_spi_updater.hpp
@@ -160,7 +160,7 @@
* @param[in] enable - The desired SPS passthough mode.
* @return indicates if the passthrough mode is successfully set.
*/
- bool setSpsPassthrough(const bool enable);
+ bool setSpsPassthrough(bool enable);
/** @brief SPI requires erase enough space before write
*
diff --git a/host_command.hpp b/host_command.hpp
index bea42a4..2cec09a 100644
--- a/host_command.hpp
+++ b/host_command.hpp
@@ -51,9 +51,9 @@
explicit HostCommandImpl(MessageIntf* msg, boost::asio::io_context* ioc,
LogCollectorUtil* logCollectorUtil,
- const std::string name, size_t max_retries = 0,
+ std::string name, size_t max_retries = 0,
bool allowLegacyVerify = true,
- const uint32_t uartChannelId = 0);
+ uint32_t uartChannelId = 0);
std::vector<uint8_t>
sendCommand(const std::vector<uint8_t>& command) override;
diff --git a/hoth_state.cpp b/hoth_state.cpp
index 40596b0..ca18830 100644
--- a/hoth_state.cpp
+++ b/hoth_state.cpp
@@ -128,6 +128,7 @@
e.what());
}
timer.expires_after(std::chrono::seconds(kTimerIntervalSeconds));
+ // NOLINTNEXTLINE(modernize-avoid-bind)
timer.async_wait(std::bind(&HothState::timerUpdateMetrics, this));
}
diff --git a/log_collector_util.hpp b/log_collector_util.hpp
index 31aee15..c705561 100644
--- a/log_collector_util.hpp
+++ b/log_collector_util.hpp
@@ -138,8 +138,8 @@
* @param[in] readOffset - Offset from where the buffer is to be read
*/
std::vector<uint8_t>
- generateCollectUartLogsRequest(const uint32_t channelId,
- const uint32_t readOffset) const;
+ generateCollectUartLogsRequest(uint32_t channelId,
+ uint32_t readOffset) const;
/**
* @brief Publishes the snapshot based on publish type
diff --git a/main.cpp b/main.cpp
index 254f613..eb1ed6e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -108,10 +108,10 @@
{
/* Match the hoth name from the objPath to the hoth name
* obtained from Configuration.Hoth interface */
- if (objPath.substr(objPath.find_last_of("/") + 1) ==
- assetObj.substr(assetObj.find_last_of("/") + 1))
+ if (objPath.substr(objPath.find_last_of('/') + 1) ==
+ assetObj.substr(assetObj.find_last_of('/') + 1))
{
- return objPath.substr(0, objPath.find_last_of("/"));
+ return objPath.substr(0, objPath.find_last_of('/'));
}
}
}
@@ -172,7 +172,7 @@
name = optarg;
break;
case 'a':
- addressSize = std::atoi(optarg);
+ addressSize = std::stoi(optarg);
break;
case 'r':
targetReset = parseReset(optarg);
diff --git a/payload_update.hpp b/payload_update.hpp
index c1e7714..f7a5f2b 100644
--- a/payload_update.hpp
+++ b/payload_update.hpp
@@ -74,7 +74,7 @@
{}
void initiate() const override;
- void erase(const uint32_t offset, const uint32_t size) const override;
+ void erase(uint32_t offset, uint32_t size) const override;
void eraseAndSendStaticWP(const std::string& path) const override;
void read(uint32_t offset, std::span<uint8_t> data) const override;
void verify() const override;
diff --git a/payload_update_interface.hpp b/payload_update_interface.hpp
index 8bc23e4..e537d6d 100644
--- a/payload_update_interface.hpp
+++ b/payload_update_interface.hpp
@@ -53,7 +53,7 @@
virtual ~PayloadUpdate() = default;
virtual void initiate() const = 0;
- virtual void erase(const uint32_t offset, const uint32_t size) const = 0;
+ virtual void erase(uint32_t offset, uint32_t size) const = 0;
virtual void read(uint32_t offset, std::span<uint8_t> data) const = 0;
virtual void verify() const = 0;
virtual payload_update_status getStatus() const = 0;
diff --git a/test/hoth_unittest.cpp b/test/hoth_unittest.cpp
index 36be301..7ef52d4 100644
--- a/test/hoth_unittest.cpp
+++ b/test/hoth_unittest.cpp
@@ -158,7 +158,7 @@
hoth->updateFirmware(mockFirmware);
// Ensure our flashCopy thread has exited
- waitWhileInProgress(std::bind(&Hoth::getFirmwareUpdateStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getFirmwareUpdateStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -173,7 +173,7 @@
hoth->updateFirmware(mockFirmware);
// Ensure our flashCopy thread has exited
- waitWhileInProgress(std::bind(&Hoth::getFirmwareUpdateStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getFirmwareUpdateStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
}
@@ -187,7 +187,7 @@
hoth->updateFirmware(mockFirmware);
// Ensure our flashCopy thread has exited
- waitWhileInProgress(std::bind(&Hoth::getFirmwareUpdateStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getFirmwareUpdateStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
EXPECT_EQ(hoth->getFirmwareUpdateStatus(),
@@ -204,7 +204,7 @@
hoth->updateFirmware(mockFirmware);
// Ensure our flashCopy thread has exited
- waitWhileInProgress(std::bind(&Hoth::getFirmwareUpdateStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getFirmwareUpdateStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
EXPECT_EQ(hoth->getFirmwareUpdateStatus(),
@@ -320,7 +320,7 @@
hoth->initiatePayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getInitiatePayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getInitiatePayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -336,13 +336,13 @@
hoth->sendPayload(examplePath);
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
hoth->initiatePayload();
loopCount = 0;
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getInitiatePayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getInitiatePayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -356,7 +356,7 @@
hoth->initiatePayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getInitiatePayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getInitiatePayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
}
@@ -369,7 +369,7 @@
hoth->initiatePayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getInitiatePayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getInitiatePayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
EXPECT_EQ(hoth->getInitiatePayloadStatus(),
@@ -385,7 +385,7 @@
hoth->initiatePayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getInitiatePayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getInitiatePayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
EXPECT_EQ(hoth->getInitiatePayloadStatus(),
@@ -476,7 +476,7 @@
hoth->sendPayload(examplePath);
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -492,12 +492,12 @@
hoth->initiatePayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getInitiatePayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getInitiatePayloadStatus(); });
hoth->sendPayload(examplePath);
loopCount = 0;
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -511,7 +511,7 @@
hoth->sendPayload(examplePath);
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
}
@@ -524,7 +524,7 @@
hoth->sendPayload(examplePath);
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
EXPECT_EQ(hoth->getSendPayloadStatus(), Hoth::FirmwareUpdateStatus::Done);
@@ -539,7 +539,7 @@
hoth->sendPayload(examplePath);
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
EXPECT_EQ(hoth->getSendPayloadStatus(), Hoth::FirmwareUpdateStatus::Error);
@@ -706,7 +706,7 @@
hoth->verifyPayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getVerifyPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getVerifyPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -722,13 +722,13 @@
hoth->sendPayload(examplePath);
// Ensure our send thread has exited
- waitWhileInProgress(std::bind(&Hoth::getSendPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getSendPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
hoth->verifyPayload();
loopCount = 0;
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getVerifyPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getVerifyPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
}
@@ -742,7 +742,7 @@
hoth->verifyPayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getVerifyPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getVerifyPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
}
@@ -755,7 +755,7 @@
hoth->verifyPayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getVerifyPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getVerifyPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Done);
EXPECT_EQ(hoth->getVerifyPayloadStatus(), Hoth::FirmwareUpdateStatus::Done);
@@ -770,7 +770,7 @@
hoth->verifyPayload();
// Ensure our initiate thread has exited
- waitWhileInProgress(std::bind(&Hoth::getVerifyPayloadStatus, hoth.get()));
+ waitWhileInProgress([thread = hoth.get()] { return thread->getVerifyPayloadStatus(); });
EXPECT_EQ(result, Hoth::FirmwareUpdateStatus::Error);
EXPECT_EQ(hoth->getVerifyPayloadStatus(),
diff --git a/test/message_util_unittest.cpp b/test/message_util_unittest.cpp
index 940653e..9a29694 100644
--- a/test/message_util_unittest.cpp
+++ b/test/message_util_unittest.cpp
@@ -227,7 +227,9 @@
{
ASSERT_THROW(populateReqHeader(0, 0, nullptr, 0, nullptr), CommandFailure);
+ // NOLINTNEXTLINE(cert-msc30-c, cert-msc50-cpp)
uint16_t command = std::rand() % UINT16_MAX;
+ // NOLINTNEXTLINE(cert-msc30-c, cert-msc50-cpp)
uint8_t command_version = std::rand() % UINT8_MAX;
constexpr size_t kRequestSize = 15;
diff --git a/test/mtd_util_unittest.cpp b/test/mtd_util_unittest.cpp
index 6cbbb40..623fd85 100644
--- a/test/mtd_util_unittest.cpp
+++ b/test/mtd_util_unittest.cpp
@@ -344,7 +344,7 @@
TEST_P(FlashCopyFakeTest, fakeTest)
{
FakeMtd file(GetParam().first);
- std::vector<uint8_t> data(file.deviceSize);
+ std::vector<uint8_t> data(FakeMtd::deviceSize);
std::mt19937 gen(0);
std::generate(data.begin(), data.end(), gen);
diff --git a/tools/dbus_interface.hpp b/tools/dbus_interface.hpp
index 2ae8d19..7856e86 100644
--- a/tools/dbus_interface.hpp
+++ b/tools/dbus_interface.hpp
@@ -44,7 +44,7 @@
virtual bool setTargetResetOption(const std::string& hothId,
ec_target_reset_option option) = 0;
virtual bool setSpsPassthrough(const std::string& hothId,
- const bool enable) = 0;
+ bool enable) = 0;
virtual std::optional<bool>
getSpsPassthrough(const std::string& hothId) = 0;
virtual bool expectConfirmPayload() = 0;
diff --git a/tools/hoth_dbus.hpp b/tools/hoth_dbus.hpp
index bb297f6..2ba89c1 100644
--- a/tools/hoth_dbus.hpp
+++ b/tools/hoth_dbus.hpp
@@ -77,7 +77,7 @@
bool setTargetResetOption(const std::string& hothId,
ec_target_reset_option option) override;
bool setSpsPassthrough(const std::string& hothId,
- const bool enable) override;
+ bool enable) override;
std::optional<bool> getSpsPassthrough(const std::string& hothId) override;
bool expectConfirmPayload() override;
diff --git a/tools/hoth_updater_cli.cpp b/tools/hoth_updater_cli.cpp
index 07098c1..073b72c 100644
--- a/tools/hoth_updater_cli.cpp
+++ b/tools/hoth_updater_cli.cpp
@@ -331,7 +331,7 @@
// Strip out the hoth family in the version string, because it's not
// guaranteed to be returned completely.
std::string_view version_stripped(response.version.version_string_rw);
- size_t split_pos = version_stripped.find_first_of("/");
+ size_t split_pos = version_stripped.find_first_of('/');
if (split_pos != std::string::npos)
{
version_stripped = version_stripped.substr(0, split_pos);
diff --git a/tools/hoth_updater_cli.hpp b/tools/hoth_updater_cli.hpp
index 64318b3..289134c 100644
--- a/tools/hoth_updater_cli.hpp
+++ b/tools/hoth_updater_cli.hpp
@@ -77,12 +77,12 @@
virtual ~HothUpdaterCLI()
{}
void updateFirmware(sdbusplus::bus::bus& bus, std::string_view hoth_id,
- const std::span<const uint8_t> image);
+ std::span<const uint8_t> image);
void doUpdate(const Args& args);
void doActivationCheck(const Args& args);
void doFirmwareVersion(const Args& args);
virtual void spiWrite(sdbusplus::bus::bus& bus, std::string_view hoth_id,
- const std::span<const uint8_t> image,
+ std::span<const uint8_t> image,
std::optional<uint32_t> address);
virtual std::vector<uint8_t>
readFileIntoByteArray(std::string_view filename);
@@ -98,6 +98,6 @@
void setupCLIApp(CLI::App& app, HothUpdaterCLI& cli, Args& args);
-std::vector<std::string> splitString(const std::string& s, const char delim);
+std::vector<std::string> splitString(const std::string& s, char delim);
} // namespace google::hoth::tools
diff --git a/tools/test/fake_bus.hpp b/tools/test/fake_bus.hpp
index 5063767..d5b084e 100644
--- a/tools/test/fake_bus.hpp
+++ b/tools/test/fake_bus.hpp
@@ -68,7 +68,7 @@
bool setTargetResetOption(const std::string& hothId,
ec_target_reset_option option) override;
bool setSpsPassthrough(const std::string& hothId,
- const bool enable) override;
+ bool enable) override;
std::optional<bool> getSpsPassthrough(const std::string& hothId) override;
bool expectConfirmPayload()
{
diff --git a/usb_reset/main.cpp b/usb_reset/main.cpp
index 45f9af6..a9bcd68 100644
--- a/usb_reset/main.cpp
+++ b/usb_reset/main.cpp
@@ -218,6 +218,6 @@
handler(systemBus);
});
});
- boost::asio::post(io, std::bind(handler, systemBus));
+ boost::asio::post(io, [systemBus] { handler(systemBus); });
io.run();
}