Patrick Venture | 79e131f | 2018-08-01 13:34:35 -0700 | [diff] [blame] | 1 | #include "flash-ipmi.hpp" |
| 2 | #include "ipmi.hpp" |
| 3 | |
| 4 | #include "updater_mock.hpp" |
| 5 | |
| 6 | #include <cstring> |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | using ::testing::ElementsAreArray; |
| 10 | using ::testing::Return; |
| 11 | using ::testing::StrictMock; |
| 12 | |
| 13 | // ipmid.hpp isn't installed where we can grab it and this value is per BMC |
| 14 | // SoC. |
| 15 | #define MAX_IPMI_BUFFER 64 |
| 16 | |
Patrick Venture | 79e131f | 2018-08-01 13:34:35 -0700 | [diff] [blame] | 17 | TEST(IpmiFlashData, DataReceivedIsPassedOnOk) |
| 18 | { |
| 19 | // If valid data was passed in, it'll pass it onto the update handler. |
| 20 | |
| 21 | StrictMock<UpdaterMock> updater; |
| 22 | |
| 23 | size_t dataLen; |
| 24 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 25 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 26 | |
| 27 | struct ChunkHdr tx; |
| 28 | tx.cmd = FlashSubCmds::flashDataBlock; |
| 29 | tx.offset = 0x00; |
| 30 | std::memcpy(request, &tx, sizeof(tx)); |
| 31 | |
| 32 | uint8_t bytes[] = {0x04, 0x05}; |
| 33 | std::memcpy(&request[sizeof(struct ChunkHdr)], bytes, sizeof(bytes)); |
| 34 | |
| 35 | dataLen = sizeof(struct ChunkHdr) + sizeof(bytes); |
| 36 | |
| 37 | EXPECT_CALL(updater, |
| 38 | flashData(0x00, ElementsAreArray(bytes, sizeof(bytes)))) |
| 39 | .WillOnce(Return(true)); |
| 40 | |
| 41 | EXPECT_EQ(IPMI_CC_OK, dataBlock(&updater, request, reply, &dataLen)); |
| 42 | EXPECT_EQ(sizeof(uint8_t), dataLen); |
| 43 | EXPECT_EQ(0, reply[0]); |
| 44 | } |