From 1daa2632fbabf0afc2f406218f55d9331c4ccbf3 Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Thu, 25 Feb 2021 09:48:38 +0100 Subject: [PATCH] allow to generate code coverage --- .gitignore | 3 +++ Makefile.in | 21 ++++++++++++++++----- configure.ac | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 4e16b85..7ea8681 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,10 @@ *.d /iast /tests/test +/tests/coverage *.1.gz +*.gcno +*.gcda /Makefile /configure diff --git a/Makefile.in b/Makefile.in index 6c3fb33..02e165b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,11 +12,13 @@ bindir = @bindir@ datarootdir = @datarootdir@ mandir = @mandir@ -CFLAGS = -Wall @CFLAGS@ +USE_GCOV = @USE_GCOV@ + +CFLAGS = -Wall @CFLAGS@ @COVERAGE_CFLAGS@ LFLAGS = TEST_CFLAGS = @CFLAGS@ @CHECK_CFLAGS@ -TEST_LFLAGS = @CHECK_LIBS@ +TEST_LFLAGS = @CHECK_LIBS@ @COVERAGE_LFLAGS@ OBJECTS = iast.o iast-czech.o transliteration.o transcription.o utf8.o velthuis.o TEST_OBJECTS = tests/main.o tests/translit.o tests/transcript.o tests/velthuis.o @@ -31,7 +33,7 @@ include $(wildcard *.d tests/*.d) $(PROGNAME): main.o $(OBJECTS) $(QUIET_LD) $(CC) $^ -o $@ $(LFLAGS) -test: all +test: tests/test tests/test %.o: %.c @@ -41,7 +43,7 @@ tests/%.o: tests/%.c $(QUIET_CC) $(CC) -MMD -MP -c $< -o $@ $(TEST_CFLAGS) tests/test: $(OBJECTS) $(TEST_OBJECTS) - $(QUIET_LD) $(CC) $^ -o $@ $(TEST_CFLAGS) $(TEST_LFLAGS) + $(QUIET_LD) $(CC) $^ -o $@ $(TEST_LFLAGS) %.1.gz: %.1 $(QUIET_GEN) cat $< | gzip -f >$@ @@ -57,13 +59,22 @@ uninstall: clean: $(RM) $(PROGNAME) tests/test $(PROGNAME).1.gz - $(RM) *.o */*.o */*.d *.d + $(RM) -r *.o */*.o */*.d *.d *.gcda *.gcno tests/coverage clean-aux: $(RM) -r $(AUX_FILES) distclean: clean clean-aux +ifeq ($(USE_GCOV),yes) +coverage: + $(MAKE) test + $(MKDIR_P) tests/coverage + lcov --no-external -c -d $(shell pwd) -o tests/coverage/coverage.info + genhtml -o tests/coverage -t "IAST Test Coverage" \ + tests/coverage/coverage.info +endif + ifndef V QUIET_CC = @echo " CC $@"; diff --git a/configure.ac b/configure.ac index 86653ec..0fb5bc4 100644 --- a/configure.ac +++ b/configure.ac @@ -29,5 +29,29 @@ AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([memmove]) +# Enable for gcov if option --enable-gcov is present. +USE_GCOV=no +AC_MSG_CHECKING([whether gcov should be enabled]) +AC_ARG_ENABLE(gcov, + AS_HELP_STRING([--enable-gcov], [enable gcov code coverage analysis]), [ + if test "x$enableval" != "xno" ; then + if test "$GCC" != "yes"; then + AC_MSG_ERROR([gcc is required for --enable-gcov]) + fi + AC_MSG_RESULT(yes) + COVERAGE_CFLAGS="-O0 -g -fno-inline -fprofile-arcs -ftest-coverage" + COVERAGE_LFLAGS="-fprofile-arcs -lgcov" + USE_GCOV=yes + else + AC_MSG_RESULT(no) + COVERAGE_CFLAGS="" + COVERAGE_LFLAGS="" + USE_GCOV=no + fi +], [AC_MSG_RESULT(no)]) +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_LFLAGS) +AC_SUBST(USE_GCOV) + AC_CONFIG_FILES([Makefile]) AC_OUTPUT