1 /** 2 * The goal of these tests is to verify the behavior of all blob commands given 3 * the current state is notYetStarted. The initial state. 4 */ 5 #include "firmware_handler.hpp" 6 #include "firmware_unittest.hpp" 7 8 #include <cstdint> 9 #include <string> 10 #include <vector> 11 12 #include <gtest/gtest.h> 13 14 namespace ipmi_flash 15 { 16 namespace 17 { 18 19 using ::testing::Return; 20 using ::testing::UnorderedElementsAreArray; 21 22 class FirmwareHandlerNotYetStartedTest : public IpmiOnlyFirmwareStaticTest 23 {}; 24 25 /* 26 * There are the following calls (parameters may vary): 27 * Note: you cannot have a session yet, so only commands that don't take a 28 * session parameter are valid. Once you open() from this state, we will vary 29 * you transition out of this state (ensuring the above is true). Technically 30 * the firmware handler receives the session number with open(), but the blob 31 * manager is providing this normally. 32 * 33 * canHandleBlob 34 * getBlobIds 35 * deleteBlob 36 * stat 37 * open 38 * 39 * canHandleBlob is just a count check (or something similar) against what is 40 * returned by getBlobIds. It is tested in firmware_canhandle_unittest 41 */ 42 43 /* 44 * deleteBlob() 45 */ 46 TEST_F(FirmwareHandlerNotYetStartedTest, DeleteBlobInStateReturnsFalse) 47 { 48 auto blobs = handler->getBlobIds(); 49 for (const auto& b : blobs) 50 { 51 EXPECT_FALSE(handler->deleteBlob(b)); 52 } 53 } 54 55 /* canHandleBlob, getBlobIds */ 56 TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents) 57 { 58 /* By only checking that the hash and static blob ids are present to start 59 * with, we're also verifying others aren't. 60 */ 61 EXPECT_THAT(handler->getBlobIds(), 62 UnorderedElementsAreArray(startingBlobs)); 63 64 /* Verify canHandleBlob is reading from the same list (basically) */ 65 for (const auto& blob : startingBlobs) 66 { 67 EXPECT_TRUE(handler->canHandleBlob(blob)); 68 } 69 } 70 71 /* stat(blob_id) */ 72 TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults) 73 { 74 /* In this original state, calling stat() on the blob ids will return the 75 * idle status 76 */ 77 78 auto blobs = handler->getBlobIds(); 79 for (const auto& blob : blobs) 80 { 81 blobs::BlobMeta meta = {}; 82 EXPECT_TRUE(handler->stat(blob, &meta)); 83 EXPECT_EQ(expectedIdleMeta, meta); 84 } 85 } 86 87 /* open(each blob id) (verifyblobid will no longer be available at this state. 88 */ 89 TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange) 90 { 91 EXPECT_CALL(*imageMock2, open(staticLayoutBlobId, std::ios::out)) 92 .WillOnce(Return(true)); 93 EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true)); 94 95 EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId)); 96 97 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); 98 99 EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId)); 100 } 101 102 TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange) 103 { 104 EXPECT_CALL(*hashImageMock, open(hashBlobId, std::ios::out)) 105 .WillOnce(Return(true)); 106 /* Opening the hash blob id doesn't trigger a preparation, only a firmware 107 * blob. 108 */ 109 EXPECT_CALL(*prepareMockPtr, trigger()).Times(0); 110 111 EXPECT_TRUE(handler->open(session, flags, hashBlobId)); 112 113 expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); 114 115 EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId)); 116 } 117 118 /* 119 * expire(session) 120 */ 121 TEST_F(FirmwareHandlerNotYetStartedTest, ExpireOnNotYetStartedAbortsProcess) 122 { 123 ASSERT_TRUE(handler->expire(session)); 124 125 EXPECT_THAT(handler->getBlobIds(), 126 UnorderedElementsAreArray(startingBlobs)); 127 128 expectedState(FirmwareBlobHandler::UpdateState::notYetStarted); 129 } 130 131 } // namespace 132 } // namespace ipmi_flash 133