Refactor to use new version of OEM IPMI Handler

Using the new version of ipmi handler provide a higher level wrapper
over the same functionalities. It helps us parse the input and output to
have more control of the input/output we see.

Changes to note,
- All cmd are removed from the request data. That is automatically
  extracted now.

Tested:
Unit Test Passed.

All IPMI OEM command still works the same as before this change.

```
$ burn_my_bmc -command stage -image /tmp/test.txt -interface ipmipci
Set up ipmi flash updater with /flash/dummy
Received failure on delete: Received IPMI_CC: 255
Sending over the firmware image.
Find [0x1050 0x750]
bar0[0x94000000]
Upload to BMC 100% |Goooooooooooooooooooooooooooooooooooooooooooooooooooooooogle| Time: 00:00:00
Opening the verification file
Committing to /flash/verify to trigger service
Calling stat on /flash/verify session to check status
success
succeeded
```

Also tested gBMC Update workflow which worked fine.

Change-Id: Ib2bfeab0c2ec5aa72ede1ff457ef5f90e488053c
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/test/ipmi_open_unittest.cpp b/test/ipmi_open_unittest.cpp
index 5b18631..b938cbe 100644
--- a/test/ipmi_open_unittest.cpp
+++ b/test/ipmi_open_unittest.cpp
@@ -1,3 +1,4 @@
+#include "helper.hpp"
 #include "ipmi.hpp"
 #include "manager_mock.hpp"
 
@@ -15,59 +16,44 @@
 using ::testing::Return;
 using ::testing::StrEq;
 
-// ipmid.hpp isn't installed where we can grab it and this value is per BMC
-// SoC.
-#define MAX_IPMI_BUFFER 64
-
 TEST(BlobOpenTest, InvalidRequestLengthReturnsFailure)
 {
     // There is a minimum blobId length of one character, this test verifies
     // we check that.
-
     ManagerMock mgr;
-    size_t dataLen;
-    uint8_t request[MAX_IPMI_BUFFER] = {0};
-    uint8_t reply[MAX_IPMI_BUFFER] = {0};
-    auto req = reinterpret_cast<struct BmcBlobOpenTx*>(request);
+    std::vector<uint8_t> request;
+    BmcBlobOpenTx req;
     std::string blobId = "abc";
 
-    req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen);
-    req->crc = 0;
-    req->flags = 0;
-    // length() doesn't include the nul-terminator.
-    std::memcpy(req + 1, blobId.c_str(), blobId.length());
+    req.crc = 0;
+    req.flags = 0;
 
-    dataLen = sizeof(struct BmcBlobOpenTx) + blobId.length();
+    // Missintg the nul-terminator.
+    request.resize(sizeof(struct BmcBlobOpenTx));
+    std::memcpy(request.data(), &req, sizeof(struct BmcBlobOpenTx));
+    request.insert(request.end(), blobId.begin(), blobId.end());
 
-    EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
-              openBlob(&mgr, request, reply, &dataLen));
+    EXPECT_EQ(ipmi::responseReqDataLenInvalid(), openBlob(&mgr, request));
 }
 
 TEST(BlobOpenTest, RequestRejectedReturnsFailure)
 {
     // The blobId is rejected for any reason.
-
     ManagerMock mgr;
-    size_t dataLen;
-    uint8_t request[MAX_IPMI_BUFFER] = {0};
-    uint8_t reply[MAX_IPMI_BUFFER] = {0};
-    auto req = reinterpret_cast<struct BmcBlobOpenTx*>(request);
+    std::vector<uint8_t> request;
+    BmcBlobOpenTx req;
     std::string blobId = "a";
 
-    req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen);
-    req->crc = 0;
-    req->flags = 0;
-    // length() doesn't include the nul-terminator, request buff is initialized
-    // to 0s
-    std::memcpy(req + 1, blobId.c_str(), blobId.length());
+    req.crc = 0;
+    req.flags = 0;
+    request.resize(sizeof(struct BmcBlobOpenTx));
+    std::memcpy(request.data(), &req, sizeof(struct BmcBlobOpenTx));
+    request.insert(request.end(), blobId.begin(), blobId.end());
+    request.emplace_back('\0');
 
-    dataLen = sizeof(struct BmcBlobOpenTx) + blobId.length() + 1;
+    EXPECT_CALL(mgr, open(req.flags, StrEq(blobId), _)).WillOnce(Return(false));
 
-    EXPECT_CALL(mgr, open(req->flags, StrEq(blobId), _))
-        .WillOnce(Return(false));
-
-    EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR,
-              openBlob(&mgr, request, reply, &dataLen));
+    EXPECT_EQ(ipmi::responseUnspecifiedError(), openBlob(&mgr, request));
 }
 
 TEST(BlobOpenTest, BlobOpenReturnsOk)
@@ -75,35 +61,32 @@
     // The boring case where the blobId opens.
 
     ManagerMock mgr;
-    size_t dataLen;
-    uint8_t request[MAX_IPMI_BUFFER] = {0};
-    uint8_t reply[MAX_IPMI_BUFFER] = {0};
-    auto req = reinterpret_cast<struct BmcBlobOpenTx*>(request);
+    std::vector<uint8_t> request;
+    BmcBlobOpenTx req;
     struct BmcBlobOpenRx rep;
     std::string blobId = "a";
 
-    req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen);
-    req->crc = 0;
-    req->flags = 0;
-    // length() doesn't include the nul-terminator, request buff is initialized
-    // to 0s
-    std::memcpy(req + 1, blobId.c_str(), blobId.length());
+    req.crc = 0;
+    req.flags = 0;
+    request.resize(sizeof(struct BmcBlobOpenTx));
+    std::memcpy(request.data(), &req, sizeof(struct BmcBlobOpenTx));
+    request.insert(request.end(), blobId.begin(), blobId.end());
+    request.emplace_back('\0');
 
-    dataLen = sizeof(struct BmcBlobOpenTx) + blobId.length() + 1;
     uint16_t returnedSession = 0x54;
 
-    EXPECT_CALL(mgr, open(req->flags, StrEq(blobId), NotNull()))
+    EXPECT_CALL(mgr, open(req.flags, StrEq(blobId), NotNull()))
         .WillOnce(Invoke([&](uint16_t, const std::string&, uint16_t* session) {
             (*session) = returnedSession;
             return true;
         }));
 
-    EXPECT_EQ(IPMI_CC_OK, openBlob(&mgr, request, reply, &dataLen));
+    auto result = validateReply(openBlob(&mgr, request));
 
     rep.crc = 0;
     rep.sessionId = returnedSession;
 
-    EXPECT_EQ(sizeof(rep), dataLen);
-    EXPECT_EQ(0, std::memcmp(reply, &rep, sizeof(rep)));
+    EXPECT_EQ(sizeof(rep), result.size());
+    EXPECT_EQ(0, std::memcmp(result.data(), &rep, sizeof(rep)));
 }
 } // namespace blobs