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