blob: ef292b0020b70597396eb8fac99c43cbd36f184e [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 Venture8c535332018-11-08 15:58:00 -080022{
Patrick Venturead7c73d2019-05-17 18:50:27 -070023};
Patrick Venture8c535332018-11-08 15:58:00 -080024
Patrick Venturead7c73d2019-05-17 18:50:27 -070025TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
26{
Patrick Ventured4e20de2019-07-18 12:48:05 -070027 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080028
29 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070030 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080031
32 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
33
34 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
35}
36
Patrick Venturead7c73d2019-05-17 18:50:27 -070037TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
Patrick Venture8c535332018-11-08 15:58:00 -080038{
Patrick Venture6e307a72018-11-09 18:21:17 -080039 EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
Patrick Ventured4e20de2019-07-18 12:48:05 -070040 EXPECT_CALL(*imageMock, open("asdf")).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080041
42 EXPECT_TRUE(handler->open(
Patrick Venture84778b82019-06-26 20:11:09 -070043 0, blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::lpc, "asdf"));
Patrick Venture8c535332018-11-08 15:58:00 -080044
45 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
46
Patrick Venture74304642019-01-17 09:31:04 -080047 EXPECT_CALL(dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
Patrick Venture8c535332018-11-08 15:58:00 -080048 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
49}
50
Patrick Ventured4e20de2019-07-18 12:48:05 -070051} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070052} // namespace ipmi_flash