Merge "Add parameter for device file interface name"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f6d0b51
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,32 @@
+.deps/
+Makefile
+Makefile.in
+aclocal.m4
+ar-lib
+autom4te.cache/
+compile
+config.guess
+config.h
+config.h.in
+config.h.in~
+config.log
+config.status
+config.sub
+configure
+depcomp
+install-sh
+ltmain.sh
+missing
+snoopd
+snooper
+snoopd-main.o
+snooper-example.o
+stamp-h1
+test-driver
+x86_64-openbmc-linux-libtool
+x86_64-libtool
+test/post_reporter_test
+test/post_reporter_test.log
+test/post_reporter_test.o
+test/post_reporter_test.trs
+test/test-suite.log
diff --git a/Makefile.am b/Makefile.am
index 950ebac..890eddf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,4 +13,4 @@
 # Installs in $(includedir)/lpcsnoop/
 nobase_include_HEADERS = lpcsnoop/snoop.hpp lpcsnoop/snoop_listen.hpp
 
-SUBDIRS = .
+SUBDIRS = . test
diff --git a/configure.ac b/configure.ac
index c7c49fa..21970ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,7 +14,7 @@
 
 # Checks for typedefs, structures, and compiler characteristics.
 AX_CXX_COMPILE_STDCXX_14([noext])
-AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
+AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
 
 # Checks for libraries.
 # AC_CHECK_LIB([mapper], [mapper_get_service], ,[AC_MSG_ERROR([Could not find libmapper...openbmc/phosphor-objmgr package required])])
@@ -26,7 +26,35 @@
 # Checks for library functions.
 LT_INIT # Required for systemd linking
 
-# Create configured output
-AC_CONFIG_FILES([Makefile])
-AC_OUTPUT
+# Check/set gtest specific functions.
+PKG_CHECK_MODULES([GTEST], [gtest], [], [AC_MSG_NOTICE([gtest not found, tests will not build])])
+PKG_CHECK_MODULES([GMOCK], [gmock], [], [AC_MSG_NOTICE([gmock not found, tests will not build])])
+AX_PTHREAD([GTEST_CFLAGS+=" -DGTEST_HAS_PTHREAD=1 "],[GTEST_CFLAGS+=" -DGTEST_HAS_PTHREAD=0 "])
 
+# Add --enable-oe-sdk flag to configure script
+AC_ARG_ENABLE([oe-sdk],
+    AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
+)
+
+# Check for OECORE_TARGET_SYSROOT in the environment.
+AC_ARG_VAR(OECORE_TARGET_SYSROOT,
+    [Path to the OE SDK SYSROOT])
+
+# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
+# used in test/Makefile.am
+AS_IF([test "x$enable_oe_sdk" == "xyes"],
+    AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
+          AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
+    )
+    AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
+    [
+        testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
+        testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
+        testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
+    ]
+    AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
+)
+
+# Create configured output
+AC_CONFIG_FILES([Makefile test/Makefile])
+AC_OUTPUT
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..e28604d
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,15 @@
+# Common flags for all binaries in this subdirectory.
+# Per-program specific flags can be specified using
+# prg_CPPFLAGS = ....
+AM_CPPFLAGS = -I${top_srcdir} $(GTEST_CFLAGS)
+AM_CXXFLAGS = $(PTHREAD_CFLAGS) $(GTEST_CFLAGS)
+AM_LDFLAGS = $(GTEST_LIBS) $(PTHREAD_LIBS) $(OESDK_TESTCASE_FLAGS)
+
+# The list of unit test programs we are building and running.
+check_PROGRAMS = post_reporter_test
+
+# Run all 'check' test programs
+TESTS = $(check_PROGRAMS)
+
+# List sources for each test.
+post_reporter_test_SOURCES = post_reporter_test.cpp
diff --git a/test/post_reporter_test.cpp b/test/post_reporter_test.cpp
new file mode 100644
index 0000000..738982d
--- /dev/null
+++ b/test/post_reporter_test.cpp
@@ -0,0 +1,10 @@
+#include <gtest/gtest.h>
+
+class PostReporterTest : public ::testing::Test
+{
+};
+
+TEST(PostReporterTest, DummyTest)
+{
+    EXPECT_EQ(1, 1);
+}