summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2016-09-09 12:15:46 -0500
committerPatrick Williams <patrick@stwcx.xyz>2016-09-28 13:34:35 +0000
commit00b1e5be1ce0d74541e371790e36a53146cb3b44 (patch)
treec07eb4866e773bc60952fabea72014ee2734bc89
parent41cae2b51107f06bfa50c6dd0fbc68a799a6c219 (diff)
downloadphosphor-host-ipmid-00b1e5be1ce0d74541e371790e36a53146cb3b44.zip
phosphor-host-ipmid-00b1e5be1ce0d74541e371790e36a53146cb3b44.tar.gz
Propose and implement unit test framework
Enable use of GoogleTest and created a sample unit test case. Change-Id: Ie370745a32777d4ed81ee24145364029c8e7bf02 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r--Makefile.am15
-rw-r--r--configure.ac30
-rw-r--r--sample.cpp11
-rw-r--r--sample.h6
-rw-r--r--test/Makefile.am12
-rw-r--r--test/sample_unittest.cpp6
6 files changed, 64 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am
index 4cab12c..429d962 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,17 +47,4 @@ libhostservice_la_CXXFLAGS = $(SYSTEMD_CFLAGS) $(libmapper_CFLAGS)
nobase_include_HEADERS = \
host-ipmid/ipmid-api.h
-check_PROGRAMS = \
- testit
-# testaddsel
-
-testit_SOURCES = \
- ipmisensor.cpp \
- testit.cpp
-testit_LDFLAGS = $(SYSTEMD_LIBS) $(LIBADD_DLOPEN)
-
-#testaddsel_SOURCES = \
-# testaddsel.cpp \
-# storageaddsel.cpp
-#testaddsel_LDFLAGS = $(SYSTEMD_CFLAGS) $(SYSTEMD_LIBS) $(LIBADD_DLOPEN)
-
+SUBDIRS = test
diff --git a/configure.ac b/configure.ac
index 8e1b587..2d4f822 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,10 +3,10 @@ AC_PREREQ([2.69])
AC_INIT([phosphor-host-ipmid], [1.0], [https://github.com/openbmc/phosphor-host-ipmid/issues])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_SILENT_RULES([yes])
# Checks for programs.
AC_PROG_CXX
-AX_CXX_COMPILE_STDCXX_14([noext])
AC_PROG_CC
AM_PROG_AR
AC_PROG_INSTALL
@@ -20,10 +20,36 @@ PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 221])
AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find systemd/sd-bus.h...systemd developement package required])])
# Checks for typedefs, structures, and compiler characteristics.
+AX_CXX_COMPILE_STDCXX_14([noext])
+AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CFLAGS])
+AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
# Checks for library functions.
LT_INIT([dlopen disable-static shared])
LT_LIB_DLLOAD
-AC_CONFIG_FILES([Makefile])
+# Check/set gtest specific functions.
+AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=0"])
+AC_SUBST(GTEST_CPPFLAGS)
+
+AC_ARG_ENABLE([oe-sdk],
+ AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
+)
+AC_ARG_VAR(OECORE_TARGET_SYSROOT,
+ [Path to the OE SDK SYSROOT])
+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/sample.cpp b/sample.cpp
new file mode 100644
index 0000000..451c6c4
--- /dev/null
+++ b/sample.cpp
@@ -0,0 +1,11 @@
+#include <sample.h>
+
+int Factorial(int n)
+{
+ int result = 1;
+ for (int i=1; i<=n; i++)
+ {
+ result *= i;
+ }
+ return result;
+}
diff --git a/sample.h b/sample.h
new file mode 100644
index 0000000..6ff3cf9
--- /dev/null
+++ b/sample.h
@@ -0,0 +1,6 @@
+#ifndef GTEST_SAMPLE
+#define GTEST_SAMPLE
+
+int Factorial(int n);
+
+#endif
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..6bed2cb
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,12 @@
+check_PROGRAMS =
+
+# Run all 'check' test programs
+TESTS = $(check_PROGRAMS)
+
+# Build/add sample_unittest to test suite
+check_PROGRAMS += sample_unittest
+sample_unittest_CPPFLAGS = -Igtest $(GTEST_CPPFLAGS)
+sample_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
+sample_unittest_LDFLAGS = -lgtest_main -lgtest $(PTHREAD_LIBS) $(OESDK_TESTCASE_FLAGS)
+sample_unittest_SOURCES = sample_unittest.cpp
+sample_unittest_LDADD = $(top_builddir)/sample.o
diff --git a/test/sample_unittest.cpp b/test/sample_unittest.cpp
new file mode 100644
index 0000000..2a27279
--- /dev/null
+++ b/test/sample_unittest.cpp
@@ -0,0 +1,6 @@
+#include "sample.h"
+#include <gtest/gtest.h>
+
+TEST(FactorialTest, Zero) {
+ EXPECT_EQ(1, Factorial(0));
+}
OpenPOWER on IntegriCloud