blob: ad7f25b77186084cb4ee171eb2a0328a4c7aa886 [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"
Patrick Venture7dad86f2019-05-17 08:52:20 -07004#include "util.hpp"
Patrick Venture8c535332018-11-08 15:58:00 -08005
Patrick Venture4eb55952018-11-16 15:36:24 -08006#include <sdbusplus/test/sdbus_mock.hpp>
7
Patrick Venture8c535332018-11-08 15:58:00 -08008#include <gtest/gtest.h>
9
10namespace blobs
11{
12using ::testing::Eq;
13using ::testing::Return;
14
15TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
16{
17 ImageHandlerMock imageMock1, imageMock2;
18 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070019 {hashBlobId, &imageMock1},
Patrick Venture8c535332018-11-08 15:58:00 -080020 {"asdf", &imageMock2},
21 };
22
23 DataHandlerMock dataMock;
24
25 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080026 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
27 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
Patrick Venture8c535332018-11-08 15:58:00 -080028 };
29
Patrick Venture4eb55952018-11-16 15:36:24 -080030 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 Venture8c535332018-11-08 15:58:00 -080035
36 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
37
38 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080039 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080040
41 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
42
43 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
44}
45
46TEST(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
47{
48 ImageHandlerMock imageMock1, imageMock2;
49 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070050 {hashBlobId, &imageMock1},
Patrick Venture8c535332018-11-08 15:58:00 -080051 {"asdf", &imageMock2},
52 };
53
54 DataHandlerMock dataMock;
55
56 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080057 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
58 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
Patrick Venture8c535332018-11-08 15:58:00 -080059 };
60
Patrick Venture4eb55952018-11-16 15:36:24 -080061 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 Venture8c535332018-11-08 15:58:00 -080066
Patrick Venture6e307a72018-11-09 18:21:17 -080067 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080068 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
69
70 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080071 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080072
73 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
74
Patrick Venture74304642019-01-17 09:31:04 -080075 EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080076 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
77}
78
79} // namespace blobs