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/flash_unittest.cpp b/test/flash_unittest.cpp
index f4337f7..3d575df 100644
--- a/test/flash_unittest.cpp
+++ b/test/flash_unittest.cpp
@@ -15,6 +15,7 @@
#include "commands.hpp"
#include "flash_size.hpp"
#include "handler_mock.hpp"
+#include "helper.hpp"
#include <cstdint>
#include <cstring>
@@ -23,8 +24,6 @@
#include <gtest/gtest.h>
-#define MAX_IPMI_BUFFER 64
-
using ::testing::Return;
namespace google
@@ -32,34 +31,24 @@
namespace ipmi
{
-TEST(FlashSizeCommandTest, InvalidCommandLength)
-{
- // GetFlashSizeRequest is one byte, let's send 0.
- std::vector<std::uint8_t> request = {};
- size_t dataLen = request.size();
- std::uint8_t reply[MAX_IPMI_BUFFER];
-
- HandlerMock hMock;
- EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
- getFlashSize(request.data(), reply, &dataLen, &hMock));
-}
-
TEST(FlashSizeCommandTest, ValidRequest)
{
- std::vector<std::uint8_t> request = {SysOEMCommands::SysGetFlashSize};
- size_t dataLen = request.size();
- std::uint8_t reply[MAX_IPMI_BUFFER];
+ std::vector<std::uint8_t> request = {};
uint32_t flashSize = 5422312; // 0x52BCE8
HandlerMock hMock;
EXPECT_CALL(hMock, getFlashSize()).WillOnce(Return(flashSize));
- EXPECT_EQ(IPMI_CC_OK,
- getFlashSize(request.data(), reply, &dataLen, &hMock));
- EXPECT_EQ(dataLen, 5);
- EXPECT_EQ(reply[4], 0);
- EXPECT_EQ(reply[3], 0x52);
- EXPECT_EQ(reply[2], 0xBC);
- EXPECT_EQ(reply[1], 0xE8);
+
+ auto reply = getFlashSize(request, &hMock);
+ auto result = ValidateReply(reply);
+ auto& data = result.second;
+
+ EXPECT_EQ(sizeof(struct GetFlashSizeReply), data.size());
+ EXPECT_EQ(SysOEMCommands::SysGetFlashSize, result.first);
+ EXPECT_EQ(0, data[3]);
+ EXPECT_EQ(0x52, data[2]);
+ EXPECT_EQ(0xBC, data[1]);
+ EXPECT_EQ(0xE8, data[0]);
}
} // namespace ipmi