From 24dafff9093bcec93037b9e8b65b29d37d6f4d2e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 6 Jan 2017 09:48:48 +1000 Subject: 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 Acked-by: Benjamin Tissoires --- test/Makefile.am | 51 ++++++++++---------------------------------- test/generate-gcov-report.sh | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 40 deletions(-) create mode 100755 test/generate-gcov-report.sh (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index b0642ca..264d3f9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 - -gcov-clean: - @rm -f *.gcov - -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 "========== =============== ========" >> $@; \ - ) +CLEANFILES = gcov-reports/*.gcov gcov-reports/summary.txt *.gcno *.gcda + +gcov-report: generate-gcov-report.sh check-TESTS + $(AM_V_GEN)$(srcdir)/generate-gcov-report.sh gcov-reports $(top_builddir)/libevdev $(builddir) -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 diff --git a/test/generate-gcov-report.sh b/test/generate-gcov-report.sh new file mode 100755 index 0000000..f871a5b --- /dev/null +++ b/test/generate-gcov-report.sh @@ -0,0 +1,38 @@ +#!/bin/bash -e + +if [[ $# -lt 2 ]]; then + echo "Usage: ./generate-gcov-report.sh [ ... ]" + 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" -- cgit v1.2.1