Add support for coverage reports with lcov
[platform/upstream/glib.git] / Makefile.decl
1 # GLIB - Library of useful C routines
2
3 #GTESTER = gtester                      # for non-GLIB packages
4 GTESTER = $(top_builddir)/glib/gtester                  # for the GLIB package
5 GTESTER_REPORT = $(top_builddir)/glib/gtester-report    # for the GLIB package
6
7 # initialize variables for unconditional += appending
8 EXTRA_DIST =
9 TEST_PROGS =
10
11 ### testing rules
12
13 # test: run all tests in cwd and subdirs
14 test:   ${TEST_PROGS}
15 if OS_UNIX
16         @test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
17         @ for subdir in $(SUBDIRS) . ; do \
18             test "$$subdir" = "." -o "$$subdir" = "po" || \
19             ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
20           done
21 endif
22
23 # test-report: run tests in subdirs and generate report
24 # perf-report: run tests in subdirs with -m perf and generate report
25 # full-report: like test-report: with -m perf and -m slow
26 test-report perf-report full-report:    ${TEST_PROGS}
27         @test -z "${TEST_PROGS}" || { \
28           case $@ in \
29           test-report) test_options="-k";; \
30           perf-report) test_options="-k -m=perf";; \
31           full-report) test_options="-k -m=perf -m=slow";; \
32           esac ; \
33           if test -z "$$GTESTER_LOGDIR" ; then  \
34             ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
35           elif test -n "${TEST_PROGS}" ; then \
36             ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
37           fi ; \
38         }
39         @ ignore_logdir=true ; \
40           if test -z "$$GTESTER_LOGDIR" ; then \
41             GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
42             ignore_logdir=false ; \
43           fi ; \
44           for subdir in $(SUBDIRS) . ; do \
45             test "$$subdir" = "." -o "$$subdir" = "po" || \
46             ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
47           done ; \
48           $$ignore_logdir || { \
49             echo '<?xml version="1.0"?>'            > $@.xml ; \
50             echo '<report-collection>'             >> $@.xml ; \
51             echo '<info>'                          >> $@.xml ; \
52             echo '  <package>$(PACKAGE)</package>' >> $@.xml ; \
53             echo '  <version>$(VERSION)</version>' >> $@.xml ; \
54             echo '</info>'                         >> $@.xml ; \
55             for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
56               sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
57             done ; \
58             echo >> $@.xml ; \
59             echo '</report-collection>' >> $@.xml ; \
60             rm -rf "$$GTESTER_LOGDIR"/ ; \
61             ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
62           }
63 .PHONY: test test-report perf-report full-report
64
65 .PHONY: lcov genlcov lcov-clean
66 # use recursive makes in order to ignore errors during check
67 lcov:
68         -$(MAKE) $(AM_MAKEFLAGS) -k check
69         $(MAKE) $(AM_MAKEFLAGS) genlcov
70
71 # we have to massage the lcov.info file slightly to hide the effect of libtool
72 # placing the objects files in the .libs/ directory separate from the *.c
73 # we also have to delete tests/.libs/libmoduletestplugin_*.gcda
74 genlcov:
75         rm -f $(top_builddir)/tests/.libs/libmoduletestplugin_*.gcda
76         $(LTP) --directory $(top_builddir) --capture --output-file glib-lcov.info --test-name GLIB_PERF --no-checksum
77         $(SED) -e 's#.libs/##' < glib-lcov.info > glib-lcov.info.tmp
78         LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory glib-lcov --title "GLib Code Coverage" --legend --show-details glib-lcov.info.tmp
79         rm -f glib-lcov.info.tmp
80
81 lcov-clean:
82         -$(LTP) --directory $(top_builddir) -z
83         -rm -rf glib-lcov.info glib-lcov
84         -find -name '*.gcda' -print | xargs rm
85
86 # run make test as part of make check
87 check-local: test