diff --git a/.gitignore b/.gitignore index 6fe1958..5cf99f8 100644 --- a/.gitignore +++ b/.gitignore @@ -58,6 +58,7 @@ Makefile.in /tests/*-test.log /tests/*-test.trs /tests/test-suite.log +/swe-glib-lcov* # Translation related files /ABOUT-NLS diff --git a/Makefile.am b/Makefile.am index f410c88..1ce1898 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +include $(top_srcdir)/swe-glib.mk + ACLOCAL_AMFLAGS = -I m4 SUBDIRS = swe swe/src swe/doc src po data tests @@ -9,11 +11,11 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc intltool_extra = intltool-extract.in intltool-merge.in intltool-update.in -EXTRA_DIST = $(intltool_extra) $(header_DATA) autogen.sh +EXTRA_DIST += $(intltool_extra) $(header_DATA) autogen.sh -DISTCLEANFILES = intltool-extract intltool-merge intltool-update +DISTCLEANFILES += intltool-extract intltool-merge intltool-update -MAINTAINERCLEANFILES = ChangeLog +MAINTAINERCLEANFILES += ChangeLog distclean-local: if test "$(srcdir)" = "."; then :; else \ diff --git a/configure.ac b/configure.ac index ac01457..a10577f 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,14 @@ AC_INIT([SWE-GLib], [swe_glib_version], [gergely@polonkai.eu], [swe-glib]) AM_INIT_AUTOMAKE([-Wall foreign]) AC_CONFIG_HEADERS([config.h]) AM_SILENT_RULES([yes]) -AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug], [compile with debugging support])], , enable_debug=no) + +dnl ******************************** +dnl *** Enable debugging support *** +dnl ******************************** +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--enable-debug], + [compile with debugging support]), + [enable_debug=$enableval], [enable_debug=no]) if test "x$enable_debug" = "xyes" ; then AC_DEFINE([DEBUG], [1], [Define if debugging is enabled]) @@ -68,6 +75,84 @@ AM_CONDITIONAL(OS_WIN32, [test "$native_win32" = "yes"]) AM_CONDITIONAL(OS_UNIX, [test "$native_win32" != "yes"]) AC_PATH_PROG([GTESTER], [gtester]) AC_PATH_PROG([GTESTER_REPORT], [gtester-report]) + +dnl ************************************ +dnl *** Enable lcov coverage reports *** +dnl ************************************ + +AC_ARG_ENABLE(coverage, + AS_HELP_STRING([--enable-coverage], + [enable coverage testing with gcov]), + [use_gcov=$enableval], [use_gcov=no]) + +AS_IF([ test "x$use_gcov" = "xyes"], [ + dnl we need gcc: + if test "$GCC" != "yes"; then + AC_MSG_ERROR([GCC is required for --enable-coverage]) + fi + + dnl Check if ccache is being used + AC_CHECK_PROG(SHTOOL, shtool, shtool) + case `$SHTOOL path $CC` in + *ccache*[)] gcc_ccache=yes;; + *[)] gcc_ccache=no;; + esac + + if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then + AC_MSG_ERROR([ccache must be disabled when --enable-coverage option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) + fi + + ltp_version_list="1.6 1.7 1.8 1.9 1.10" + AC_CHECK_PROG(LTP, lcov, lcov) + AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml) + + AS_IF([ test "$LTP" ], [ + AC_CACHE_CHECK([for ltp version], glib_cv_ltp_version, [ + glib_cv_ltp_version=invalid + ltp_version=`$LTP -v 2>/dev/null | $SED -e 's/^.* //'` + for ltp_check_version in $ltp_version_list; do + if test "$ltp_version" = "$ltp_check_version"; then + glib_cv_ltp_version="$ltp_check_version (ok)" + fi + done + ]) + ], [ + ltp_msg="To enable code coverage reporting you must have one of the following LTP versions installed: $ltp_version_list" + AC_MSG_ERROR([$ltp_msg]) + ]) + + case $glib_cv_ltp_version in + ""|invalid[)] + ltp_msg="You must have one of the following versions of LTP: $ltp_version_list (found: $ltp_version)." + AC_MSG_ERROR([$ltp_msg]) + LTP="exit 0;" + ;; + esac + + if test -z "$LTP_GENHTML"; then + AC_MSG_ERROR([Could not find genhtml from the LTP package]) + fi + + dnl Remove all optimization flags from CFLAGS + changequote({,}) + CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` + changequote([,]) + + dnl Add the special gcc flags + CFLAGS="$CFLAGS -O0 -fprofile-arcs -ftest-coverage" + LDFLAGS="$LDFLAGS -lgcov" +]) + +if test "x$enable_debug" = "xyes" ; then + AC_DEFINE([DEBUG], [1], [Define if debugging is enabled]) + if test x$cflags_set != xset ; then + case " $CFLAGS " in + *[[\ \ ]]-g[[\ \ ]]*) ;; + *) CFLAGS="$CFLAGS -g" ;; + esac + fi +fi + PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.32.0]) PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.32.0]) PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.26]) diff --git a/src/Makefile.am b/src/Makefile.am index 87a27ee..6e4c14d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,7 @@ ## Process this file with automake to produce Makefile.in + +include $(top_srcdir)/swe-glib.mk + AM_CPPFLAGS = -DG_LOG_DOMAIN=\"SWE-GLib\" -DLOCALEDIR=\"$(localedir)\" -D__SWE_GLIB_BUILDING__ -DPKGDATADIR=\"$(pkgdatadir)\" lib_LTLIBRARIES = libswe-glib-2.0.la diff --git a/swe-glib.mk b/swe-glib.mk new file mode 100644 index 0000000..33d4993 --- /dev/null +++ b/swe-glib.mk @@ -0,0 +1,132 @@ +# SWE-GLib - GLib wrapper around the Swiss Ephemeris library + +GTESTER = gtester +GTESTER_REPORT = gtester-report +NULL = + +# initialize variables for unconditional += appending +BUILT_SOURCES = +BUILT_EXTRA_DIST = +CLEANFILES = *.log *.trs +DISTCLEANFILES = +MAINTAINERCLEANFILES = +EXTRA_DIST = +TEST_PROGS = + +noinst_LTLIBRARIES = +noinst_PROGRAMS = +noinst_SCRIPTS = +noinst_DATA = + +check_LTLIBRARIES = +check_PROGRAMS = +check_SCRIPTS = +check_DATA = + +TESTS = + +# test-nonrecursive: run tests only in cwd +if OS_UNIX +test-nonrecursive: ${TEST_PROGS} + @test -z "${TEST_PROGS}" || G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" G_DEBUG=gc-friendly MALLOC_CHECK_=2 MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) ${GTESTER} --verbose ${TEST_PROGS} +else +test-nonrecursive: +endif + +.PHONY: test-nonrecursive + +.PHONY: lcov genlcov lcov-clean +# use recursive makes in order to ignore errors during check +lcov: + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) genlcov + +# we have to massage the lcov.info file slightly to hide the effect of libtool +# placing the objects files in the .libs/ directory separate from the *.c +# we also have to delete tests/.libs/libmoduletestplugin_*.gcda +genlcov: + $(AM_V_GEN) rm -f $(top_builddir)/tests/.libs/libmoduletestplugin_*.gcda; \ + $(LTP) --quiet --directory $(top_builddir) --capture --output-file swe-glib-lcov.info --test-name SWE_GLIB_PERF --no-checksum --compat-libtool --ignore-errors source; \ + $(LTP) --quiet --output-file swe-glib-lcov.info --remove swe-glib-lcov.info docs/reference/\* /tmp/\* gio/tests/gdbus-object-manager-example/\* ; \ + LANG=C $(LTP_GENHTML) --quiet --prefix $(top_builddir) --output-directory swe-glib-lcov --title "SWE-GLib Code Coverage" --legend --frames --show-details swe-glib-lcov.info --ignore-errors source + @echo "file://$(abs_top_builddir)/swe-glib-lcov/index.html" + +lcov-clean: + if test -n "$(LTP)"; then \ + $(LTP) --quiet --directory $(top_builddir) -z; \ + fi + +# run tests in cwd as part of make check +check-local: test-nonrecursive + +# We support a fairly large range of possible variables. It is expected that all types of files in a test suite +# will belong in exactly one of the following variables. +# +# First, we support the usual automake suffixes, but in lowercase, with the customary meaning: +# +# test_programs, test_scripts, test_data, test_ltlibraries +# +# The above are used to list files that are involved in both uninstalled and installed testing. The +# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite. +# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data is +# installed in the same way as it appears in the package layout. +# +# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled', +# like so: +# +# installed_test_programs, uninstalled_test_programs +# installed_test_scripts, uninstalled_test_scripts +# installed_test_data, uninstalled_test_data +# installed_test_ltlibraries, uninstalled_test_ltlibraries +# +# Additionally, we support 'extra' infixes for programs and scripts. This is used for support programs/scripts +# that should not themselves be run as testcases (but exist to be used from other testcases): +# +# test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs +# test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts +# +# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or data +# file automatically end up in the tarball. +# +# dist_test_scripts, dist_test_data, dist_test_extra_scripts +# dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts +# dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts +# +# Note that no file is automatically disted unless it appears in one of the dist_ variables. This follows the +# standard automake convention of not disting programs scripts or data by default. +# +# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their disted +# variants) will be run as part of the in-tree 'make check'. These are all assumed to be runnable under +# gtester. That's a bit strange for scripts, but it's possible. + +# we use test -z "$(TEST_PROGS)" above, so make sure we have no extra whitespace... +TEST_PROGS += $(strip $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \ + $(dist_test_scripts) $(dist_uninstalled_test_scripts)) + +if OS_WIN32 +TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \ + $(dist_test_scripts) $(dist_uninstalled_test_scripts) +endif + +# Note: build even the installed-only targets during 'make check' to ensure that they still work. +# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to +# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were +# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'. +all_test_programs = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \ + $(test_extra_programs) $(uninstalled_test_extra_programs) $(installed_test_extra_programs) +all_test_scripts = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \ + $(test_extra_scripts) $(uninstalled_test_extra_scripts) $(installed_test_extra_scripts) +all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts) \ + $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts) $(dist_installed_test_extra_scripts) +all_test_scripts += $(all_dist_test_scripts) +EXTRA_DIST += $(all_dist_test_scripts) +all_test_data = $(test_data) $(uninstalled_test_data) $(installed_test_data) +all_dist_test_data = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data) +all_test_data += $(all_dist_test_data) +EXTRA_DIST += $(all_dist_test_data) +all_test_ltlibs = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries) + +check_LTLIBRARIES += $(all_test_ltlibs) +check_PROGRAMS += $(all_test_programs) +check_SCRIPTS += $(all_test_scripts) +check_DATA += $(all_test_data) diff --git a/tests/Makefile.am b/tests/Makefile.am index bdba2af..3865b06 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,186 +1,4 @@ -# glib.mk - Borrowed from GLib -# initialize variables for unconditional += appending -BUILT_SOURCES = -BUILT_EXTRA_DIST = -CLEANFILES = *.log *.trs -DISTCLEANFILES = -MAINTAINERCLEANFILES = -EXTRA_DIST = -TEST_PROGS = - -noinst_LTLIBRARIES = -noinst_PROGRAMS = -noinst_SCRIPTS = -noinst_DATA = - -check_LTLIBRARIES = -check_PROGRAMS = -check_SCRIPTS = -check_DATA = - -TESTS = - -### testing rules - -# test: run all tests in cwd and subdirs -test: test-nonrecursive -if OS_UNIX - @ for subdir in $(SUBDIRS) . ; do \ - test "$$subdir" = "." -o "$$subdir" = "po" || \ - ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \ - done - -# test-nonrecursive: run tests only in cwd -test-nonrecursive: ${TEST_PROGS} - @test -z "${TEST_PROGS}" || G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" G_DEBUG=gc-friendly MALLOC_CHECK_=2 MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) ${GTESTER} --verbose ${TEST_PROGS} -else -test-nonrecursive: -endif - -# test-report: run tests in subdirs and generate report -# perf-report: run tests in subdirs with -m perf and generate report -# full-report: like test-report: with -m perf and -m slow -test-report perf-report full-report: ${TEST_PROGS} - @test -z "${TEST_PROGS}" || { \ - case $@ in \ - test-report) test_options="-k";; \ - perf-report) test_options="-k -m=perf";; \ - full-report) test_options="-k -m=perf -m=slow";; \ - esac ; \ - if test -z "$$GTESTER_LOGDIR" ; then \ - G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \ - elif test -n "${TEST_PROGS}" ; then \ - G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \ - fi ; \ - } - @ ignore_logdir=true ; \ - if test -z "$$GTESTER_LOGDIR" ; then \ - GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \ - ignore_logdir=false ; \ - fi ; \ - if test -d "$(top_srcdir)/.git" ; then \ - REVISION=`git describe` ; \ - else \ - REVISION=$(VERSION) ; \ - fi ; \ - for subdir in $(SUBDIRS) . ; do \ - test "$$subdir" = "." -o "$$subdir" = "po" || \ - ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \ - done ; \ - $$ignore_logdir || { \ - echo '' > $@.xml ; \ - echo '' >> $@.xml ; \ - echo '' >> $@.xml ; \ - echo ' $(PACKAGE)' >> $@.xml ; \ - echo ' $(VERSION)' >> $@.xml ; \ - echo " $$REVISION" >> $@.xml ; \ - echo '' >> $@.xml ; \ - for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \ - sed '1,1s/^?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \ - done ; \ - echo >> $@.xml ; \ - echo '' >> $@.xml ; \ - rm -rf "$$GTESTER_LOGDIR"/ ; \ - ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \ - } -.PHONY: test test-report perf-report full-report test-nonrecursive - -.PHONY: lcov genlcov lcov-clean -# use recursive makes in order to ignore errors during check -lcov: - -$(MAKE) $(AM_MAKEFLAGS) -k check - $(MAKE) $(AM_MAKEFLAGS) genlcov - -# we have to massage the lcov.info file slightly to hide the effect of libtool -# placing the objects files in the .libs/ directory separate from the *.c -# we also have to delete tests/.libs/libmoduletestplugin_*.gcda -genlcov: - rm -f $(top_builddir)/tests/.libs/libmoduletestplugin_*.gcda - $(LTP) --directory $(top_builddir) --capture --output-file glib-lcov.info --test-name GLIB_PERF --no-checksum --compat-libtool - LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory glib-lcov --title "GLib Code Coverage" --legend --show-details glib-lcov.info - @echo "file://$(abs_top_builddir)/glib-lcov/index.html" - -lcov-clean: - -$(LTP) --directory $(top_builddir) -z - -rm -rf glib-lcov.info glib-lcov - -find -name '*.gcda' -print | xargs rm - -# run tests in cwd as part of make check -check-local: test-nonrecursive - -# We support a fairly large range of possible variables. It is expected that all types of files in a test suite -# will belong in exactly one of the following variables. -# -# First, we support the usual automake suffixes, but in lowercase, with the customary meaning: -# -# test_programs, test_scripts, test_data, test_ltlibraries -# -# The above are used to list files that are involved in both uninstalled and installed testing. The -# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite. -# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data is -# installed in the same way as it appears in the package layout. -# -# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled', -# like so: -# -# installed_test_programs, uninstalled_test_programs -# installed_test_scripts, uninstalled_test_scripts -# installed_test_data, uninstalled_test_data -# installed_test_ltlibraries, uninstalled_test_ltlibraries -# -# Additionally, we support 'extra' infixes for programs and scripts. This is used for support programs/scripts -# that should not themselves be run as testcases (but exist to be used from other testcases): -# -# test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs -# test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts -# -# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or data -# file automatically end up in the tarball. -# -# dist_test_scripts, dist_test_data, dist_test_extra_scripts -# dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts -# dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts -# -# Note that no file is automatically disted unless it appears in one of the dist_ variables. This follows the -# standard automake convention of not disting programs scripts or data by default. -# -# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their disted -# variants) will be run as part of the in-tree 'make check'. These are all assumed to be runnable under -# gtester. That's a bit strange for scripts, but it's possible. - -# we use test -z "$(TEST_PROGS)" above, so make sure we have no extra whitespace... -TEST_PROGS += $(strip $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \ - $(dist_test_scripts) $(dist_uninstalled_test_scripts)) - -if OS_WIN32 -TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \ - $(dist_test_scripts) $(dist_uninstalled_test_scripts) -endif - -# Note: build even the installed-only targets during 'make check' to ensure that they still work. -# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to -# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were -# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'. -all_test_programs = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \ - $(test_extra_programs) $(uninstalled_test_extra_programs) $(installed_test_extra_programs) -all_test_scripts = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \ - $(test_extra_scripts) $(uninstalled_test_extra_scripts) $(installed_test_extra_scripts) -all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts) \ - $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts) $(dist_installed_test_extra_scripts) -all_test_scripts += $(all_dist_test_scripts) -EXTRA_DIST += $(all_dist_test_scripts) -all_test_data = $(test_data) $(uninstalled_test_data) $(installed_test_data) -all_dist_test_data = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data) -all_test_data += $(all_dist_test_data) -EXTRA_DIST += $(all_dist_test_data) -all_test_ltlibs = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries) - -check_LTLIBRARIES += $(all_test_ltlibs) -check_PROGRAMS += $(all_test_programs) -check_SCRIPTS += $(all_test_scripts) -check_DATA += $(all_test_data) - -# End of glib.mk +include $(top_srcdir)/swe-glib.mk LDADD = $(top_builddir)/src/libswe-glib-2.0.la DEFS = -DG_LOG_DOMAIN=\"SWE-GLib\" @@ -189,4 +7,3 @@ AM_CFLAGS = -g test_programs = gswe-timestamp-test TESTS += $(test_programs) - diff --git a/tests/gswe-timestamp-test.c b/tests/gswe-timestamp-test.c index cf70786..a78317a 100644 --- a/tests/gswe-timestamp-test.c +++ b/tests/gswe-timestamp-test.c @@ -75,4 +75,3 @@ main(int argc, char **argv) return g_test_run(); } -