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 | |
Patrick Venture | 73e2bdf | 2019-05-31 11:21:52 -0700 | [diff] [blame^] | 21 | using ::testing::IsEmpty; |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 22 | using ::testing::Return; |
Patrick Venture | d9a9578 | 2019-05-31 10:46:56 -0700 | [diff] [blame] | 23 | using ::testing::UnorderedElementsAreArray; |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * There are the following calls (parameters may vary): |
| 27 | * canHandleBlob(blob) |
| 28 | * getBlobIds |
| 29 | * deleteBlob(blob) |
| 30 | * stat(blob) |
| 31 | * stat(session) |
| 32 | * open(blob) |
| 33 | * close(session) |
| 34 | * writemeta(session) |
| 35 | * write(session) |
| 36 | * read(session) |
| 37 | * commit(session) |
| 38 | */ |
| 39 | |
| 40 | class FirmwareHandlerUpdateStartedTest : public IpmiOnlyFirmwareStaticTest |
| 41 | { |
| 42 | }; |
| 43 | |
Patrick Venture | f515b9c | 2019-05-31 10:38:16 -0700 | [diff] [blame] | 44 | /* |
| 45 | * open(blob) |
| 46 | */ |
| 47 | TEST_F(FirmwareHandlerUpdateStartedTest, AttemptToOpenFilesReturnsFailure) |
| 48 | { |
| 49 | /* In state updateStarted a file is open, which means no others can be. */ |
| 50 | getToUpdateStarted(); |
| 51 | |
| 52 | auto blobsToOpen = handler->getBlobIds(); |
| 53 | for (const auto& blob : blobsToOpen) |
| 54 | { |
| 55 | EXPECT_FALSE(handler->open(session + 1, flags, blob)); |
| 56 | } |
| 57 | } |
| 58 | |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 59 | /* canHandleBlob(blob) |
| 60 | * getBlobIds |
| 61 | */ |
Patrick Venture | d9a9578 | 2019-05-31 10:46:56 -0700 | [diff] [blame] | 62 | TEST_F(FirmwareHandlerUpdateStartedTest, VerifyListOfBlobs) |
| 63 | { |
| 64 | getToUpdateStarted(); |
| 65 | |
| 66 | std::vector<std::string> expected = {updateBlobId, hashBlobId, |
| 67 | activeImageBlobId, staticLayoutBlobId}; |
| 68 | EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected)); |
| 69 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * TODO: deleteBlob(blob) |
| 73 | */ |
| 74 | |
| 75 | /* |
| 76 | * stat(blob) |
| 77 | */ |
Patrick Venture | fc34cfa | 2019-05-31 11:02:51 -0700 | [diff] [blame] | 78 | TEST_F(FirmwareHandlerUpdateStartedTest, StatOnActiveImageReturnsFailure) |
| 79 | { |
| 80 | getToUpdateStarted(); |
| 81 | |
| 82 | ASSERT_TRUE(handler->canHandleBlob(activeImageBlobId)); |
| 83 | |
| 84 | blobs::BlobMeta meta; |
| 85 | EXPECT_FALSE(handler->stat(activeImageBlobId, &meta)); |
| 86 | } |
| 87 | |
| 88 | TEST_F(FirmwareHandlerUpdateStartedTest, StatOnUpdateBlobReturnsFailure) |
| 89 | { |
| 90 | getToUpdateStarted(); |
| 91 | |
| 92 | ASSERT_TRUE(handler->canHandleBlob(updateBlobId)); |
| 93 | |
| 94 | blobs::BlobMeta meta; |
| 95 | EXPECT_FALSE(handler->stat(updateBlobId, &meta)); |
| 96 | } |
| 97 | |
| 98 | TEST_F(FirmwareHandlerUpdateStartedTest, StatOnNormalBlobsReturnsSuccess) |
| 99 | { |
| 100 | getToUpdateStarted(); |
| 101 | |
| 102 | blobs::BlobMeta expected; |
| 103 | expected.blobState = FirmwareBlobHandler::UpdateFlags::ipmi; |
| 104 | expected.size = 0; |
| 105 | |
| 106 | std::vector<std::string> testBlobs = {staticLayoutBlobId, hashBlobId}; |
| 107 | for (const auto& blob : testBlobs) |
| 108 | { |
| 109 | ASSERT_TRUE(handler->canHandleBlob(blob)); |
| 110 | |
| 111 | blobs::BlobMeta meta = {}; |
| 112 | EXPECT_TRUE(handler->stat(blob, &meta)); |
| 113 | EXPECT_EQ(expected, meta); |
| 114 | } |
| 115 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 116 | |
| 117 | /* |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 118 | * writemeta(session) |
| 119 | */ |
Patrick Venture | b6ce52b | 2019-05-31 11:16:41 -0700 | [diff] [blame] | 120 | TEST_F(FirmwareHandlerUpdateStartedTest, WriteMetaToUpdateBlobReturnsFailure) |
| 121 | { |
| 122 | getToUpdateStarted(); |
| 123 | EXPECT_FALSE(handler->writeMeta(session, 0, {0x01})); |
| 124 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * write(session) |
| 128 | */ |
Patrick Venture | 575118d | 2019-05-31 11:20:35 -0700 | [diff] [blame] | 129 | TEST_F(FirmwareHandlerUpdateStartedTest, WriteToUpdateBlobReturnsFailure) |
| 130 | { |
| 131 | getToUpdateStarted(); |
| 132 | EXPECT_FALSE(handler->write(session, 0, {0x01})); |
| 133 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * read(session) |
| 137 | */ |
Patrick Venture | 73e2bdf | 2019-05-31 11:21:52 -0700 | [diff] [blame^] | 138 | TEST_F(FirmwareHandlerUpdateStartedTest, ReadFromUpdateBlobReturnsEmpty) |
| 139 | { |
| 140 | getToUpdateStarted(); |
| 141 | EXPECT_THAT(handler->read(session, 0, 1), IsEmpty()); |
| 142 | } |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 143 | |
| 144 | /* |
Patrick Venture | b6ce52b | 2019-05-31 11:16:41 -0700 | [diff] [blame] | 145 | * stat(session) - this will trigger a check, and the state may change. |
| 146 | */ |
| 147 | |
| 148 | /* |
| 149 | * TODO: close(session) - this will abort. |
| 150 | */ |
| 151 | |
| 152 | /* |
Patrick Venture | 16ab2a1 | 2019-05-31 08:52:51 -0700 | [diff] [blame] | 153 | * commit(session) |
| 154 | */ |
| 155 | |
| 156 | } // namespace |
| 157 | } // namespace ipmi_flash |