Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame^] | 1 | #include "handler_mock.hpp" |
| 2 | #include "main.hpp" |
| 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, |
| 28 | PsuHardReset(request.data(), reply, &dataLen, &hMock)); |
| 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, |
| 46 | PsuHardReset(request.data(), reply, &dataLen, &hMock)); |
| 47 | } |
| 48 | |
| 49 | } // namespace ipmi |
| 50 | } // namespace google |