Mir

Merge lp:~cemil-azizoglu/mir/fix-1556210 into lp:mir

Proposed by Cemil Azizoglu
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 3392
Proposed branch: lp:~cemil-azizoglu/mir/fix-1556210
Merge into: lp:mir
Diff against target: 96 lines (+26/-4)
4 files modified
src/platforms/mesa/server/x11/input/input_platform.cpp (+1/-2)
tests/include/mir/test/doubles/mock_x11.h (+1/-0)
tests/mir_test_doubles/mock_x11.cpp (+9/-1)
tests/unit-tests/input/test_x11_platform.cpp (+15/-1)
To merge this branch: bzr merge lp:~cemil-azizoglu/mir/fix-1556210
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Mir CI Bot continuous-integration Approve
Alan Griffiths Needs Fixing
Andreas Pokorny (community) Approve
Review via email: mp+288845@code.launchpad.net

Commit message

XNextEvent is a blocking call. Check to make sure there is an event before calling it. (LP: #1556210)

Description of the change

XNextEvent is a blocking call. Check to make sure there is an event before calling it.

To post a comment you must log in.
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Let me know if there is a better way to handle the gmock ugliness.

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3386
https://mir-jenkins.ubuntu.com/job/mir-ci/551/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/433
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/463
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/455
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/455
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/442
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/442/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/442
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/442/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/442
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/442/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/442
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/442/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/442
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/442/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/551/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

Yes.

On the mock default action...

 ON_CALL(*this, XPending(_))
    .WillByDefault(InvokeWithoutArgs([this](){ return fake_x11.event_vector.size();}));

 ON_CALL(*this, XNextEvent(_,_)
     .WillByDefault(Invoke([this](Display *, XEvent *dest)
                           {
                              *dest = fake_x11.event_vector.front();
                              fake_x11.event_vector.pop_front();
                           });

... or something like that.

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I was confused for a moment as the diff doesn't show the relevant XNextEvent.

But yeah this looks right...

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Fixes the linked bug.

But the test code is confusing (as you obviously realize) and seems to relate more to other tests than the one proposed.

It seems that we need some stub logic (to link XPending and XNextEvent) rather than a pure Mock for the global X11 test double.

Perhaps something like:

    ON_CALL(*this, XPending(_))
        .WillByDefault(InvokeWithoutArgs([this](){ return fake_x11.pending_events; }));

int XNextEvent(Display* display, XEvent* event_return)
{
    auto const result = global_mock->XNextEvent(display, event_return);
    if (result) --global_mock->fake_x11.pending_events;
    return result;
}

And XMaskEvent etc.

review: Needs Fixing
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

@Alan, @Andreas, thanks for your suggestions. Should be fixed now.

Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

@Alan, @Andreas, thanks for your suggestions. Should be fixed now.

Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3387
https://mir-jenkins.ubuntu.com/job/mir-ci/565/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/457
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/487
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/479
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/479
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/466
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/466/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/466
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/466/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/466
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/466/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/466
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/466/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/466
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/466/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/565/rebuild

review: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Fix still looks OK

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/platforms/mesa/server/x11/input/input_platform.cpp'
2--- src/platforms/mesa/server/x11/input/input_platform.cpp 2016-03-02 08:43:21 +0000
3+++ src/platforms/mesa/server/x11/input/input_platform.cpp 2016-03-14 20:56:18 +0000
4@@ -80,7 +80,7 @@
5
6 void mix::XInputPlatform::process_input_event()
7 {
8- do
9+ while(XPending(x11_connection.get()))
10 {
11 // This code is based on :
12 // https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html
13@@ -248,5 +248,4 @@
14 else
15 mir::log_error("input event received with no sink to handle it");
16 }
17- while(XPending(x11_connection.get()));
18 }
19
20=== modified file 'tests/include/mir/test/doubles/mock_x11.h'
21--- tests/include/mir/test/doubles/mock_x11.h 2016-03-02 08:43:21 +0000
22+++ tests/include/mir/test/doubles/mock_x11.h 2016-03-14 20:56:18 +0000
23@@ -47,6 +47,7 @@
24 XEvent focus_out_event_return = { 0 };
25 XEvent vscroll_event_return = { 0 };
26 XEvent motion_event_return = { 0 };
27+ int pending_events = 1;
28 };
29
30 class MockX11
31
32=== modified file 'tests/mir_test_doubles/mock_x11.cpp'
33--- tests/mir_test_doubles/mock_x11.cpp 2016-03-02 08:43:21 +0000
34+++ tests/mir_test_doubles/mock_x11.cpp 2016-03-14 20:56:18 +0000
35@@ -71,6 +71,12 @@
36
37 ON_CALL(*this, XInitThreads())
38 .WillByDefault(Return(1));
39+
40+ ON_CALL(*this, XPending(_))
41+ .WillByDefault(InvokeWithoutArgs([this]()
42+ {
43+ return fake_x11.pending_events;
44+ }));
45 }
46
47 mtd::MockX11::~MockX11()
48@@ -135,7 +141,9 @@
49
50 int XNextEvent(Display* display, XEvent* event_return)
51 {
52- return global_mock->XNextEvent(display, event_return);
53+ auto const result = global_mock->XNextEvent(display, event_return);
54+ if (result) --global_mock->fake_x11.pending_events;
55+ return result;
56 }
57
58 int XLookupString(XKeyEvent* event_struct, char* buffer_return, int bytes_buffer, KeySym* keysym_return, XComposeStatus* status_in_out)
59
60=== modified file 'tests/unit-tests/input/test_x11_platform.cpp'
61--- tests/unit-tests/input/test_x11_platform.cpp 2016-03-02 08:43:21 +0000
62+++ tests/unit-tests/input/test_x11_platform.cpp 2016-03-14 20:56:18 +0000
63@@ -30,7 +30,6 @@
64 #include "mir/test/doubles/mock_input_sink.h"
65 #include "mir/test/doubles/mock_input_device_registry.h"
66 #include "mir/test/doubles/mock_x11.h"
67-#include "mir/test/doubles/mock_x11.h"
68 #include "mir/test/fake_shared.h"
69 #include "mir/cookie/authority.h"
70 #include "mir/test/event_matchers.h"
71@@ -176,6 +175,8 @@
72
73 TEST_F(X11PlatformTest, motion_event_trigger_pointer_movement)
74 {
75+ mock_x11.fake_x11.pending_events = 2;
76+
77 prepare_event_processing();
78
79 InSequence seq;
80@@ -231,3 +232,16 @@
81
82 process_input_event();
83 }
84+
85+TEST_F(X11PlatformTest, does_not_block_on_events)
86+{
87+ prepare_event_processing();
88+
89+ ON_CALL(mock_x11, XPending(_))
90+ .WillByDefault(Return(0));
91+
92+ EXPECT_CALL(mock_x11, XNextEvent(_,_))
93+ .Times(Exactly(0));
94+
95+ process_input_event();
96+}

Subscribers

People subscribed via source and target branches