1 #include "data_mock.hpp"
2 #include "firmware_handler.hpp"
3 #include "firmware_unittest.hpp"
4 #include "image_mock.hpp"
5 #include "triggerable_mock.hpp"
6 #include "util.hpp"
7
8 #include <memory>
9 #include <vector>
10
11 #include <gtest/gtest.h>
12
13 namespace ipmi_flash
14 {
15 namespace
16 {
17
18 using ::testing::Eq;
19 using ::testing::Return;
20
21 class FirmwareHandlerWriteMetaTest : public FakeLpcFirmwareTest
22 {};
23
TEST_F(FirmwareHandlerWriteMetaTest,WriteConfigParametersFailIfOverIPMI)24 TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersFailIfOverIPMI)
25 {
26 EXPECT_CALL(*imageMock, open("asdf", std::ios::out)).WillOnce(Return(true));
27
28 EXPECT_TRUE(
29 handler->open(0,
30 static_cast<std::uint16_t>(blobs::OpenFlags::write) |
31 FirmwareFlags::UpdateFlags::ipmi,
32 "asdf"));
33
34 std::vector<std::uint8_t> bytes = {0xaa, 0x55};
35
36 EXPECT_FALSE(handler->writeMeta(0, 0, bytes));
37 }
38
TEST_F(FirmwareHandlerWriteMetaTest,WriteConfigParametersPassedThrough)39 TEST_F(FirmwareHandlerWriteMetaTest, WriteConfigParametersPassedThrough)
40 {
41 EXPECT_CALL(*dataMock, open()).WillOnce(Return(true));
42 EXPECT_CALL(*imageMock, open("asdf", std::ios::out)).WillOnce(Return(true));
43
44 EXPECT_TRUE(
45 handler->open(0,
46 static_cast<std::uint16_t>(blobs::OpenFlags::write) |
47 FirmwareFlags::UpdateFlags::lpc,
48 "asdf"));
49
50 std::vector<std::uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
51
52 EXPECT_CALL(*dataMock, writeMeta(Eq(bytes))).WillOnce(Return(true));
53 EXPECT_TRUE(handler->writeMeta(0, 0, bytes));
54 }
55
56 } // namespace
57 } // namespace ipmi_flash
58