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: |
| 27 | ImageHandlerMock imageMock1, imageMock2; |
| 28 | std::vector<HandlerPack> blobs; |
| 29 | std::vector<DataHandlerPack> data; |
| 30 | |
| 31 | void SetUp() override |
| 32 | { |
| 33 | blobs = { |
| 34 | {hashBlobId, &imageMock1}, |
| 35 | {"asdf", &imageMock2}, |
| 36 | }; |
| 37 | |
| 38 | data = { |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 39 | {FirmwareFlags::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 40 | }; |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnFlashImage) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 45 | { |
| 46 | /* Verify the flash image returns failure on this command. It's a fairly |
| 47 | * artificial test. |
| 48 | */ |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 49 | |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 50 | /* Verify it doesn't get called by using StrictMock. */ |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 51 | std::unique_ptr<TriggerableActionInterface> verifyMock = |
| 52 | std::make_unique<StrictMock<TriggerMock>>(); |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 53 | |
| 54 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame^] | 55 | blobs, data, std::move(CreateActionMap("asdf"))); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 56 | |
| 57 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 58 | |
| 59 | EXPECT_TRUE(handler->open( |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 60 | 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 61 | |
| 62 | EXPECT_FALSE(handler->commit(0, {})); |
| 63 | } |
| 64 | |
Patrick Venture | 481cd4a | 2019-05-17 17:53:11 -0700 | [diff] [blame] | 65 | TEST_F(FirmwareHandlerCommitTest, VerifyCannotCommitOnHashFile) |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 66 | { |
| 67 | /* Verify the hash file returns failure on this command. It's a fairly |
| 68 | * artificial test. |
| 69 | */ |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 70 | |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 71 | /* Verify it doesn't get called by using StrictMock. */ |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 72 | std::unique_ptr<TriggerableActionInterface> verifyMock = |
| 73 | std::make_unique<StrictMock<TriggerMock>>(); |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 74 | |
| 75 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame^] | 76 | blobs, data, std::move(CreateActionMap("asdf"))); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 77 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 78 | EXPECT_CALL(imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 79 | |
| 80 | EXPECT_TRUE(handler->open( |
Patrick Venture | 84778b8 | 2019-06-26 20:11:09 -0700 | [diff] [blame] | 81 | 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 82 | hashBlobId)); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 83 | |
| 84 | EXPECT_FALSE(handler->commit(0, {})); |
| 85 | } |
| 86 | |
Patrick Venture | fa06a5f | 2019-07-01 09:22:38 -0700 | [diff] [blame^] | 87 | } // namespace |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 88 | } // namespace ipmi_flash |