1*a2056e9cSWilly Tu // Copyright 2021 Google LLC 2*a2056e9cSWilly Tu // 3*a2056e9cSWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 4*a2056e9cSWilly Tu // you may not use this file except in compliance with the License. 5*a2056e9cSWilly Tu // You may obtain a copy of the License at 6*a2056e9cSWilly Tu // 7*a2056e9cSWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 8*a2056e9cSWilly Tu // 9*a2056e9cSWilly Tu // Unless required by applicable law or agreed to in writing, software 10*a2056e9cSWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 11*a2056e9cSWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*a2056e9cSWilly Tu // See the License for the specific language governing permissions and 13*a2056e9cSWilly Tu // limitations under the License. 14*a2056e9cSWilly Tu 150e9aae5dSPatrick Venture #include "commands.hpp" 16bb90d4fdSPatrick Venture #include "cpld.hpp" 17bb90d4fdSPatrick Venture #include "handler_mock.hpp" 18bb90d4fdSPatrick Venture 19bb90d4fdSPatrick Venture #include <cstdint> 20bb90d4fdSPatrick Venture #include <tuple> 21bb90d4fdSPatrick Venture #include <vector> 22bb90d4fdSPatrick Venture 23bb90d4fdSPatrick Venture #include <gtest/gtest.h> 24bb90d4fdSPatrick Venture 25bb90d4fdSPatrick Venture #define MAX_IPMI_BUFFER 64 26bb90d4fdSPatrick Venture 27bb90d4fdSPatrick Venture using ::testing::Return; 28bb90d4fdSPatrick Venture 29bb90d4fdSPatrick Venture namespace google 30bb90d4fdSPatrick Venture { 31bb90d4fdSPatrick Venture namespace ipmi 32bb90d4fdSPatrick Venture { 33bb90d4fdSPatrick Venture 34bb90d4fdSPatrick Venture TEST(CpldCommandTest, RequestTooSmall) 35bb90d4fdSPatrick Venture { 36bb90d4fdSPatrick Venture std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion}; 37bb90d4fdSPatrick Venture size_t dataLen = request.size(); 38bb90d4fdSPatrick Venture std::uint8_t reply[MAX_IPMI_BUFFER]; 39bb90d4fdSPatrick Venture 40bb90d4fdSPatrick Venture HandlerMock hMock; 41bb90d4fdSPatrick Venture EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, 4245fad1bbSPatrick Venture cpldVersion(request.data(), reply, &dataLen, &hMock)); 43bb90d4fdSPatrick Venture } 44bb90d4fdSPatrick Venture 45bb90d4fdSPatrick Venture TEST(CpldCommandTest, ValidRequestReturnsHappy) 46bb90d4fdSPatrick Venture { 47bb90d4fdSPatrick Venture std::vector<std::uint8_t> request = {SysOEMCommands::SysCpldVersion, 0x04}; 48bb90d4fdSPatrick Venture size_t dataLen = request.size(); 49bb90d4fdSPatrick Venture std::uint8_t reply[MAX_IPMI_BUFFER]; 50bb90d4fdSPatrick Venture std::uint8_t expectedMaj = 0x5; 51bb90d4fdSPatrick Venture std::uint8_t expectedMin = 0x3; 52bb90d4fdSPatrick Venture std::uint8_t expectedPt = 0x7; 53bb90d4fdSPatrick Venture std::uint8_t expectedSbPtr = 0x9; 54bb90d4fdSPatrick Venture 55bb90d4fdSPatrick Venture HandlerMock hMock; 56bb90d4fdSPatrick Venture EXPECT_CALL(hMock, getCpldVersion(0x04)) 57bb90d4fdSPatrick Venture .WillOnce(Return(std::make_tuple(expectedMaj, expectedMin, expectedPt, 58bb90d4fdSPatrick Venture expectedSbPtr))); 59bb90d4fdSPatrick Venture 6045fad1bbSPatrick Venture EXPECT_EQ(IPMI_CC_OK, cpldVersion(request.data(), reply, &dataLen, &hMock)); 61bb90d4fdSPatrick Venture EXPECT_EQ(expectedMaj, reply[1]); 62bb90d4fdSPatrick Venture EXPECT_EQ(expectedMin, reply[2]); 63bb90d4fdSPatrick Venture EXPECT_EQ(expectedPt, reply[3]); 64bb90d4fdSPatrick Venture EXPECT_EQ(expectedSbPtr, reply[4]); 65bb90d4fdSPatrick Venture } 66bb90d4fdSPatrick Venture 67bb90d4fdSPatrick Venture } // namespace ipmi 68bb90d4fdSPatrick Venture } // namespace google 69