configure.ac: enable subdir-objects

The main thing holding us back here was our gcov hacks. We used to rebuild the
libevdev sources locally inside test/ with the gcov flags so that we could
leave the main libevdev sources untouched. This doesn't work well with
subdir-objects - we have to link to libevdev.la instead.

To enable gcov, we now have to apply the gcov flags to the main library
object. But this also means that when running, the notes files will be
somewhere within the libevdev/ directory, not the test/ directory. Working
around this in automake gets nasty quickly, so just add a script that knows
how to search for things.

No functional changes unless --enable-gcov is given at configure time - then
don't install the library.

The gcov reports are now in test/gcov-reports/

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Peter Hutterer 2017-01-06 09:48:48 +10:00
parent 1ee17e18ac
commit 24dafff909
4 changed files with 55 additions and 41 deletions

View file

@ -32,7 +32,7 @@ AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])
AC_USE_SYSTEM_EXTENSIONS
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz subdir-objects])
# Before making a release, the LIBEVDEV_LT_VERSION string should be
# modified.

View file

@ -1,6 +1,7 @@
lib_LTLIBRARIES=libevdev.la
AM_CPPFLAGS = $(GCC_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)
AM_CPPFLAGS = $(GCC_CFLAGS) $(GCOV_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)
AM_LDFLAGS = $(GCOV_LDFLAGS)
libevdev_la_SOURCES = \
libevdev.h \
@ -16,6 +17,7 @@ libevdev_la_SOURCES = \
../include/linux/uinput.h
libevdev_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info $(LIBEVDEV_LT_VERSION) \
-Wl,--version-script="$(srcdir)/libevdev.sym" \
$(GNU_LD_FLAGS)
@ -33,3 +35,6 @@ EXTRA_DIST = make-event-names.py libevdev.sym
CLEANFILES = event-names.h
BUILT_SOURCES = event-names.h
if GCOV_ENABLED
CLEANFILES += *.gcno
endif

View file

@ -22,7 +22,6 @@ test_static_link_LDADD = $(top_builddir)/libevdev/libevdev.la
test_static_link_LDFLAGS = $(AM_LDFLAGS) -static
check_local_deps =
clean_local_deps =
if ENABLE_RUNTIME_TESTS
run_tests = test-libevdev test-kernel
@ -35,15 +34,7 @@ if RUN_TESTS
TESTS = $(run_tests)
endif
libevdev_sources = $(top_srcdir)/libevdev/libevdev.c \
$(top_srcdir)/libevdev/libevdev.h \
$(top_srcdir)/libevdev/libevdev-names.c \
$(top_srcdir)/libevdev/libevdev-uinput.h \
$(top_srcdir)/libevdev/libevdev-uinput.c \
$(top_srcdir)/libevdev/libevdev-uinput-int.h \
$(top_srcdir)/libevdev/libevdev-util.h \
$(top_srcdir)/libevdev/libevdev-int.h
common_sources = $(libevdev_sources) \
common_sources = \
test-common-uinput.c \
test-common-uinput.h \
test-common.c \
@ -64,13 +55,13 @@ test_libevdev_SOURCES = \
test-uinput.c \
$(common_sources)
test_libevdev_LDADD = $(CHECK_LIBS)
test_libevdev_LDADD = $(CHECK_LIBS) $(top_builddir)/libevdev/libevdev.la
test_kernel_SOURCES = \
test-kernel.c \
$(common_sources)
test_kernel_CFLAGS = -I$(top_srcdir)
test_kernel_LDADD = $(CHECK_LIBS)
test_kernel_LDADD = $(CHECK_LIBS) $(top_builddir)/libevdev/libevdev.la
if HAVE_VALGRIND
VALGRIND_FLAGS=--leak-check=full \
@ -85,35 +76,19 @@ check_local_deps += valgrind
endif
EXTRA_DIST = valgrind.suppressions
EXTRA_DIST = valgrind.suppressions generate-gcov-report.sh
if GCOV_ENABLED
CLEANFILES = gcov-report.txt
CLEANFILES = gcov-reports/*.gcov gcov-reports/summary.txt *.gcno *.gcda
gcov-clean:
@rm -f *.gcov
gcov-report: generate-gcov-report.sh check-TESTS
$(AM_V_GEN)$(srcdir)/generate-gcov-report.sh gcov-reports $(top_builddir)/libevdev $(builddir)
gcov-report.txt: gcov-clean check-TESTS
$(AM_V_GEN)(rm -rf $@; \
echo "========== coverage report ========" >> $@; \
for file in `find $(top_srcdir)/libevdev -name "*.c" -printf "%P\n"`; do \
gcov $$file > /dev/null; \
if test -f $$file.gcov; then \
total=`grep -v " -:" $$file.gcov | wc -l`; \
missing=`grep "#####" $$file.gcov | wc -l`; \
hit=$$((total - missing)); \
echo -e "$$file: total lines: $$total not tested: $$missing ($$((($$hit * 100)/$$total))%)"; \
fi \
done >> $@; \
echo "========== =============== ========" >> $@; \
)
gcov: gcov-report.txt
@cat gcov-report.txt
gcov: gcov-report
@cat gcov-reports/summary.txt
check_local_deps += gcov
clean_local_deps += gcov-clean
else
@ -123,12 +98,10 @@ gcov-report.txt:
gcov:
@true
gcov-clean:
@true
endif # GCOV_ENABLED
.PHONY: gcov gcov-clean gcov-report.txt
.PHONY: gcov gcov-clean gcov-report
endif # ENABLE_RUNTIME_TESTS
@ -155,5 +128,3 @@ endif # HAVE_NM
check-local: $(check_local_deps)
clean-local: $(clean_local_deps)
rm -f *.gcno *.gcda

38
test/generate-gcov-report.sh Executable file
View file

@ -0,0 +1,38 @@
#!/bin/bash -e
if [[ $# -lt 2 ]]; then
echo "Usage: ./generate-gcov-report.sh <rel-target-dir> <srcdir> [<srcdir> ... ]"
exit 1
fi
target_dir=$1
shift
source_dirs=$*
if [[ "${target_dir:0:1}" != '/' ]]; then
target_dir="$PWD/$target_dir"
fi
summary_file="$target_dir/summary.txt"
mkdir -p "$target_dir"
rm -f "$target_dir"/*.gcov
for dir in $source_dirs; do
pushd "$dir" > /dev/null
for file in *.c; do
find ./ -name "*${file/\.c/.gcda}" -exec gcov {} \; > /dev/null
done
find ./ -name "*.gcov" \! -path "*/`basename "$target_dir"`/*" -exec mv {} "$target_dir" \;
popd > /dev/null
done
echo "========== coverage report ========" > "$summary_file"
for file in "$target_dir"/*.gcov; do
total=`grep -v " -:" "$file" | wc -l`
missing=`grep "#####" "$file" | wc -l`
hit=$((total - missing));
percent=$((($hit * 100)/$total))
fname=`basename "$file"`
printf "%-32s total lines: %4s not tested: %4s (%3s%%)\n" "$fname" "$total" "$missing" "$percent">> "$summary_file"
done
echo "========== =============== ========" >> "$summary_file"