Patrick Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame] | 1 | #include "commands.hpp" |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 2 | #include "handler_mock.hpp" |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 3 | #include "psu.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 | using ::testing::Return; |
| 14 | |
| 15 | namespace google |
| 16 | { |
| 17 | namespace ipmi |
| 18 | { |
| 19 | |
| 20 | TEST(PsuCommandTest, InvalidRequestLength) |
| 21 | { |
| 22 | std::vector<std::uint8_t> request = {SysOEMCommands::SysPsuHardReset}; |
| 23 | size_t dataLen = request.size(); |
| 24 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 25 | |
| 26 | HandlerMock hMock; |
| 27 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 28 | psuHardReset(request.data(), reply, &dataLen, &hMock)); |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | TEST(PsuCommandTest, ValidRequest) |
| 32 | { |
| 33 | std::uint32_t delayValue = 0x45; |
| 34 | struct PsuResetRequest requestContents; |
| 35 | requestContents.subcommand = SysOEMCommands::SysPsuHardReset; |
| 36 | requestContents.delay = delayValue; |
| 37 | |
| 38 | std::vector<std::uint8_t> request(sizeof(requestContents)); |
| 39 | std::memcpy(request.data(), &requestContents, sizeof(requestContents)); |
| 40 | size_t dataLen = request.size(); |
| 41 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 42 | |
| 43 | HandlerMock hMock; |
| 44 | EXPECT_CALL(hMock, psuResetDelay(delayValue)); |
| 45 | EXPECT_EQ(IPMI_CC_OK, |
Patrick Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 46 | psuHardReset(request.data(), reply, &dataLen, &hMock)); |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 49 | TEST(PsuResetOnShutdownCommandTest, InvalidRequestLength) |
| 50 | { |
| 51 | std::vector<std::uint8_t> request; |
| 52 | size_t dataLen = request.size(); |
| 53 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 54 | |
| 55 | HandlerMock hMock; |
| 56 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
| 57 | psuHardResetOnShutdown(request.data(), reply, &dataLen, &hMock)); |
| 58 | } |
| 59 | |
| 60 | TEST(PsuResetOnShutdownCommandTest, ValidRequest) |
| 61 | { |
| 62 | struct PsuResetOnShutdownRequest requestContents; |
| 63 | requestContents.subcommand = SysOEMCommands::SysPsuHardReset; |
| 64 | |
| 65 | std::vector<std::uint8_t> request(sizeof(requestContents)); |
| 66 | std::memcpy(request.data(), &requestContents, sizeof(requestContents)); |
| 67 | size_t dataLen = request.size(); |
| 68 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 69 | |
| 70 | HandlerMock hMock; |
| 71 | EXPECT_CALL(hMock, psuResetOnShutdown()); |
| 72 | EXPECT_EQ(IPMI_CC_OK, |
| 73 | psuHardResetOnShutdown(request.data(), reply, &dataLen, &hMock)); |
| 74 | } |
| 75 | |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 76 | } // namespace ipmi |
| 77 | } // namespace google |