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