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" |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 18 | |
| 19 | #include <cstdint> |
| 20 | #include <tuple> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | #define MAX_IPMI_BUFFER 64 |
| 26 | |
| 27 | using ::testing::Return; |
| 28 | |
| 29 | namespace google |
| 30 | { |
| 31 | namespace ipmi |
| 32 | { |
| 33 | |
| 34 | TEST(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 Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 42 | cpldVersion(request.data(), reply, &dataLen, &hMock)); |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | TEST(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 Venture | 45fad1b | 2019-03-18 16:52:14 -0700 | [diff] [blame] | 60 | EXPECT_EQ(IPMI_CC_OK, cpldVersion(request.data(), reply, &dataLen, &hMock)); |
Patrick Venture | bb90d4f | 2019-03-15 13:42:06 -0700 | [diff] [blame] | 61 | 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 |