blob: f9ab539f2cdc77ced0da4df5644f2801b77ecfbc [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 Venturebb90d4f2019-03-15 13:42:06 -070016#include "cpld.hpp"
17#include "handler_mock.hpp"
Patrick Venturebb90d4f2019-03-15 13:42:06 -070018
19#include <cstdint>
20#include <tuple>
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(CpldCommandTest, RequestTooSmall)
35{
36 std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion};
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 cpldVersion(request.data(), reply, &dataLen, &hMock));
Patrick Venturebb90d4f2019-03-15 13:42:06 -070043}
44
45TEST(CpldCommandTest, ValidRequestReturnsHappy)
46{
47 std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion, 0x04};
48 size_t dataLen = request.size();
49 std::uint8_t reply[MAX_IPMI_BUFFER];
50 std::uint8_t expectedMaj = 0x5;
51 std::uint8_t expectedMin = 0x3;
52 std::uint8_t expectedPt = 0x7;
53 std::uint8_t expectedSbPtr = 0x9;
54
55 HandlerMock hMock;
56 EXPECT_CALL(hMock, getCpldVersion(0x04))
57 .WillOnce(Return(std::make_tuple(expectedMaj, expectedMin, expectedPt,
58 expectedSbPtr)));
59
Patrick Venture45fad1b2019-03-18 16:52:14 -070060 EXPECT_EQ(IPMI_CC_OK, cpldVersion(request.data(), reply, &dataLen, &hMock));
Patrick Venturebb90d4f2019-03-15 13:42:06 -070061 EXPECT_EQ(expectedMaj, reply[1]);
62 EXPECT_EQ(expectedMin, reply[2]);
63 EXPECT_EQ(expectedPt, reply[3]);
64 EXPECT_EQ(expectedSbPtr, reply[4]);
65}
66
67} // namespace ipmi
68} // namespace google