Patrick Venture | 0cd945c | 2019-05-30 13:36:53 -0700 | [diff] [blame] | 1 | /* The goal of these tests is to verify the behavior of all blob commands given |
| 2 | * the current state is updatePending. This state is achieved as an exit from |
| 3 | * verificationCompleted. |
| 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 | ad93383 | 2019-05-30 14:13:29 -0700 | [diff] [blame^] | 22 | using ::testing::UnorderedElementsAreArray; |
Patrick Venture | 0cd945c | 2019-05-30 13:36:53 -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 | * Testing canHandleBlob is uninteresting in this state. Getting the BlobIDs |
| 39 | * will inform what canHandleBlob will return. |
| 40 | */ |
| 41 | |
| 42 | class FirmwareHandlerUpdatePendingTest : public IpmiOnlyFirmwareStaticTest |
| 43 | { |
| 44 | protected: |
| 45 | void getToUpdatePending() |
| 46 | { |
| 47 | /* The hash was not sent up, as it's technically optional. Therefore, |
| 48 | * there is no active hash file. |
| 49 | */ |
| 50 | EXPECT_CALL(imageMock, open(staticLayoutBlobId)).WillOnce(Return(true)); |
| 51 | EXPECT_TRUE(handler->open(session, flags, staticLayoutBlobId)); |
| 52 | expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress); |
| 53 | |
| 54 | EXPECT_CALL(imageMock, close()).WillRepeatedly(Return()); |
| 55 | handler->close(session); |
| 56 | expectedState(FirmwareBlobHandler::UpdateState::verificationPending); |
| 57 | |
| 58 | EXPECT_TRUE(handler->open(session, flags, verifyBlobId)); |
| 59 | EXPECT_CALL(*verifyMockPtr, triggerVerification()) |
| 60 | .WillOnce(Return(true)); |
| 61 | |
| 62 | EXPECT_TRUE(handler->commit(session, {})); |
| 63 | expectedState(FirmwareBlobHandler::UpdateState::verificationStarted); |
| 64 | |
| 65 | EXPECT_CALL(*verifyMockPtr, checkVerificationState()) |
| 66 | .WillOnce(Return(VerifyCheckResponses::success)); |
| 67 | blobs::BlobMeta meta; |
| 68 | EXPECT_TRUE(handler->stat(session, &meta)); |
| 69 | expectedState(FirmwareBlobHandler::UpdateState::verificationCompleted); |
| 70 | |
| 71 | handler->close(session); |
| 72 | expectedState(FirmwareBlobHandler::UpdateState::updatePending); |
| 73 | } |
| 74 | |
| 75 | std::uint16_t session = 1; |
| 76 | std::uint16_t flags = |
| 77 | blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi; |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * There are the following calls (parameters may vary): |
| 82 | * canHandleBlob(blob) |
| 83 | * getBlobIds |
| 84 | */ |
Patrick Venture | ad93383 | 2019-05-30 14:13:29 -0700 | [diff] [blame^] | 85 | TEST_F(FirmwareHandlerUpdatePendingTest, GetBlobsListHasExpectedValues) |
| 86 | { |
| 87 | getToUpdatePending(); |
| 88 | |
| 89 | std::vector<std::string> expected = {updateBlobId, activeImageBlobId, |
| 90 | hashBlobId, staticLayoutBlobId}; |
| 91 | EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected)); |
| 92 | } |
| 93 | |
Patrick Venture | 0cd945c | 2019-05-30 13:36:53 -0700 | [diff] [blame] | 94 | /* |
| 95 | * deleteBlob(blob) |
| 96 | */ |
| 97 | |
| 98 | /* |
| 99 | * stat(blob) |
| 100 | */ |
| 101 | |
| 102 | /* |
| 103 | * stat(session) |
| 104 | */ |
| 105 | |
| 106 | /* |
| 107 | * open(blob) |
| 108 | */ |
| 109 | |
| 110 | /* |
| 111 | * close(session) |
| 112 | */ |
| 113 | |
| 114 | /* |
| 115 | * writemeta(session) |
| 116 | */ |
| 117 | |
| 118 | /* |
| 119 | * write(session) |
| 120 | */ |
| 121 | |
| 122 | /* |
| 123 | * read(session) |
| 124 | */ |
| 125 | |
| 126 | /* |
| 127 | * commit(session) |
| 128 | */ |
| 129 | |
| 130 | } // namespace |
| 131 | } // namespace ipmi_flash |