Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 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 <gtest/gtest.h> |
| 9 | |
| 10 | namespace ipmi_flash |
| 11 | { |
| 12 | namespace |
| 13 | { |
| 14 | |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 15 | using ::testing::Return; |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 16 | using ::testing::UnorderedElementsAreArray; |
| 17 | |
| 18 | class FirmwareHandlerNotYetStartedTest : public IpmiOnlyFirmwareStaticTest |
| 19 | { |
| 20 | }; |
| 21 | |
| 22 | /* |
| 23 | * There are the following calls (parameters may vary): |
| 24 | * Note: you cannot have a session yet, so only commands that don't take a |
| 25 | * session parameter are valid. Once you open() from this state, we will vary |
| 26 | * you transition out of this state (ensuring the above is true). Technically |
| 27 | * the firmware handler receives the session number with open(), but the blob |
| 28 | * manager is providing this normally. |
| 29 | * |
| 30 | * canHandleBlob |
| 31 | * getBlobIds |
| 32 | * deleteBlob |
| 33 | * stat |
| 34 | * open |
| 35 | * |
| 36 | * canHandleBlob is just a count check (or something similar) against what is |
| 37 | * returned by getBlobIds. It is tested in firmware_canhandle_unittest |
| 38 | */ |
| 39 | |
| 40 | TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents) |
| 41 | { |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 42 | /* TODO: Presently, /flash/verify is present from the beginning, however, |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 43 | * this is going to change to simplify handling of open(). |
| 44 | */ |
| 45 | std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId, |
| 46 | verifyBlobId}; |
| 47 | |
| 48 | EXPECT_THAT(handler->getBlobIds(), |
| 49 | UnorderedElementsAreArray(expectedBlobs)); |
| 50 | } |
| 51 | |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 52 | /* TODO: Try deleting some blobs -- in this state it should just return failure, |
| 53 | * but it's not yet implemented |
| 54 | */ |
| 55 | |
| 56 | /* stat(blob_id) */ |
| 57 | TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults) |
| 58 | { |
| 59 | /* In this original state, calling stat() on the blob ids will return the |
| 60 | * transported supported. |
| 61 | */ |
| 62 | blobs::BlobMeta expected; |
| 63 | expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi; |
| 64 | expected.size = 0; |
| 65 | |
| 66 | /* TODO: note, once verifyblobid isn't present in this state we can use |
| 67 | * getblobids()'s output as input |
| 68 | */ |
| 69 | std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId}; |
| 70 | for (const auto& blob : testBlobs) |
| 71 | { |
| 72 | blobs::BlobMeta meta = {}; |
| 73 | EXPECT_TRUE(handler->stat(blob, &meta)); |
| 74 | EXPECT_EQ(expected, meta); |
| 75 | } |
| 76 | } |
| 77 | |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 78 | /* open(each blob id) (verifyblobid will no longer be available at this state. |
| 79 | */ |
| 80 | TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange) |
| 81 | { |
| 82 | std::uint16_t flags = |
| 83 | blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi; |
| 84 | auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get()); |
| 85 | |
| 86 | EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true)); |
| 87 | |
| 88 | EXPECT_TRUE(handler->open(1, flags, staticLayoutBlobId)); |
| 89 | EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress, |
| 90 | realHandler->getCurrentState()); |
| 91 | } |
| 92 | |
| 93 | TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange) |
| 94 | { |
| 95 | std::uint16_t flags = |
| 96 | blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi; |
| 97 | auto realHandler = dynamic_cast<FirmwareBlobHandler*>(handler.get()); |
| 98 | |
| 99 | EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true)); |
| 100 | |
| 101 | EXPECT_TRUE(handler->open(1, flags, hashBlobId)); |
| 102 | EXPECT_EQ(FirmwareBlobHandler::UpdateState::uploadInProgress, |
| 103 | realHandler->getCurrentState()); |
| 104 | } |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 105 | |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 106 | } // namespace |
| 107 | } // namespace ipmi_flash |