blob: 512754ad22599aa3416e26537c9fa1640ee89268 [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{
Patrick Ventured4e20de2019-07-18 12:48:05 -070015namespace
16{
17
Patrick Venture8c535332018-11-08 15:58:00 -080018using ::testing::Eq;
19using ::testing::Return;
20
Patrick Venture1361a122019-05-20 07:36:05 -070021class FirmwareHandlerWriteMetaTest : public FakeLpcFirmwareTest
Patrick Venture9b37b092020-05-28 20:58:57 -070022{};
Patrick Venture8c535332018-11-08 15:58:00 -080023
Patrick Venturead7c73d2019-05-17 18:50:27 -070024TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
25{
Patrick Ventured4e20de2019-07-18 12:48:05 -070026 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080027
28 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070029 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080030
31 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
32
33 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
34}
35
Patrick Venturead7c73d2019-05-17 18:50:27 -070036TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
Patrick Venture8c535332018-11-08 15:58:00 -080037{
Patrick Venture4934daa2020-09-22 16:37:44 -070038 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true));
Patrick Ventured4e20de2019-07-18 12:48:05 -070039 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080040
41 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070042 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080043
44 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
45
Patrick Venture4934daa2020-09-22 16:37:44 -070046 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 Ventured4e20de2019-07-18 12:48:05 -070050} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070051} // namespace ipmi_flash