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