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