From 931b2b0f50e4446a705d2238274914f78b681b6d Mon Sep 17 00:00:00 2001 From: Timo Tietavainen Date: Mon, 11 May 2020 11:48:39 +0300 Subject: [PATCH] Add unit test code coverage (gcov) make target 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 Change-Id: I40edf53ad4abe599a86e963326b338d27f3c002f --- .gitignore | 3 +++ Makefile.am | 17 +++++++++++++++++ README.md | 25 +++++++++++++++++++++++++ configure.ac | 17 +++++++++++++++++ debian/changelog.in | 6 ++++++ docs/developer-guide.rst | 23 +++++++++++++++++++++++ docs/release-notes.rst | 4 ++++ rpm/sdl.spec.in | 5 ++++- 8 files changed, 99 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c11b9dd..cf75c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,9 @@ /doxygen-doc/ /run-tests.sh /testrunner +*.gcov +*.gcda +*.gcno .tox docs/_build/ *.log diff --git a/Makefile.am b/Makefile.am index 1e75af9..499b862 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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@ diff --git a/README.md b/README.md index 52e6503..9f43ec6 100644 --- 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. diff --git a/configure.ac b/configure.ac index f725e1b..6d073c6 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/debian/changelog.in b/debian/changelog.in index baf5140..2b1875f 100644 --- a/debian/changelog.in +++ b/debian/changelog.in @@ -1,3 +1,9 @@ +sdl (1.1.1-1) UNRELEASED; urgency=low + + * Add unit test code coverage (gcov) make target. + + -- Timo Tietavainen Mon, 11 May 2020 11:35:53 +0300 + sdl (1.1.0-1) unstable; urgency=medium * Add public helper classes for UT mocking. diff --git a/docs/developer-guide.rst b/docs/developer-guide.rst index b8dc8e1..cdf5567 100644 --- a/docs/developer-guide.rst +++ b/docs/developer-guide.rst @@ -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 ================ diff --git a/docs/release-notes.rst b/docs/release-notes.rst index a109c43..e328775 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -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. diff --git a/rpm/sdl.spec.in b/rpm/sdl.spec.in index 5709bb7..fae0561 100755 --- a/rpm/sdl.spec.in +++ b/rpm/sdl.spec.in @@ -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 - 1.1.1-1 +- Add unit test code coverage (gcov) make target. + * Thu Jan 09 2020 Timo Tietavainen - 1.1.0-1 - Add public helper classes for UT mocking. -- 2.16.6