Add new google ipmi sys command: SysHostPowerOff
New google ipmi sys command to let the BMC knows host shutdown,
allow host to gracefully shutdown and disable the watchdog with given
time delay.
Signed-off-by: Yunyun Lin <linyuny@google.com>
Change-Id: I02171c9cfed57ae5d10d66b515e4ab7ee8856466
diff --git a/test/Makefile.am b/test/Makefile.am
index c97f480..a502e77 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -52,3 +52,7 @@
check_PROGRAMS += flash_unittest
flash_unittest_SOURCES = flash_unittest.cpp
flash_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
+
+check_PROGRAMS += poweroff_unittest
+poweroff_unittest_SOURCES = poweroff_unittest.cpp
+poweroff_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
diff --git a/test/handler_mock.hpp b/test/handler_mock.hpp
index d539f7b..edd2aec 100644
--- a/test/handler_mock.hpp
+++ b/test/handler_mock.hpp
@@ -34,6 +34,7 @@
MOCK_CONST_METHOD0(getI2cPcieMappingSize, size_t());
MOCK_CONST_METHOD1(getI2cEntry,
std::tuple<std::uint32_t, std::string>(unsigned int));
+ MOCK_CONST_METHOD1(hostPowerOffDelay, void(std::uint32_t));
};
} // namespace ipmi
diff --git a/test/poweroff_unittest.cpp b/test/poweroff_unittest.cpp
new file mode 100644
index 0000000..ce9501b
--- /dev/null
+++ b/test/poweroff_unittest.cpp
@@ -0,0 +1,49 @@
+#include "commands.hpp"
+#include "handler_mock.hpp"
+#include "host_power_off.hpp"
+
+#include <cstdint>
+#include <cstring>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#define MAX_IPMI_BUFFER 64
+
+namespace google
+{
+namespace ipmi
+{
+
+TEST(PowerOffCommandTest, InvalidRequestLength)
+{
+ std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff};
+ size_t dataLen = request.size();
+ std::uint8_t reply[MAX_IPMI_BUFFER];
+
+ HandlerMock hMock;
+ EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
+ hostPowerOff(request.data(), reply, &dataLen, &hMock));
+}
+
+TEST(PowerOffCommandTest, ValidRequest)
+{
+ // Set the dealy to 15 mins
+ std::uint32_t delayValue = 0x384;
+ struct HostPowerOffRequest requestContents;
+ requestContents.subcommand = SysOEMCommands::SysHostPowerOff;
+ requestContents.delay = delayValue;
+
+ std::vector<std::uint8_t> request(sizeof(requestContents));
+ std::memcpy(request.data(), &requestContents, sizeof(requestContents));
+ size_t dataLen = request.size();
+ std::uint8_t reply[MAX_IPMI_BUFFER];
+
+ HandlerMock hMock;
+ EXPECT_CALL(hMock, hostPowerOffDelay(delayValue));
+ EXPECT_EQ(IPMI_CC_OK,
+ hostPowerOff(request.data(), reply, &dataLen, &hMock));
+}
+
+} // namespace ipmi
+} // namespace google