blob: adf32783fc26531b45bf9580145171e9f2c75f11 [file] [log] [blame]
#include "commands.hpp"
#include "handler_mock.hpp"
#include "psu.hpp"
#include <cstdint>
#include <cstring>
#include <vector>
#include <gtest/gtest.h>
#define MAX_IPMI_BUFFER 64
using ::testing::Return;
namespace google
{
namespace ipmi
{
TEST(PsuCommandTest, InvalidRequestLength)
{
std::vector<std::uint8_t> request = {SysOEMCommands::SysPsuHardReset};
size_t dataLen = request.size();
std::uint8_t reply[MAX_IPMI_BUFFER];
HandlerMock hMock;
EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
psuHardReset(request.data(), reply, &dataLen, &hMock));
}
TEST(PsuCommandTest, ValidRequest)
{
std::uint32_t delayValue = 0x45;
struct PsuResetRequest requestContents;
requestContents.subcommand = SysOEMCommands::SysPsuHardReset;
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, psuResetDelay(delayValue));
EXPECT_EQ(IPMI_CC_OK,
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