[clang-tidy] Fix clang-tidy errors from g3/gsys config
Fix the following clang-tidy errors:
performance-enum-size
modernize-redundant-void-arg
google-explicit-constructor
readability-convert-member-functions-to-static
llvm-qualified-auto
google-build-using-namespace
Google-Bug-Id: 380138111
Change-Id: Id79c99ef6cfc99697eb7d23c8893d78444388b44
Signed-off-by: David Tang <davtang@google.com>
diff --git a/pldm-oem-google.h b/pldm-oem-google.h
index 99fc6b6..e31c842 100644
--- a/pldm-oem-google.h
+++ b/pldm-oem-google.h
@@ -24,6 +24,8 @@
#include <stddef.h>
#include <stdint.h>
+#include <cstdint>
+
/* PLDM OEM event */
#define PLDM_EVENT_CLASS_OEM_GOOGLE (0xF6)
@@ -42,21 +44,25 @@
* following enum, it will get kept forever. This means the following enum value
* definition will only be appended, no change, no deletion.
*/
-enum pldm_event_oem_google_id
+enum pldm_event_oem_google_id : std::uint16_t
{
PLDM_EVENT_OEM_GOOGLE_ID_UNDEFINED = 0,
PLDM_EVENT_OEM_GOOGLE_SOC_RESET_ME = 1,
+
+ _RESERVED_PLDM_EVENT_OEM_ID = 0xFFFF,
};
/*
* Supported SOC reset type
* SOC_RESET_ME_AUTO: BMC make the choice of best reset avaiable reset type.
*/
-enum pldm_event_oem_google_soc_reset_me_type
+enum pldm_event_oem_google_soc_reset_me_type : std::uint16_t
{
SOC_RESET_ME_AUTO = 0,
SOC_RESET_ME_COLD = 1,
SOC_RESET_ME_WARM = 2,
+
+ _RESERVED_SOC_RESET_ME_TYPE = 0xFFFF,
};
/*
diff --git a/src/soc-reset-me.cpp b/src/soc-reset-me.cpp
index 25e0964..dc40705 100644
--- a/src/soc-reset-me.cpp
+++ b/src/soc-reset-me.cpp
@@ -66,7 +66,7 @@
.intf = "xyz.openbmc_project.State.Host",
.prop = "RequestedHostTransition",
};
-const ResetDBusParams* cn1DbusParams(void)
+const ResetDBusParams* cn1DbusParams()
{
return &socResetDbusParamsCn1;
}
@@ -77,7 +77,7 @@
.intf = "xyz.openbmc_project.State.Host",
.prop = "RequestedHostTransition",
};
-const ResetDBusParams* cn2DbusParams(void)
+const ResetDBusParams* cn2DbusParams()
{
return &socResetDbusParamsCn2;
}
diff --git a/src/soc-reset-me.hpp b/src/soc-reset-me.hpp
index 2e1d64f..43fca30 100644
--- a/src/soc-reset-me.hpp
+++ b/src/soc-reset-me.hpp
@@ -29,7 +29,7 @@
namespace soc_reset_me
{
// Define the SoC Id
-enum class SocId : int
+enum class SocId : std::uint8_t
{
cnDefault = 0,
cn1 = 1,
@@ -43,11 +43,11 @@
{
public:
static bool setWithPldmdInstanceParam(const std::string& instance);
- static SocId value(void)
+ static SocId value()
{
return socId.value_or(SocId::cnDefault);
}
- static bool isDefault(void)
+ static bool isDefault()
{
return !socId.has_value();
}
@@ -74,8 +74,8 @@
const char* prop;
};
-const ResetDBusParams* cn1DbusParams(void);
-const ResetDBusParams* cn2DbusParams(void);
+const ResetDBusParams* cn1DbusParams();
+const ResetDBusParams* cn2DbusParams();
class SocResetMeHandler
{
public:
@@ -107,7 +107,7 @@
class InvalidSoCIdException : public std::exception
{
public:
- InvalidSoCIdException(int invalidId) :
+ explicit InvalidSoCIdException(int invalidId) :
errorMessage("SoC ID " + std::to_string(invalidId) + " is invalid")
{}
const char* what() const noexcept override
diff --git a/test/test-soc-reset-me.cpp b/test/test-soc-reset-me.cpp
index e831af8..c5e0fef 100644
--- a/test/test-soc-reset-me.cpp
+++ b/test/test-soc-reset-me.cpp
@@ -92,20 +92,21 @@
"xyz.openbmc_project.State.Host.Transition.Reboot";
static constexpr auto dbusPropIntf = "org.freedesktop.DBus.Properties";
::testing::NiceMock<sdbusplus::SdBusMock> mock;
- auto dbusParams(SocResetMeHandler& h)
+ static auto dbusParams(SocResetMeHandler& h)
{
return h.dbusParams;
}
- void resetSoC(SocResetMeHandler& h)
+ static void resetSoC(SocResetMeHandler& h)
{
h.resetSoC(SOC_RESET_ME_AUTO);
}
- auto quicentEnd(SocResetMeHandler& h)
+ static auto quicentEnd(SocResetMeHandler& h)
{
return h.quiescentEnd;
}
- void mockQuiecentEnd(SocResetMeHandler& h,
- decltype(SocResetMeHandler::quiescentEnd) mocktime)
+ static void
+ mockQuiecentEnd(SocResetMeHandler& h,
+ decltype(SocResetMeHandler::quiescentEnd) mocktime)
{
h.quiescentEnd = mocktime;
}
@@ -145,7 +146,7 @@
memset(&data, 0, sizeof(data));
memcpy(data + sizeof(struct pldm_event_oem_google_soc_reset_me),
resetReason.data(), resetReason.length());
- auto msg =
+ auto* msg =
reinterpret_cast<struct pldm_event_oem_google_soc_reset_me*>(data);
msg->descLen = resetReason.length();
msg->resetQuiesent = quiescentPeriod;
@@ -196,9 +197,10 @@
// handleTime + requestQuiesent
TEST_F(SocResetMeHandlerTest, HandleSocResetMeFirstTime)
{
- using namespace std::chrono;
- auto reason = "HandleSocResetMeFirstTime";
- auto msg = resetMeRequestMsg(0, reason);
+ using std::chrono::seconds;
+ using std::chrono::_V2::steady_clock;
+ const auto* reason = "HandleSocResetMeFirstTime";
+ auto* msg = resetMeRequestMsg(0, reason);
MockSocResetMeHandler mockHandler(SocId::cn1,
sdbusplus::get_mocked_new(&mock));
@@ -222,9 +224,10 @@
// reset SoC and update quiecentEnd to handletTime + requestQuiesent
TEST_F(SocResetMeHandlerTest, HandleSocResetMeOutQuiesent)
{
- using namespace std::chrono;
- auto reason = "HandleSocResetMeOutQuiesent";
- auto msg = resetMeRequestMsg(10, reason);
+ using std::chrono::seconds;
+ using std::chrono::_V2::steady_clock;
+ const auto* reason = "HandleSocResetMeOutQuiesent";
+ auto* msg = resetMeRequestMsg(10, reason);
MockSocResetMeHandler mockHandler(SocId::cn1,
sdbusplus::get_mocked_new(&mock));
auto mocktime = steady_clock::now() - seconds(30);
@@ -248,9 +251,10 @@
// ingore this request and w/o resetting SoC nor updating quiecentEnd
TEST_F(SocResetMeHandlerTest, HandleSocResetMeInQuiesent)
{
- using namespace std::chrono;
- auto reason = "HandleSocResetMeInQuiesent";
- auto msg = resetMeRequestMsg(10, reason);
+ using std::chrono::seconds;
+ using std::chrono::_V2::steady_clock;
+ const auto* reason = "HandleSocResetMeInQuiesent";
+ auto* msg = resetMeRequestMsg(10, reason);
MockSocResetMeHandler mockHandler(SocId::cn1,
sdbusplus::get_mocked_new(&mock));