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