Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 1 | #include "data_mock.hpp" |
| 2 | #include "firmware_handler.hpp" |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 3 | #include "firmware_unittest.hpp" |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 4 | #include "image_mock.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 5 | #include "util.hpp" |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 6 | #include "verification_mock.hpp" |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 7 | |
Patrick Venture | 7941258 | 2019-05-17 17:34:45 -0700 | [diff] [blame] | 8 | #include <memory> |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
| 11 | #include <gmock/gmock.h> |
| 12 | #include <gtest/gtest.h> |
| 13 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 14 | namespace ipmi_flash |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 15 | { |
| 16 | using ::testing::Eq; |
| 17 | using ::testing::Return; |
| 18 | using ::testing::StrEq; |
| 19 | |
Patrick Venture | 1361a12 | 2019-05-20 07:36:05 -0700 | [diff] [blame] | 20 | class FirmwareHandlerCloseTest : public FakeLpcFirmwareTest |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 21 | { |
Patrick Venture | 7941258 | 2019-05-17 17:34:45 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithDataHandler) |
| 25 | { |
| 26 | /* Boring test where you open a blob_id, then verify that when it's closed |
| 27 | * everything looks right. |
| 28 | */ |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 29 | EXPECT_CALL(dataMock, open()).WillOnce(Return(true)); |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 30 | EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 31 | |
| 32 | EXPECT_TRUE(handler->open( |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 33 | 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 34 | hashBlobId)); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 35 | |
| 36 | /* The active hash blob_id was added. */ |
| 37 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 38 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 39 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 40 | activeHashBlobId)); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 41 | |
| 42 | /* Set up close() expectations. */ |
| 43 | EXPECT_CALL(dataMock, close()); |
| 44 | EXPECT_CALL(imageMock, close()); |
| 45 | EXPECT_TRUE(handler->close(0)); |
| 46 | |
| 47 | /* Close does not delete the active blob id. This indicates that there is |
| 48 | * data queued. |
| 49 | */ |
| 50 | } |
| 51 | |
Patrick Venture | 7941258 | 2019-05-17 17:34:45 -0700 | [diff] [blame] | 52 | TEST_F(FirmwareHandlerCloseTest, CloseSucceedsWithoutDataHandler) |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 53 | { |
| 54 | /* Boring test where you open a blob_id using ipmi, so there's no data |
| 55 | * handler, and it's closed and everything looks right. |
| 56 | */ |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 57 | EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 58 | |
| 59 | EXPECT_TRUE(handler->open( |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 60 | 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 61 | hashBlobId)); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 62 | |
| 63 | /* The active hash blob_id was added. */ |
| 64 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 65 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 66 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 67 | activeHashBlobId)); |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 68 | |
| 69 | /* Set up close() expectations. */ |
| 70 | EXPECT_CALL(imageMock, close()); |
| 71 | EXPECT_TRUE(handler->close(0)); |
| 72 | } |
| 73 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame^] | 74 | } // namespace ipmi_flash |