test: firmware updatePending: initial empty test
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I6d3362fecf8a5d80e0d679530cd7e6dc367dafe6
diff --git a/test/Makefile.am b/test/Makefile.am
index f0358a6..8aca7f1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -37,7 +37,8 @@
firmware_state_uploadinprogress_unittest \
firmware_state_verificationpending_unittest \
firmware_state_verificationstarted_unittest \
- firmware_state_verificationcompleted_unittest
+ firmware_state_verificationcompleted_unittest \
+ firmware_state_updatepending_unittest
if BUILD_HOST_TOOL
check_PROGRAMS += \
@@ -99,6 +100,9 @@
firmware_state_verificationcompleted_unittest_SOURCES = firmware_state_verificationcompleted_unittest.cpp
firmware_state_verificationcompleted_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
+firmware_state_updatepending_unittest_SOURCES = firmware_state_updatepending_unittest.cpp
+firmware_state_updatepending_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_updatepending_unittest.cpp b/test/firmware_state_updatepending_unittest.cpp
new file mode 100644
index 0000000..3c2bc3e
--- /dev/null
+++ b/test/firmware_state_updatepending_unittest.cpp
@@ -0,0 +1,121 @@
+/* The goal of these tests is to verify the behavior of all blob commands given
+ * the current state is updatePending. This state is achieved as an exit from
+ * verificationCompleted.
+ */
+#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)
+ *
+ * Testing canHandleBlob is uninteresting in this state. Getting the BlobIDs
+ * will inform what canHandleBlob will return.
+ */
+
+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;
+};
+
+/*
+ * 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)
+ */
+
+} // namespace
+} // namespace ipmi_flash