Merge lp:~mterry/qtmir/ms-compressed-timestamps into lp:qtmir

Proposed by Michael Terry
Status: Rejected
Rejected by: Michael Terry
Proposed branch: lp:~mterry/qtmir/ms-compressed-timestamps
Merge into: lp:qtmir
Diff against target: 74 lines (+21/-6)
3 files modified
src/common/timestamp_impl.h (+3/-3)
tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp (+15/-0)
tests/modules/General/timestamp_test.cpp (+3/-3)
To merge this branch: bzr merge lp:~mterry/qtmir/ms-compressed-timestamps
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Mir development team Pending
Review via email: mp+276048@code.launchpad.net

Commit message

Hand Qt millisecond timestamps rather than nanosecond.

We do this by treating compressed timestamps as millisecond timestamps themselves. (We could alternately divide by 1000000 everywhere we use them, but since we use only use them when dealing with Qt, where we want to provide milliseconds, I figured this was less fragile.)

The new TimestampInMilliseconds test actually catches the error (Qt was seeing milliseconds). The changes to timestamp_test.cpp merely reflect the changes to compressed handling.

Description of the change

 * Are there any related MPs required for this MP to build/function as expected? Please list.
 No

 * Did you perform an exploratory manual test run of your code change and any related functionality?
 Only tests so far, I'm going to run this with my u8 branch that noticed this problem and see if it's fixed. Will keep you posted.

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
 NA

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Terry (mterry) wrote :
Revision history for this message
Michael Terry (mterry) wrote :

The wily CI failures seem unrelated.

Revision history for this message
Gerry Boland (gerboland) wrote :

+ std::chrono::nanoseconds result = (timestamp - startTime) / 1000000;
shouldn't the result be in std::chrono::milliseconds? chrono does implicit conversion between nano & milliseconds, should be able to use that instead of the explicit division.

Your editor does something odd to the file line endings, can you undo that?

I'll let Daniel or Nick review the principle

Revision history for this message
Gerry Boland (gerboland) wrote :

On testing, this problem was cause of https://bugs.launchpad.net/qtmir/+bug/1510571 and several other gesture failures! Nice catch!

Revision history for this message
Michael Terry (mterry) wrote :

> + std::chrono::nanoseconds result = (timestamp - startTime) / 1000000;
> shouldn't the result be in std::chrono::milliseconds? chrono does
> implicit conversion between nano & milliseconds, should be able to use
> that instead of the explicit division.

We could, but later in that function, we want to test for overflow. So we want to keep the delta calculation in a type that is the same size as the nanoseconds type (i.e. we don't want to lose any accuracy before checking if we're about to lose any accuracy).

So we either do what I did or (1) don't divide by 100000 here, (2) multiply std::chrono::nanoseconds(std::numeric_limits<T>::max()) by 1000000 in the later comparison, and finally (3) divide 'result' by 1000000 right before returning.

But dividing by 100000 from the start seemed easier. I added a comment to explain that I was doing the division just for convenience of the overflow check later.

But I'm fine with doing the 1.2.3. steps instead if you think that they are more obvious.

Revision history for this message
Michael Terry (mterry) wrote :

Unmerged revisions

399. By Michael Terry

Treat compressed timestamps as milliseconds

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/common/timestamp_impl.h'
2--- src/common/timestamp_impl.h 2015-09-16 17:04:52 +0000
3+++ src/common/timestamp_impl.h 2015-10-28 20:02:22 +0000
4@@ -12,7 +12,7 @@
5 T compressTimestamp(std::chrono::nanoseconds timestamp)
6 {
7 std::chrono::nanoseconds startTime = getStartTime(timestamp);
8- std::chrono::nanoseconds result = timestamp - startTime;
9+ std::chrono::nanoseconds result = (timestamp - startTime) / 1000000; // ms in nanosecond type to compare overflow
10
11 if (std::numeric_limits<std::chrono::nanoseconds::rep>::max() > std::numeric_limits<T>::max() &&
12 result > std::chrono::nanoseconds(std::numeric_limits<T>::max())) {
13@@ -27,8 +27,8 @@
14 template<typename T>
15 std::chrono::nanoseconds uncompressTimestamp(T timestamp)
16 {
17- auto tsNS = std::chrono::nanoseconds(timestamp);
18+ auto tsNS = std::chrono::milliseconds(timestamp);
19 return getStartTime(tsNS, false) + std::chrono::nanoseconds(tsNS);
20 }
21
22-}
23\ No newline at end of file
24+}
25
26=== modified file 'tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp'
27--- tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp 2015-10-21 11:46:33 +0000
28+++ tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp 2015-10-28 20:02:22 +0000
29@@ -265,3 +265,18 @@
30
31 ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
32 }
33+
34+TEST_F(QtEventFeederTest, TimestampInMilliseconds)
35+{
36+ setIrrelevantMockWindowSystemExpectations();
37+ EXPECT_CALL(*mockWindowSystem, handleTouchEvent(_,0,_,_,_)).Times(1);
38+ auto ev1 = mev::make_event(MirInputDeviceId(), std::chrono::milliseconds(123), 0 /* mac */, 0);
39+ qtEventFeeder->dispatch(*ev1);
40+ ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
41+
42+ setIrrelevantMockWindowSystemExpectations();
43+ EXPECT_CALL(*mockWindowSystem, handleTouchEvent(_,2,_,_,_)).Times(1);
44+ auto ev2 = mev::make_event(MirInputDeviceId(), std::chrono::milliseconds(125), 0 /* mac */, 0);
45+ qtEventFeeder->dispatch(*ev2);
46+ ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
47+}
48
49=== modified file 'tests/modules/General/timestamp_test.cpp'
50--- tests/modules/General/timestamp_test.cpp 2015-09-16 16:19:00 +0000
51+++ tests/modules/General/timestamp_test.cpp 2015-10-28 20:02:22 +0000
52@@ -41,7 +41,7 @@
53
54 ulong compressedTimestamp = qtmir::compressTimestamp<ulong>(timestamp);
55
56- EXPECT_EQ(addToTimestamp.count(), compressedTimestamp);
57+ EXPECT_EQ(addToTimestamp.count(), compressedTimestamp * 1000000);
58 EXPECT_EQ(qtmir::uncompressTimestamp<ulong>(compressedTimestamp), timestamp);
59
60 addToTimestamp += std::chrono::milliseconds(1);
61@@ -63,10 +63,10 @@
62 quint32 compressedTimestamp = qtmir::compressTimestamp<quint32>(timestamp);
63
64 // Add the quint32 limit +1 to get an overflow when we compress the timestamp
65- timestamp += std::chrono::nanoseconds(std::numeric_limits<quint32>::max()) + std::chrono::nanoseconds(1);
66+ timestamp += std::chrono::milliseconds(std::numeric_limits<quint32>::max()) + std::chrono::milliseconds(1);
67 compressedTimestamp = qtmir::compressTimestamp<quint32>(timestamp);
68
69 EXPECT_EQ(0, compressedTimestamp);
70 // ensure the uncompression will yields the original timestamp
71 EXPECT_EQ(qtmir::uncompressTimestamp<quint32>(compressedTimestamp), timestamp);
72-}
73\ No newline at end of file
74+}

Subscribers

People subscribed via source and target branches