Add unit test code coverage (gcov) make target 63/3663/8
authorTimo Tietavainen <timo.tietavainen@nokia.com>
Mon, 11 May 2020 08:48:39 +0000 (11:48 +0300)
committerTimo Tietavainen <timo.tietavainen@nokia.com>
Wed, 13 May 2020 09:55:35 +0000 (12:55 +0300)
Add autotool configure option to enable coverage analysis
and to specify location of coverage result (*.gcov) files:
  configure --with-gcov-report-dir=DIR

Add a new make target to run unit test and collect code coverage
analysis reports (*.gcov):
  make test_gcov

Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I40edf53ad4abe599a86e963326b338d27f3c002f

.gitignore
Makefile.am
README.md
configure.ac
debian/changelog.in
docs/developer-guide.rst
docs/release-notes.rst
rpm/sdl.spec.in

index c11b9dd..cf75c9e 100644 (file)
@@ -37,6 +37,9 @@
 /doxygen-doc/
 /run-tests.sh
 /testrunner
+*.gcov
+*.gcda
+*.gcno
 .tox
 docs/_build/
 *.log
index 1e75af9..499b862 100644 (file)
@@ -387,8 +387,25 @@ TESTS = \
 test: testrunner
        ./run-tests.sh
 
+if ENABLE_GCOV
+AM_CXXFLAGS= -O0 --coverage
+AM_LDFLAGS= --coverage
+
+test_gcov: test
+       @for p in src/.libs/*.o src/redis/.libs/*.o; do \
+               gcov -abcfru $$p 1>/dev/null; \
+       done
+       mkdir -p @GCOV_REPORT_DIR@
+       mv *.gcov @GCOV_REPORT_DIR@
+       ls -la @GCOV_REPORT_DIR@
+endif
+
 clean-local:
        rm -f libsdl.pc
+if ENABLE_GCOV
+       rm -rf @GCOV_REPORT_DIR@
+       @find . -name '*.gcno' -o -name '*.gcda'| xargs -r rm
+endif
 
 @DX_RULES@
 
index 52e6503..9f43ec6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -172,6 +172,31 @@ line options gtest supports, for example:
     make testrunner
     ./testrunner --help
 
+## Running unit tests with gcov
+
+Enable unit test gcov code coverage analysis by configuring gcov reporting
+directory:
+
+    configure --with-gcov-report-dir=DIR
+
+Directory can be an absolute path or a relative path to an SDL source root.
+Unit test build creates directory if it does not exist.
+
+Build and run unit tests with code coverage analysis:
+
+    make test_gcov
+
+After successful unit test run code coverage (.gcov) result files are in
+a directory, what was defined by '--with-gcov-report-dir' configure option.
+
+In addition, graphical gcov front-ends such as lcov can be used for coverage
+analysis:
+
+       lcov --directory tst/ --directory src --capture --output-file coverage.info
+       genhtml coverage.info --output-directory out
+
+Open the out/index.html using any web browser.
+
 ## Using SDL in application pod
 
 SDL is not yet available in O-RAN-SC PackageCloud.io repository.
index f725e1b..6d073c6 100644 (file)
@@ -72,6 +72,23 @@ AM_CONDITIONAL([HIREDIS], [test xtrue])
 AC_DEFINE(HAVE_HIREDIS_VIP, [0], [Have hiredis-vip])
 AM_CONDITIONAL([HIREDIS_VIP], [test "xyes" = "xno"])
 
+AC_ARG_WITH([gcov-report-dir],
+    AS_HELP_STRING([--with-gcov-report-dir=DIR],
+        [Directory for GCOV report files]),
+    [],
+    [with_gcov_report_dir=no])
+AC_MSG_CHECKING([gcov])
+if test "x$with_gcov_report_dir" = "xno"; then
+    AC_MSG_RESULT([no])
+    GCOV_REPORT_DIR="gcov_report"
+else
+    AC_MSG_RESULT([yes])
+    AC_MSG_NOTICE([gcov report directory: $with_gcov_report_dir])
+    GCOV_REPORT_DIR="$with_gcov_report_dir"
+fi
+AC_SUBST(GCOV_REPORT_DIR)
+AM_CONDITIONAL([ENABLE_GCOV],[test "x$with_gcov_report_dir" != "xno"])
+
 DX_DOT_FEATURE(ON)
 DX_INIT_DOXYGEN([shareddatalayer], [Doxyfile], [doxygen-doc])
 SDL_LT_VERSION=m4_format("%d:%d:%d", SDL_CURRENT, SDL_REVISION, SDL_AGE)
index baf5140..2b1875f 100644 (file)
@@ -1,3 +1,9 @@
+sdl (1.1.1-1) UNRELEASED; urgency=low
+
+  * Add unit test code coverage (gcov) make target.
+
+ -- Timo Tietavainen <timo.tietavainen@nokia.com>  Mon, 11 May 2020 11:35:53 +0300
+
 sdl (1.1.0-1) unstable; urgency=medium
 
   * Add public helper classes for UT mocking.
index b8dc8e1..cdf5567 100644 (file)
@@ -209,6 +209,29 @@ supports, for example::
     ./testrunner
     ./testrunner --gtest_filter=AsyncStorageTest*
 
+To get unit test code coverage analysis enable unit test gcov code coverage
+analysis by configuring gcov reporting directory:
+
+    configure --with-gcov-report-dir=DIR
+
+Directory can be an absolute path or a relative path to an SDL source root.
+Unit test build creates directory if it does not exist.
+
+Build and run unit tests with code coverage analysis:
+
+    make test_gcov
+
+After successful unit test run code coverage (.gcov) result files are in
+a directory, what was defined by '--with-gcov-report-dir' configure option.
+
+In addition, graphical gcov front-ends such as lcov can be used for coverage
+analysis:
+
+    lcov --directory tst/ --directory src --capture --output-file coverage.info
+    genhtml coverage.info --output-directory out
+
+Open the out/index.html using any web browser.
+
 Functional Tests
 ================
 
index a109c43..e328775 100644 (file)
@@ -30,6 +30,10 @@ ric-plt/sdl.
 Version history
 ---------------
 
+[1.1.1] - 2020-05-11
+
+* Add unit test code coverage (gcov) make target.
+
 [1.1.0] - 2020-01-09
 
 * Add public helper classes for UT mocking.
index 5709bb7..fae0561 100755 (executable)
@@ -1,5 +1,5 @@
 Name:     sdl
-Version:  1.1.0
+Version:  1.1.1
 Release:  1%{?dist}
 Summary:  C++ API library for Shared Data Layer clients
 
@@ -50,6 +50,9 @@ rm -f %{buildroot}%{_libdir}/lib*.*a
 %{_includedir}/sdl
 
 %changelog
+* Mon May 11 2020 Timo Tietavainen <timo.tietavainen@nokia.com> - 1.1.1-1
+- Add unit test code coverage (gcov) make target.
+
 * Thu Jan 09 2020 Timo Tietavainen <timo.tietavainen@nokia.com> - 1.1.0-1
 - Add public helper classes for UT mocking.