test: add basic tests for eth command
Add basic tests for eth command.
Change-Id: I2232b8769ada0fe3405e9cafb8909e7351089ecb
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 3a400d5..82b61c5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,4 +1,16 @@
-
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/ \
+ $(GTEST_CFLAGS) \
+ $(GMOCK_CFLAGS)
+AM_LDFLAGS = \
+ $(GTEST_LIBS) \
+ $(GMOCK_LIBS) \
+ -lgmock_main \
+ $(OESDK_TESTCASE_FLAGS)
check_PROGRAMS =
TESTS = $(check_PROGRAMS)
+
+check_PROGRAMS += eth_unittest
+eth_unittest_SOURCES = eth_unittest.cpp
+eth_unittest_LDADD = $(top_builddir)/libsyscmds_common.la
diff --git a/test/eth_unittest.cpp b/test/eth_unittest.cpp
new file mode 100644
index 0000000..f0e4d23
--- /dev/null
+++ b/test/eth_unittest.cpp
@@ -0,0 +1,37 @@
+#include "eth.hpp"
+#include "main.hpp"
+
+#include <cstdint>
+#include <cstring>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#define MAX_IPMI_BUFFER 64
+
+namespace google
+{
+namespace ipmi
+{
+
+TEST(EthCommandTest, ValidRequestReturnsSuccess)
+{
+ // This command requests no input, therefore it will just return what it
+ // knows.
+ std::vector<std::uint8_t> request = {SysOEMCommands::SysGetEthDevice};
+ size_t dataLen = request.size();
+ std::uint8_t reply[MAX_IPMI_BUFFER];
+ const std::uint8_t expectedAnswer[4] = {'e', 't', 'h', '0'};
+
+ EXPECT_EQ(IPMI_CC_OK, GetEthDevice(request.data(), &reply[0], &dataLen));
+ struct EthDeviceReply check;
+ std::memcpy(&check, &reply[0], sizeof(check));
+ EXPECT_EQ(check.subcommand, SysOEMCommands::SysGetEthDevice);
+ EXPECT_EQ(check.channel, 1);
+ EXPECT_EQ(check.if_name_len, sizeof(expectedAnswer));
+ EXPECT_EQ(0, std::memcmp(expectedAnswer, &reply[sizeof(check)],
+ sizeof(expectedAnswer)));
+}
+
+} // namespace ipmi
+} // namespace google