google-ipmi-sys: 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.

The input and output will be
`std::uint8_t, std::optional<std::vector<uint8_t>>`.

This represents `subcommand` and any input data.

Changes to note,
- all subcommand in the request/response struct are removed. It will be
  managed by the wrapper directly.
    - Unit tests checking for input with only the subcommand are
      removed.
- Move all reply struct to header files to be accessible in unit test.

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

Change-Id: I4230ab84a497a867248fe82224e32cc69b314b64
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/test/eth_unittest.cpp b/test/eth_unittest.cpp
index 2b5192a..14b0875 100644
--- a/test/eth_unittest.cpp
+++ b/test/eth_unittest.cpp
@@ -15,17 +15,16 @@
 #include "commands.hpp"
 #include "eth.hpp"
 #include "handler_mock.hpp"
+#include "helper.hpp"
 
 #include <cstdint>
 #include <cstring>
-#include <string>
+#include <string_view>
 #include <tuple>
 #include <vector>
 
 #include <gtest/gtest.h>
 
-#define MAX_IPMI_BUFFER 64
-
 using ::testing::Return;
 
 namespace google
@@ -37,54 +36,50 @@
 {
     // This command requests no input, therefore it will just return what it
     // knows.
-    std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice};
-    size_t dataLen = request.size();
-    std::uint8_t reply[MAX_IPMI_BUFFER];
-    const std::uint8_t expectedAnswer[4] = {'e', 't', 'h', '0'};
+    std::vector<std::uint8_t> request = {};
+    const std::string_view expectedAnswer = "eth0";
     const std::uint8_t expectedChannel = 14;
 
     HandlerMock hMock;
     EXPECT_CALL(hMock, getEthDetails(""))
-        .WillOnce(Return(std::make_tuple(
-            expectedChannel,
-            std::string(expectedAnswer,
-                        expectedAnswer + sizeof(expectedAnswer)))));
+        .WillOnce(
+            Return(std::make_tuple(expectedChannel, expectedAnswer.data())));
 
-    EXPECT_EQ(IPMI_CC_OK,
-              getEthDevice(request.data(), &reply[0], &dataLen, &hMock));
-    struct EthDeviceReply check;
-    std::memcpy(&check, &reply[0], sizeof(check));
-    EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice);
-    EXPECT_EQ(check.channel, expectedChannel);
-    EXPECT_EQ(check.ifNameLength, sizeof(expectedAnswer));
-    EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)],
-                             sizeof(expectedAnswer)));
+    auto reply = getEthDevice(request, &hMock);
+    auto result = ValidateReply(reply);
+    auto& data = result.second;
+
+    EXPECT_EQ(sizeof(EthDeviceReply) + expectedAnswer.size(), data.size());
+    EXPECT_EQ(SysOEMCommands::SysGetEthDevice, result.first);
+    EXPECT_EQ(expectedChannel, data[0]);
+    EXPECT_EQ(expectedAnswer.size(), data[1]);
+    EXPECT_EQ(
+        expectedAnswer.data(),
+        std::string(data.begin() + sizeof(struct EthDeviceReply), data.end()));
 }
 
 TEST(EthCommandTest, ValidPopulatedReturnsSuccess)
 {
-    std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice, 'e'};
-    size_t dataLen = request.size();
-    std::uint8_t reply[MAX_IPMI_BUFFER];
-    const std::uint8_t expectedAnswer[1] = {'e'};
+    std::vector<std::uint8_t> request = {'e'};
+    const std::string_view expectedAnswer = "e";
     const std::uint8_t expectedChannel = 11;
 
     HandlerMock hMock;
     EXPECT_CALL(hMock, getEthDetails("e"))
-        .WillOnce(Return(std::make_tuple(
-            expectedChannel,
-            std::string(expectedAnswer,
-                        expectedAnswer + sizeof(expectedAnswer)))));
+        .WillOnce(
+            Return(std::make_tuple(expectedChannel, expectedAnswer.data())));
 
-    EXPECT_EQ(IPMI_CC_OK,
-              getEthDevice(request.data(), &reply[0], &dataLen, &hMock));
-    struct EthDeviceReply check;
-    std::memcpy(&check, &reply[0], sizeof(check));
-    EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice);
-    EXPECT_EQ(check.channel, expectedChannel);
-    EXPECT_EQ(check.ifNameLength, sizeof(expectedAnswer));
-    EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)],
-                             sizeof(expectedAnswer)));
+    auto reply = getEthDevice(request, &hMock);
+    auto result = ValidateReply(reply);
+    auto& data = result.second;
+
+    EXPECT_EQ(sizeof(EthDeviceReply) + expectedAnswer.size(), data.size());
+    EXPECT_EQ(SysOEMCommands::SysGetEthDevice, result.first);
+    EXPECT_EQ(expectedChannel, data[0]);
+    EXPECT_EQ(expectedAnswer.size(), data[1]);
+    EXPECT_EQ(
+        expectedAnswer.data(),
+        std::string(data.begin() + sizeof(struct EthDeviceReply), data.end()));
 }
 } // namespace ipmi
 } // namespace google