blob: adf32783fc26531b45bf9580145171e9f2c75f11 [file] [log] [blame]
Patrick Venture0e9aae52020-08-13 13:07:09 -07001#include "commands.hpp"
Patrick Ventureaa374122019-03-15 15:09:10 -07002#include "handler_mock.hpp"
Patrick Ventureaa374122019-03-15 15:09:10 -07003#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
13using ::testing::Return;
14
15namespace google
16{
17namespace ipmi
18{
19
20TEST(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 Venture45fad1b2019-03-18 16:52:14 -070028 psuHardReset(request.data(), reply, &dataLen, &hMock));
Patrick Ventureaa374122019-03-15 15:09:10 -070029}
30
31TEST(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 Venture45fad1b2019-03-18 16:52:14 -070046 psuHardReset(request.data(), reply, &dataLen, &hMock));
Patrick Ventureaa374122019-03-15 15:09:10 -070047}
48
Shounak Mitraac4a16f2021-02-02 11:11:44 -080049TEST(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
60TEST(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 Ventureaa374122019-03-15 15:09:10 -070076} // namespace ipmi
77} // namespace google