10e9aae5dSPatrick Venture #include "commands.hpp" 21ddb94ffSPatrick Venture #include "eth.hpp" 3f085d91dSPatrick Venture #include "handler_mock.hpp" 41ddb94ffSPatrick Venture 51ddb94ffSPatrick Venture #include <cstdint> 61ddb94ffSPatrick Venture #include <cstring> 7f085d91dSPatrick Venture #include <string> 8f085d91dSPatrick Venture #include <tuple> 91ddb94ffSPatrick Venture #include <vector> 101ddb94ffSPatrick Venture 111ddb94ffSPatrick Venture #include <gtest/gtest.h> 121ddb94ffSPatrick Venture 131ddb94ffSPatrick Venture #define MAX_IPMI_BUFFER 64 141ddb94ffSPatrick Venture 15f085d91dSPatrick Venture using ::testing::Return; 16f085d91dSPatrick Venture 171ddb94ffSPatrick Venture namespace google 181ddb94ffSPatrick Venture { 191ddb94ffSPatrick Venture namespace ipmi 201ddb94ffSPatrick Venture { 211ddb94ffSPatrick Venture 221ddb94ffSPatrick Venture TEST(EthCommandTest, ValidRequestReturnsSuccess) 231ddb94ffSPatrick Venture { 241ddb94ffSPatrick Venture // This command requests no input, therefore it will just return what it 251ddb94ffSPatrick Venture // knows. 261ddb94ffSPatrick Venture std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice}; 271ddb94ffSPatrick Venture size_t dataLen = request.size(); 281ddb94ffSPatrick Venture std::uint8_t reply[MAX_IPMI_BUFFER]; 291ddb94ffSPatrick Venture const std::uint8_t expectedAnswer[4] = {'e', 't', 'h', '0'}; 30*b69209b4SWilliam A. Kennington III const std::uint8_t expectedChannel = 14; 311ddb94ffSPatrick Venture 32f085d91dSPatrick Venture HandlerMock hMock; 33*b69209b4SWilliam A. Kennington III EXPECT_CALL(hMock, getEthDetails("")) 34f085d91dSPatrick Venture .WillOnce(Return(std::make_tuple( 35f085d91dSPatrick Venture expectedChannel, 36f085d91dSPatrick Venture std::string(expectedAnswer, 37f085d91dSPatrick Venture expectedAnswer + sizeof(expectedAnswer))))); 38f085d91dSPatrick Venture 39f085d91dSPatrick Venture EXPECT_EQ(IPMI_CC_OK, 4045fad1bbSPatrick Venture getEthDevice(request.data(), &reply[0], &dataLen, &hMock)); 411ddb94ffSPatrick Venture struct EthDeviceReply check; 421ddb94ffSPatrick Venture std::memcpy(&check, &reply[0], sizeof(check)); 431ddb94ffSPatrick Venture EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice); 44f085d91dSPatrick Venture EXPECT_EQ(check.channel, expectedChannel); 4545fad1bbSPatrick Venture EXPECT_EQ(check.ifNameLength, sizeof(expectedAnswer)); 461ddb94ffSPatrick Venture EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)], 471ddb94ffSPatrick Venture sizeof(expectedAnswer))); 481ddb94ffSPatrick Venture } 491ddb94ffSPatrick Venture 50*b69209b4SWilliam A. Kennington III TEST(EthCommandTest, ValidPopulatedReturnsSuccess) 51*b69209b4SWilliam A. Kennington III { 52*b69209b4SWilliam A. Kennington III std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice, 'e'}; 53*b69209b4SWilliam A. Kennington III size_t dataLen = request.size(); 54*b69209b4SWilliam A. Kennington III std::uint8_t reply[MAX_IPMI_BUFFER]; 55*b69209b4SWilliam A. Kennington III const std::uint8_t expectedAnswer[1] = {'e'}; 56*b69209b4SWilliam A. Kennington III const std::uint8_t expectedChannel = 11; 57*b69209b4SWilliam A. Kennington III 58*b69209b4SWilliam A. Kennington III HandlerMock hMock; 59*b69209b4SWilliam A. Kennington III EXPECT_CALL(hMock, getEthDetails("e")) 60*b69209b4SWilliam A. Kennington III .WillOnce(Return(std::make_tuple( 61*b69209b4SWilliam A. Kennington III expectedChannel, 62*b69209b4SWilliam A. Kennington III std::string(expectedAnswer, 63*b69209b4SWilliam A. Kennington III expectedAnswer + sizeof(expectedAnswer))))); 64*b69209b4SWilliam A. Kennington III 65*b69209b4SWilliam A. Kennington III EXPECT_EQ(IPMI_CC_OK, 66*b69209b4SWilliam A. Kennington III getEthDevice(request.data(), &reply[0], &dataLen, &hMock)); 67*b69209b4SWilliam A. Kennington III struct EthDeviceReply check; 68*b69209b4SWilliam A. Kennington III std::memcpy(&check, &reply[0], sizeof(check)); 69*b69209b4SWilliam A. Kennington III EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice); 70*b69209b4SWilliam A. Kennington III EXPECT_EQ(check.channel, expectedChannel); 71*b69209b4SWilliam A. Kennington III EXPECT_EQ(check.ifNameLength, sizeof(expectedAnswer)); 72*b69209b4SWilliam A. Kennington III EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)], 73*b69209b4SWilliam A. Kennington III sizeof(expectedAnswer))); 74*b69209b4SWilliam A. Kennington III } 751ddb94ffSPatrick Venture } // namespace ipmi 761ddb94ffSPatrick Venture } // namespace google 77