tests: generating coverage version of the libraries 26/114926/1 accepted/tizen/common/20170309.175450 accepted/tizen/ivi/20170310.031857 accepted/tizen/mobile/20170310.031756 accepted/tizen/tv/20170310.031822 accepted/tizen/unified/20170310.080539 accepted/tizen/wearable/20170310.031840 submit/tizen/20170309.042420 submit/tizen_unified/20170310.011402
authorAdrian Szyndela <adrian.s@samsung.com>
Mon, 6 Feb 2017 11:16:44 +0000 (12:16 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Wed, 15 Feb 2017 15:01:31 +0000 (16:01 +0100)
Change-Id: I2cb0a26bc55cd0f932d59a8fc14da96349aa0b8a

configure.ac
packaging/coverage.txt [new file with mode: 0644]
packaging/glib2.spec

index 9dbe056..a3c603e 100644 (file)
@@ -2765,6 +2765,43 @@ AS_IF([ test "x$use_gcov" = "xyes"], [
   LDFLAGS="$LDFLAGS -lgcov"
 ])
 
+dnl ************************************
+dnl *** Enable gcov (without lcov) coverage reports ***
+dnl ************************************
+
+AC_ARG_ENABLE(gcov-coverage,
+  AS_HELP_STRING([--enable-gcov-coverage],
+                [enable coverage testing with gcov, without lcov]),
+  [use_only_gcov=$enableval], [use_only_gcov=no])
+
+AS_IF([ test "x$use_only_gcov" = "xyes"], [
+  dnl we need gcc:
+  if test "$GCC" != "yes"; then
+    AC_MSG_ERROR([GCC is required for --enable-gcov-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
+
+  dnl Remove all optimization flags from CFLAGS
+  changequote({,})
+  CFLAGS=`echo "$CFLAGS" | $SED -e 's/-Wl,-O[0-9]*//g'`
+  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"
+])
+
 dnl ******************************
 dnl *** output the whole stuff ***
 dnl ******************************
diff --git a/packaging/coverage.txt b/packaging/coverage.txt
new file mode 100644 (file)
index 0000000..ef5e4d4
--- /dev/null
@@ -0,0 +1,19 @@
+How to analyze coverage:
+1. gbs build adding --define '_with_coverage 1'
+2. take *.o and *.gcno files from compilation (
+               <gbs-build-root>/home/abuild/rpmbuild/BUILD/glib2-2.44.1/gio/.libs
+               <gbs-build-root>/home/abuild/rpmbuild/BUILD/glib2-2.44.1/glib/.libs
+               <gbs-build-root>/home/abuild/rpmbuild/BUILD/glib2-2.44.1/gmodule/.libs
+               <gbs-build-root>/home/abuild/rpmbuild/BUILD/glib2-2.44.1/gobject/.libs
+               <gbs-build-root>/home/abuild/rpmbuild/BUILD/glib2-2.44.1/gthread/.libs
+               ) into a /safe/place
+       you may also use generated rpm package glib2-coverage-objects.
+3. install coverage package (glib2-coverage) on the target
+4. run test programs adding LD_LIBRARY_PATH=/usr/lib/dbus-tests/coverage-libs
+       Data gathering is cumulative, so you can run multiple programs one after another.
+       Use GCOV_PREFIX and GCOV_PREFIX_STRIP environment variables to set output directory.
+       If not set, data files (*.gcda) will be generated in /home/abuild/rpmbuild/BUILD/glib2-2.44.1/.
+5. download generated gcda files from the target to /safe/place
+6. put source code *.c files together with object files into a /safe/place
+7. run gcov /safe/place/*.o
+       or gcov -r /safe/place/*.o for only local source code output
index 6dbb5d3..9ce05eb 100644 (file)
@@ -1,4 +1,5 @@
 %bcond_with dbuspolicy
+%bcond_with coverage
 %define baseline 2.40
 %define with_systemtap 0
 %define keepstatic 1
@@ -185,6 +186,24 @@ Requires:       %{name} = %{version}
 This package is part of 'dbus-integratnion-tests' framework and contains set of tests
 for gdbus component.
 
+%if %{with coverage}
+%package coverage
+Summary:    Special version of glib libraries for getting coverage analysis
+
+%description coverage
+Special version of glib libraries for getting coverage analysis. *.gcda coverage files
+are generated on each use of library in directory set by GCOV_PREFIX and GCOV_PREFIX_STRIP.
+Use the library by modifying LD_LIBRARY_PATH.
+This package is intended for debug/test use only.
+
+%package coverage-objects
+Summary:    Generated object files and gcov notes for coverage analysis
+
+%description coverage-objects
+Objects and gcno files to analyze coverage.
+This package is intended for debug/test use only.
+%endif
+
 %prep
 %setup -q -n %{name}-%{version}
 
@@ -198,6 +217,30 @@ if ! test -f %{_datadir}/aclocal/gtk-doc.m4 ; then
 fi
 NOAUTORECONF=1 NOCONFIGURE=1 ./autogen.sh
 export CFLAGS+=" -D_TIZEN_DBUS_TOUCH"
+
+# Support for generating separate packages with libraries generating coverage files
+# WARNING: if coverage build is enabled, incremental builds will not work correctly.
+#          Use the option only to generate glib2-coverage packages.
+%if %{with coverage}
+%reconfigure \
+    --disable-static \
+%if %{with dbuspolicy}
+    --enable-libdbuspolicy \
+%endif
+    --with-pcre=system \
+       --enable-gcov-coverage
+
+%{__make} %{?_smp_mflags} V=1
+
+mkdir -p coverage
+mv gio/.libs/libgio-2.0.so* glib/.libs/libglib-2.0.so* gthread/.libs/libgthread-2.0.so* gobject/.libs/libgobject-2.0.so* gmodule/.libs/libgmodule-2.0.so* coverage
+mkdir -p coverage-objects
+find g* -name '*.o' -exec mv '{}' coverage-objects ';'
+find g* -name '*.gcno' -exec mv '{}' coverage-objects ';'
+
+%{__make} clean
+%endif
+
 %reconfigure \
     --enable-static \
 %if 0%{?with_systemtap}
@@ -208,6 +251,9 @@ export CFLAGS+=" -D_TIZEN_DBUS_TOUCH"
 %endif
     --enable-always-build-tests \
     --enable-installed-tests \
+%if %{with coverage}
+       --disable-gcov-coverage \
+%endif
     --with-pcre=system
 
 %{__make} %{?_smp_mflags} V=1
@@ -238,20 +284,35 @@ touch %{buildroot}%{_libdir}/gio/modules/giomodule.cache
 touch %{buildroot}%{_datadir}/glib-2.0/schemas/gschemas.compiled
 # remove files we don't care about
 find %{buildroot}%{_libdir} -name '*.la' -type f -delete -print
-# preapre tests for 'dbus-integration-test' framework
-install -D -m 755 %{_builddir}/%{name}-%{version}/glib-tests %{buildroot}%{_prefix}/lib/dbus-tests/runner/glib-tests
-mkdir -p %{buildroot}%{_prefix}/lib/dbus-tests/test-suites/glib-tests/
-mv %{buildroot}%{_prefix}/libexec/installed-tests/glib/*gdbus-* %{buildroot}%{_prefix}/lib/dbus-tests/test-suites/glib-tests/
+
+# prepare tests for 'dbus-integration-test' framework
+%define relative_dbus_tests_base_dir %{_prefix}/lib/dbus-tests
+%define dbus_tests_base_dir %{buildroot}%{relative_dbus_tests_base_dir}
+
+install -D -m 755 %{_builddir}/%{name}-%{version}/glib-tests %{dbus_tests_base_dir}/runner/glib-tests
+mkdir -p %{dbus_tests_base_dir}/test-suites/glib-tests/
+mv %{buildroot}%{_prefix}/libexec/installed-tests/glib/*gdbus-* %{dbus_tests_base_dir}/test-suites/glib-tests/
 # workaround for UNIX fd passing test (gdbus-peer)
-echo "Testfile - check for UNIX fd passing" > %{buildroot}%{_prefix}/lib/dbus-tests/test-suites/glib-tests/file.c
-rm %{buildroot}%{_prefix}/lib/dbus-tests/test-suites/glib-tests/gdbus-testserver
+echo "Testfile - check for UNIX fd passing" > %{dbus_tests_base_dir}/test-suites/glib-tests/file.c
+rm %{dbus_tests_base_dir}/test-suites/glib-tests/gdbus-testserver
 rm -Rf %{buildroot}%{_prefix}/libexec/installed-tests/glib/
 rm -Rf %{buildroot}%{_prefix}/share/installed-tests/glib/
+
 # Install rpm macros
 mkdir -p %{buildroot}%{_sysconfdir}/rpm
 cp %{S:6} %{buildroot}%{_sysconfdir}/rpm
 %fdupes %{buildroot}
 
+# install libraries with coverage analysis enabled
+%if %{with coverage}
+%define relative_cov_lib_dir %{relative_dbus_tests_base_dir}/coverage-libs
+%define cov_lib_dir %{buildroot}%{relative_cov_lib_dir}
+
+mkdir -p %{cov_lib_dir}
+mkdir -p %{cov_lib_dir}/objects
+install -m 0755 coverage/*.so* %{cov_lib_dir}
+install -m 0644 coverage-objects/* %{cov_lib_dir}/objects
+%endif
 
 %post -n libglib -p /sbin/ldconfig
 
@@ -385,7 +446,14 @@ cp %{S:6} %{buildroot}%{_sysconfdir}/rpm
 
 %files tests
 %manifest %{name}.manifest
-%{_prefix}/lib/dbus-tests/test-suites/glib-tests/
-%{_prefix}/lib/dbus-tests/runner/glib-tests
+%{relative_dbus_tests_base_dir}/test-suites/glib-tests/
+%{relative_dbus_tests_base_dir}/runner/glib-tests
+
+%if %{with coverage}
+%files coverage
+%{relative_cov_lib_dir}/*.so*
+%files coverage-objects
+%{relative_cov_lib_dir}/objects/*
+%endif
 
 %changelog