blob: 257baadf1d60b4fcdda22933ab1ed16366e0f69b [file] [log] [blame]
Willy Tua2056e92021-10-10 13:36:16 -07001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Patrick Venture0e9aae52020-08-13 13:07:09 -070015#include "commands.hpp"
Patrick Ventureaa374122019-03-15 15:09:10 -070016#include "handler_mock.hpp"
Patrick Ventureaa374122019-03-15 15:09:10 -070017#include "psu.hpp"
18
19#include <cstdint>
20#include <cstring>
21#include <vector>
22
23#include <gtest/gtest.h>
24
25#define MAX_IPMI_BUFFER 64
26
27using ::testing::Return;
28
29namespace google
30{
31namespace ipmi
32{
33
34TEST(PsuCommandTest, InvalidRequestLength)
35{
36 std::vector<std::uint8_t> request = {SysOEMCommands::SysPsuHardReset};
37 size_t dataLen = request.size();
38 std::uint8_t reply[MAX_IPMI_BUFFER];
39
40 HandlerMock hMock;
41 EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
Patrick Venture45fad1b2019-03-18 16:52:14 -070042 psuHardReset(request.data(), reply, &dataLen, &hMock));
Patrick Ventureaa374122019-03-15 15:09:10 -070043}
44
45TEST(PsuCommandTest, ValidRequest)
46{
47 std::uint32_t delayValue = 0x45;
48 struct PsuResetRequest requestContents;
49 requestContents.subcommand = SysOEMCommands::SysPsuHardReset;
50 requestContents.delay = delayValue;
51
52 std::vector<std::uint8_t> request(sizeof(requestContents));
53 std::memcpy(request.data(), &requestContents, sizeof(requestContents));
54 size_t dataLen = request.size();
55 std::uint8_t reply[MAX_IPMI_BUFFER];
56
57 HandlerMock hMock;
58 EXPECT_CALL(hMock, psuResetDelay(delayValue));
59 EXPECT_EQ(IPMI_CC_OK,
Patrick Venture45fad1b2019-03-18 16:52:14 -070060 psuHardReset(request.data(), reply, &dataLen, &hMock));
Patrick Ventureaa374122019-03-15 15:09:10 -070061}
62
Shounak Mitraac4a16f2021-02-02 11:11:44 -080063TEST(PsuResetOnShutdownCommandTest, InvalidRequestLength)
64{
65 std::vector<std::uint8_t> request;
66 size_t dataLen = request.size();
67 std::uint8_t reply[MAX_IPMI_BUFFER];
68
69 HandlerMock hMock;
70 EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
71 psuHardResetOnShutdown(request.data(), reply, &dataLen, &hMock));
72}
73
74TEST(PsuResetOnShutdownCommandTest, ValidRequest)
75{
76 struct PsuResetOnShutdownRequest requestContents;
77 requestContents.subcommand = SysOEMCommands::SysPsuHardReset;
78
79 std::vector<std::uint8_t> request(sizeof(requestContents));
80 std::memcpy(request.data(), &requestContents, sizeof(requestContents));
81 size_t dataLen = request.size();
82 std::uint8_t reply[MAX_IPMI_BUFFER];
83
84 HandlerMock hMock;
85 EXPECT_CALL(hMock, psuResetOnShutdown());
86 EXPECT_EQ(IPMI_CC_OK,
87 psuHardResetOnShutdown(request.data(), reply, &dataLen, &hMock));
88}
89
Patrick Ventureaa374122019-03-15 15:09:10 -070090} // namespace ipmi
91} // namespace google