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 | { |
| 24 | }; |
| 25 | |
| 26 | /* |
| 27 | * There are the following calls (parameters may vary): |
| 28 | * Note: you cannot have a session yet, so only commands that don't take a |
| 29 | * session parameter are valid. Once you open() from this state, we will vary |
| 30 | * you transition out of this state (ensuring the above is true). Technically |
| 31 | * the firmware handler receives the session number with open(), but the blob |
| 32 | * manager is providing this normally. |
| 33 | * |
| 34 | * canHandleBlob |
| 35 | * getBlobIds |
| 36 | * deleteBlob |
| 37 | * stat |
| 38 | * open |
| 39 | * |
| 40 | * canHandleBlob is just a count check (or something similar) against what is |
| 41 | * returned by getBlobIds. It is tested in firmware_canhandle_unittest |
| 42 | */ |
| 43 | |
Patrick Venture | 9b57a4c | 2019-05-28 12:54:09 -0700 | [diff] [blame] | 44 | /* canHandleBlob, getBlobIds */ |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 45 | TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents) |
| 46 | { |
Patrick Venture | 9b57a4c | 2019-05-28 12:54:09 -0700 | [diff] [blame] | 47 | /* By only checking that the hash and static blob ids are present to start |
| 48 | * with, we're also verifying others aren't. |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 49 | */ |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 50 | std::vector<std::string> expectedBlobs = {staticLayoutBlobId, hashBlobId}; |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 51 | |
| 52 | EXPECT_THAT(handler->getBlobIds(), |
| 53 | UnorderedElementsAreArray(expectedBlobs)); |
Patrick Venture | 02c0ead | 2019-05-24 09:01:54 -0700 | [diff] [blame] | 54 | |
Patrick Venture | 9b57a4c | 2019-05-28 12:54:09 -0700 | [diff] [blame] | 55 | /* Verify canHandleBlob is reading from the same list (basically) */ |
Patrick Venture | 02c0ead | 2019-05-24 09:01:54 -0700 | [diff] [blame] | 56 | for (const auto& blob : expectedBlobs) |
| 57 | { |
| 58 | EXPECT_TRUE(handler->canHandleBlob(blob)); |
| 59 | } |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 62 | /* TODO: Try deleting some blobs -- in this state it should just return failure, |
| 63 | * but it's not yet implemented |
| 64 | */ |
| 65 | |
| 66 | /* stat(blob_id) */ |
| 67 | TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults) |
| 68 | { |
| 69 | /* In this original state, calling stat() on the blob ids will return the |
| 70 | * transported supported. |
| 71 | */ |
| 72 | blobs::BlobMeta expected; |
| 73 | expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi; |
| 74 | expected.size = 0; |
| 75 | |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 76 | auto blobs = handler->getBlobIds(); |
| 77 | for (const auto& blob : blobs) |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 78 | { |
| 79 | blobs::BlobMeta meta = {}; |
| 80 | EXPECT_TRUE(handler->stat(blob, &meta)); |
| 81 | EXPECT_EQ(expected, meta); |
| 82 | } |
| 83 | } |
| 84 | |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 85 | /* open(each blob id) (verifyblobid will no longer be available at this state. |
| 86 | */ |
| 87 | TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange) |
| 88 | { |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 89 | EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true)); |
| 90 | |
Patrick Venture | 65055fb | 2019-05-23 17:36:01 -0700 | [diff] [blame] | 91 | EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId)); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 92 | |
| 93 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
Patrick Venture | efba42d | 2019-05-24 10:48:16 -0700 | [diff] [blame] | 94 | |
| 95 | EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId)); |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange) |
| 99 | { |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 100 | EXPECT_CALL(imageMock, open(hashBlobId)).WillOnce(Return(true)); |
| 101 | |
Patrick Venture | 65055fb | 2019-05-23 17:36:01 -0700 | [diff] [blame] | 102 | EXPECT_TRUE(handler->open(session, flags, hashBlobId)); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 103 | |
| 104 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
Patrick Venture | efba42d | 2019-05-24 10:48:16 -0700 | [diff] [blame] | 105 | |
| 106 | EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId)); |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 107 | } |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 108 | |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 109 | } // namespace |
| 110 | } // namespace ipmi_flash |