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/entity_unittest.cpp b/test/entity_unittest.cpp
index a939a8a..7b7e843 100644
--- a/test/entity_unittest.cpp
+++ b/test/entity_unittest.cpp
@@ -15,6 +15,7 @@
#include "commands.hpp"
#include "entity_name.hpp"
#include "handler_mock.hpp"
+#include "helper.hpp"
#include <cstdint>
#include <cstring>
@@ -35,32 +36,34 @@
TEST(EntityNameCommandTest, InvalidCommandLength)
{
// GetEntityNameRequest is three bytes, let's send 2.
- std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName, 0x01};
- size_t dataLen = request.size();
- std::uint8_t reply[MAX_IPMI_BUFFER];
-
+ std::vector<std::uint8_t> request = {0x01};
HandlerMock hMock;
- EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
- getEntityName(request.data(), reply, &dataLen, &hMock));
+
+ EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
+ getEntityName(request, &hMock));
}
TEST(EntityNameCommandTest, ValidRequest)
{
std::uint8_t entityId = 3;
std::uint8_t entityInstance = 5;
- std::vector<std::uint8_t> request = {SysOEMCommands::SysEntityName,
- entityId, entityInstance};
- size_t dataLen = request.size();
- std::uint8_t reply[MAX_IPMI_BUFFER];
+ std::vector<std::uint8_t> request = {entityId, entityInstance};
std::string entityName = "asdf";
HandlerMock hMock;
EXPECT_CALL(hMock, getEntityName(entityId, entityInstance))
.WillOnce(Return(entityName));
- EXPECT_EQ(IPMI_CC_OK,
- getEntityName(request.data(), reply, &dataLen, &hMock));
- EXPECT_EQ(reply[1], entityName.length());
- EXPECT_EQ(0, std::memcmp(&reply[2], entityName.c_str(), reply[1]));
+
+ auto reply = getEntityName(request, &hMock);
+ auto result = ValidateReply(reply);
+ auto& data = result.second;
+
+ EXPECT_EQ(sizeof(GetEntityNameReply) + entityName.size(), data.size());
+ EXPECT_EQ(SysOEMCommands::SysEntityName, result.first);
+ EXPECT_EQ(entityName.length(), data[0]);
+ EXPECT_EQ(entityName.data(),
+ std::string(data.begin() + sizeof(struct GetEntityNameReply),
+ data.end()));
}
} // namespace ipmi