Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 1 | #include "firmware_handler.hpp" |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 2 | #include "image_mock.hpp" |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 3 | |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 4 | #include <algorithm> |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 5 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 6 | #include <vector> |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace blobs |
| 11 | { |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 12 | |
| 13 | TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails) |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 14 | { |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 15 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 16 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 17 | }; |
| 18 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 19 | sdbusplus::SdBusMock sdbus_mock; |
| 20 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 21 | |
| 22 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 23 | std::move(bus_mock), {}, data); |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 24 | EXPECT_EQ(handler, nullptr); |
| 25 | } |
| 26 | TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails) |
| 27 | { |
| 28 | ImageHandlerMock imageMock; |
| 29 | |
| 30 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 31 | {FirmwareBlobHandler::hashBlobID, &imageMock}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 32 | {"asdf", &imageMock}, |
| 33 | }; |
| 34 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 35 | sdbusplus::SdBusMock sdbus_mock; |
| 36 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 37 | |
| 38 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 39 | std::move(bus_mock), blobs, {}); |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 40 | EXPECT_EQ(handler, nullptr); |
| 41 | } |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 42 | TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness) |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 43 | { |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 44 | /* This works fine only if you also pass in the hash handler. */ |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 45 | ImageHandlerMock imageMock; |
| 46 | |
| 47 | std::vector<HandlerPack> blobs = { |
| 48 | {"asdf", &imageMock}, |
| 49 | }; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 50 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 51 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 52 | }; |
Patrick Venture | a78e39f | 2018-11-06 18:37:06 -0800 | [diff] [blame] | 53 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 54 | sdbusplus::SdBusMock sdbus_mock; |
| 55 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 56 | |
| 57 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 58 | std::move(bus_mock), blobs, data); |
Patrick Venture | 18235e6 | 2018-11-08 10:21:09 -0800 | [diff] [blame] | 59 | EXPECT_EQ(handler, nullptr); |
| 60 | |
| 61 | blobs.push_back({FirmwareBlobHandler::hashBlobID, &imageMock}); |
| 62 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 63 | handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
| 64 | std::move(bus_mock), blobs, data); |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 65 | auto result = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 66 | EXPECT_EQ(3, result.size()); |
| 67 | EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") + |
Patrick Venture | 5285462 | 2018-11-06 12:30:00 -0800 | [diff] [blame] | 68 | std::count(result.begin(), result.end(), |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 69 | FirmwareBlobHandler::hashBlobID) + |
| 70 | std::count(result.begin(), result.end(), |
| 71 | FirmwareBlobHandler::verifyBlobID)); |
Patrick Venture | 21be45a | 2018-11-06 12:08:52 -0800 | [diff] [blame] | 72 | } |
| 73 | } // namespace blobs |