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