test: firmware uploadInProgress: getBlobIds
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I922f2206853c8e96aae8f8fb96e9a4769ffaf7eb
diff --git a/test/Makefile.am b/test/Makefile.am
index 049a002..abac332 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -33,7 +33,8 @@
firmware_sessionstat_unittest \
firmware_commit_unittest \
file_handler_unittest \
- firmware_state_notyetstarted_unittest
+ firmware_state_notyetstarted_unittest \
+ firmware_state_uploadinprogress_unittest
if BUILD_HOST_TOOL
check_PROGRAMS += \
@@ -83,6 +84,9 @@
firmware_state_notyetstarted_unittest_SOURCES = firmware_state_notyetstarted_unittest.cpp
firmware_state_notyetstarted_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
+firmware_state_uploadinprogress_unittest_SOURCES = firmware_state_uploadinprogress_unittest.cpp
+firmware_state_uploadinprogress_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_uploadinprogress_unittest.cpp b/test/firmware_state_uploadinprogress_unittest.cpp
new file mode 100644
index 0000000..c5c0fee
--- /dev/null
+++ b/test/firmware_state_uploadinprogress_unittest.cpp
@@ -0,0 +1,78 @@
+/**
+ * The goal of these tests is to verify the behavior of all blob commands given
+ * the current state is uploadInProgress. This state is achieved when an image
+ * or hash blob is opened and the handler is expected to receive bytes.
+ */
+#include "firmware_handler.hpp"
+#include "firmware_unittest.hpp"
+
+#include <gtest/gtest.h>
+
+namespace ipmi_flash
+{
+namespace
+{
+
+using ::testing::Return;
+using ::testing::UnorderedElementsAreArray;
+
+/*
+ * 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)
+ *
+ * Testing canHandleBlob is uninteresting in this state. Getting the BlobIDs
+ * will inform what canHandleBlob will return.
+ */
+class FirmwareHandlerUploadInProgressTest : public IpmiOnlyFirmwareStaticTest
+{
+};
+
+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());
+
+ std::vector<std::string> expectedAfterImage = {
+ staticLayoutBlobId, hashBlobId, verifyBlobId, activeImageBlobId};
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(expectedAfterImage));
+}
+
+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());
+
+ std::vector<std::string> expectedAfterImage = {
+ staticLayoutBlobId, hashBlobId, verifyBlobId, activeHashBlobId};
+ EXPECT_THAT(handler->getBlobIds(),
+ UnorderedElementsAreArray(expectedAfterImage));
+}
+
+} // namespace
+} // namespace ipmi_flash