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 |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame^] | 23 | {}; |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 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 | |
Patrick Venture | 7267676 | 2019-06-17 11:22:38 -0700 | [diff] [blame] | 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 | |
Patrick Venture | 9b57a4c | 2019-05-28 12:54:09 -0700 | [diff] [blame] | 55 | /* canHandleBlob, getBlobIds */ |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 56 | TEST_F(FirmwareHandlerNotYetStartedTest, GetBlobListValidateListContents) |
| 57 | { |
Patrick Venture | 9b57a4c | 2019-05-28 12:54:09 -0700 | [diff] [blame] | 58 | /* By only checking that the hash and static blob ids are present to start |
| 59 | * with, we're also verifying others aren't. |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 60 | */ |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 61 | EXPECT_THAT(handler->getBlobIds(), |
Patrick Venture | 9a69f73 | 2019-06-17 14:05:13 -0700 | [diff] [blame] | 62 | UnorderedElementsAreArray(startingBlobs)); |
Patrick Venture | 02c0ead | 2019-05-24 09:01:54 -0700 | [diff] [blame] | 63 | |
Patrick Venture | 9b57a4c | 2019-05-28 12:54:09 -0700 | [diff] [blame] | 64 | /* Verify canHandleBlob is reading from the same list (basically) */ |
Patrick Venture | 9a69f73 | 2019-06-17 14:05:13 -0700 | [diff] [blame] | 65 | for (const auto& blob : startingBlobs) |
Patrick Venture | 02c0ead | 2019-05-24 09:01:54 -0700 | [diff] [blame] | 66 | { |
| 67 | EXPECT_TRUE(handler->canHandleBlob(blob)); |
| 68 | } |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 71 | /* stat(blob_id) */ |
| 72 | TEST_F(FirmwareHandlerNotYetStartedTest, StatEachBlobIdVerifyResults) |
| 73 | { |
| 74 | /* In this original state, calling stat() on the blob ids will return the |
Benjamin Fair | 1290198 | 2019-11-12 13:55:46 -0800 | [diff] [blame] | 75 | * idle status |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 76 | */ |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 77 | |
Patrick Venture | 930c7b7 | 2019-05-24 11:11:08 -0700 | [diff] [blame] | 78 | auto blobs = handler->getBlobIds(); |
| 79 | for (const auto& blob : blobs) |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 80 | { |
| 81 | blobs::BlobMeta meta = {}; |
| 82 | EXPECT_TRUE(handler->stat(blob, &meta)); |
Benjamin Fair | 1290198 | 2019-11-12 13:55:46 -0800 | [diff] [blame] | 83 | EXPECT_EQ(expectedIdleMeta, meta); |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 87 | /* open(each blob id) (verifyblobid will no longer be available at this state. |
| 88 | */ |
| 89 | TEST_F(FirmwareHandlerNotYetStartedTest, OpenStaticImageFileVerifyStateChange) |
| 90 | { |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 91 | EXPECT_CALL(*imageMock2, open(staticLayoutBlobId)).WillOnce(Return(true)); |
Patrick Venture | 6d7735d | 2019-06-21 10:03:19 -0700 | [diff] [blame] | 92 | EXPECT_CALL(*prepareMockPtr, trigger()).WillOnce(Return(true)); |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 93 | |
Patrick Venture | 65055fb | 2019-05-23 17:36:01 -0700 | [diff] [blame] | 94 | EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId)); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 95 | |
| 96 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
Patrick Venture | efba42d | 2019-05-24 10:48:16 -0700 | [diff] [blame] | 97 | |
| 98 | EXPECT_TRUE(handler->canHandleBlob(activeImageBlobId)); |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | TEST_F(FirmwareHandlerNotYetStartedTest, OpenHashFileVerifyStateChange) |
| 102 | { |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 103 | EXPECT_CALL(*hashImageMock, open(hashBlobId)).WillOnce(Return(true)); |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 104 | /* Opening the hash blob id doesn't trigger a preparation, only a firmware |
| 105 | * blob. |
| 106 | */ |
| 107 | EXPECT_CALL(*prepareMockPtr, trigger()).Times(0); |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 108 | |
Patrick Venture | 65055fb | 2019-05-23 17:36:01 -0700 | [diff] [blame] | 109 | EXPECT_TRUE(handler->open(session, flags, hashBlobId)); |
Patrick Venture | 6fdd02e | 2019-05-28 13:02:04 -0700 | [diff] [blame] | 110 | |
| 111 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
Patrick Venture | efba42d | 2019-05-24 10:48:16 -0700 | [diff] [blame] | 112 | |
| 113 | EXPECT_TRUE(handler->canHandleBlob(activeHashBlobId)); |
Patrick Venture | b1a8f70 | 2019-05-23 10:10:57 -0700 | [diff] [blame] | 114 | } |
Patrick Venture | 86c2208 | 2019-05-23 09:53:25 -0700 | [diff] [blame] | 115 | |
Patrick Venture | 8a4f2aa | 2019-05-23 08:40:21 -0700 | [diff] [blame] | 116 | } // namespace |
| 117 | } // namespace ipmi_flash |