Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 1 | #include "data_mock.hpp" |
| 2 | #include "firmware_handler.hpp" |
| 3 | #include "image_mock.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 4 | #include "util.hpp" |
Patrick Venture | 3ecb350 | 2019-05-17 11:03:51 -0700 | [diff] [blame] | 5 | #include "verification_mock.hpp" |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 6 | |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 7 | #include <memory> |
| 8 | #include <vector> |
| 9 | |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | namespace blobs |
| 13 | { |
| 14 | using ::testing::Eq; |
| 15 | using ::testing::Return; |
| 16 | |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 17 | class FirmwareHandlerWriteMetaTest : public ::testing::Test |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 18 | { |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 19 | protected: |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 20 | DataHandlerMock dataMock; |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 21 | ImageHandlerMock imageMock1, imageMock2; |
| 22 | std::vector<HandlerPack> blobs; |
| 23 | std::vector<DataHandlerPack> data; |
| 24 | std::unique_ptr<GenericBlobInterface> handler; |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 25 | |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 26 | void SetUp() override |
| 27 | { |
| 28 | blobs = { |
| 29 | {hashBlobId, &imageMock1}, |
| 30 | {"asdf", &imageMock2}, |
| 31 | }; |
| 32 | data = { |
| 33 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 34 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
| 35 | }; |
| 36 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 37 | blobs, data, CreateVerifyMock()); |
| 38 | } |
| 39 | }; |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 40 | |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 41 | TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI) |
| 42 | { |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 43 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 44 | |
| 45 | EXPECT_TRUE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 46 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 47 | |
| 48 | std::vector<std::uint8_t> bytes = {0xaa, 0x55}; |
| 49 | |
| 50 | EXPECT_FALSE(handler->writeMeta(0, 0, bytes)); |
| 51 | } |
| 52 | |
Patrick Venture | ad7c73d | 2019-05-17 18:50:27 -0700 | [diff] [blame^] | 53 | TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough) |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 54 | { |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 55 | EXPECT_CALL(dataMock, open()).WillOnce(Return(true)); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 56 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 57 | |
| 58 | EXPECT_TRUE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 59 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf")); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 60 | |
| 61 | std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04}; |
| 62 | |
Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 63 | EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true)); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 64 | EXPECT_TRUE(handler->writeMeta(0, 0, bytes)); |
| 65 | } |
| 66 | |
| 67 | } // namespace blobs |