add handler logic to handle SysEntityName
Add handler logic to handler for SysEntityName such that it splits the
true IPMI processing from the business logic.
Tested: Only ran unit-tests (added new ones).
Change-Id: I6d672a80f85843ff98c2c7e5daf4689932ff96f9
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 04b6836..0243d44 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -34,3 +34,7 @@
check_PROGRAMS += psu_unittest
psu_unittest_SOURCES = psu_unittest.cpp
psu_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
+
+check_PROGRAMS += entity_unittest
+entity_unittest_SOURCES = entity_unittest.cpp
+entity_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
diff --git a/test/entity_unittest.cpp b/test/entity_unittest.cpp
new file mode 100644
index 0000000..74495c6
--- /dev/null
+++ b/test/entity_unittest.cpp
@@ -0,0 +1,53 @@
+#include "entity_name.hpp"
+#include "handler_mock.hpp"
+#include "main.hpp"
+
+#include <cstdint>
+#include <cstring>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#define MAX_IPMI_BUFFER 64
+
+using ::testing::Return;
+
+namespace google
+{
+namespace ipmi
+{
+
+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];
+
+ HandlerMock hMock;
+ EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
+ GetEntityName(request.data(), reply, &dataLen, &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::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]));
+}
+
+} // namespace ipmi
+} // namespace google
diff --git a/test/handler_mock.hpp b/test/handler_mock.hpp
index 6eb929a..6394f68 100644
--- a/test/handler_mock.hpp
+++ b/test/handler_mock.hpp
@@ -21,6 +21,7 @@
std::tuple<std::uint8_t, std::uint8_t, std::uint8_t,
std::uint8_t>(unsigned int));
MOCK_CONST_METHOD1(psuResetDelay, void(std::uint32_t));
+ MOCK_METHOD2(getEntityName, std::string(std::uint8_t, std::uint8_t));
};
} // namespace ipmi