| #include "flash-ipmi.hpp" |
| #include "ipmi.hpp" |
| |
| #include "updater_mock.hpp" |
| |
| #include <cstring> |
| #include <gtest/gtest.h> |
| |
| using ::testing::ElementsAreArray; |
| using ::testing::Return; |
| using ::testing::StrictMock; |
| |
| // ipmid.hpp isn't installed where we can grab it and this value is per BMC |
| // SoC. |
| #define MAX_IPMI_BUFFER 64 |
| |
| TEST(IpmiFlashData, DataReceivedIsPassedOnOk) |
| { |
| // If valid data was passed in, it'll pass it onto the update handler. |
| |
| StrictMock<UpdaterMock> updater; |
| |
| size_t dataLen; |
| uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| |
| struct ChunkHdr tx; |
| tx.cmd = FlashSubCmds::flashDataBlock; |
| tx.offset = 0x00; |
| std::memcpy(request, &tx, sizeof(tx)); |
| |
| uint8_t bytes[] = {0x04, 0x05}; |
| std::memcpy(&request[sizeof(struct ChunkHdr)], bytes, sizeof(bytes)); |
| |
| dataLen = sizeof(struct ChunkHdr) + sizeof(bytes); |
| |
| EXPECT_CALL(updater, |
| flashData(0x00, ElementsAreArray(bytes, sizeof(bytes)))) |
| .WillOnce(Return(true)); |
| |
| EXPECT_EQ(IPMI_CC_OK, dataBlock(&updater, request, reply, &dataLen)); |
| EXPECT_EQ(sizeof(uint8_t), dataLen); |
| EXPECT_EQ(0, reply[0]); |
| } |