Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #include "ipmi.hpp" |
Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 2 | #include "manager_mock.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 3 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 4 | #include <cstring> |
| 5 | #include <string> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | namespace blobs |
| 10 | { |
| 11 | |
| 12 | using ::testing::Return; |
| 13 | |
| 14 | // ipmid.hpp isn't installed where we can grab it and this value is per BMC |
| 15 | // SoC. |
| 16 | #define MAX_IPMI_BUFFER 64 |
| 17 | |
| 18 | TEST(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure) |
| 19 | { |
| 20 | // This tests to verify that if the index is invalid, it'll return failure. |
| 21 | |
| 22 | ManagerMock mgr; |
| 23 | size_t dataLen; |
| 24 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 25 | struct BmcBlobEnumerateTx req; |
| 26 | uint8_t* request = reinterpret_cast<uint8_t*>(&req); |
| 27 | |
Patrick Venture | 00d5f0d | 2019-05-17 19:21:35 -0700 | [diff] [blame] | 28 | req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 29 | req.blobIdx = 0; |
| 30 | dataLen = sizeof(struct BmcBlobEnumerateTx); |
| 31 | |
| 32 | EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return("")); |
| 33 | |
Patrick Venture | 4125880 | 2018-11-12 10:46:30 -0800 | [diff] [blame] | 34 | EXPECT_EQ(IPMI_CC_INVALID_FIELD_REQUEST, |
| 35 | enumerateBlob(&mgr, request, reply, &dataLen)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | TEST(BlobEnumerateTest, BoringRequestByIdAndReceive) |
| 39 | { |
| 40 | // This tests that if an index into the blob_id cache is valid, the command |
| 41 | // will return the blobId. |
| 42 | |
| 43 | ManagerMock mgr; |
| 44 | size_t dataLen; |
| 45 | uint8_t reply[MAX_IPMI_BUFFER] = {0}; |
| 46 | struct BmcBlobEnumerateTx req; |
| 47 | struct BmcBlobEnumerateRx* rep; |
| 48 | uint8_t* request = reinterpret_cast<uint8_t*>(&req); |
| 49 | std::string blobId = "/asdf"; |
| 50 | |
Patrick Venture | 00d5f0d | 2019-05-17 19:21:35 -0700 | [diff] [blame] | 51 | req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 52 | req.blobIdx = 0; |
| 53 | dataLen = sizeof(struct BmcBlobEnumerateTx); |
| 54 | |
| 55 | EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId)); |
| 56 | |
| 57 | EXPECT_EQ(IPMI_CC_OK, enumerateBlob(&mgr, request, reply, &dataLen)); |
| 58 | |
| 59 | // We're expecting this as a response. |
| 60 | // blobId.length + 1 + sizeof(uint16_t); |
| 61 | EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), dataLen); |
| 62 | |
| 63 | rep = reinterpret_cast<struct BmcBlobEnumerateRx*>(reply); |
William A. Kennington III | 117912d | 2021-06-15 18:22:44 -0700 | [diff] [blame] | 64 | EXPECT_EQ(0, std::memcmp(rep + 1, blobId.c_str(), blobId.length() + 1)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 65 | } |
| 66 | } // namespace blobs |