1 #include "eth.hpp" 2 #include "main.hpp" 3 4 #include <cstdint> 5 #include <cstring> 6 #include <vector> 7 8 #include <gtest/gtest.h> 9 10 #define MAX_IPMI_BUFFER 64 11 12 namespace google 13 { 14 namespace ipmi 15 { 16 17 TEST(EthCommandTest, ValidRequestReturnsSuccess) 18 { 19 // This command requests no input, therefore it will just return what it 20 // knows. 21 std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice}; 22 size_t dataLen = request.size(); 23 std::uint8_t reply[MAX_IPMI_BUFFER]; 24 const std::uint8_t expectedAnswer[4] = {'e', 't', 'h', '0'}; 25 26 EXPECT_EQ(IPMI_CC_OK, GetEthDevice(request.data(), &reply[0], &dataLen)); 27 struct EthDeviceReply check; 28 std::memcpy(&check, &reply[0], sizeof(check)); 29 EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice); 30 EXPECT_EQ(check.channel, 1); 31 EXPECT_EQ(check.if_name_len, sizeof(expectedAnswer)); 32 EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)], 33 sizeof(expectedAnswer))); 34 } 35 36 } // namespace ipmi 37 } // namespace google 38