Skip to contentSkip to conversation

Simplify notification handling

PATCH Applied Luiz Augusto von Dentz 1 participant 4 messages Dec 10, 2014 – Dec 12, 2014

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

v2 cover Simplify notification handling

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

This attempts to simplify notification handling by making queue_foreach safe from entry removals during callback. In addition to that a couples there are a couple of new unit test to emulate removal during event callback and because of that Ive also included the coverage support again since I used it to check what part of the code is being exercised.

v2: Make coverage target depend on lcov to be present and update test coverage.

Luiz Augusto von Dentz (13):
build: Add coverage support
unit/test-queue: Add /queue/foreach_remove test unit/test-queue: Add /queue/foreach_remove_backward test shared/queue: Add reference counting to entries unit/test-mgmt: Add /mgmt/response/1 test unit/test-mgmt: Add /mgmt/response/2 test unit/test-mgmt: Add /mgmt/event/1 test unit/test-mgmt: Add /mgmt/event/2 test unit/test-mgmt: Add /mgmt/unregister/1 test unit/test-mgmt: Add /mgmt/unregister/2 test unit/test-mgmt: Add /mgmt/destroy/1 test shared/mgmt: Remove unnecessary code
doc: Update mgmt-tester test coverage

 .gitignore            |   4 +
 Makefile.am           |  20 +++++
 acinclude.m4          |   4 +
 configure.ac          |   5 ++
 doc/test-coverage.txt |   4 +-
 src/shared/mgmt.c     |  89 +++-----------------
 src/shared/queue.c    |  77 +++++++++++-------
 unit/test-mgmt.c      | 220 +++++++++++++++++++++++++++++++++++++++++++++++++-
 unit/test-queue.c     |  46 +++++++++++
 9 files changed, 356 insertions(+), 113 deletions(-)
Signature · 1 line
1.9.3
author maintainer
#1 lore raw

PATCH v2 1/13 build: Add coverage support

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

Coverage is enabled with --enable-maintainer-mode, 2 new targets are added 'coverage' and 'clean-coverage', the first generate the reports using lcov and depend on the second to cleanup previous generated reports and .gcda files.

---
 .gitignore   |  4 ++++
 Makefile.am  | 20 ++++++++++++++++++++
 acinclude.m4 |  4 ++++
 configure.ac |  5 +++++
 4 files changed, 33 insertions(+)
.gitignore +4 -0
index 484f41f..a0c9389 100644
@@ -3,6 +3,8 @@
 *.lo
 *.la
 *.so
+*.gcno
+*.gcda
 .deps
 .libs
 .dirstamp
@@ -27,7 +29,9 @@ stamp-h1
 autom4te.cache
 test-driver
 test-suite.log
+coverage.info
 
+coverage
 lib/bluez.pc
 lib/bluetooth
 src/builtin.h
Makefile.am +20 -0
index c506122..cb42033 100644
@@ -442,5 +442,25 @@ 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:
+	@lcov --directory $(top_builddir) --zerocounters
+	$(RM) -r coverage $(top_builddir)/coverage.info
+
+coverage: check
+	@lcov --compat-libtool --directory $(top_builddir) --capture \
+				--output-file $(top_builddir)/coverage.info
+	$(AM_V_at)$(MKDIR_P) coverage
+	@genhtml -o coverage/ $(top_builddir)/coverage.info
+
+clean-local: clean-coverage
+	-find $(top_builddir) -name "*.gcno" -delete
+	-find $(top_builddir) -name "*.gcda" -delete
+	$(RM) -r lib/bluetooth
+
+else
 clean-local:
+	-find $(top_builddir) -name "*.gcno" -delete
+	-find $(top_builddir) -name "*.gcda" -delete
 	$(RM) -r lib/bluetooth
+endif
acinclude.m4 +4 -0
index 4c241bf..4cfc80a 100644
@@ -52,6 +52,10 @@ AC_DEFUN([MISC_FLAGS], [
 			misc_ldflags="$misc_ldflags -pie"
 		fi
 	])
+	if (test "$USE_MAINTAINER_MODE" = "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)
 ])
configure.ac +5 -0
index 6533cab..952914a 100644
@@ -274,4 +274,9 @@ fi
 AC_DEFINE_UNQUOTED(ANDROID_STORAGEDIR, "${storagedir}/android",
 			[Directory for the Android daemon storage files])
 
+if (test "$USE_MAINTAINER_MODE" = "yes"); then
+	AC_CHECK_PROG([LCOV], [lcov], [yes], AC_MSG_ERROR(lcov is required))
+fi
+AM_CONDITIONAL(COVERAGE, test "$LCOV" = "yes")
+
 AC_OUTPUT(Makefile src/bluetoothd.8 lib/bluez.pc)
Signature · 1 line
1.9.3
author maintainer
#2 lore raw

PATCH v2 2/13 unit/test-queue: Add /queue/foreach_remove test

In reply to Luiz Augusto von Dentz

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

This tests queue_remove from queue_foreach callback.

---
 unit/test-queue.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
unit/test-queue.c +22 -0
index f72f2e6..6261612 100644
@@ -78,6 +78,27 @@ static void test_foreach_destroy(void)
 	queue_foreach(queue, foreach_destroy, queue);
 }
 
+static void foreach_remove(void *data, void *user_data)
+{
+	struct queue *queue = user_data;
+
+	g_assert(queue_remove(queue, data));
+}
+
+static void test_foreach_remove(void)
+{
+	struct queue *queue;
+
+	queue = queue_new();
+	g_assert(queue != NULL);
+
+	queue_push_tail(queue, UINT_TO_PTR(1));
+	queue_push_tail(queue, UINT_TO_PTR(2));
+
+	queue_foreach(queue, foreach_remove, queue);
+	queue_destroy(queue, NULL);
+}
+
 static void foreach_remove_all(void *data, void *user_data)
 {
 	struct queue *queue = user_data;
@@ -177,6 +198,7 @@ int main(int argc, char *argv[])
 
 	g_test_add_func("/queue/basic", test_basic);
 	g_test_add_func("/queue/foreach_destroy", test_foreach_destroy);
+	g_test_add_func("/queue/foreach_remove", test_foreach_remove);
 	g_test_add_func("/queue/foreach_remove_all", test_foreach_remove_all);
 	g_test_add_func("/queue/destroy_remove", test_destroy_remove);
 	g_test_add_func("/queue/push_after", test_push_after);
Signature · 1 line
1.9.3
author maintainer Applied
#3 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 37 lines · Luiz Augusto von Dentz

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

This attempts to simplify notification handling by making queue_foreach safe from entry removals during callback. In addition to that a couples there are a couple of new unit test to emulate removal during event callback and because of that Ive also included the coverage support again since I used it to check what part of the code is being exercised.

v2: Make coverage target depend on lcov to be present and update test coverage.

Luiz Augusto von Dentz (13):
build: Add coverage support
unit/test-queue: Add /queue/foreach_remove test unit/test-queue: Add /queue/foreach_remove_backward test shared/queue: Add reference counting to entries unit/test-mgmt: Add /mgmt/response/1 test unit/test-mgmt: Add /mgmt/response/2 test unit/test-mgmt: Add /mgmt/event/1 test unit/test-mgmt: Add /mgmt/event/2 test unit/test-mgmt: Add /mgmt/unregister/1 test unit/test-mgmt: Add /mgmt/unregister/2 test unit/test-mgmt: Add /mgmt/destroy/1 test shared/mgmt: Remove unnecessary code
doc: Update mgmt-tester test coverage

 .gitignore            |   4 +
 Makefile.am           |  20 +++++
 acinclude.m4          |   4 +
 configure.ac          |   5 ++
 doc/test-coverage.txt |   4 +-
 src/shared/mgmt.c     |  89 +++-----------------
 src/shared/queue.c    |  77 +++++++++++-------
 unit/test-mgmt.c      | 220 +++++++++++++++++++++++++++++++++++++++++++++++++-
 unit/test-queue.c     |  46 +++++++++++
 9 files changed, 356 insertions(+), 113 deletions(-)
Quoted 2 lines

--
1.9.3

Applied.

Signature · 1 line
Luiz Augusto von Dentz