Merge lp:~vanvugt/mir/posix-timestamp-or-equal into lp:mir
- posix-timestamp-or-equal
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Daniel van Vugt |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3873 |
Proposed branch: | lp:~vanvugt/mir/posix-timestamp-or-equal |
Merge into: | lp:mir |
Diff against target: |
47 lines (+26/-0) 2 files modified
include/common/mir/time/posix_timestamp.h (+12/-0) tests/unit-tests/test_posix_timestamp.cpp (+14/-0) |
To merge this branch: | bzr merge lp:~vanvugt/mir/posix-timestamp-or-equal |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Approve | ||
Mir CI Bot | continuous-integration | Approve | |
Chris Halse Rogers | Needs Fixing | ||
Review via email: mp+311574@code.launchpad.net |
Commit message
PosixTimestamp: Add missing operators >= <=
Description of the change
Mir CI Bot (mir-ci-bot) wrote : | # |
Chris Halse Rogers (raof) wrote : | # |
This looks fine for CLOCK_MONOTONIC.
This is incorrect for CLOCK_REALTIME, or rather, worse, this is misleading for CLOCK_REALTIME. Given CLOCK_REALTIME values a, b:
a < b does not imply that a was before b.
a > b does not imply that a was after b.
a == b does not imply that they refer to the same time.
We should remove these operations for CLOCK_REALTIME; we can't correctly implement them (without a large amount of extra work, and external dependencies)
Chris Halse Rogers (raof) wrote : | # |
(This would appear to be a retrospective review of some of the earlier PosixTimestamp work, too)
Daniel van Vugt (vanvugt) wrote : | # |
Technically correct, but I think that's being slightly too pedantic.
The whole point of PosixTimestamp is that the choice of clock is not known till run time. It's specified by the graphics driver actually. So you can't "remove" the operations as much as say "if (clock_id == CLOCK_REALTIME) throw".
And actually even if you were using CLOCK_REALTIME, having comparison operators that work numerically is still required. So "removing" or throwing in that case is unacceptable. The caller should just be aware that some clocks are not always monotonic and design their algorithm accordingly...
Daniel van Vugt (vanvugt) wrote : | # |
Actually "Technically correct" is not right. You propose something that never works (just refuses to compile or crashes). I propose something that works most of the time for a poorly designed algorithm and all of the time for a well-designed algorithm.
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3844
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Alan Griffiths (alan-griffiths) wrote : | # |
One nit:
+TEST(PosixTime
the test name doesn't seem meaningful. How about "comparison_
Alan Griffiths (alan-griffiths) wrote : | # |
> This looks fine for CLOCK_MONOTONIC.
>
> This is incorrect for CLOCK_REALTIME, or rather, worse, this is misleading for
> CLOCK_REALTIME. Given CLOCK_REALTIME values a, b:
>
> a < b does not imply that a was before b.
> a > b does not imply that a was after b.
> a == b does not imply that they refer to the same time.
>
> We should remove these operations for CLOCK_REALTIME; we can't correctly
> implement them (without a large amount of extra work, and external
> dependencies)
Well, the C++ time_point is comparable even for non-steady clocks. So the committee decided on the same trade off Daniel proposes. Good enough for me.
They also made the comparisons constexpr (I can't imagine a PosixTimestamp is often a compile time constant but...)
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3846
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Daniel van Vugt (vanvugt) wrote : | # |
^^^
Bug 1646558
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3847
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Daniel van Vugt (vanvugt) wrote : | # |
^^^
Bug 1523621 and bug 1646558
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3848
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Daniel van Vugt (vanvugt) wrote : | # |
^^^
Bug 1523621
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3849
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Alan Griffiths (alan-griffiths) wrote : | # |
One nit:
+TEST(PosixTime
the test name doesn't seem meaningful. How about "comparison_
Daniel van Vugt (vanvugt) wrote : | # |
Because another separate test already exists for the older comparison operators :)
Alan Griffiths (alan-griffiths) wrote : | # |
The proposed test name starts with a conjunction. I've no objection to this in writing where there is a clear reference to the preceding sentence, but as a test name?
How do the other test names justify this?
Of the comparison operators operator==() is tested in "PosixTimestamp
There is no test (or implementation of) operator!=().
Two of the relational operators are tested in "PosixTimestamp
This tests covers the remaining relational operators. (They could be more simply implemented as negations of the last two mentioned above, but that doesn't really gain anything.)
Daniel van Vugt (vanvugt) wrote : | # |
Indeed the name starts with a virtual conjunction, and virtual quotes too :)
"or-equal" comparison operators
I can see how that creates a mildly confusing test name, but I don't see why other other test name "PosixTimestamp
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3851
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Daniel van Vugt (vanvugt) wrote : | # |
^^^
Bug 1523621 as usual
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:3852
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Daniel van Vugt (vanvugt) wrote : | # |
^^^
Bug 1570698
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3853
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Alan Griffiths (alan-griffiths) wrote : | # |
OK. (All my remaining objections are to things that are pre-existing.)
Preview Diff
1 | === modified file 'include/common/mir/time/posix_timestamp.h' |
2 | --- include/common/mir/time/posix_timestamp.h 2016-11-01 04:16:07 +0000 |
3 | +++ include/common/mir/time/posix_timestamp.h 2016-12-08 07:08:57 +0000 |
4 | @@ -103,6 +103,18 @@ |
5 | return a.nanoseconds < b.nanoseconds; |
6 | } |
7 | |
8 | +inline bool operator>=(PosixTimestamp const& a, PosixTimestamp const& b) |
9 | +{ |
10 | + assert_same_clock(a, b); |
11 | + return a.nanoseconds >= b.nanoseconds; |
12 | +} |
13 | + |
14 | +inline bool operator<=(PosixTimestamp const& a, PosixTimestamp const& b) |
15 | +{ |
16 | + assert_same_clock(a, b); |
17 | + return a.nanoseconds <= b.nanoseconds; |
18 | +} |
19 | + |
20 | inline void sleep_until(PosixTimestamp const& t) |
21 | { |
22 | long long ns = t.nanoseconds.count(); |
23 | |
24 | === modified file 'tests/unit-tests/test_posix_timestamp.cpp' |
25 | --- tests/unit-tests/test_posix_timestamp.cpp 2016-11-01 03:55:50 +0000 |
26 | +++ tests/unit-tests/test_posix_timestamp.cpp 2016-12-08 07:08:57 +0000 |
27 | @@ -80,6 +80,20 @@ |
28 | EXPECT_THROW((void)(a > bb), std::logic_error); |
29 | EXPECT_THROW((void)(aa > b), std::logic_error); |
30 | EXPECT_THROW((void)(aa < b), std::logic_error); |
31 | + |
32 | + EXPECT_TRUE(a <= b); |
33 | + EXPECT_TRUE(a <= a); |
34 | + EXPECT_TRUE(b >= a); |
35 | + EXPECT_TRUE(b >= b); |
36 | + EXPECT_TRUE(aa <= bb); |
37 | + EXPECT_TRUE(aa <= aa); |
38 | + EXPECT_TRUE(bb >= aa); |
39 | + EXPECT_TRUE(bb >= bb); |
40 | + |
41 | + EXPECT_THROW((void)(a <= bb), std::logic_error); |
42 | + EXPECT_THROW((void)(a >= bb), std::logic_error); |
43 | + EXPECT_THROW((void)(aa >= b), std::logic_error); |
44 | + EXPECT_THROW((void)(aa <= b), std::logic_error); |
45 | } |
46 | |
47 | TEST(PosixTimestamp, sleeps) |
PASSED: Continuous integration, rev:3842 /mir-jenkins. ubuntu. com/job/ mir-ci/ 2255/ /mir-jenkins. ubuntu. com/job/ build-mir/ 2922 /mir-jenkins. ubuntu. com/job/ build-0- fetch/2987 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= vivid+overlay/ 2979 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= xenial+ overlay/ 2979 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= yakkety/ 2979 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= yakkety/ 2951 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= yakkety/ 2951/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2951 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2951/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= yakkety/ 2951 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= yakkety/ 2951/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= android, release= vivid+overlay/ 2951 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= android, release= vivid+overlay/ 2951/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= android, release= vivid+overlay/ 2951 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= android, release= vivid+overlay/ 2951/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2951 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial+ overlay/ 2951/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /mir-jenkins. ubuntu. com/job/ mir-ci/ 2255/rebuild
https:/