Add sys command for powercycle on host shutdown.

The new command will trigger a power cycle the next time the host shuts
down. This can exist in parallel with the existing mechanism to trigger
a power cycle after a specified time interval.

The implementation of host state detection and power cycling is platfrom
specific; the new command will just add a temporary file that marks the
system ready to powercycle on the next shutdown. Usually, a systemd unit
would be enabled by the presence of this file to handle the power
cycling process.

Signed-off-by: Shounak Mitra <shounak@google.com>
Change-Id: I0cc40307748fb996be3f6062d8cba1a4b5049683
diff --git a/test/psu_unittest.cpp b/test/psu_unittest.cpp
index 7127c3d..adf3278 100644
--- a/test/psu_unittest.cpp
+++ b/test/psu_unittest.cpp
@@ -46,5 +46,32 @@
               psuHardReset(request.data(), reply, &dataLen, &hMock));
 }
 
+TEST(PsuResetOnShutdownCommandTest, InvalidRequestLength)
+{
+    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,
+              psuHardResetOnShutdown(request.data(), reply, &dataLen, &hMock));
+}
+
+TEST(PsuResetOnShutdownCommandTest, ValidRequest)
+{
+    struct PsuResetOnShutdownRequest requestContents;
+    requestContents.subcommand = SysOEMCommands::SysPsuHardReset;
+
+    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, psuResetOnShutdown());
+    EXPECT_EQ(IPMI_CC_OK,
+              psuHardResetOnShutdown(request.data(), reply, &dataLen, &hMock));
+}
+
 } // namespace ipmi
 } // namespace google