blob: a08f040beb861c9e00242b652c93999f4e465648 [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"
Willy Tuff3cd8e2021-09-14 22:49:55 -070017#include "helper.hpp"
Patrick Ventureaa374122019-03-15 15:09:10 -070018#include "psu.hpp"
19
20#include <cstdint>
21#include <cstring>
22#include <vector>
23
24#include <gtest/gtest.h>
25
Patrick Ventureaa374122019-03-15 15:09:10 -070026using ::testing::Return;
27
28namespace google
29{
30namespace ipmi
31{
32
33TEST(PsuCommandTest, InvalidRequestLength)
34{
Willy Tuff3cd8e2021-09-14 22:49:55 -070035 std::vector<std::uint8_t> request = {};
Patrick Ventureaa374122019-03-15 15:09:10 -070036 HandlerMock hMock;
Willy Tuff3cd8e2021-09-14 22:49:55 -070037
38 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
39 psuHardReset(request, &hMock));
Patrick Ventureaa374122019-03-15 15:09:10 -070040}
41
42TEST(PsuCommandTest, ValidRequest)
43{
Willy Tuff3cd8e2021-09-14 22:49:55 -070044 std::uint8_t delayValue = 0x45;
Patrick Ventureaa374122019-03-15 15:09:10 -070045 struct PsuResetRequest requestContents;
Patrick Ventureaa374122019-03-15 15:09:10 -070046 requestContents.delay = delayValue;
Patrick Ventureaa374122019-03-15 15:09:10 -070047 std::vector<std::uint8_t> request(sizeof(requestContents));
48 std::memcpy(request.data(), &requestContents, sizeof(requestContents));
Patrick Ventureaa374122019-03-15 15:09:10 -070049
50 HandlerMock hMock;
51 EXPECT_CALL(hMock, psuResetDelay(delayValue));
Patrick Ventureaa374122019-03-15 15:09:10 -070052
Willy Tuff3cd8e2021-09-14 22:49:55 -070053 auto reply = psuHardReset(request, &hMock);
54 auto result = ValidateReply(reply, /*hasData=*/false);
Shounak Mitraac4a16f2021-02-02 11:11:44 -080055
Willy Tuff3cd8e2021-09-14 22:49:55 -070056 EXPECT_EQ(SysOEMCommands::SysPsuHardReset, result.first);
Shounak Mitraac4a16f2021-02-02 11:11:44 -080057}
58
59TEST(PsuResetOnShutdownCommandTest, ValidRequest)
60{
Willy Tuff3cd8e2021-09-14 22:49:55 -070061 std::vector<std::uint8_t> request = {};
Shounak Mitraac4a16f2021-02-02 11:11:44 -080062
63 HandlerMock hMock;
64 EXPECT_CALL(hMock, psuResetOnShutdown());
Willy Tuff3cd8e2021-09-14 22:49:55 -070065
66 auto reply = psuHardResetOnShutdown(request, &hMock);
67 auto result = ValidateReply(reply, /*hasData=*/false);
68
69 EXPECT_EQ(SysOEMCommands::SysPsuHardResetOnShutdown, result.first);
Shounak Mitraac4a16f2021-02-02 11:11:44 -080070}
71
Patrick Ventureaa374122019-03-15 15:09:10 -070072} // namespace ipmi
73} // namespace google