blob: dd3c73f4f93e3f0413c98134e667408860326ce2 [file] [log] [blame]
Patrick Venture1ddb94f2019-03-13 16:01:35 -07001#include "eth.hpp"
Patrick Venturef085d912019-03-15 08:50:00 -07002#include "handler_mock.hpp"
Patrick Venture1ddb94f2019-03-13 16:01:35 -07003#include "main.hpp"
4
5#include <cstdint>
6#include <cstring>
Patrick Venturef085d912019-03-15 08:50:00 -07007#include <string>
8#include <tuple>
Patrick Venture1ddb94f2019-03-13 16:01:35 -07009#include <vector>
10
11#include <gtest/gtest.h>
12
13#define MAX_IPMI_BUFFER 64
14
Patrick Venturef085d912019-03-15 08:50:00 -070015using ::testing::Return;
16
Patrick Venture1ddb94f2019-03-13 16:01:35 -070017namespace google
18{
19namespace ipmi
20{
21
22TEST(EthCommandTest, ValidRequestReturnsSuccess)
23{
24 // This command requests no input, therefore it will just return what it
25 // knows.
26 std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice};
27 size_t dataLen = request.size();
28 std::uint8_t reply[MAX_IPMI_BUFFER];
29 const std::uint8_t expectedAnswer[4] = {'e', 't', 'h', '0'};
Patrick Venturef085d912019-03-15 08:50:00 -070030 const std::uint8_t expectedChannel = 1;
Patrick Venture1ddb94f2019-03-13 16:01:35 -070031
Patrick Venturef085d912019-03-15 08:50:00 -070032 HandlerMock hMock;
33 EXPECT_CALL(hMock, getEthDetails())
34 .WillOnce(Return(std::make_tuple(
35 expectedChannel,
36 std::string(expectedAnswer,
37 expectedAnswer + sizeof(expectedAnswer)))));
38
39 EXPECT_EQ(IPMI_CC_OK,
40 GetEthDevice(request.data(), &reply[0], &dataLen, &hMock));
Patrick Venture1ddb94f2019-03-13 16:01:35 -070041 struct EthDeviceReply check;
42 std::memcpy(&check, &reply[0], sizeof(check));
43 EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice);
Patrick Venturef085d912019-03-15 08:50:00 -070044 EXPECT_EQ(check.channel, expectedChannel);
Patrick Venture1ddb94f2019-03-13 16:01:35 -070045 EXPECT_EQ(check.if_name_len, sizeof(expectedAnswer));
46 EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)],
47 sizeof(expectedAnswer)));
48}
49
50} // namespace ipmi
51} // namespace google