Check in a clang-tidy
This should've been done when we first created the repo, but better late
than never.
Signed-off-by: Ed Tanous <edtanous@google.com>
Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: I68da1d13167ec94f9d008dea307c9f23a991d42c
diff --git a/src/test/erase/crypto_test.cpp b/src/test/erase/crypto_test.cpp
index 917b23b..9eefa9d 100644
--- a/src/test/erase/crypto_test.cpp
+++ b/src/test/erase/crypto_test.cpp
@@ -20,25 +20,23 @@
{
using estoraged::CryptErase;
-using estoraged::Cryptsetup;
-using estoraged::CryptsetupInterface;
using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
using sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound;
-using sdbusplus::xyz::openbmc_project::Inventory::Item::server::Volume;
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
-class cryptoEraseTest : public testing::Test
+const std::string testFileName = "testFile";
+
+class CryptoEraseTest : public testing::Test
{
public:
- static constexpr char testFileName[] = "testfile";
std::ofstream testFile;
void SetUp() override
{
/* Create an empty file that we'll pretend is a 'storage device'. */
- testFile.open(testFileName,
+ testFile.open(testFileName.c_str(),
std::ios::out | std::ios::binary | std::ios::trunc);
testFile.close();
if (testFile.fail())
@@ -49,7 +47,7 @@
}
};
-TEST_F(cryptoEraseTest, EraseCryptPass)
+TEST_F(CryptoEraseTest, EraseCryptPass)
{
std::unique_ptr<MockCryptsetupInterface> mockCryptIface =
std::make_unique<MockCryptsetupInterface>();
@@ -66,11 +64,11 @@
EXPECT_CALL(*mockCryptIface, cryptKeyslotDestroy(_, 0)).Times(1);
CryptErase myCryptErase =
- CryptErase(testFileName, std::move(mockCryptIface));
+ CryptErase(testFileName.c_str(), std::move(mockCryptIface));
EXPECT_NO_THROW(myCryptErase.doErase());
}
-TEST_F(cryptoEraseTest, EraseCrypMaxSlotFails)
+TEST_F(CryptoEraseTest, EraseCrypMaxSlotFails)
{
std::unique_ptr<MockCryptsetupInterface> mockCryptIface =
std::make_unique<MockCryptsetupInterface>();
@@ -82,11 +80,11 @@
.WillOnce(Return(-1));
CryptErase myCryptErase =
- CryptErase(testFileName, std::move(mockCryptIface));
+ CryptErase(testFileName.c_str(), std::move(mockCryptIface));
EXPECT_THROW(myCryptErase.doErase(), ResourceNotFound);
}
-TEST_F(cryptoEraseTest, EraseCrypMaxSlotZero)
+TEST_F(CryptoEraseTest, EraseCrypMaxSlotZero)
{
std::unique_ptr<MockCryptsetupInterface> mockCryptIface =
std::make_unique<MockCryptsetupInterface>();
@@ -98,11 +96,11 @@
.WillOnce(Return(0));
CryptErase myCryptErase =
- CryptErase(testFileName, std::move(mockCryptIface));
+ CryptErase(testFileName.c_str(), std::move(mockCryptIface));
EXPECT_THROW(myCryptErase.doErase(), ResourceNotFound);
}
-TEST_F(cryptoEraseTest, EraseCrypOnlyInvalid)
+TEST_F(CryptoEraseTest, EraseCrypOnlyInvalid)
{
std::unique_ptr<MockCryptsetupInterface> mockCryptIface =
std::make_unique<MockCryptsetupInterface>();
@@ -117,11 +115,11 @@
.WillRepeatedly(Return(CRYPT_SLOT_INVALID));
CryptErase myCryptErase =
- CryptErase(testFileName, std::move(mockCryptIface));
+ CryptErase(testFileName.c_str(), std::move(mockCryptIface));
EXPECT_NO_THROW(myCryptErase.doErase());
}
-TEST_F(cryptoEraseTest, EraseCrypDestoryFails)
+TEST_F(CryptoEraseTest, EraseCrypDestoryFails)
{
std::unique_ptr<MockCryptsetupInterface> mockCryptIface =
std::make_unique<MockCryptsetupInterface>();
@@ -139,7 +137,7 @@
.WillOnce(Return(-1));
CryptErase myCryptErase =
- CryptErase(testFileName, std::move(mockCryptIface));
+ CryptErase(testFileName.c_str(), std::move(mockCryptIface));
EXPECT_THROW(myCryptErase.doErase(), InternalFailure);
}
diff --git a/src/test/erase/pattern_test.cpp b/src/test/erase/pattern_test.cpp
index 98eb374..e0192a0 100644
--- a/src/test/erase/pattern_test.cpp
+++ b/src/test/erase/pattern_test.cpp
@@ -63,7 +63,8 @@
int dummyValue = 88;
testFile.open(testFileName, std::ios::binary | std::ios::out);
- testFile.write((const char*)&dummyValue, sizeof(dummyValue));
+ testFile.write((reinterpret_cast<const char*>(&dummyValue)),
+ sizeof(dummyValue));
testFile.close();
EXPECT_NO_THROW(pass.writePattern(size - sizeof(dummyValue)));
diff --git a/src/test/erase/zero_test.cpp b/src/test/erase/zero_test.cpp
index 70a62e2..846059d 100644
--- a/src/test/erase/zero_test.cpp
+++ b/src/test/erase/zero_test.cpp
@@ -17,7 +17,6 @@
using estoraged::Zero;
using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-using stdplus::fd::ManagedFd;
namespace estoraged_test
{
@@ -61,9 +60,10 @@
std::ofstream testFile;
// open the file and write none zero to it
- int dummyValue = 0x88776655;
+ uint32_t dummyValue = 0x88776655;
testFile.open(testFileName, std::ios::binary | std::ios::out);
- testFile.write((const char*)&dummyValue, sizeof(dummyValue));
+ testFile.write((reinterpret_cast<const char*>(&dummyValue)),
+ sizeof(dummyValue));
testFile.close();
uint64_t size = 4096;
Zero pass(testFileName);
@@ -88,7 +88,7 @@
uint64_t size = 4096;
Zero pass(testFileName);
- int dummyValue = 88;
+ uint32_t dummyValue = 88;
EXPECT_NO_THROW(pass.writeZero(size - sizeof(dummyValue)));
// open the file and write none zero to it
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index 10357fe..7a3286c 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -38,23 +38,23 @@
*/
sdbusplus::SdBusMock sdbusMock;
-class eStoragedTest : public testing::Test
+class EStoragedTest : public testing::Test
{
public:
- static constexpr char testFileName[] = "testfile";
- static constexpr char testLuksDevName[] = "testfile_luksDev";
+ const char* testFileName = "testfile";
+ const char* testLuksDevName = "testfile_luksDev";
std::ofstream testFile;
- std::unique_ptr<estoraged::eStoraged> esObject;
- static constexpr auto TEST_PATH = "/test/openbmc_project/storage/test_dev";
- static constexpr auto ESTORAGED_INTERFACE =
+ std::unique_ptr<estoraged::EStoraged> esObject;
+ const char* testPath = "/test/openbmc_project/storage/test_dev";
+ const char* estoragedInterface =
"xyz.openbmc_project.Inventory.Item.Volume";
sdbusplus::bus::bus bus;
std::string passwordString;
std::vector<uint8_t> password;
- MockCryptsetupInterface* mockCryptIface;
- MockFilesystemInterface* mockFsIface;
+ MockCryptsetupInterface* mockCryptIface{};
+ MockFilesystemInterface* mockFsIface{};
- eStoragedTest() :
+ EStoragedTest() :
bus(sdbusplus::get_mocked_new(&sdbusMock)), passwordString("password"),
password(passwordString.begin(), passwordString.end())
{}
@@ -71,16 +71,16 @@
}
EXPECT_CALL(sdbusMock,
- sd_bus_add_object_vtable(IsNull(), _, StrEq(TEST_PATH),
- StrEq(ESTORAGED_INTERFACE), _, _))
+ sd_bus_add_object_vtable(IsNull(), _, StrEq(testPath),
+ StrEq(estoragedInterface), _, _))
.WillRepeatedly(Return(0));
EXPECT_CALL(sdbusMock,
- sd_bus_emit_object_added(IsNull(), StrEq(TEST_PATH)))
+ sd_bus_emit_object_added(IsNull(), StrEq(testPath)))
.WillRepeatedly(Return(0));
EXPECT_CALL(sdbusMock,
- sd_bus_emit_object_removed(IsNull(), StrEq(TEST_PATH)))
+ sd_bus_emit_object_removed(IsNull(), StrEq(testPath)))
.WillRepeatedly(Return(0));
std::unique_ptr<MockCryptsetupInterface> cryptIface =
@@ -90,9 +90,8 @@
std::make_unique<MockFilesystemInterface>();
mockFsIface = fsIface.get();
- esObject = std::make_unique<estoraged::eStoraged>(
- bus, TEST_PATH, std::string(testFileName),
- std::string(testLuksDevName), std::move(cryptIface),
+ esObject = std::make_unique<estoraged::EStoraged>(
+ bus, testPath, testFileName, testLuksDevName, std::move(cryptIface),
std::move(fsIface));
}
@@ -103,11 +102,11 @@
};
/* Test case to format and then lock the LUKS device. */
-TEST_F(eStoragedTest, FormatPass)
+TEST_F(EStoragedTest, FormatPass)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -153,11 +152,11 @@
* Test case where the mount point directory already exists, so it shouldn't
* try to create it.
*/
-TEST_F(eStoragedTest, MountPointExistsPass)
+TEST_F(EStoragedTest, MountPointExistsPass)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -200,7 +199,7 @@
}
/* Test case where the device/file doesn't exist. */
-TEST_F(eStoragedTest, FormatNoDeviceFail)
+TEST_F(EStoragedTest, FormatNoDeviceFail)
{
/* Delete the test file. */
EXPECT_EQ(0, unlink(testFileName));
@@ -216,7 +215,7 @@
}
/* Test case where we fail to format the LUKS device. */
-TEST_F(eStoragedTest, FormatFail)
+TEST_F(EStoragedTest, FormatFail)
{
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _))
.WillOnce(Return(-1));
@@ -227,11 +226,11 @@
}
/* Test case where we fail to set the password for the LUKS device. */
-TEST_F(eStoragedTest, AddKeyslotFail)
+TEST_F(EStoragedTest, AddKeyslotFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -245,11 +244,11 @@
}
/* Test case where we fail to load the LUKS header. */
-TEST_F(eStoragedTest, LoadLuksHeaderFail)
+TEST_F(EStoragedTest, LoadLuksHeaderFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -265,11 +264,11 @@
}
/* Test case where we fail to activate the LUKS device. */
-TEST_F(eStoragedTest, ActivateFail)
+TEST_F(EStoragedTest, ActivateFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -288,11 +287,11 @@
}
/* Test case where we fail to create the filesystem. */
-TEST_F(eStoragedTest, CreateFilesystemFail)
+TEST_F(EStoragedTest, CreateFilesystemFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -313,11 +312,11 @@
}
/* Test case where we fail to create the mount point. */
-TEST_F(eStoragedTest, CreateMountPointFail)
+TEST_F(EStoragedTest, CreateMountPointFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -344,11 +343,11 @@
}
/* Test case where we fail to mount the filesystem. */
-TEST_F(eStoragedTest, MountFail)
+TEST_F(EStoragedTest, MountFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -383,11 +382,11 @@
}
/* Test case where we fail to unmount the filesystem. */
-TEST_F(eStoragedTest, UnmountFail)
+TEST_F(EStoragedTest, UnmountFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -424,11 +423,11 @@
}
/* Test case where we fail to remove the mount point. */
-TEST_F(eStoragedTest, RemoveMountPointFail)
+TEST_F(EStoragedTest, RemoveMountPointFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
@@ -469,11 +468,11 @@
}
/* Test case where we fail to deactivate the LUKS device. */
-TEST_F(eStoragedTest, DeactivateFail)
+TEST_F(EStoragedTest, DeactivateFail)
{
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
- IsNull(), StrEq(TEST_PATH), StrEq(ESTORAGED_INTERFACE), _))
+ IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
.WillRepeatedly(Return(0));
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);