blob: 5747ce537fc4133c9e8e371dfe9ee0b17a824227 [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"
Willy Tuff3cd8e2021-09-14 22:49:55 -070018#include "helper.hpp"
Patrick Venturebb90d4f2019-03-15 13:42:06 -070019
20#include <cstdint>
21#include <tuple>
22#include <vector>
23
24#include <gtest/gtest.h>
25
Patrick Venturebb90d4f2019-03-15 13:42:06 -070026using ::testing::Return;
27
28namespace google
29{
30namespace ipmi
31{
32
33TEST(CpldCommandTest, RequestTooSmall)
34{
Willy Tuff3cd8e2021-09-14 22:49:55 -070035 std::vector<std::uint8_t> request = {};
Patrick Venturebb90d4f2019-03-15 13:42:06 -070036 HandlerMock hMock;
Willy Tuff3cd8e2021-09-14 22:49:55 -070037
38 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
39 cpldVersion(request, &hMock));
Patrick Venturebb90d4f2019-03-15 13:42:06 -070040}
41
42TEST(CpldCommandTest, ValidRequestReturnsHappy)
43{
Willy Tuff3cd8e2021-09-14 22:49:55 -070044 std::vector<std::uint8_t> request = {0x04};
45
Patrick Venturebb90d4f2019-03-15 13:42:06 -070046 std::uint8_t expectedMaj = 0x5;
47 std::uint8_t expectedMin = 0x3;
48 std::uint8_t expectedPt = 0x7;
49 std::uint8_t expectedSbPtr = 0x9;
50
51 HandlerMock hMock;
52 EXPECT_CALL(hMock, getCpldVersion(0x04))
53 .WillOnce(Return(std::make_tuple(expectedMaj, expectedMin, expectedPt,
54 expectedSbPtr)));
55
Willy Tuff3cd8e2021-09-14 22:49:55 -070056 // Reply is in the form of
57 // std::tuple<ipmi::Cc, std::optional<std::tuple<RetTypes...>>>
58 auto reply = cpldVersion(request, &hMock);
59 auto result = ValidateReply(reply);
60 auto& data = result.second;
61
62 EXPECT_EQ(sizeof(struct CpldReply), data.size());
63 EXPECT_EQ(SysOEMCommands::SysCpldVersion, result.first);
64 EXPECT_EQ(expectedMaj, data[0]);
65 EXPECT_EQ(expectedMin, data[1]);
66 EXPECT_EQ(expectedPt, data[2]);
67 EXPECT_EQ(expectedSbPtr, data[3]);
Patrick Venturebb90d4f2019-03-15 13:42:06 -070068}
69
70} // namespace ipmi
71} // namespace google