test: firmware verificationStarted: stat(session)
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I66869f84c2e28aca82abd04d7bba909f434dd4e2
diff --git a/test/Makefile.am b/test/Makefile.am
index b98cf53..540c3b7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -35,7 +35,8 @@
file_handler_unittest \
firmware_state_notyetstarted_unittest \
firmware_state_uploadinprogress_unittest \
- firmware_state_verificationpending_unittest
+ firmware_state_verificationpending_unittest \
+ firmware_state_verificationstarted_unittest
if BUILD_HOST_TOOL
check_PROGRAMS += \
@@ -91,6 +92,9 @@
firmware_state_verificationpending_unittest_SOURCES = firmware_state_verificationpending_unittest.cpp
firmware_state_verificationpending_unittest_LDADD = $(top_builddir)/libfirmwareblob_common.la
+firmware_state_verificationstarted_unittest_SOURCES = firmware_state_verificationstarted_unittest.cpp
+firmware_state_verificationstarted_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_verificationpending_unittest.cpp b/test/firmware_state_verificationpending_unittest.cpp
index c7ef667..ba8360b 100644
--- a/test/firmware_state_verificationpending_unittest.cpp
+++ b/test/firmware_state_verificationpending_unittest.cpp
@@ -217,98 +217,6 @@
EXPECT_EQ(expectedMeta, meta);
}
-TEST_F(FirmwareHandlerVerificationPendingTest,
- StatOnVerifyBlobIdAfterCommitChecksStateAndReturnsRunning)
-{
- getToVerificationPending(staticLayoutBlobId);
- EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
- EXPECT_CALL(*verifyMockPtr, triggerVerification()).WillOnce(Return(true));
- EXPECT_CALL(*verifyMockPtr, checkVerificationState())
- .WillOnce(Return(VerifyCheckResponses::running));
-
- blobs::BlobMeta meta, expectedMeta = {};
- expectedMeta.size = 0;
- expectedMeta.blobState = flags | blobs::StateFlags::committing;
- expectedMeta.metadata.push_back(
- static_cast<std::uint8_t>(VerifyCheckResponses::running));
-
- EXPECT_TRUE(handler->commit(session, {}));
- EXPECT_TRUE(handler->stat(session, &meta));
- EXPECT_EQ(expectedMeta, meta);
-}
-
-TEST_F(FirmwareHandlerVerificationPendingTest,
- StatOnVerifyBlobIdAfterCommitCheckStateAndReturnsFailed)
-{
- /* If the returned state from the verification handler is failed, it sets
- * commit_error and transitions to verificationCompleted.
- */
- getToVerificationPending(staticLayoutBlobId);
- EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
- EXPECT_CALL(*verifyMockPtr, triggerVerification()).WillOnce(Return(true));
- EXPECT_CALL(*verifyMockPtr, checkVerificationState())
- .WillOnce(Return(VerifyCheckResponses::failed));
-
- blobs::BlobMeta meta, expectedMeta = {};
- expectedMeta.size = 0;
- expectedMeta.blobState = flags | blobs::StateFlags::commit_error;
- expectedMeta.metadata.push_back(
- static_cast<std::uint8_t>(VerifyCheckResponses::failed));
-
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
- realHandler->getCurrentState());
-
- EXPECT_TRUE(handler->commit(session, {}));
-
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationStarted,
- realHandler->getCurrentState());
-
- EXPECT_TRUE(handler->stat(session, &meta));
- EXPECT_EQ(expectedMeta, meta);
-
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
- realHandler->getCurrentState());
-}
-
-TEST_F(FirmwareHandlerVerificationPendingTest,
- StatOnVerifyBlobIdAfterCommitCheckStateAndReturnsSuccess)
-{
- /* If the returned state from the verification handler is success, it sets
- * committed and transitions to verificationCompleted.
- */
- getToVerificationPending(staticLayoutBlobId);
- EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
- EXPECT_CALL(*verifyMockPtr, triggerVerification()).WillOnce(Return(true));
- EXPECT_CALL(*verifyMockPtr, checkVerificationState())
- .WillOnce(Return(VerifyCheckResponses::success));
-
- blobs::BlobMeta meta, expectedMeta = {};
- expectedMeta.size = 0;
- expectedMeta.blobState = flags | blobs::StateFlags::committed;
- expectedMeta.metadata.push_back(
- static_cast<std::uint8_t>(VerifyCheckResponses::success));
-
- auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
- realHandler->getCurrentState());
-
- EXPECT_TRUE(handler->commit(session, {}));
-
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationStarted,
- realHandler->getCurrentState());
-
- EXPECT_TRUE(handler->stat(session, &meta));
- EXPECT_EQ(expectedMeta, meta);
-
- EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
- realHandler->getCurrentState());
-}
-
-/* TODO: Once verificationCompleted is the state, canHandleBlob should accept
- * updateBlobId.
- */
-
/*
* writemeta(session)
*/
diff --git a/test/firmware_state_verificationstarted_unittest.cpp b/test/firmware_state_verificationstarted_unittest.cpp
new file mode 100644
index 0000000..b8fb579
--- /dev/null
+++ b/test/firmware_state_verificationstarted_unittest.cpp
@@ -0,0 +1,156 @@
+/* The goal of these tests is to verify the behavior of all blob commands given
+ * the current state is verificationStarted. This state is achieved as a out of
+ * verificationPending.
+ */
+#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 FirmwareHandlerVerificationStartedTest : public IpmiOnlyFirmwareStaticTest
+{
+ protected:
+ void getToVerificationStarted(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());
+ EXPECT_CALL(imageMock, close()).WillRepeatedly(Return());
+ handler->close(session);
+ EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationPending,
+ realHandler->getCurrentState());
+
+ EXPECT_TRUE(handler->open(session, flags, verifyBlobId));
+ EXPECT_CALL(*verifyMockPtr, triggerVerification())
+ .WillOnce(Return(true));
+
+ EXPECT_TRUE(handler->commit(session, {}));
+ EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationStarted,
+ realHandler->getCurrentState());
+ }
+
+ std::uint16_t session = 1;
+ std::uint16_t flags =
+ blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi;
+};
+
+/*
+ * stat(session)
+ */
+TEST_F(FirmwareHandlerVerificationStartedTest,
+ StatOnVerifyBlobIdAfterCommitChecksStateAndReturnsRunning)
+{
+ getToVerificationStarted(staticLayoutBlobId);
+ EXPECT_CALL(*verifyMockPtr, checkVerificationState())
+ .WillOnce(Return(VerifyCheckResponses::running));
+
+ blobs::BlobMeta meta, expectedMeta = {};
+ expectedMeta.size = 0;
+ expectedMeta.blobState = flags | blobs::StateFlags::committing;
+ expectedMeta.metadata.push_back(
+ static_cast<std::uint8_t>(VerifyCheckResponses::running));
+
+ EXPECT_TRUE(handler->stat(session, &meta));
+ EXPECT_EQ(expectedMeta, meta);
+}
+
+TEST_F(FirmwareHandlerVerificationStartedTest,
+ StatOnVerifyBlobIdAfterCommitCheckStateAndReturnsFailed)
+{
+ /* If the returned state from the verification handler is failed, it sets
+ * commit_error and transitions to verificationCompleted.
+ */
+ getToVerificationStarted(staticLayoutBlobId);
+ EXPECT_CALL(*verifyMockPtr, checkVerificationState())
+ .WillOnce(Return(VerifyCheckResponses::failed));
+
+ blobs::BlobMeta meta, expectedMeta = {};
+ expectedMeta.size = 0;
+ expectedMeta.blobState = flags | blobs::StateFlags::commit_error;
+ expectedMeta.metadata.push_back(
+ static_cast<std::uint8_t>(VerifyCheckResponses::failed));
+
+ auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
+ EXPECT_TRUE(handler->stat(session, &meta));
+ EXPECT_EQ(expectedMeta, meta);
+
+ EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
+ realHandler->getCurrentState());
+}
+
+TEST_F(FirmwareHandlerVerificationStartedTest,
+ StatOnVerifyBlobIdAfterCommitCheckStateAndReturnsSuccess)
+{
+ /* If the returned state from the verification handler is success, it sets
+ * committed and transitions to verificationCompleted.
+ */
+ getToVerificationStarted(staticLayoutBlobId);
+ EXPECT_CALL(*verifyMockPtr, checkVerificationState())
+ .WillOnce(Return(VerifyCheckResponses::success));
+
+ blobs::BlobMeta meta, expectedMeta = {};
+ expectedMeta.size = 0;
+ expectedMeta.blobState = flags | blobs::StateFlags::committed;
+ expectedMeta.metadata.push_back(
+ static_cast<std::uint8_t>(VerifyCheckResponses::success));
+
+ auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get());
+ EXPECT_TRUE(handler->stat(session, &meta));
+ EXPECT_EQ(expectedMeta, meta);
+
+ EXPECT_EQ(FirmwareBlobHandler::UpdateState::verificationCompleted,
+ realHandler->getCurrentState());
+}
+
+/* TODO: Once verificationCompleted is the state, canHandleBlob should accept
+ * updateBlobId.
+ */
+
+/* TODO:
+ * canHandleBlob(blob)
+ * getBlobIds
+ * deleteBlob(blob)
+ * stat(blob)
+ * open(blob) - there is nothing you can open, this state has an open file.
+ * close(session)
+ * writemeta(session)
+ * write(session)
+ * read(session)
+ * commit(session)
+ */
+
+} // namespace
+} // namespace ipmi_flash