Skip to contentSkip to conversation

build: Add coverage support

RFC Superseded Luiz Augusto von Dentz 3 participants 3 messages Dec 12, 2013 – Dec 13, 2013

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

RFC v2 1/1 build: Add coverage support

From: Luiz Augusto von Dentz <[email protected]>

Coverage is disabled by default but it is automatically enabled by bootstrap-configure using --enable-coverage, it creates a new make target 'coverage' that can be run after make check or any tester that produces .gdca files.

The build time using --enable-coverage is considerable bigger so if that is a problem just disable it, also this is the reason why it is not added directly under --enable-maintainer-mode so it is possible to turn off coverage without having to turn off maintainer mode.

Since lcov apparently cannot detect changes to .gcda there is another make target 'clean-coverage' so after that make coverage can be run again.

---
 Makefile.am         | 17 +++++++++++++++++
 acinclude.m4        |  8 ++++++++
 bootstrap-configure |  1 +
 configure.ac        |  5 +++++
 4 files changed, 31 insertions(+)
Makefile.am +17 -0
index 15cc149..4b3351a 100644
@@ -331,5 +331,22 @@ lib/bluetooth/%.h: lib/%.h
 	$(AM_V_at)$(MKDIR_P) lib/bluetooth
 	$(AM_V_GEN)$(LN_S) -f "$(abs_top_builddir)"/$< $@
 
+if COVERAGE
+clean-coverage:
+	$(RM) -r coverage
+
+coverage:
+	$(AM_V_at)$(MKDIR_P) -p coverage
+	@lcov --compat-libtool --directory $(top_builddir) --capture \
+					--output-file coverage/check.info
+	@genhtml -o coverage/ coverage/check.info
+
+clean-local: clean-coverage
+	@find $(top_builddir) -name "*.gcda" -exec $(RM) {} \;
+	@find $(top_builddir) -name "*.gcno" -exec $(RM) {} \;
+	@lcov --directory . --zerocounters
+	$(RM) -r lib/bluetooth
+else
 clean-local:
 	$(RM) -r lib/bluetooth
+endif
acinclude.m4 +8 -0
index 2065852..4bb8bde 100644
@@ -51,6 +51,14 @@ AC_DEFUN([MISC_FLAGS], [
 			misc_ldflags="$misc_ldflags -pie"
 		fi
 	])
+	AC_ARG_ENABLE(coverage, AC_HELP_STRING([--enable-coverage],
+						[enable coverage flags]), [
+		enable_coverage=${enableval}
+		if (test "${enable_coverage}" = "yes"); then
+			misc_cflags="$misc_cflags --coverage"
+			misc_ldflags="$misc_ldflags --coverage"
+		fi
+	])
 	AC_SUBST([MISC_CFLAGS], $misc_cflags)
 	AC_SUBST([MISC_LDFLAGS], $misc_ldflags)
 ])
bootstrap-configure +1 -0
index c7f08ed..35aa98b 100755
@@ -14,4 +14,5 @@ fi
 		--enable-experimental \
 		--enable-android \
 		--enable-sixaxis \
+		--enable-coverage \
 		--disable-datafiles $*
configure.ac +5 -0
index 18d0b55..5e684a3 100644
@@ -252,4 +252,9 @@ AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
 					[enable_android=${enableval}])
 AM_CONDITIONAL(ANDROID, test "${enable_android}" = "yes")
 
+if (test "${enable_coverage}" = "yes"); then
+	AC_CHECK_PROG([LCOV], [lcov], [yes], AC_MSG_ERROR(lcov is required))
+fi
+AM_CONDITIONAL([COVERAGE], [test "${enable_coverage}" = "yes"])
+
 AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw

Hi Luiz,

Quoted 27 lines

Coverage is disabled by default but it is automatically enabled by bootstrap-configure using --enable-coverage, it creates a new make target 'coverage' that can be run after make check or any tester that produces .gdca files.

The build time using --enable-coverage is considerable bigger so if that is a problem just disable it, also this is the reason why it is not added directly under --enable-maintainer-mode so it is possible to turn off coverage without having to turn off maintainer mode.

Since lcov apparently cannot detect changes to .gcda there is another make target 'clean-coverage' so after that make coverage can be run again.
---

Makefile.am         | 17 +++++++++++++++++
acinclude.m4        |  8 ++++++++
bootstrap-configure |  1 +
configure.ac        |  5 +++++
4 files changed, 31 insertions(+)
Makefile.am +0 -0
index 15cc149..4b3351a 100644
@@ -331,5 +331,22 @@ lib/bluetooth/%.h: lib/%.h
 	$(AM_V_at)$(MKDIR_P) lib/bluetooth
 	$(AM_V_GEN)$(LN_S) -f "$(abs_top_builddir)"/$< $@

Makefile.am lib/bluetooth/%.h: lib/%.h · line 342

Quoted 10 lines
Makefile.am +9 -0
 
+if COVERAGE
+clean-coverage:
+	$(RM) -r coverage
+
+coverage:
+	$(AM_V_at)$(MKDIR_P) -p coverage
+	@lcov --compat-libtool --directory $(top_builddir) --capture \
+					--output-file coverage/check.info
+	@genhtml -o coverage/ coverage/check.info

I would actually prefer if we can have some sort AM_V_GEN thing working here. So that make V=1 will end up showing the exact command.

Quoted 10 lines
Makefile.am +7 -0
+
+clean-local: clean-coverage
+	@find $(top_builddir) -name "*.gcda" -exec $(RM) {} \;
+	@find $(top_builddir) -name "*.gcno" -exec $(RM) {} \;
+	@lcov --directory . --zerocounters
+	$(RM) -r lib/bluetooth
+else

clean-local:

	$(RM) -r lib/bluetooth

+endif

This if for clean-local is not something I like that much. Can we not come up with a better way and leave clean-local as it is. Just make clean-coverage a null-op.

Quoted 34 lines
acinclude.m4 +8 -0
index 2065852..4bb8bde 100644
@@ -51,6 +51,14 @@ AC_DEFUN([MISC_FLAGS], [
 			misc_ldflags="$misc_ldflags -pie"
 		fi
 	])
+	AC_ARG_ENABLE(coverage, AC_HELP_STRING([--enable-coverage],
+						[enable coverage flags]), [
+		enable_coverage=${enableval}
+		if (test "${enable_coverage}" = "yes"); then
+			misc_cflags="$misc_cflags --coverage"
+			misc_ldflags="$misc_ldflags --coverage"
+		fi
+	])
 	AC_SUBST([MISC_CFLAGS], $misc_cflags)
 	AC_SUBST([MISC_LDFLAGS], $misc_ldflags)
 ])
bootstrap-configure +1 -0
index c7f08ed..35aa98b 100755
@@ -14,4 +14,5 @@ fi
 		--enable-experimental \
 		--enable-android \
 		--enable-sixaxis \
+		--enable-coverage \
 		--disable-datafiles $*
configure.ac +0 -0
index 18d0b55..5e684a3 100644

configure.ac AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android], · line 259

Quoted 8 lines
configure.ac +5 -0
@@ -252,4 +252,9 @@ AC_ARG_ENABLE(android, AC_HELP_STRING([--enable-android],
 					[enable_android=${enableval}])
 AM_CONDITIONAL(ANDROID, test "${enable_android}" = "yes")
 
+if (test "${enable_coverage}" = "yes"); then
+	AC_CHECK_PROG([LCOV], [lcov], [yes], AC_MSG_ERROR(lcov is required))
+fi
+AM_CONDITIONAL([COVERAGE], [test "${enable_coverage}" = "yes"])
+

Still not 100% convinced that we really want this. I get the feeling that maintainer-mode would be just fine.

Regards

Marcel

#2 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Makefile.am lib/bluetooth/%.h: lib/%.h · line 346

Quoted 3 lines · Luiz Augusto von Dentz
Makefile.am +3 -0
+clean-local: clean-coverage
+       @find $(top_builddir) -name "*.gcda" -exec $(RM) {} \;
+       @find $(top_builddir) -name "*.gcno" -exec $(RM) {} \;

Another simplification suggestion: Replace " -exec $(RM) {} \;" with "-delete", e.g.:

@find $(top_builddir) -name "*.gcda" -delete

BTW if the deletion fails (e.g. file was created as root but cleanup is done as non-root), the find command will fail. If it is desirable that the cleanup never fail, you may need to add a "-" before the command (or use "|| true", whatever is the convention in BlueZ).

Best Regards,

Signature · 3 lines
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil