blob: 869ed48fb5e5a140b8aae06374fdf412f500b7d7 [file] [log] [blame]
Patrick Venture8c535332018-11-08 15:58:00 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
3#include "image_mock.hpp"
4
Patrick Venture4eb55952018-11-16 15:36:24 -08005#include <sdbusplus/test/sdbus_mock.hpp>
6
Patrick Venture8c535332018-11-08 15:58:00 -08007#include <gtest/gtest.h>
8
9namespace blobs
10{
11using ::testing::Eq;
12using ::testing::Return;
13
14TEST(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 Venture05abf7e2018-11-09 11:02:56 -080025 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
26 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
Patrick Venture8c535332018-11-08 15:58:00 -080027 };
28
Patrick Venture4eb55952018-11-16 15:36:24 -080029 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 Venture8c535332018-11-08 15:58:00 -080034
35 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
36
37 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080038 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080039
40 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
41
42 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
43}
44
45TEST(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 Venture05abf7e2018-11-09 11:02:56 -080056 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
57 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
Patrick Venture8c535332018-11-08 15:58:00 -080058 };
59
Patrick Venture4eb55952018-11-16 15:36:24 -080060 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 Venture8c535332018-11-08 15:58:00 -080065
Patrick Venture6e307a72018-11-09 18:21:17 -080066 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080067 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
68
69 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080070 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080071
72 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
73
74 EXPECT_CALL(dataMock, write(Eq(bytes))).WillOnce(Return(true));
75 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
76}
77
78} // namespace blobs