test: firmware updateStarted: empty and cleanup
Also cleanup the various state goal methods.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I585738781babe55170eaaa3d9e44ed4a076871f9
diff --git a/test/Makefile.am b/test/Makefile.am
index 8aca7f1..41e859b 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -38,7 +38,8 @@
firmware_state_verificationpending_unittest \
firmware_state_verificationstarted_unittest \
firmware_state_verificationcompleted_unittest \
- firmware_state_updatepending_unittest
+ firmware_state_updatepending_unittest \
+ firmware_state_updatestarted_unittest
if BUILD_HOST_TOOL
check_PROGRAMS += \
@@ -103,6 +104,9 @@
firmware_state_updatepending_unittest_SOURCES = firmware_state_updatepending_unittest.cpp
firmware_state_updatepending_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
+firmware_state_updatestarted_unittest_SOURCES = firmware_state_updatestarted_unittest.cpp
+firmware_state_updatestarted_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
+
if BUILD_HOST_TOOL
tools_bt_unittest_SOURCES = tools_bt_unittest.cpp
tools_bt_unittest_LDADD = $(top_builddir)/tools/libupdater.la
diff --git a/test/firmware_state_notyetstarted_unittest.cpp b/test/firmware_state_notyetstarted_unittest.cpp
index f662820..bb6fecf 100644
--- a/test/firmware_state_notyetstarted_unittest.cpp
+++ b/test/firmware_state_notyetstarted_unittest.cpp
@@ -21,10 +21,6 @@
class FirmwareHandlerNotYetStartedTest : public IpmiOnlyFirmwareStaticTest
{
- protected:
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
/*
diff --git a/test/firmware_state_updatepending_unittest.cpp b/test/firmware_state_updatepending_unittest.cpp
index 7a1e480..87df67d 100644
--- a/test/firmware_state_updatepending_unittest.cpp
+++ b/test/firmware_state_updatepending_unittest.cpp
@@ -42,40 +42,6 @@
class FirmwareHandlerUpdatePendingTest : public IpmiOnlyFirmwareStaticTest
{
- protected:
- void getToUpdatePending()
- {
- /* The hash was not sent up, as it's technically optional. Therefore,
- * there is no active hash file.
- */
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
- expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
-
- EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
- handler->close(session);
- expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
-
- EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
- EXPECT_CALL(*verifyMockPtr, triggerVerification())
- .WillOnce(Return(true));
-
- EXPECT_TRUE(handler->commit(session, {}));
- expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
-
- EXPECT_CALL(*verifyMockPtr, checkVerificationState())
- .WillOnce(Return(VerifyCheckResponses::success));
- blobs::BlobMeta meta;
- EXPECT_TRUE(handler->stat(session, &meta));
- expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted);
-
- handler->close(session);
- expectedState(FirmwareBlobHandler::UpdateState::updatePending);
- }
-
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
/*
diff --git a/test/firmware_state_updatestarted_unittest.cpp b/test/firmware_state_updatestarted_unittest.cpp
new file mode 100644
index 0000000..34e6666
--- /dev/null
+++ b/test/firmware_state_updatestarted_unittest.cpp
@@ -0,0 +1,82 @@
+/* The goal of these tests is to verify the behavior of all blob commands given
+ * the current state is updateStarted. This state is achieved as an exit from
+ * updatePending.
+ */
+#include "firmware_handler.hpp"
+#include "firmware_unittest.hpp"
+#include "status.hpp"
+#include "util.hpp"
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace ipmi_flash
+{
+namespace
+{
+
+using ::testing::Return;
+
+/*
+ * There are the following calls (parameters may vary):
+ * canHandleBlob(blob)
+ * getBlobIds
+ * deleteBlob(blob)
+ * stat(blob)
+ * stat(session)
+ * open(blob)
+ * close(session)
+ * writemeta(session)
+ * write(session)
+ * read(session)
+ * commit(session)
+ */
+
+class FirmwareHandlerUpdateStartedTest : public IpmiOnlyFirmwareStaticTest
+{
+};
+
+/* canHandleBlob(blob)
+ * getBlobIds
+ */
+
+/*
+ * TODO: deleteBlob(blob)
+ */
+
+/*
+ * stat(blob)
+ */
+
+/*
+ * stat(session)
+ */
+/*
+ * open(blob)
+ */
+
+/*
+ * close(session)
+ */
+
+/*
+ * writemeta(session)
+ */
+
+/*
+ * write(session)
+ */
+
+/*
+ * read(session)
+ */
+
+/*
+ * commit(session)
+ */
+
+} // namespace
+} // namespace ipmi_flash
diff --git a/test/firmware_state_uploadinprogress_unittest.cpp b/test/firmware_state_uploadinprogress_unittest.cpp
index f33e547..5ed5491 100644
--- a/test/firmware_state_uploadinprogress_unittest.cpp
+++ b/test/firmware_state_uploadinprogress_unittest.cpp
@@ -41,17 +41,6 @@
*/
class FirmwareHandlerUploadInProgressTest : public IpmiOnlyFirmwareStaticTest
{
- protected:
- void openToInProgress(const std::string& blobId)
- {
- EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(session, flags, blobId));
- expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
- }
-
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
TEST_F(FirmwareHandlerUploadInProgressTest, GetBlobIdsVerifyOutputActiveImage)
diff --git a/test/firmware_state_verificationcompleted_unittest.cpp b/test/firmware_state_verificationcompleted_unittest.cpp
index e82a011..f36427d 100644
--- a/test/firmware_state_verificationcompleted_unittest.cpp
+++ b/test/firmware_state_verificationcompleted_unittest.cpp
@@ -45,37 +45,6 @@
class FirmwareHandlerVerificationCompletedTest
: public IpmiOnlyFirmwareStaticTest
{
- protected:
- void getToVerificationCompleted(VerifyCheckResponses checkResponse)
- {
- /* The hash was not sent up, as it's technically optional. Therefore,
- * there is no active hash file.
- */
- EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId));
- expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
-
- EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
- handler->close(session);
- expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
-
- EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
- EXPECT_CALL(*verifyMockPtr, triggerVerification())
- .WillOnce(Return(true));
-
- EXPECT_TRUE(handler->commit(session, {}));
- expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
-
- EXPECT_CALL(*verifyMockPtr, checkVerificationState())
- .WillOnce(Return(checkResponse));
- blobs::BlobMeta meta;
- EXPECT_TRUE(handler->stat(session, &meta));
- expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted);
- }
-
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
/* TODO: deleteBlob(blob) */
diff --git a/test/firmware_state_verificationpending_unittest.cpp b/test/firmware_state_verificationpending_unittest.cpp
index 61b25c2..4452f17 100644
--- a/test/firmware_state_verificationpending_unittest.cpp
+++ b/test/firmware_state_verificationpending_unittest.cpp
@@ -44,21 +44,6 @@
class FirmwareHandlerVerificationPendingTest : public IpmiOnlyFirmwareStaticTest
{
- protected:
- void getToVerificationPending(const std::string& blobId)
- {
- EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(session, flags, blobId));
- expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
-
- EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
- handler->close(session);
- expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
- }
-
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
/*
diff --git a/test/firmware_state_verificationstarted_unittest.cpp b/test/firmware_state_verificationstarted_unittest.cpp
index 1e73c98..9072ab9 100644
--- a/test/firmware_state_verificationstarted_unittest.cpp
+++ b/test/firmware_state_verificationstarted_unittest.cpp
@@ -42,28 +42,6 @@
class FirmwareHandlerVerificationStartedTest : public IpmiOnlyFirmwareStaticTest
{
- protected:
- void getToVerificationStarted(const std::string& blobId)
- {
- EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
- EXPECT_TRUE(handler->open(session, flags, blobId));
- expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
-
- EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
- handler->close(session);
- expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
-
- EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
- EXPECT_CALL(*verifyMockPtr, triggerVerification())
- .WillOnce(Return(true));
-
- EXPECT_TRUE(handler->commit(session, {}));
- expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
- }
-
- std::uint16_t session = 1;
- std::uint16_t flags =
- blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
/*
diff --git a/test/firmware_unittest.hpp b/test/firmware_unittest.hpp
index 0aa7e12..d49e9f5 100644
--- a/test/firmware_unittest.hpp
+++ b/test/firmware_unittest.hpp
@@ -14,6 +14,10 @@
namespace ipmi_flash
{
+namespace
+{
+
+using ::testing::Return;
class IpmiOnlyFirmwareStaticTest : public ::testing::Test
{
@@ -43,6 +47,63 @@
EXPECT_EQ(state, realHandler->getCurrentState());
}
+ void openToInProgress(const std::string& blobId)
+ {
+ EXPECT_CALL(imageMock, open(blobId)).WillOnce(Return(true));
+ EXPECT_TRUE(handler->open(session, flags, blobId));
+ expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
+ }
+
+ void getToVerificationPending(const std::string& blobId)
+ {
+ openToInProgress(blobId);
+
+ EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
+ handler->close(session);
+ expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
+ }
+
+ void getToVerificationStarted(const std::string& blobId)
+ {
+ getToVerificationPending(blobId);
+
+ EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
+ EXPECT_CALL(*verifyMockPtr, triggerVerification())
+ .WillOnce(Return(true));
+
+ EXPECT_TRUE(handler->commit(session, {}));
+ expectedState(FirmwareBlobHandler::UpdateState::verificationStarted);
+ }
+
+ void getToVerificationCompleted(VerifyCheckResponses checkResponse)
+ {
+ getToVerificationStarted(staticLayoutBlobId);
+
+ EXPECT_CALL(*verifyMockPtr, checkVerificationState())
+ .WillOnce(Return(checkResponse));
+ blobs::BlobMeta meta;
+ EXPECT_TRUE(handler->stat(session, &meta));
+ expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted);
+ }
+
+ void getToUpdatePending()
+ {
+ getToVerificationCompleted(VerifyCheckResponses::success);
+
+ handler->close(session);
+ expectedState(FirmwareBlobHandler::UpdateState::updatePending);
+ }
+
+ void getToUpdateStarted()
+ {
+ getToUpdatePending();
+ EXPECT_TRUE(handler->open(session, flags, updateBlobId));
+
+ EXPECT_CALL(*updateMockPtr, triggerUpdate()).WillOnce(Return(true));
+ EXPECT_TRUE(handler->commit(session, {}));
+ expectedState(FirmwareBlobHandler::UpdateState::updateStarted);
+ }
+
ImageHandlerMock imageMock;
std::vector<HandlerPack> blobs;
std::vector<DataHandlerPack> data = {
@@ -50,6 +111,10 @@
std::unique_ptr<blobs::GenericBlobInterface> handler;
VerificationMock* verifyMockPtr;
UpdateMock* updateMockPtr;
+
+ std::uint16_t session = 1;
+ std::uint16_t flags =
+ blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
};
class IpmiOnlyFirmwareTest : public ::testing::Test
@@ -96,4 +161,5 @@
}
};
+} // namespace
} // namespace ipmi_flash