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 | |
| 7 | #include <gtest/gtest.h> |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 8 | namespace blobs |
| 9 | { |
| 10 | |
| 11 | using ::testing::ElementsAreArray; |
| 12 | using ::testing::Return; |
| 13 | |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 14 | TEST(BlobWriteTest, ManagerReturnsFailureReturnsFailure) |
| 15 | { |
| 16 | // This verifies a failure from the manager is passed back. |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 17 | ManagerMock mgr; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 18 | std::vector<uint8_t> request; |
| 19 | struct BmcBlobWriteTx req; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 20 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 21 | req.crc = 0; |
| 22 | req.sessionId = 0x54; |
| 23 | req.offset = 0x100; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 24 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 25 | request.resize(sizeof(struct BmcBlobWriteTx)); |
| 26 | std::memcpy(request.data(), &req, sizeof(struct BmcBlobWriteTx)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 27 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 28 | std::array<uint8_t, 2> expectedBytes = {0x66, 0x67}; |
| 29 | request.insert(request.end(), expectedBytes.begin(), expectedBytes.end()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 30 | |
Patrick Williams | 97e69ca | 2024-08-16 15:21:49 -0400 | [diff] [blame^] | 31 | EXPECT_CALL(mgr, write(req.sessionId, req.offset, |
| 32 | ElementsAreArray(expectedBytes))) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 33 | .WillOnce(Return(false)); |
| 34 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 35 | EXPECT_EQ(ipmi::responseUnspecifiedError(), writeBlob(&mgr, request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | TEST(BlobWriteTest, ManagerReturnsTrueWriteSucceeds) |
| 39 | { |
| 40 | // The case where everything works. |
| 41 | |
| 42 | ManagerMock mgr; |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 43 | std::vector<uint8_t> request; |
| 44 | struct BmcBlobWriteTx req; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 45 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 46 | req.crc = 0; |
| 47 | req.sessionId = 0x54; |
| 48 | req.offset = 0x100; |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 49 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 50 | request.resize(sizeof(struct BmcBlobWriteTx)); |
| 51 | std::memcpy(request.data(), &req, sizeof(struct BmcBlobWriteTx)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 52 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 53 | std::array<uint8_t, 2> expectedBytes = {0x66, 0x67}; |
| 54 | request.insert(request.end(), expectedBytes.begin(), expectedBytes.end()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 55 | |
Patrick Williams | 97e69ca | 2024-08-16 15:21:49 -0400 | [diff] [blame^] | 56 | EXPECT_CALL(mgr, write(req.sessionId, req.offset, |
| 57 | ElementsAreArray(expectedBytes))) |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 58 | .WillOnce(Return(true)); |
| 59 | |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 60 | EXPECT_EQ(ipmi::responseSuccess(std::vector<uint8_t>{}), |
| 61 | writeBlob(&mgr, request)); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 62 | } |
| 63 | } // namespace blobs |