blob: 93887d2634d4158275ca54b627a5b68ca688abe1 [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 Venture3ecb3502019-05-17 11:03:51 -07005#include "verification_mock.hpp"
Patrick Venture4eb55952018-11-16 15:36:24 -08006
Patrick Venturead7c73d2019-05-17 18:50:27 -07007#include <memory>
8#include <vector>
9
Patrick Venture8c535332018-11-08 15:58:00 -080010#include <gtest/gtest.h>
11
12namespace blobs
13{
14using ::testing::Eq;
15using ::testing::Return;
16
Patrick Venturead7c73d2019-05-17 18:50:27 -070017class FirmwareHandlerWriteMetaTest : public ::testing::Test
Patrick Venture8c535332018-11-08 15:58:00 -080018{
Patrick Venturead7c73d2019-05-17 18:50:27 -070019 protected:
Patrick Venture8c535332018-11-08 15:58:00 -080020 DataHandlerMock dataMock;
Patrick Venturead7c73d2019-05-17 18:50:27 -070021 ImageHandlerMock imageMock1, imageMock2;
22 std::vector<HandlerPack> blobs;
23 std::vector<DataHandlerPack> data;
24 std::unique_ptr<GenericBlobInterface> handler;
Patrick Venture8c535332018-11-08 15:58:00 -080025
Patrick Venturead7c73d2019-05-17 18:50:27 -070026 void SetUp() override
27 {
28 blobs = {
29 {hashBlobId, &imageMock1},
30 {"asdf", &imageMock2},
31 };
32 data = {
33 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
34 {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
35 };
36 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
37 blobs, data, CreateVerifyMock());
38 }
39};
Patrick Venture8c535332018-11-08 15:58:00 -080040
Patrick Venturead7c73d2019-05-17 18:50:27 -070041TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
42{
Patrick Venture8c535332018-11-08 15:58:00 -080043 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
44
45 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080046 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080047
48 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
49
50 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
51}
52
Patrick Venturead7c73d2019-05-17 18:50:27 -070053TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
Patrick Venture8c535332018-11-08 15:58:00 -080054{
Patrick Venture6e307a72018-11-09 18:21:17 -080055 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080056 EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
57
58 EXPECT_TRUE(handler->open(
Patrick Venture05abf7e2018-11-09 11:02:56 -080059 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080060
61 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
62
Patrick Venture74304642019-01-17 09:31:04 -080063 EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080064 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
65}
66
67} // namespace blobs