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" |
| 4 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 5 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 6 | |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | namespace blobs |
| 10 | { |
| 11 | using ::testing::Eq; |
| 12 | using ::testing::Return; |
| 13 | |
| 14 | TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI) |
| 15 | { |
| 16 | ImageHandlerMock imageMock1, imageMock2; |
| 17 | std::vector<HandlerPack> blobs = { |
| 18 | {FirmwareBlobHandler::hashBlobID, &imageMock1}, |
| 19 | {"asdf", &imageMock2}, |
| 20 | }; |
| 21 | |
| 22 | DataHandlerMock dataMock; |
| 23 | |
| 24 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 25 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 26 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 27 | }; |
| 28 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 29 | sdbusplus::SdBusMock sdbus_mock; |
| 30 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 31 | |
| 32 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 33 | std::move(bus_mock), blobs, data); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 34 | |
| 35 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 36 | |
| 37 | EXPECT_TRUE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 38 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 39 | |
| 40 | std::vector<std::uint8_t> bytes = {0xaa, 0x55}; |
| 41 | |
| 42 | EXPECT_FALSE(handler->writeMeta(0, 0, bytes)); |
| 43 | } |
| 44 | |
| 45 | TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough) |
| 46 | { |
| 47 | ImageHandlerMock imageMock1, imageMock2; |
| 48 | std::vector<HandlerPack> blobs = { |
| 49 | {FirmwareBlobHandler::hashBlobID, &imageMock1}, |
| 50 | {"asdf", &imageMock2}, |
| 51 | }; |
| 52 | |
| 53 | DataHandlerMock dataMock; |
| 54 | |
| 55 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 56 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 57 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 60 | sdbusplus::SdBusMock sdbus_mock; |
| 61 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 62 | |
| 63 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 64 | std::move(bus_mock), blobs, data); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 65 | |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 66 | EXPECT_CALL(dataMock, open()).WillOnce(Return(true)); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 67 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 68 | |
| 69 | EXPECT_TRUE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 70 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf")); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 71 | |
| 72 | std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04}; |
| 73 | |
Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 74 | EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true)); |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 75 | EXPECT_TRUE(handler->writeMeta(0, 0, bytes)); |
| 76 | } |
| 77 | |
| 78 | } // namespace blobs |