add handler logic to handle SysCpldVersion
Add handler logic to handler for SysCpldVersion such that it splits the
true IPMI processing from the business logic.
Tested: Only ran unit-tests (added new ones).
Change-Id: I09d95d8be8fbe75648b3332af898336b00074c2f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 90e42e1..df796d7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -26,3 +26,7 @@
check_PROGRAMS += cable_unittest
cable_unittest_SOURCES = cable_unittest.cpp
cable_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
+
+check_PROGRAMS += cpld_unittest
+cpld_unittest_SOURCES = cpld_unittest.cpp
+cpld_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
diff --git a/test/cpld_unittest.cpp b/test/cpld_unittest.cpp
new file mode 100644
index 0000000..1c6caa3
--- /dev/null
+++ b/test/cpld_unittest.cpp
@@ -0,0 +1,54 @@
+#include "cpld.hpp"
+#include "handler_mock.hpp"
+#include "main.hpp"
+
+#include <cstdint>
+#include <tuple>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#define MAX_IPMI_BUFFER 64
+
+using ::testing::Return;
+
+namespace google
+{
+namespace ipmi
+{
+
+TEST(CpldCommandTest, RequestTooSmall)
+{
+ std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion};
+ size_t dataLen = request.size();
+ std::uint8_t reply[MAX_IPMI_BUFFER];
+
+ HandlerMock hMock;
+ EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
+ CpldVersion(request.data(), reply, &dataLen, &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::uint8_t expectedMaj = 0x5;
+ std::uint8_t expectedMin = 0x3;
+ std::uint8_t expectedPt = 0x7;
+ std::uint8_t expectedSbPtr = 0x9;
+
+ HandlerMock hMock;
+ EXPECT_CALL(hMock, getCpldVersion(0x04))
+ .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]);
+}
+
+} // namespace ipmi
+} // namespace google
diff --git a/test/handler_mock.hpp b/test/handler_mock.hpp
index a99f131..a92606a 100644
--- a/test/handler_mock.hpp
+++ b/test/handler_mock.hpp
@@ -17,6 +17,9 @@
MOCK_CONST_METHOD0(getEthDetails, std::tuple<std::uint8_t, std::string>());
MOCK_CONST_METHOD1(getRxPackets, std::int64_t(const std::string&));
+ MOCK_CONST_METHOD1(getCpldVersion,
+ std::tuple<std::uint8_t, std::uint8_t, std::uint8_t,
+ std::uint8_t>(unsigned int));
};
} // namespace ipmi