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/cpld_unittest.cpp b/test/cpld_unittest.cpp
index f9ab539..5747ce5 100644
--- a/test/cpld_unittest.cpp
+++ b/test/cpld_unittest.cpp
@@ -15,6 +15,7 @@
#include "commands.hpp"
#include "cpld.hpp"
#include "handler_mock.hpp"
+#include "helper.hpp"
#include <cstdint>
#include <tuple>
@@ -22,8 +23,6 @@
#include <gtest/gtest.h>
-#define MAX_IPMI_BUFFER 64
-
using ::testing::Return;
namespace google
@@ -33,20 +32,17 @@
TEST(CpldCommandTest, RequestTooSmall)
{
- std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion};
- size_t dataLen = request.size();
- std::uint8_t reply[MAX_IPMI_BUFFER];
-
+ std::vector<std::uint8_t> request = {};
HandlerMock hMock;
- EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
- cpldVersion(request.data(), reply, &dataLen, &hMock));
+
+ EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
+ cpldVersion(request, &hMock));
}
TEST(CpldCommandTest, ValidRequestReturnsHappy)
{
- std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion, 0x04};
- size_t dataLen = request.size();
- std::uint8_t reply[MAX_IPMI_BUFFER];
+ std::vector<std::uint8_t> request = {0x04};
+
std::uint8_t expectedMaj = 0x5;
std::uint8_t expectedMin = 0x3;
std::uint8_t expectedPt = 0x7;
@@ -57,11 +53,18 @@
.WillOnce(Return(std::make_tuple(expectedMaj, expectedMin, expectedPt,
expectedSbPtr)));
- EXPECT_EQ(IPMI_CC_OK, cpldVersion(request.data(), reply, &dataLen, &hMock));
- EXPECT_EQ(expectedMaj, reply[1]);
- EXPECT_EQ(expectedMin, reply[2]);
- EXPECT_EQ(expectedPt, reply[3]);
- EXPECT_EQ(expectedSbPtr, reply[4]);
+ // Reply is in the form of
+ // std::tuple<ipmi::Cc, std::optional<std::tuple<RetTypes...>>>
+ auto reply = cpldVersion(request, &hMock);
+ auto result = ValidateReply(reply);
+ auto& data = result.second;
+
+ EXPECT_EQ(sizeof(struct CpldReply), data.size());
+ EXPECT_EQ(SysOEMCommands::SysCpldVersion, result.first);
+ EXPECT_EQ(expectedMaj, data[0]);
+ EXPECT_EQ(expectedMin, data[1]);
+ EXPECT_EQ(expectedPt, data[2]);
+ EXPECT_EQ(expectedSbPtr, data[3]);
}
} // namespace ipmi