blob: 65e73bd3a1b74ad507171cee394e28744110eef3 [file] [log] [blame]
Patrick Venture21be45a2018-11-06 12:08:52 -08001#include "firmware_handler.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08002#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07003#include "util.hpp"
Patrick Venture21be45a2018-11-06 12:08:52 -08004
Patrick Venture52854622018-11-06 12:30:00 -08005#include <algorithm>
Patrick Venture4eb55952018-11-16 15:36:24 -08006#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturea78e39f2018-11-06 18:37:06 -08007#include <vector>
Patrick Venture21be45a2018-11-06 12:08:52 -08008
9#include <gtest/gtest.h>
10
11namespace blobs
12{
Patrick Venture52854622018-11-06 12:30:00 -080013
14TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails)
Patrick Venture21be45a2018-11-06 12:08:52 -080015{
Patrick Venture1cde5f92018-11-07 08:26:47 -080016 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080017 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080018 };
19
Patrick Venture4eb55952018-11-16 15:36:24 -080020 sdbusplus::SdBusMock sdbus_mock;
21 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
22
23 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture74059d62019-05-17 10:40:26 -070024 std::move(bus_mock), {}, data, "");
Patrick Venture1cde5f92018-11-07 08:26:47 -080025 EXPECT_EQ(handler, nullptr);
26}
27TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
28{
29 ImageHandlerMock imageMock;
30
31 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070032 {hashBlobId, &imageMock},
Patrick Venture1cde5f92018-11-07 08:26:47 -080033 {"asdf", &imageMock},
34 };
35
Patrick Venture4eb55952018-11-16 15:36:24 -080036 sdbusplus::SdBusMock sdbus_mock;
37 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
38
39 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture74059d62019-05-17 10:40:26 -070040 std::move(bus_mock), blobs, {}, "");
Patrick Venture52854622018-11-06 12:30:00 -080041 EXPECT_EQ(handler, nullptr);
42}
Patrick Venture18235e62018-11-08 10:21:09 -080043TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
Patrick Venture52854622018-11-06 12:30:00 -080044{
Patrick Venture18235e62018-11-08 10:21:09 -080045 /* This works fine only if you also pass in the hash handler. */
Patrick Venturea78e39f2018-11-06 18:37:06 -080046 ImageHandlerMock imageMock;
47
48 std::vector<HandlerPack> blobs = {
49 {"asdf", &imageMock},
50 };
Patrick Venture1cde5f92018-11-07 08:26:47 -080051 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080052 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080053 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080054
Patrick Venture4eb55952018-11-16 15:36:24 -080055 sdbusplus::SdBusMock sdbus_mock;
56 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
57
58 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture74059d62019-05-17 10:40:26 -070059 std::move(bus_mock), blobs, data, "");
Patrick Venture18235e62018-11-08 10:21:09 -080060 EXPECT_EQ(handler, nullptr);
61
Patrick Venture7dad86f2019-05-17 08:52:20 -070062 blobs.push_back({hashBlobId, &imageMock});
Patrick Venture18235e62018-11-08 10:21:09 -080063
Patrick Venture4eb55952018-11-16 15:36:24 -080064 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture74059d62019-05-17 10:40:26 -070065 std::move(bus_mock), blobs, data, "");
Patrick Venture21be45a2018-11-06 12:08:52 -080066 auto result = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080067 EXPECT_EQ(3, result.size());
68 EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") +
Patrick Venture7dad86f2019-05-17 08:52:20 -070069 std::count(result.begin(), result.end(), hashBlobId) +
70 std::count(result.begin(), result.end(), verifyBlobId));
Patrick Venture21be45a2018-11-06 12:08:52 -080071}
72} // namespace blobs