Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 1 | #include "data_mock.hpp" |
| 2 | #include "firmware_handler.hpp" |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 3 | #include "flags.hpp" |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -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 | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 7 | |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 8 | #include <memory> |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
| 11 | #include <gtest/gtest.h> |
| 12 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 13 | namespace ipmi_flash |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 14 | { |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 15 | namespace |
| 16 | { |
Patrick Venture | cabc117 | 2018-11-16 16:14:26 -0800 | [diff] [blame] | 17 | using ::testing::_; |
| 18 | using ::testing::IsNull; |
| 19 | using ::testing::NotNull; |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 20 | using ::testing::Return; |
Patrick Venture | cabc117 | 2018-11-16 16:14:26 -0800 | [diff] [blame] | 21 | using ::testing::StrEq; |
| 22 | using ::testing::StrictMock; |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 23 | |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 24 | class FirmwareHandlerCommitTest : public ::testing::Test |
| 25 | { |
| 26 | protected: |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 27 | ImageHandlerMock *imageMock1, *imageMock2; |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 28 | std::vector<HandlerPack> blobs; |
| 29 | std::vector<DataHandlerPack> data; |
| 30 | |
| 31 | void SetUp() override |
| 32 | { |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 33 | std::unique_ptr<ImageHandlerInterface> image = |
| 34 | std::make_unique<ImageHandlerMock>(); |
| 35 | imageMock1 = reinterpret_cast<ImageHandlerMock*>(image.get()); |
Patrick Venture | c6ba8ff | 2020-09-23 12:42:57 -0700 | [diff] [blame] | 36 | blobs.emplace_back(hashBlobId, std::move(image)); |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 37 | |
| 38 | image = std::make_unique<ImageHandlerMock>(); |
| 39 | imageMock2 = reinterpret_cast<ImageHandlerMock*>(image.get()); |
Patrick Venture | c6ba8ff | 2020-09-23 12:42:57 -0700 | [diff] [blame] | 40 | blobs.emplace_back("asdf", std::move(image)); |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 41 | |
Patrick Venture | 4934daa | 2020-09-22 16:37:44 -0700 | [diff] [blame] | 42 | data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 43 | } |
| 44 | }; |
| 45 | |
| 46 | TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 47 | { |
| 48 | /* Verify the flash image returns failure on this command. It's a fairly |
| 49 | * artificial test. |
| 50 | */ |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 51 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | da4d4a4 | 2020-09-28 11:41:05 -0700 | [diff] [blame^] | 52 | std::move(blobs), std::move(data), CreateActionMap("asdf")); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 53 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 54 | EXPECT_CALL(*imageMock2, open("asdf")).WillOnce(Return(true)); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 55 | |
| 56 | EXPECT_TRUE(handler->open( |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 57 | 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 58 | |
| 59 | EXPECT_FALSE(handler->commit(0, {})); |
| 60 | } |
| 61 | |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 62 | TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 63 | { |
| 64 | /* Verify the hash file returns failure on this command. It's a fairly |
| 65 | * artificial test. |
| 66 | */ |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 67 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | da4d4a4 | 2020-09-28 11:41:05 -0700 | [diff] [blame^] | 68 | std::move(blobs), std::move(data), CreateActionMap("asdf")); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 69 | |
Patrick Venture | d4e20de | 2019-07-18 12:48:05 -0700 | [diff] [blame] | 70 | EXPECT_CALL(*imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 71 | |
| 72 | EXPECT_TRUE(handler->open( |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 73 | 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 74 | hashBlobId)); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 75 | |
| 76 | EXPECT_FALSE(handler->commit(0, {})); |
| 77 | } |
| 78 | |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame] | 79 | } // namespace |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 80 | } // namespace ipmi_flash |