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