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