linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 1 | #include "commands.hpp" |
| 2 | #include "handler_mock.hpp" |
| 3 | #include "host_power_off.hpp" |
| 4 | |
| 5 | #include <cstdint> |
| 6 | #include <cstring> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | #define MAX_IPMI_BUFFER 64 |
| 12 | |
| 13 | namespace google |
| 14 | { |
| 15 | namespace ipmi |
| 16 | { |
| 17 | |
| 18 | TEST(PowerOffCommandTest, InvalidRequestLength) |
| 19 | { |
| 20 | std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff}; |
| 21 | size_t dataLen = request.size(); |
| 22 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 23 | |
| 24 | HandlerMock hMock; |
| 25 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
| 26 | hostPowerOff(request.data(), reply, &dataLen, &hMock)); |
| 27 | } |
| 28 | |
| 29 | TEST(PowerOffCommandTest, ValidRequest) |
| 30 | { |
| 31 | // Set the dealy to 15 mins |
| 32 | std::uint32_t delayValue = 0x384; |
| 33 | struct HostPowerOffRequest requestContents; |
| 34 | requestContents.subcommand = SysOEMCommands::SysHostPowerOff; |
| 35 | requestContents.delay = delayValue; |
| 36 | |
| 37 | std::vector<std::uint8_t> request(sizeof(requestContents)); |
| 38 | std::memcpy(request.data(), &requestContents, sizeof(requestContents)); |
| 39 | size_t dataLen = request.size(); |
| 40 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 41 | |
| 42 | HandlerMock hMock; |
| 43 | EXPECT_CALL(hMock, hostPowerOffDelay(delayValue)); |
| 44 | EXPECT_EQ(IPMI_CC_OK, |
| 45 | hostPowerOff(request.data(), reply, &dataLen, &hMock)); |
| 46 | } |
| 47 | |
| 48 | } // namespace ipmi |
| 49 | } // namespace google |