blob: 4bbd40a9946bebda8493a312fdbe359e18fa9505 [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
linyuny8cfa4c42021-06-16 13:53:08 -070015#include "commands.hpp"
16#include "handler_mock.hpp"
17#include "host_power_off.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
27namespace google
28{
29namespace ipmi
30{
31
32TEST(PowerOffCommandTest, InvalidRequestLength)
33{
34 std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff};
35 size_t dataLen = request.size();
36 std::uint8_t reply[MAX_IPMI_BUFFER];
37
38 HandlerMock hMock;
39 EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
40 hostPowerOff(request.data(), reply, &dataLen, &hMock));
41}
42
43TEST(PowerOffCommandTest, ValidRequest)
44{
45 // Set the dealy to 15 mins
46 std::uint32_t delayValue = 0x384;
47 struct HostPowerOffRequest requestContents;
48 requestContents.subcommand = SysOEMCommands::SysHostPowerOff;
49 requestContents.delay = delayValue;
50
51 std::vector<std::uint8_t> request(sizeof(requestContents));
52 std::memcpy(request.data(), &requestContents, sizeof(requestContents));
53 size_t dataLen = request.size();
54 std::uint8_t reply[MAX_IPMI_BUFFER];
55
56 HandlerMock hMock;
57 EXPECT_CALL(hMock, hostPowerOffDelay(delayValue));
58 EXPECT_EQ(IPMI_CC_OK,
59 hostPowerOff(request.data(), reply, &dataLen, &hMock));
60}
61
62} // namespace ipmi
63} // namespace google