blob: 491d669792885bb7023ba3dd18a38677c9f4cc5e [file] [log] [blame]
Patrick Venture8c535332018-11-08 15:58:00 -08001#include "data_mock.hpp"
2#include "firmware_handler.hpp"
Patrick Venture1361a122019-05-20 07:36:05 -07003#include "firmware_unittest.hpp"
Patrick Venture8c535332018-11-08 15:58:00 -08004#include "image_mock.hpp"
Patrick Venture1d66fe62019-06-03 14:57:27 -07005#include "triggerable_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07006#include "util.hpp"
Patrick Venture4eb55952018-11-16 15:36:24 -08007
Patrick Venturead7c73d2019-05-17 18:50:27 -07008#include <memory>
9#include <vector>
10
Patrick Venture8c535332018-11-08 15:58:00 -080011#include <gtest/gtest.h>
12
Patrick Venture1d5a31c2019-05-20 11:38:22 -070013namespace ipmi_flash
Patrick Venture8c535332018-11-08 15:58:00 -080014{
15using ::testing::Eq;
16using ::testing::Return;
17
Patrick Venture1361a122019-05-20 07:36:05 -070018class FirmwareHandlerWriteMetaTest : public FakeLpcFirmwareTest
Patrick Venture8c535332018-11-08 15:58:00 -080019{
Patrick Venturead7c73d2019-05-17 18:50:27 -070020};
Patrick Venture8c535332018-11-08 15:58:00 -080021
Patrick Venturead7c73d2019-05-17 18:50:27 -070022TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
23{
Patrick Venture1361a122019-05-20 07:36:05 -070024 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080025
26 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070027 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi,
28 "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080029
30 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
31
32 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
33}
34
Patrick Venturead7c73d2019-05-17 18:50:27 -070035TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
Patrick Venture8c535332018-11-08 15:58:00 -080036{
Patrick Venture6e307a72018-11-09 18:21:17 -080037 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Venture1361a122019-05-20 07:36:05 -070038 EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080039
40 EXPECT_TRUE(handler->open(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070041 0, blobs::OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc,
42 "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080043
44 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
45
Patrick Venture74304642019-01-17 09:31:04 -080046 EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080047 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
48}
49
Patrick Venture1d5a31c2019-05-20 11:38:22 -070050} // namespace ipmi_flash