test: firmware uploadInProgress: minor cleanup
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I75a9cdba1897153201bf8226e1d668c1b5f60a46
diff --git a/test/firmware_state_uploadinprogress_unittest.cpp b/test/firmware_state_uploadinprogress_unittest.cpp
index 6748a29..dda95ee 100644
--- a/test/firmware_state_uploadinprogress_unittest.cpp
+++ b/test/firmware_state_uploadinprogress_unittest.cpp
@@ -35,20 +35,25 @@
*/
class FirmwareHandlerUploadInProgressTest : public IpmiOnlyFirmwareStaticTest
{
+ protected:
+ void openToInProgress(const std::string& blobId)
+ {
+ auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
+ EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
+ EXPECT_TRUE(handler->open(session, flags, blobId));
+ EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
+ realHandler->getCurrentState());
+ }
+
+ std::uint16_t session = 1;
+ std::uint16_t flags =
+ blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
TEST_F(FirmwareHandlerUploadInProgressTest, GetBlobIdsVerifyOutputActiveImage)
{
/* Opening the image file will add the active image blob id */
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(staticLayoutBlobId);
std::vector<std::string> expectedAfterImage = {
staticLayoutBlobId, hashBlobId, verifyBlobId, activeImageBlobId};
@@ -59,15 +64,7 @@
TEST_F(FirmwareHandlerUploadInProgressTest, GetBlobIdsVerifyOutputActiveHash)
{
/* Opening the image file will add the active image blob id */
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, hashBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(hashBlobId);
std::vector<std::string> expectedAfterImage = {
staticLayoutBlobId, hashBlobId, verifyBlobId, activeHashBlobId};
@@ -87,15 +84,7 @@
/* you cannot call stat() on the active image or the active hash or the
* verify blob.
*/
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(staticLayoutBlobId);
blobs::BlobMeta meta;
EXPECT_FALSE(handler->stat(activeImageBlobId, &meta));
@@ -106,15 +95,7 @@
/* this test is separate from the active image one so that the state doesn't
* change from close.
*/
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, hashBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(hashBlobId);
blobs::BlobMeta meta;
EXPECT_FALSE(handler->stat(activeHashBlobId, &meta));
@@ -129,15 +110,7 @@
expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi;
expected.size = 0;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(staticLayoutBlobId);
std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId};
for (const auto& blob : testBlobs)
@@ -162,16 +135,7 @@
/* This test will verify that the underlying image handler is called with
* this stat, in addition to the normal information.
*/
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(staticLayoutBlobId);
EXPECT_CALL(imageMock, getSize()).WillOnce(Return(32));
@@ -192,15 +156,7 @@
* active image (or tarball) or the hash file. Also verifies you can't just
* re-open the currently open file.
*/
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(staticLayoutBlobId);
std::vector<std::string> blobsToTry = {
hashBlobId, activeImageBlobId, activeHashBlobId, staticLayoutBlobId};
@@ -212,15 +168,7 @@
TEST_F(FirmwareHandlerUploadInProgressTest, OpeningImageFileWhileHashOpenFails)
{
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, hashBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(hashBlobId);
std::vector<std::string> blobsToTry = {
hashBlobId, activeImageBlobId, activeHashBlobId, staticLayoutBlobId};
@@ -242,8 +190,6 @@
TEST_F(FirmwareHandlerUploadInProgressTest,
ClosingImageFileTransitionsToVerificationPending)
{
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
/* TODO: uncomment this when verify is properly added. */
@@ -251,7 +197,7 @@
EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
+ EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
realHandler->getCurrentState());
@@ -265,8 +211,6 @@
TEST_F(FirmwareHandlerUploadInProgressTest,
ClosingHashFileTransitionsToVerificationPending)
{
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
/* TODO: uncomment this when verify is properly added. */
@@ -274,7 +218,7 @@
EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(1, flags, hashBlobId));
+ EXPECT_TRUE(handler->open(session, flags, hashBlobId));
EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
realHandler->getCurrentState());
@@ -294,25 +238,18 @@
* this case because the blob will just pass the call along. Whereas
* calling against the verify or update blob may be more interesting.
*/
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
-
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
-
- EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId));
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress,
- realHandler->getCurrentState());
+ openToInProgress(staticLayoutBlobId);
/* Note: with IPMI as the transport there's no data handler, so this should
* fail nicely. */
std::vector<std::uint8_t> bytes = {0x01, 0x02};
- EXPECT_FALSE(handler->writeMeta(1, 0, bytes));
+ EXPECT_FALSE(handler->writeMeta(session, 0, bytes));
}
/*
* write(session)
* read(session)
+ * commit(session)
*/
} // namespace