Patrick Venture | 54c3b53 | 2018-08-01 11:45:49 -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::NotNull; |
| 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 | #define THIRTYTWO_MIB 33554432 |
| 17 | |
| 18 | TEST(IpmiStartTransferTest, InvalidRequestLengthReturnsFailure) |
| 19 | { |
| 20 | // Verify that the request is sanity checked w.r.t length. |
| 21 | |
| 22 | StrictMock<UpdaterMock> updater; |
| 23 | |
| 24 | size_t dataLen; |
| 25 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 26 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 27 | |
| 28 | struct StartTx tx; |
| 29 | tx.cmd = FlashSubCmds::flashStartTransfer; |
| 30 | tx.length = THIRTYTWO_MIB; |
| 31 | std::memcpy(request, &tx, sizeof(tx)); |
| 32 | |
| 33 | dataLen = sizeof(tx) - 1; // It's too small to be a valid packet. |
| 34 | |
| 35 | EXPECT_EQ(IPMI_CC_INVALID, |
| 36 | startTransfer(&updater, request, reply, &dataLen)); |
| 37 | } |
| 38 | |
| 39 | TEST(IpmiStartTransferTest, ValidRequestBoringCase) |
| 40 | { |
| 41 | // Verify that if the request is valid it calls into the flash updater. |
| 42 | |
| 43 | StrictMock<UpdaterMock> updater; |
| 44 | |
| 45 | size_t dataLen; |
| 46 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 47 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 48 | |
| 49 | struct StartTx tx; |
| 50 | tx.cmd = FlashSubCmds::flashStartTransfer; |
| 51 | tx.length = THIRTYTWO_MIB; |
| 52 | std::memcpy(request, &tx, sizeof(tx)); |
| 53 | |
| 54 | dataLen = sizeof(tx); |
| 55 | |
| 56 | EXPECT_CALL(updater, start(THIRTYTWO_MIB)).WillOnce(Return(true)); |
| 57 | |
| 58 | EXPECT_EQ(IPMI_CC_OK, startTransfer(&updater, request, reply, &dataLen)); |
| 59 | EXPECT_EQ(sizeof(uint8_t), dataLen); |
| 60 | EXPECT_EQ(0, reply[0]); |
| 61 | } |