Merge lp:~3v1n0/unity/debug-property-matching-fix into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3800
Proposed branch: lp:~3v1n0/unity/debug-property-matching-fix
Merge into: lp:unity
Diff against target: 59 lines (+24/-4)
1 file modified
unity-shared/DebugDBusInterface.cpp (+24/-4)
To merge this branch: bzr merge lp:~3v1n0/unity/debug-property-matching-fix
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+215785@code.launchpad.net

Commit message

DebugDBusInterface: match properties if they are in the AP array form [<type>, <value>]

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Looks good to me. I ran the autopilot tests and all but 10 passed (an those 10 failures weren't obviously related to this branch).

It would be good to have someone else familiar with the code (i.e. on the unity team) to approve this code too.

I see there are no tests with this fix, I understand there isn't any testing for this area already setup and thus would be a bit of a commitment.
Perhaps if some of the tests were updated to use select_single/select_many + attribute selections that could add a small amount of coverage (as it's actively exercising this code).

Revision history for this message
Christopher Lee (veebers) wrote :

Actually I'm going to double back on my comment :-\

After conferring with Thomi he reminded me that all propertie value should always be an array (type, value).

The unpacking would be best to go into GetPropertyValue so it returns the value of the property (not the property array as it currently does).

review: Disapprove
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Mh, wait... GetPropertyValue isn't also called to fetch the properties? And thus why should we hide the type from the returned value?

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Branch updated to match veebers' review

Revision history for this message
Christopher Lee (veebers) wrote :

Nice, that's much better. Cheers :-).

On IRC I brought up concerns that:
  We know how the data will be packed (an array [<type>, <value>]) and
  thus we shouldn't need the recursion as we should be able to do the
  unpack on diff-line 17.
  This is fine for simple (int, bool, string) types but not the
  complex types (i.e. Point) which might be a Variant -> Variant ->
  Variant.
  This shouldn't be an issue as GetPropertyValue is only
  called in Match[int,bool,string]Property (complex type matching is
  done client side i.e. within autopilot).

I bring this up as the code currently is it adds complexity (in the
form of more lines of code) that isn't currently required. This might
also gloss over any break in the xpathselect 1.4 spec in regards to
data layout.

As it stands this code works and resolves the issue.

Can I get another Unity team member to sanity check the code too please?

Revision history for this message
Christopher Lee (veebers) wrote :

Ugh, sorry to flip-flop but after reading the xpathselect protocol docs[1] again it looks like GetPropertyValue is incorrect.

The data format is [type_id, val, ..(more possible vals)..]

So for instance if there is a query like //typename[globalRect=0] the actual property would be something like: [TYPE_RECT, 0, 0, 100, 100].

Currently UnpackPropertyValue would return [TYPE_RECT, 0, 0, 100, 100] (due to line 14) so that is wrong.
Assuming the removal of that check it would return 0 (the 2nd element in the array) which is also wrong.

I think what we actually want here is to remove the first (0th) element in that array and return the remainder. (so [TYPE_SIMPLE, 12] will return 12)
There shouldn't need a check for an array, as the protocol states that it should _always_ be an array and if it's not it is an error.

[1] http://developer.ubuntu.com/api/devel/ubuntu-14.04/autopilot/appendix/protocol.html#returning-state-data

review: Disapprove
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Ugh, sorry to flip-flop but after reading the xpathselect protocol docs[1]
> again it looks like GetPropertyValue is incorrect.
>
> The data format is [type_id, val, ..(more possible vals)..]
>
> So for instance if there is a query like //typename[globalRect=0] the actual
> property would be something like: [TYPE_RECT, 0, 0, 100, 100].
>
> Currently UnpackPropertyValue would return [TYPE_RECT, 0, 0, 100, 100] (due to
> line 14) so that is wrong.

Yes, but then the matching functions will refuse it, since it's not a simple type they know. So at the end nothing will match and this is correct.

> Assuming the removal of that check it would return 0 (the 2nd element in the
> array) which is also wrong.

That would be wrong, at the end.

> I think what we actually want here is to remove the first (0th) element in
> that array and return the remainder. (so [TYPE_SIMPLE, 12] will return 12)
> There shouldn't need a check for an array, as the protocol states that it
> should _always_ be an array and if it's not it is an error.

The protocol might support also other "raw" types (or more complex) as we do for launcher icon per-monitor states (and they are still in array under the type-0 case, so the checks are needed anyway). BTW, everything is in a such array already (done by IntrospectionData).

So, the only change (not actually relevant to make this to work) we might do is to ensure that the child_value[0] == 0, but this isn't either so relevant since the only other type that will actually might match is the "Date or Date/Time" format, which is the only one we have in the form [TYPE_ID, SIMPLE_VALUE], and I wouldn't consider this matching an error.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Awesome, thanks Marco. LGTM. The test in the linked bug now passes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-shared/DebugDBusInterface.cpp'
2--- unity-shared/DebugDBusInterface.cpp 2014-01-15 16:04:41 +0000
3+++ unity-shared/DebugDBusInterface.cpp 2014-04-23 22:09:26 +0000
4@@ -84,7 +84,8 @@
5 {
6 if (!g_variant_is_of_type(prop_value, G_VARIANT_TYPE_STRING))
7 {
8- LOG_WARNING(logger) << "Unable to match '"<< name << "', it's not a string property.";
9+ LOG_WARNING(logger) << "Unable to match '"<< name << "', '" <<
10+ prop_value << "' is not a string property.";
11 return false;
12 }
13
14@@ -102,7 +103,8 @@
15 {
16 if (!g_variant_is_of_type(prop_value, G_VARIANT_TYPE_BOOLEAN))
17 {
18- LOG_WARNING(logger) << "Unable to match '"<< name << "', it's not a boolean property.";
19+ LOG_WARNING(logger) << "Unable to match '"<< name << "', '" <<
20+ prop_value << "' is not a boolean property.";
21 return false;
22 }
23
24@@ -138,7 +140,8 @@
25 case G_VARIANT_CLASS_UINT64:
26 return static_cast<uint64_t>(value) == prop_value.GetUInt64();
27 default:
28- LOG_WARNING(logger) << "Unable to match '"<< name << "' against property of unknown integer type.";
29+ LOG_WARNING(logger) << "Unable to match '"<< name << "', '" <<
30+ prop_value << "' is not a known integer property.";
31 };
32 }
33
34@@ -152,7 +155,24 @@
35
36 IntrospectionData introspection;
37 node_->AddProperties(introspection);
38- return g_variant_lookup_value(glib::Variant(introspection.Get()), name.c_str(), nullptr);
39+
40+ glib::Variant value(g_variant_lookup_value(glib::Variant(introspection.Get()), name.c_str(), nullptr), glib::StealRef());
41+
42+ if (!value)
43+ return nullptr;
44+
45+ if (!g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY) || g_variant_n_children(value) != 2)
46+ {
47+ LOG_ERROR(logger) << "Property value for '"<< name << "' should be a 2-sized array, got instead '" << value << "'";
48+ return nullptr;
49+ }
50+
51+ glib::Variant child(g_variant_get_child_value(value, 1), glib::StealRef());
52+
53+ if (g_variant_is_of_type(child, G_VARIANT_TYPE_VARIANT))
54+ return child.GetVariant();
55+
56+ return child;
57 }
58
59 std::vector<xpathselect::Node::Ptr> Children() const