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
=== modified file 'src/common/timestamp_impl.h'
--- src/common/timestamp_impl.h 2015-09-16 17:04:52 +0000
+++ src/common/timestamp_impl.h 2015-10-28 20:02:22 +0000
@@ -12,7 +12,7 @@
12T compressTimestamp(std::chrono::nanoseconds timestamp)12T compressTimestamp(std::chrono::nanoseconds timestamp)
13{13{
14 std::chrono::nanoseconds startTime = getStartTime(timestamp);14 std::chrono::nanoseconds startTime = getStartTime(timestamp);
15 std::chrono::nanoseconds result = timestamp - startTime;15 std::chrono::nanoseconds result = (timestamp - startTime) / 1000000; // ms in nanosecond type to compare overflow
1616
17 if (std::numeric_limits<std::chrono::nanoseconds::rep>::max() > std::numeric_limits<T>::max() &&17 if (std::numeric_limits<std::chrono::nanoseconds::rep>::max() > std::numeric_limits<T>::max() &&
18 result > std::chrono::nanoseconds(std::numeric_limits<T>::max())) {18 result > std::chrono::nanoseconds(std::numeric_limits<T>::max())) {
@@ -27,8 +27,8 @@
27template<typename T>27template<typename T>
28std::chrono::nanoseconds uncompressTimestamp(T timestamp)28std::chrono::nanoseconds uncompressTimestamp(T timestamp)
29{29{
30 auto tsNS = std::chrono::nanoseconds(timestamp);30 auto tsNS = std::chrono::milliseconds(timestamp);
31 return getStartTime(tsNS, false) + std::chrono::nanoseconds(tsNS);31 return getStartTime(tsNS, false) + std::chrono::nanoseconds(tsNS);
32}32}
3333
34}
35\ No newline at end of file34\ No newline at end of file
35}
3636
=== modified file 'tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp'
--- tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp 2015-10-21 11:46:33 +0000
+++ tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp 2015-10-28 20:02:22 +0000
@@ -265,3 +265,18 @@
265265
266 ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));266 ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
267}267}
268
269TEST_F(QtEventFeederTest, TimestampInMilliseconds)
270{
271 setIrrelevantMockWindowSystemExpectations();
272 EXPECT_CALL(*mockWindowSystem, handleTouchEvent(_,0,_,_,_)).Times(1);
273 auto ev1 = mev::make_event(MirInputDeviceId(), std::chrono::milliseconds(123), 0 /* mac */, 0);
274 qtEventFeeder->dispatch(*ev1);
275 ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
276
277 setIrrelevantMockWindowSystemExpectations();
278 EXPECT_CALL(*mockWindowSystem, handleTouchEvent(_,2,_,_,_)).Times(1);
279 auto ev2 = mev::make_event(MirInputDeviceId(), std::chrono::milliseconds(125), 0 /* mac */, 0);
280 qtEventFeeder->dispatch(*ev2);
281 ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
282}
268283
=== modified file 'tests/modules/General/timestamp_test.cpp'
--- tests/modules/General/timestamp_test.cpp 2015-09-16 16:19:00 +0000
+++ tests/modules/General/timestamp_test.cpp 2015-10-28 20:02:22 +0000
@@ -41,7 +41,7 @@
4141
42 ulong compressedTimestamp = qtmir::compressTimestamp<ulong>(timestamp);42 ulong compressedTimestamp = qtmir::compressTimestamp<ulong>(timestamp);
4343
44 EXPECT_EQ(addToTimestamp.count(), compressedTimestamp);44 EXPECT_EQ(addToTimestamp.count(), compressedTimestamp * 1000000);
45 EXPECT_EQ(qtmir::uncompressTimestamp<ulong>(compressedTimestamp), timestamp);45 EXPECT_EQ(qtmir::uncompressTimestamp<ulong>(compressedTimestamp), timestamp);
4646
47 addToTimestamp += std::chrono::milliseconds(1);47 addToTimestamp += std::chrono::milliseconds(1);
@@ -63,10 +63,10 @@
63 quint32 compressedTimestamp = qtmir::compressTimestamp<quint32>(timestamp);63 quint32 compressedTimestamp = qtmir::compressTimestamp<quint32>(timestamp);
6464
65 // Add the quint32 limit +1 to get an overflow when we compress the timestamp65 // Add the quint32 limit +1 to get an overflow when we compress the timestamp
66 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);67 compressedTimestamp = qtmir::compressTimestamp<quint32>(timestamp);
6868
69 EXPECT_EQ(0, compressedTimestamp);69 EXPECT_EQ(0, compressedTimestamp);
70 // ensure the uncompression will yields the original timestamp70 // ensure the uncompression will yields the original timestamp
71 EXPECT_EQ(qtmir::uncompressTimestamp<quint32>(compressedTimestamp), timestamp);71 EXPECT_EQ(qtmir::uncompressTimestamp<quint32>(compressedTimestamp), timestamp);
72}
73\ No newline at end of file72\ No newline at end of file
73}

Subscribers

People subscribed via source and target branches