Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 1 | // 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 Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame] | 15 | #include "commands.hpp" |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 16 | #include "cpld.hpp" |
| 17 | #include "handler_mock.hpp" |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 18 | #include "helper.hpp" |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 19 | |
| 20 | #include <cstdint> |
| 21 | #include <tuple> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 26 | using ::testing::Return; |
| 27 | |
| 28 | namespace google |
| 29 | { |
| 30 | namespace ipmi |
| 31 | { |
| 32 | |
| 33 | TEST(CpldCommandTest, RequestTooSmall) |
| 34 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 35 | std::vector<std::uint8_t> request = {}; |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 36 | HandlerMock hMock; |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 37 | |
| 38 | EXPECT_EQ(::ipmi::responseReqDataLenInvalid(), |
| 39 | cpldVersion(request, &hMock)); |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | TEST(CpldCommandTest, ValidRequestReturnsHappy) |
| 43 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 44 | std::vector<std::uint8_t> request = {0x04}; |
| 45 | |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 46 | 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 Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 56 | // 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 Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace ipmi |
| 71 | } // namespace google |