Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 1 | /* The goal of these tests is to verify the behavior of all blob commands given |
| 2 | * the current state is updateStarted. This state is achieved as an exit from |
| 3 | * updatePending. |
| 4 | */ |
| 5 | #include "firmware_handler.hpp" |
| 6 | #include "firmware_unittest.hpp" |
| 7 | #include "status.hpp" |
| 8 | #include "util.hpp" |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
| 14 | #include <gtest/gtest.h> |
| 15 | |
| 16 | namespace ipmi_flash |
| 17 | { |
| 18 | namespace |
| 19 | { |
| 20 | |
| 21 | using ::testing::Return; |
Patrick Venture | d9a9578 | 2019-05-31 10:46:56 -0700 | [diff] [blame] | 22 | using ::testing::UnorderedElementsAreArray; |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * There are the following calls (parameters may vary): |
| 26 | * canHandleBlob(blob) |
| 27 | * getBlobIds |
| 28 | * deleteBlob(blob) |
| 29 | * stat(blob) |
| 30 | * stat(session) |
| 31 | * open(blob) |
| 32 | * close(session) |
| 33 | * writemeta(session) |
| 34 | * write(session) |
| 35 | * read(session) |
| 36 | * commit(session) |
| 37 | */ |
| 38 | |
| 39 | class FirmwareHandlerUpdateStartedTest : public IpmiOnlyFirmwareStaticTest |
| 40 | { |
| 41 | }; |
| 42 | |
Patrick Venture | f515b9c | 2019-05-31 10:38:16 -0700 | [diff] [blame] | 43 | /* |
| 44 | * open(blob) |
| 45 | */ |
| 46 | TEST_F(FirmwareHandlerUpdateStartedTest, AttemptToOpenFilesReturnsFailure) |
| 47 | { |
| 48 | /* In state updateStarted a file is open, which means no others can be. */ |
| 49 | getToUpdateStarted(); |
| 50 | |
| 51 | auto blobsToOpen = handler->getBlobIds(); |
| 52 | for (const auto& blob : blobsToOpen) |
| 53 | { |
| 54 | EXPECT_FALSE(handler->open(session + 1, flags, blob)); |
| 55 | } |
| 56 | } |
| 57 | |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 58 | /* canHandleBlob(blob) |
| 59 | * getBlobIds |
| 60 | */ |
Patrick Venture | d9a9578 | 2019-05-31 10:46:56 -0700 | [diff] [blame] | 61 | TEST_F(FirmwareHandlerUpdateStartedTest, VerifyListOfBlobs) |
| 62 | { |
| 63 | getToUpdateStarted(); |
| 64 | |
| 65 | std::vector<std::string> expected = {updateBlobId, hashBlobId, |
| 66 | activeImageBlobId, staticLayoutBlobId}; |
| 67 | EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected)); |
| 68 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * TODO: deleteBlob(blob) |
| 72 | */ |
| 73 | |
| 74 | /* |
| 75 | * stat(blob) |
| 76 | */ |
Patrick Venture | fc34cfa | 2019-05-31 11:02:51 -0700 | [diff] [blame] | 77 | TEST_F(FirmwareHandlerUpdateStartedTest, StatOnActiveImageReturnsFailure) |
| 78 | { |
| 79 | getToUpdateStarted(); |
| 80 | |
| 81 | ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId)); |
| 82 | |
| 83 | blobs::BlobMeta meta; |
| 84 | EXPECT_FALSE(handler->stat(activeImageBlobId, &meta)); |
| 85 | } |
| 86 | |
| 87 | TEST_F(FirmwareHandlerUpdateStartedTest, StatOnUpdateBlobReturnsFailure) |
| 88 | { |
| 89 | getToUpdateStarted(); |
| 90 | |
| 91 | ASSERT_TRUE(handler->canHandleBlob(updateBlobId)); |
| 92 | |
| 93 | blobs::BlobMeta meta; |
| 94 | EXPECT_FALSE(handler->stat(updateBlobId, &meta)); |
| 95 | } |
| 96 | |
| 97 | TEST_F(FirmwareHandlerUpdateStartedTest, StatOnNormalBlobsReturnsSuccess) |
| 98 | { |
| 99 | getToUpdateStarted(); |
| 100 | |
| 101 | blobs::BlobMeta expected; |
| 102 | expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi; |
| 103 | expected.size = 0; |
| 104 | |
| 105 | std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId}; |
| 106 | for (const auto& blob : testBlobs) |
| 107 | { |
| 108 | ASSERT_TRUE(handler->canHandleBlob(blob)); |
| 109 | |
| 110 | blobs::BlobMeta meta = {}; |
| 111 | EXPECT_TRUE(handler->stat(blob, &meta)); |
| 112 | EXPECT_EQ(expected, meta); |
| 113 | } |
| 114 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 115 | |
| 116 | /* |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 117 | * writemeta(session) |
| 118 | */ |
Patrick Venture | b6ce52b | 2019-05-31 11:16:41 -0700 | [diff] [blame^] | 119 | TEST_F(FirmwareHandlerUpdateStartedTest, WriteMetaToUpdateBlobReturnsFailure) |
| 120 | { |
| 121 | getToUpdateStarted(); |
| 122 | EXPECT_FALSE(handler->writeMeta(session, 0, {0x01})); |
| 123 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * write(session) |
| 127 | */ |
| 128 | |
| 129 | /* |
| 130 | * read(session) |
| 131 | */ |
| 132 | |
| 133 | /* |
Patrick Venture | b6ce52b | 2019-05-31 11:16:41 -0700 | [diff] [blame^] | 134 | * stat(session) - this will trigger a check, and the state may change. |
| 135 | */ |
| 136 | |
| 137 | /* |
| 138 | * TODO: close(session) - this will abort. |
| 139 | */ |
| 140 | |
| 141 | /* |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 142 | * commit(session) |
| 143 | */ |
| 144 | |
| 145 | } // namespace |
| 146 | } // namespace ipmi_flash |