Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 1 | #include "helper.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 2 | #include "ipmi.hpp" |
Patrick Venture | cd8dab4 | 2019-01-15 19:57:38 -0800 | [diff] [blame] | 3 | #include "manager_mock.hpp" |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 4 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 5 | #include <cstring> |
| 6 | #include <vector> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace blobs |
| 11 | { |
| 12 | |
| 13 | using ::testing::Return; |
| 14 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 15 | TEST(BlobReadTest, ManagerReturnsNoData) |
| 16 | { |
| 17 | // Verify that if no data is returned the IPMI command reply has no |
| 18 | // payload. The manager, in all failures, will just return 0 bytes. |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 19 | ManagerMock mgr; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 20 | std::vector<uint8_t> request; |
| 21 | struct BmcBlobReadTx req; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 22 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 23 | req.crc = 0; |
| 24 | req.sessionId = 0x54; |
| 25 | req.offset = 0x100; |
| 26 | req.requestedSize = 0x10; |
| 27 | request.resize(sizeof(struct BmcBlobReadTx)); |
| 28 | std::memcpy(request.data(), &req, sizeof(struct BmcBlobReadTx)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 29 | std::vector<uint8_t> data; |
| 30 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 31 | EXPECT_CALL(mgr, read(req.sessionId, req.offset, req.requestedSize)) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 32 | .WillOnce(Return(data)); |
| 33 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 34 | auto result = validateReply(readBlob(&mgr, request)); |
| 35 | EXPECT_EQ(sizeof(struct BmcBlobReadRx), result.size()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | TEST(BlobReadTest, ManagerReturnsData) |
| 39 | { |
| 40 | // Verify that if data is returned, it's placed in the expected location. |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 41 | ManagerMock mgr; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 42 | std::vector<uint8_t> request; |
| 43 | struct BmcBlobReadTx req; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 44 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 45 | req.crc = 0; |
| 46 | req.sessionId = 0x54; |
| 47 | req.offset = 0x100; |
| 48 | req.requestedSize = 0x10; |
| 49 | request.resize(sizeof(struct BmcBlobReadTx)); |
| 50 | std::memcpy(request.data(), &req, sizeof(struct BmcBlobReadTx)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 51 | std::vector<uint8_t> data = {0x02, 0x03, 0x05, 0x06}; |
| 52 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 53 | EXPECT_CALL(mgr, read(req.sessionId, req.offset, req.requestedSize)) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 54 | .WillOnce(Return(data)); |
| 55 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 56 | auto result = validateReply(readBlob(&mgr, request)); |
| 57 | EXPECT_EQ(sizeof(struct BmcBlobReadRx) + data.size(), result.size()); |
| 58 | EXPECT_EQ(0, std::memcmp(&result[sizeof(struct BmcBlobReadRx)], data.data(), |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 59 | data.size())); |
| 60 | } |
| 61 | |
| 62 | /* TODO(venture): We need a test that handles other checks such as if the size |
| 63 | * requested won't fit into a packet response. |
| 64 | */ |
| 65 | } // namespace blobs |