Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 1 | #include "ipmi.hpp" |
| 2 | |
| 3 | #include <blobs-ipmid/test/manager_mock.hpp> |
| 4 | #include <cstring> |
| 5 | |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | namespace blobs |
| 9 | { |
| 10 | using ::testing::ElementsAreArray; |
| 11 | using ::testing::Return; |
| 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 | |
| 17 | TEST(BlobWriteMetaTest, ManagerReturnsFailureReturnsFailure) |
| 18 | { |
| 19 | // This verifies a failure from the manager is passed back. |
| 20 | |
| 21 | ManagerMock mgr; |
| 22 | size_t dataLen; |
| 23 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 24 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 25 | auto req = reinterpret_cast<struct BmcBlobWriteMetaTx*>(request); |
| 26 | |
| 27 | req->cmd = BlobOEMCommands::bmcBlobWrite; |
| 28 | req->crc = 0; |
| 29 | req->sessionId = 0x54; |
| 30 | req->offset = 0x100; |
| 31 | |
| 32 | uint8_t expectedBytes[2] = {0x66, 0x67}; |
| 33 | std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes)); |
| 34 | |
| 35 | dataLen = sizeof(struct BmcBlobWriteMetaTx) + sizeof(expectedBytes); |
| 36 | |
| 37 | EXPECT_CALL( |
| 38 | mgr, writeMeta(req->sessionId, req->offset, |
| 39 | ElementsAreArray(expectedBytes, sizeof(expectedBytes)))) |
| 40 | .WillOnce(Return(false)); |
| 41 | |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 42 | EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR, |
| 43 | writeMeta(&mgr, request, reply, &dataLen)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | TEST(BlobWriteMetaTest, ManagerReturnsTrueWriteSucceeds) |
| 47 | { |
| 48 | // The case where everything works. |
| 49 | |
| 50 | ManagerMock mgr; |
| 51 | size_t dataLen; |
| 52 | uint8_t request[MAX_IPMI_BUFFER] = {0}; |
| 53 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 54 | auto req = reinterpret_cast<struct BmcBlobWriteMetaTx*>(request); |
| 55 | |
| 56 | req->cmd = BlobOEMCommands::bmcBlobWrite; |
| 57 | req->crc = 0; |
| 58 | req->sessionId = 0x54; |
| 59 | req->offset = 0x100; |
| 60 | |
| 61 | uint8_t expectedBytes[2] = {0x66, 0x67}; |
| 62 | std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes)); |
| 63 | |
| 64 | dataLen = sizeof(struct BmcBlobWriteMetaTx) + sizeof(expectedBytes); |
| 65 | |
| 66 | EXPECT_CALL( |
| 67 | mgr, writeMeta(req->sessionId, req->offset, |
| 68 | ElementsAreArray(expectedBytes, sizeof(expectedBytes)))) |
| 69 | .WillOnce(Return(true)); |
| 70 | |
| 71 | EXPECT_EQ(IPMI_CC_OK, writeMeta(&mgr, request, reply, &dataLen)); |
| 72 | } |
| 73 | } // namespace blobs |