After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 712274 - Add test suite for the BlueZ backend
Add test suite for the BlueZ backend
Status: RESOLVED FIXED
Product: folks
Classification: Platform
Component: BlueZ backend
git master
Other All
: Normal normal
: Unset
Assigned To: folks-maint
folks-maint
Depends on: 712148
Blocks: 690830
 
 
Reported: 2013-11-14 07:37 UTC by Philip Withnall
Modified: 2014-02-17 00:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
eds: Remove unused variable (1.11 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
key-file: Add missing licencing header (1.51 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
build: Factor common test build rules into test.mk (15.33 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
build: Rename AM_VALAFLAGS to TARGET_VALAFLAGS in configure.ac (8.21 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
build: Move backend.mk inclusions to the top of the files (3.83 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
tests: Add support for an isolated system bus (4.21 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
tests: Add a function for asserting personas are in an aggregator (6.36 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
tests: Add python-dbusmock support to the base TestCase class (9.93 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
bluez: Add a test suite (42.96 KB, patch)
2013-11-15 14:34 UTC, Philip Withnall
committed Details | Review
bluez: Remove BluezBackendFactory class (1.83 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
core: Unprepare all backends when destroying the BackendStore (1.39 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Add some more debug output (1.42 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Handle the optional Filename property of BlueZ (2.19 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Don’t warn about the store being offline (1.78 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Fix removal of a Map element while iterating over the Map (2.75 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Reimplement vCard parsing when updating Personas (17.44 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Calculate Persona IID checksums without the vCard PHOTO attribute (6.23 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Don’t warn if removing an OBEX session fails due to cancellation (1.18 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Correctly handle OBEX transfers which take zero time (1.44 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
bluez: Allow persona store update poll frequency to be modified (2.80 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review
eds: Remove redundant variable assignment (1.01 KB, patch)
2013-11-15 14:35 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2013-11-14 07:37:04 UTC
The BlueZ backend needs a test suite, because testing it manually is a lot harder than testing the other backends. (It requires faffing around with a phone.)
Comment 1 Philip Withnall 2013-11-15 14:34:31 UTC
Created attachment 259887 [details] [review]
eds: Remove unused variable
Comment 2 Philip Withnall 2013-11-15 14:34:34 UTC
Created attachment 259888 [details] [review]
key-file: Add missing licencing header
Comment 3 Philip Withnall 2013-11-15 14:34:37 UTC
Created attachment 259889 [details] [review]
build: Factor common test build rules into test.mk

Simplify the build system a little.
Comment 4 Philip Withnall 2013-11-15 14:34:41 UTC
Created attachment 259890 [details] [review]
build: Rename AM_VALAFLAGS to TARGET_VALAFLAGS in configure.ac

Remembering to always append to AM_VALAFLAGS, rather than define it from
scratch, is hard and error-prone. Simpler and more consistent to define a
new variable, TARGET_VALAFLAGS, which must be manually included in every
AM_VALAFLAGS or target-specific *_VALAFLAGS declaration.
Comment 5 Philip Withnall 2013-11-15 14:34:44 UTC
Created attachment 259891 [details] [review]
build: Move backend.mk inclusions to the top of the files

Make it more obvious, and also make it non-optional.
Comment 6 Philip Withnall 2013-11-15 14:34:48 UTC
Created attachment 259892 [details] [review]
tests: Add support for an isolated system bus

In addition to an isolated session bus, the tests are now run with an
isolated system bus as well. This is needed for the BlueZ backend, which
uses the org.bluez service on the system bus.

This depends on the GLib.TestDBus changes here:
https://bugzilla.gnome.org/show_bug.cgi?id=712148
Comment 7 Philip Withnall 2013-11-15 14:34:51 UTC
Created attachment 259893 [details] [review]
tests: Add a function for asserting personas are in an aggregator

This will be useful for testing the behaviour of individual
PersonaStores.
Comment 8 Philip Withnall 2013-11-15 14:34:54 UTC
Created attachment 259894 [details] [review]
tests: Add python-dbusmock support to the base TestCase class

This allows derived test cases to easily use python-dbusmock to mock up
D-Bus services which are used by the code under test. The derived code
simply needs to call:
    this.create_dbusmock_service (BusType.SESSION, "org.foo", "foo")
to allow instantiation of the ‘org.foo’ service using the ‘foo’
python-dbusmock template.
Comment 9 Philip Withnall 2013-11-15 14:34:58 UTC
Created attachment 259895 [details] [review]
bluez: Add a test suite

This adds a test suite for the BlueZ backend, using a python-dbusmock
mock up of the BlueZ and OBEX D-Bus services.

This requires the latest version of python-dbusmock, plus up-to-date
versions of GLib and Vala for binding updates. The use of the second and
third arguments to AM_PROG_VALAC in configure.ac also necessitates use
of automake 1.12 or newer.

Only a few test cases have been added so far, covering vCard parsing and
general set up of PersonaStores. Using python-dbusmock it should be easy
to add more tests covering advanced Bluetooth device
appearance/disappearance situations in future.
Comment 10 Philip Withnall 2013-11-15 14:35:01 UTC
Created attachment 259896 [details] [review]
bluez: Remove BluezBackendFactory class

It was utterly pointless.
Comment 11 Philip Withnall 2013-11-15 14:35:05 UTC
Created attachment 259897 [details] [review]
core: Unprepare all backends when destroying the BackendStore

This helps free up some reference cycles (particularly in the BlueZ
backend) and hence ensure no memory is leaked.
Comment 12 Philip Withnall 2013-11-15 14:35:08 UTC
Created attachment 259899 [details] [review]
bluez: Add some more debug output
Comment 13 Philip Withnall 2013-11-15 14:35:12 UTC
Created attachment 259900 [details] [review]
bluez: Handle the optional Filename property of BlueZ

Previously the code assumed that Filename was always set, but it’s
actually an optional property. Gracefully handle it not existing.
Comment 14 Philip Withnall 2013-11-15 14:35:15 UTC
Created attachment 259901 [details] [review]
bluez: Don’t warn about the store being offline

If the Bluetooth device is disconnected by the user between updates of
the contact metadata, the code previously printed a warning when the
next update attempt failed. Instead, just gracefully and silently fail
and schedule the next update.
Comment 15 Philip Withnall 2013-11-15 14:35:19 UTC
Created attachment 259902 [details] [review]
bluez: Fix removal of a Map element while iterating over the Map
Comment 16 Philip Withnall 2013-11-15 14:35:23 UTC
Created attachment 259903 [details] [review]
bluez: Reimplement vCard parsing when updating Personas

This completely re-implements parsing of the vCards returned from the
Bluetooth device, with the following aims:
 • Improve efficiency.
 • Correctly support multi-instance attributes (such as TEL and EMAIL).
 • Fix comparison of new and old values to reduce property notification
   spew.

Previously, the code was calling E.VCard.get_attribute() for each
attribute it expected, which iterates over the vCard’s entire attribute
list every time. Now, the code iterates over the attribute list once and
checks for the attributes it expects. This also means that unsupported
attributes can be detected. The performance improvement from this should
come from reduced iteration and better cache utilisation, although it
has not been measured. If further performance improvements are needed,
the attribute name strings could be interned and pointer comparisons
used instead of lots of strcmp()s.

The code was also previously using E.VCardAttribute.get_values() to get
the values of TEL, EMAIL and URL attributes, which is incorrect, as
those attributes are single-valued but may exist several times in the
vCard. Consequently, the code previously only parsed the first telephone
number, e-mail address and phone number in the vCard and ignored the
rest. This has now been fixed.

Finally, the code was doing pointer comparisons of elements in the
phone, e-mail and URI sets, and hence was always detecting them as
different (even if strcmp() comparison would have yielded equality).
This was causing excess property notification spew. This has been fixed
by correctly specifying the hash and equality functions to use for the
Sets.

Additionally, the code has been ported to use SmallSet instead of
HashSet. The memory and performance improvements of this change have not
been measured.
Comment 17 Philip Withnall 2013-11-15 14:35:27 UTC
Created attachment 259904 [details] [review]
bluez: Calculate Persona IID checksums without the vCard PHOTO attribute

Persona IIDs can come from two places:
 • the vCard UID attribute (preferred); or
 • a checksum of the vCard’s string representation.
Previously, the checksum was calculated over all fields in the vCard,
which interacted very badly with download_photos mode. When downloading
photos, only the PHOTO and UID attributes would be downloaded;
otherwise, all attributes except PHOTO would be downloaded. Obviously,
this meant that it was impossible to calculate the same checksum for a
Persona in download_photos and non-download_photos mode. This meant that
matching the photos up to the existing Personas was impossible. Sad
times.

Now, when in download_photos mode, download all vCard attributes
(including the PHOTO) but calculate the IID checksum over all the
attributes except the PHOTO. This should yield the same checksum as from
non-download_photos mode, unless one of the other vCard properties has
changed between downloads; a new checksum would be produced then, which
is the expected behaviour.
Comment 18 Philip Withnall 2013-11-15 14:35:30 UTC
Created attachment 259905 [details] [review]
bluez: Don’t warn if removing an OBEX session fails due to cancellation

Or due to the connection being closed.
Comment 19 Philip Withnall 2013-11-15 14:35:34 UTC
Created attachment 259906 [details] [review]
bluez: Correctly handle OBEX transfers which take zero time

If an OBEX transfer takes zero time (say, in an ideal world or, perhaps,
in a unit test) the transfer Status property will start out as
‘complete’ and never change. Previously, completed transfers were only
detected on receipt of a property change notification which, in this
situation, never came. Now, the initial value of the Status property is
also checked.
Comment 20 Philip Withnall 2013-11-15 14:35:37 UTC
Created attachment 259907 [details] [review]
bluez: Allow persona store update poll frequency to be modified

For unit testing, it’s nice to not have to wait 5s between polled
updates of the BlueZ persona store. Add a new environment variable,
FOLKS_BLUEZ_TIMEOUT_DIVISOR, which allows the poll frequency to be
divided by the specified amount.

This should speed up the unit tests 100×.
Comment 21 Philip Withnall 2013-11-15 14:35:41 UTC
Created attachment 259908 [details] [review]
eds: Remove redundant variable assignment
Comment 22 Philip Withnall 2013-11-20 16:00:49 UTC
This depends on the following changes in python-dbusmock: https://code.launchpad.net/~drbob/python-dbusmock/python-dbusmock/+merge/195977
Comment 23 Travis Reitter 2013-11-27 01:11:13 UTC
Review of attachment 259887 [details] [review]:

Looks good
Comment 24 Travis Reitter 2013-11-27 01:11:28 UTC
Review of attachment 259887 [details] [review]:

Looks good
Comment 25 Travis Reitter 2013-11-27 01:11:29 UTC
Review of attachment 259887 [details] [review]:

Looks good
Comment 26 Travis Reitter 2013-11-27 01:11:54 UTC
Review of attachment 259888 [details] [review]:

Looks good
Comment 27 Travis Reitter 2013-11-27 01:14:40 UTC
Review of attachment 259889 [details] [review]:

I haven't built it myself, but it looks good on reading
Comment 28 Travis Reitter 2013-11-27 01:17:01 UTC
Review of attachment 259890 [details] [review]:

Looks good
Comment 29 Travis Reitter 2013-11-27 01:18:22 UTC
Review of attachment 259891 [details] [review]:

Looks good
Comment 30 Travis Reitter 2013-11-27 01:22:31 UTC
Review of attachment 259892 [details] [review]:

Looks good (but not tested). Merge once the dependent code is available in the stable releases of the main distros.
Comment 31 Travis Reitter 2013-11-27 01:25:16 UTC
Review of attachment 259893 [details] [review]:

Looks good.
Comment 32 Travis Reitter 2013-11-27 01:28:21 UTC
Review of attachment 259894 [details] [review]:

Don't we need to add python-dbusmock as a dependency?

It obviously shouldn't have to be a regular build dependency but maybe be need to break out the tests as a configure flag which can add that as a build dep.
Comment 33 Philip Withnall 2013-11-27 11:00:18 UTC
Attachment #259887 [details] can’t actually be pushed yet, since it depends on a patch in bug #711827 (sorry, I’d forgotten about that dependency). I’ll push it as soon as that branch is reviewed and merged.

Thanks for the reviews! Pushed with all test cases passing.

Attachment 259888 [details] pushed as 5a38700 - key-file: Add missing licencing header
Attachment 259889 [details] pushed as 75943c1 - build: Factor common test build rules into test.mk
Attachment 259890 [details] pushed as 43d92e7 - build: Rename AM_VALAFLAGS to TARGET_VALAFLAGS in configure.ac
Attachment 259891 [details] pushed as 7fa70f1 - build: Move backend.mk inclusions to the top of the files
Attachment 259893 [details] pushed as 40d2744 - tests: Add a function for asserting personas are in an aggregator
Comment 34 Philip Withnall 2014-01-04 15:41:53 UTC
Comment on attachment 259887 [details] [review]
eds: Remove unused variable

Attachment 259887 [details] pushed as 0bdce57 - eds: Remove unused variable
Comment 35 Travis Reitter 2014-01-06 18:30:11 UTC
Review of attachment 259895 [details] [review]:

This generally looks good but we can't merge until we get the patches on bgo#712148 merged and new releases of GLib, Gobject Introspection (with updated .gir and .typelib files), and Vala (with updated VAPI files) which we can depend upon.

+        PKG_CHECK_MODULES([GLIB_2_39_2], [glib-2.0 >= 2.39.2],

+        AM_PROG_VALAC([0.22.0.45-383d-dirty],

Be sure to bump these to the first release which includes our required changes before merging.


+      /* FIXME: Have to get the display-name this way because
+       * Folks.PersonaStore.display_name is not declared as abstract. */

Is this a fixable API issue? If so, please file a bug denoted for our next API break.


+  /* Test that vCards with different numbers of values for their N (structured
+   * name) attribute are parsed correctly.. */

Extra .
Comment 36 Travis Reitter 2014-01-06 18:32:49 UTC
Review of attachment 259896 [details] [review]:

Looks good.
Comment 37 Travis Reitter 2014-01-06 18:34:03 UTC
Review of attachment 259897 [details] [review]:

Looks good
Comment 38 Travis Reitter 2014-01-06 18:34:23 UTC
Review of attachment 259899 [details] [review]:

Looks good
Comment 39 Travis Reitter 2014-01-06 18:35:29 UTC
Review of attachment 259900 [details] [review]:

Looks good
Comment 40 Travis Reitter 2014-01-06 18:36:06 UTC
Review of attachment 259901 [details] [review]:

Looks good
Comment 41 Travis Reitter 2014-01-06 18:37:08 UTC
Review of attachment 259902 [details] [review]:

Looks good
Comment 42 Travis Reitter 2014-01-06 18:40:00 UTC
Review of attachment 259903 [details] [review]:

Nice work!
Comment 43 Travis Reitter 2014-01-06 18:41:46 UTC
Review of attachment 259904 [details] [review]:

Looks good
Comment 44 Travis Reitter 2014-01-06 18:42:14 UTC
Review of attachment 259905 [details] [review]:

Looks good
Comment 45 Travis Reitter 2014-01-06 18:42:56 UTC
Review of attachment 259904 [details] [review]:

Looks good
Comment 46 Travis Reitter 2014-01-06 18:43:11 UTC
Review of attachment 259906 [details] [review]:

Looks good
Comment 47 Travis Reitter 2014-01-06 18:45:50 UTC
Review of attachment 259907 [details] [review]:

Glad to see this speedup!
Comment 48 Travis Reitter 2014-01-06 18:46:17 UTC
Review of attachment 259908 [details] [review]:

Not this bug, but sure.
Comment 49 Travis Reitter 2014-01-06 18:48:52 UTC
Philip, I think you have a few more patches on your branch that don't appear on this bug. (I haven't reviewed them).

For the record, I haven't had time to test the patches I just reviewed. They break the core tests so I didn't check the pass/failure status of the BlueZ tests.
Comment 50 Philip Withnall 2014-02-16 23:55:41 UTC
(In reply to comment #35)
> Review of attachment 259895 [details] [review]:
> 
> This generally looks good but we can't merge until we get the patches on
> bgo#712148 merged and new releases of GLib, Gobject Introspection (with updated
> .gir and .typelib files), and Vala (with updated VAPI files) which we can
> depend upon.
> 
> +        PKG_CHECK_MODULES([GLIB_2_39_2], [glib-2.0 >= 2.39.2],
> 
> +        AM_PROG_VALAC([0.22.0.45-383d-dirty],
> 
> Be sure to bump these to the first release which includes our required changes
> before merging.

So, due to the rejection of the GTestDBus patches upstream (see the discussion in bug #712148, around comment #40), I decided the most efficient use of time to stop this patch set bit rotting was to copy GTestDBus into folks, which I have done. That means we don’t need to bump our dependencies or wait for bindings updates, which is nice. On the other hand, we now have some more C code in the tests/ directory, with all the accompanying build system faff. The next distcheck is going to be a bundle of laughs.

> +      /* FIXME: Have to get the display-name this way because
> +       * Folks.PersonaStore.display_name is not declared as abstract. */
> 
> Is this a fixable API issue? If so, please file a bug denoted for our next API
> break.

Filed bug #724502.

> +  /* Test that vCards with different numbers of values for their N (structured
> +   * name) attribute are parsed correctly.. */
> 
> Extra .

Whoops. Fixed.


Attachment 259892 [details] pushed as 21b7563 - tests: Add support for an isolated system bus
Attachment 259894 [details] pushed as 02bf00d - tests: Add python-dbusmock support to the base TestCase class
Attachment 259895 [details] pushed as 6e85b2b - bluez: Add a test suite
Attachment 259896 [details] pushed as 3dbd946 - bluez: Remove BluezBackendFactory class
Attachment 259897 [details] pushed as 9064888 - core: Unprepare all backends when destroying the BackendStore
Attachment 259899 [details] pushed as d1fe72a - bluez: Add some more debug output
Attachment 259900 [details] pushed as 8a5f289 - bluez: Handle the optional Filename property of BlueZ
Attachment 259902 [details] pushed as eb8b1ad - bluez: Fix removal of a Map element while iterating over the Map
Attachment 259903 [details] pushed as d5a4faa - bluez: Reimplement vCard parsing when updating Personas
Attachment 259904 [details] pushed as 34bb166 - bluez: Calculate Persona IID checksums without the vCard PHOTO attribute
Attachment 259906 [details] pushed as 0f398ab - bluez: Correctly handle OBEX transfers which take zero time
Attachment 259907 [details] pushed as f36c4b7 - bluez: Allow persona store update poll frequency to be modified
Attachment 259908 [details] pushed as ffea273 - eds: Remove redundant variable assignment