build: enable code coverage
Enable code coverage given the tests. The current code coverage
configuration focuses on the lines that are tested, whether they're
tested, versus including missing things. It would seem.
Tested: Ran unit-tests.
Change-Id: Ie9d345de1105e35386d2aeb06cca2788f84db265
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/.gitignore b/.gitignore
index dbd5f0a..eded194 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,13 @@
# http://www.gnu.org/software/automake
+
+# Code Coverage
+*.gcda
+*.gcno
+*.trs
+*-coverage*
+
Makefile.in
/ar-lib
/mdate-sh
@@ -12,6 +19,7 @@
# http://www.gnu.org/software/autoconf
+/aminclude_static.am
/autom4te.cache
/autoscan.log
/autoscan-*.log
diff --git a/.lcovrc b/.lcovrc
new file mode 100644
index 0000000..360a8b4
--- /dev/null
+++ b/.lcovrc
@@ -0,0 +1,3 @@
+geninfo_gcov_all_blocks = 1
+lcov_function_coverage = 1
+lcov_branch_coverage = 0
diff --git a/Makefile.am b/Makefile.am
index 2f78a5f..6522adb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,16 +1,56 @@
AM_DEFAULT_SOURCE_EXT = .cpp
+# Ignore system headers
+CODE_COVERAGE_IGNORE_PATTERN = '/include/*' '/usr/include/*' '$(includedir)/*'
+export CODE_COVERAGE_IGNORE_PATTERN
+
+CODE_COVERAGE_LCOV_SHOPTS = $(CODE_COVERAGE_LCOV_SHOPTS_DEFAULT)
+# Use our configuration file for lcov
+CODE_COVERAGE_LCOV_SHOPTS += --config-file $(abs_srcdir)/.lcovrc
+export CODE_COVERAGE_LCOV_SHOPTS
+
+CODE_COVERAGE_LCOV_OPTIONS = $(CODE_COVERAGE_LCOV_OPTIONS_DEFAULT)
+# Use our configuration file for lcov
+CODE_COVERAGE_LCOV_OPTIONS += --config-file $(abs_srcdir)/.lcovrc
+export CODE_COVERAGE_LCOV_OPTIONS
+
+CODE_COVERAGE_LCOV_RMOPTS = $(CODE_COVERAGE_LCOV_RMOPTS_DEFAULT)
+# Use our configuration file for lcov
+CODE_COVERAGE_LCOV_RMOPTS += --config-file $(abs_srcdir)/.lcovrc
+export CODE_COVERAGE_LCOV_RMOPTS
+
+CODE_COVERAGE_GENHTML_OPTIONS = $(CODE_COVERAGE_GENHTML_OPTIONS_DEFAULT)
+# Use our configuration file for genhtml
+CODE_COVERAGE_GENHTML_OPTIONS += --config-file $(abs_srcdir)/.lcovrc
+# Don't generate the absolute path for each file in the HTML output
+CODE_COVERAGE_GENHTML_OPTIONS += --prefix $(abs_srcdir) --prefix $(abs_builddir)
+export CODE_COVERAGE_GENHTML_OPTIONS
+
+if AUTOCONF_CODE_COVERAGE_2019_01_06
+include $(top_srcdir)/aminclude_static.am
+clean-local: code-coverage-clean
+distclean-local: code-coverage-dist-clean
+else
+@CODE_COVERAGE_RULES@
+endif
+
+noinst_LTLIBRARIES = libethstatscmds_common.la
+libethstatscmds_common_la_SOURCES = ethstats.cpp handler.cpp
+libethstatscmds_common_la_CXXFLAGS = $(LIBIPMID_CFLAGS) $(CODE_COVERAGE_CXXFLAGS)
+libethstatscmds_common_la_LDFLAGS = $(LIBIPMID_LIBS) $(CODE_COVERAGE_LIBS) -lstdc++fs
+
libethstatscmddir = ${libdir}/ipmid-providers
libethstatscmd_LTLIBRARIES = libethstatscmd.la
-libethstatscmd_la_SOURCES = main.cpp ethstats.cpp handler.cpp
-
+libethstatscmd_la_SOURCES = main.cpp
+libethstatscmd_la_LIBADD = libethstatscmds_common.la
libethstatscmd_la_LDFLAGS = \
$(LIBIPMID_LIBS) \
+ $(CODE_COVERAGE_LIBS) \
-lstdc++fs \
-version-info 0:0:0 -shared
-
libethstatscmd_la_CXXFLAGS = \
$(LIBIPMID_CFLAGS) \
+ $(CODE_COVERAGE_CXXFLAGS) \
-flto
SUBDIRS = . test
diff --git a/configure.ac b/configure.ac
index 0aa9a59..bb12c7b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,9 +3,22 @@
AC_INIT([phosphor-ipmi-ethstats], [1.0], [https://www.github.com/openbmc/phosphor-ipmi-ethstats/issues])
AC_LANG([C++])
AC_CONFIG_HEADERS([config.h])
-AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign dist-xz])
AM_SILENT_RULES([yes])
+# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
+# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
+# to stop them from populating default CFLAGS and CXXFLAGS.
+AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
+AS_IF([test "x$enable_code_coverage" != "xno"], [
+ AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
+ AC_SUBST(CXXFLAGS, [""])
+ ])
+ AS_IF([test "x${CFLAGS+set}" != "xset"], [
+ AC_SUBST(CFLAGS, [""])
+ ])
+])
+
# Checks for programs.
AC_PROG_CXX
AM_PROG_AR
@@ -92,6 +105,13 @@
AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
])
+# Code coverage
+AX_CODE_COVERAGE
+m4_ifdef([_AX_CODE_COVERAGE_RULES],
+ [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
+ [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
+AX_ADD_AM_MACRO_STATIC([])
+
# Do you want to install with the Google OEM Number as well.
AC_ARG_ENABLE([google],
AS_HELP_STRING(
diff --git a/test/Makefile.am b/test/Makefile.am
index e754936..0468348 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,17 +1,23 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/ \
$(GTEST_CFLAGS) \
- $(GMOCK_CFLAGS)
+ $(GMOCK_CFLAGS) \
+ $(CODE_COVERAGE_CPPFLAGS)
+AM_CFLAGS = \
+ $(CODE_COVERAGE_CFLAGS)
+AM_CXXFLAGS = \
+ $(CODE_COVERAGE_CXXFLAGS)
AM_LDFLAGS = \
$(GTEST_LIBS) \
$(GMOCK_LIBS) \
-lgmock_main \
- $(OESDK_TESTCASE_FLAGS)
+ $(OESDK_TESTCASE_FLAGS) \
+ $(CODE_COVERAGE_LIBS)
check_PROGRAMS =
TESTS = $(check_PROGRAMS)
check_PROGRAMS += ethstats_unittest
ethstats_unittest_SOURCES = ethstats_unittest.cpp
-ethstats_unittest_LDADD = $(top_builddir)/ethstats.o
+ethstats_unittest_LDADD = $(top_builddir)/libethstatscmds_common.la