Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -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 | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 3 | |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 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. |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 20 | ManagerMock mgr; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 21 | std::vector<uint8_t> request; |
| 22 | struct BmcBlobWriteMetaTx req; |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 23 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 24 | req.crc = 0; |
| 25 | req.sessionId = 0x54; |
| 26 | req.offset = 0x100; |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 27 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 28 | request.resize(sizeof(struct BmcBlobWriteMetaTx)); |
| 29 | std::memcpy(request.data(), &req, sizeof(struct BmcBlobWriteMetaTx)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 30 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 31 | std::array<uint8_t, 2> expectedBytes = {0x66, 0x67}; |
| 32 | request.insert(request.end(), expectedBytes.begin(), expectedBytes.end()); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 33 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 34 | EXPECT_CALL(mgr, writeMeta(req.sessionId, req.offset, |
| 35 | ElementsAreArray(expectedBytes))) |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 36 | .WillOnce(Return(false)); |
| 37 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 38 | EXPECT_EQ(ipmi::responseUnspecifiedError(), writeMeta(&mgr, request)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | TEST(BlobWriteMetaTest, ManagerReturnsTrueWriteSucceeds) |
| 42 | { |
| 43 | // The case where everything works. |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 44 | ManagerMock mgr; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 45 | std::vector<uint8_t> request; |
| 46 | struct BmcBlobWriteMetaTx req; |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 47 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 48 | req.crc = 0; |
| 49 | req.sessionId = 0x54; |
| 50 | req.offset = 0x100; |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 51 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 52 | request.resize(sizeof(struct BmcBlobWriteMetaTx)); |
| 53 | std::memcpy(request.data(), &req, sizeof(struct BmcBlobWriteMetaTx)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 54 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 55 | std::array<uint8_t, 2> expectedBytes = {0x66, 0x67}; |
| 56 | request.insert(request.end(), expectedBytes.begin(), expectedBytes.end()); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 57 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 58 | EXPECT_CALL(mgr, writeMeta(req.sessionId, req.offset, |
| 59 | ElementsAreArray(expectedBytes))) |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 60 | .WillOnce(Return(true)); |
| 61 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 62 | EXPECT_EQ(ipmi::responseSuccess(std::vector<uint8_t>{}), |
| 63 | writeMeta(&mgr, request)); |
Patrick Venture | 5c4b17b | 2018-10-04 10:32:22 -0700 | [diff] [blame] | 64 | } |
| 65 | } // namespace blobs |