PEL: Fix more cppcheck warnings
This is the second of two commits to fix most of the cppcheck warnings
in the PEL code. It doesn't fix all of them because some are false
positives and some are just suggestions.
It's broken up into two commits to make them smaller.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Id9f462386df85fd25d09529d6b410115ff4ccba8
diff --git a/test/openpower-pels/fru_identity_test.cpp b/test/openpower-pels/fru_identity_test.cpp
index 28a8e98..24ac5fe 100644
--- a/test/openpower-pels/fru_identity_test.cpp
+++ b/test/openpower-pels/fru_identity_test.cpp
@@ -89,7 +89,7 @@
EXPECT_THROW(FRUIdentity fru{stream}, std::out_of_range);
}
-void testHWCallout(const std::string& pn, const std::string ccin,
+void testHWCallout(const std::string& pn, const std::string& ccin,
const std::string& sn, const std::string& expectedPN,
const std::string& expectedCCIN,
const std::string& expectedSN)
diff --git a/test/openpower-pels/mtms_test.cpp b/test/openpower-pels/mtms_test.cpp
index b9c0929..b0f0130 100644
--- a/test/openpower-pels/mtms_test.cpp
+++ b/test/openpower-pels/mtms_test.cpp
@@ -32,12 +32,12 @@
MTMS mtms{tm, sn};
- std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
+ const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
EXPECT_EQ("TTTT-MMM", mtms.machineTypeAndModel());
- std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
- '7', '8', '9', 'A', 'B', 'C'};
+ const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
+ '7', '8', '9', 'A', 'B', 'C'};
EXPECT_EQ(s, mtms.machineSerialNumberRaw());
EXPECT_EQ("123456789ABC", mtms.machineSerialNumber());
}
@@ -49,11 +49,11 @@
MTMS mtms{tm, sn};
- std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
+ const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', '-', 'M', 'M', 'M'};
EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
- std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
- '7', '8', '9', 'A', 'B', 'C'};
+ const std::array<uint8_t, 12> s{'1', '2', '3', '4', '5', '6',
+ '7', '8', '9', 'A', 'B', 'C'};
EXPECT_EQ(s, mtms.machineSerialNumberRaw());
}
@@ -64,11 +64,12 @@
MTMS mtms{tm, sn};
- std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0};
+ const std::array<uint8_t, 8> t{'T', 'T', 'T', 'T', 0, 0, 0, 0};
EXPECT_EQ(t, mtms.machineTypeAndModelRaw());
EXPECT_EQ("TTTT", mtms.machineTypeAndModel());
- std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0, 0, 0, 0, 0, 0, 0};
+ const std::array<uint8_t, 12> s{'1', '2', '3', '4', 0, 0,
+ 0, 0, 0, 0, 0, 0};
EXPECT_EQ(s, mtms.machineSerialNumberRaw());
EXPECT_EQ("1234", mtms.machineSerialNumber());
}
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index fc77a5e..00c3fd6 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -721,7 +721,7 @@
}
catch (
const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
- e)
+ ex)
{
ADD_FAILURE() << "PELs should have all been found";
}
diff --git a/test/openpower-pels/pel_test.cpp b/test/openpower-pels/pel_test.cpp
index 352e0ed..d5cd373 100644
--- a/test/openpower-pels/pel_test.cpp
+++ b/test/openpower-pels/pel_test.cpp
@@ -259,14 +259,12 @@
EXPECT_EQ(pel.size(), 16384);
// Make sure that there are still 2 UD sections.
- size_t udCount = 0;
- for (const auto& section : pel.optionalSections())
- {
- if (section->header().id == static_cast<uint16_t>(SectionID::userData))
- {
- udCount++;
- }
- }
+ const auto& optSections = pel.optionalSections();
+ auto udCount = std::count_if(
+ optSections.begin(), optSections.end(), [](const auto& section) {
+ return section->header().id ==
+ static_cast<uint16_t>(SectionID::userData);
+ });
EXPECT_EQ(udCount, 2); // AD section and sysInfo section
}
diff --git a/test/openpower-pels/repository_test.cpp b/test/openpower-pels/repository_test.cpp
index 73a24d8..7502dfa 100644
--- a/test/openpower-pels/repository_test.cpp
+++ b/test/openpower-pels/repository_test.cpp
@@ -659,8 +659,8 @@
// there so we can check they are removed after the prune.
for (uint32_t i = 1; i < 5; i++)
{
- Repository::LogID id{Repository::LogID::Pel{i}};
- EXPECT_TRUE(repo.getPELAttributes(id));
+ Repository::LogID logID{Repository::LogID::Pel{i}};
+ EXPECT_TRUE(repo.getPELAttributes(logID));
}
// Prune down to 15%/30%/15%/30% = 90% total
@@ -677,8 +677,8 @@
// each type, were removed.
for (uint32_t i = 1; i < 5; i++)
{
- Repository::LogID id{Repository::LogID::Pel{i}};
- EXPECT_FALSE(repo.getPELAttributes(id));
+ Repository::LogID logID{Repository::LogID::Pel{i}};
+ EXPECT_FALSE(repo.getPELAttributes(logID));
// Make sure the corresponding OpenBMC event log ID which is
// 500 + the PEL ID is in the list.
@@ -710,8 +710,8 @@
// get pruned below we'll know they were removed.
for (uint32_t i = 1; i <= 20; i++)
{
- Repository::LogID id{Repository::LogID::Pel{i}};
- EXPECT_TRUE(repo.getPELAttributes(id));
+ Repository::LogID logID{Repository::LogID::Pel{i}};
+ EXPECT_TRUE(repo.getPELAttributes(logID));
}
auto IDs = repo.prune(id);
@@ -728,8 +728,8 @@
// Can no longer find the oldest 20 PELs.
for (uint32_t i = 1; i <= 20; i++)
{
- Repository::LogID id{Repository::LogID::Pel{i}};
- EXPECT_FALSE(repo.getPELAttributes(id));
+ Repository::LogID logID{Repository::LogID::Pel{i}};
+ EXPECT_FALSE(repo.getPELAttributes(logID));
EXPECT_TRUE(std::find(IDs.begin(), IDs.end(), 500 + i) != IDs.end());
}
}
@@ -760,11 +760,11 @@
auto idToDelete = pel->obmcLogID();
repo.add(pel);
- if (0 == i)
+ if (1 == i)
{
repo.setPELHMCTransState(pel->id(), TransmissionState::acked);
}
- else if (1 == i)
+ else if (2 == i)
{
repo.setPELHostTransState(pel->id(), TransmissionState::acked);
}