Mir

Merge lp:~andreas-pokorny/mir/move-cookie-test-to-acceptance-tests into lp:mir

Proposed by Andreas Pokorny
Status: Rejected
Rejected by: Andreas Pokorny
Proposed branch: lp:~andreas-pokorny/mir/move-cookie-test-to-acceptance-tests
Merge into: lp:mir
Diff against target: 160 lines (+28/-30)
3 files modified
tests/acceptance-tests/CMakeLists.txt (+1/-0)
tests/acceptance-tests/test_client_cookie.cpp (+27/-29)
tests/umock-acceptance-tests/CMakeLists.txt (+0/-1)
To merge this branch: bzr merge lp:~andreas-pokorny/mir/move-cookie-test-to-acceptance-tests
Reviewer Review Type Date Requested Status
Alan Griffiths Needs Information
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+275502@code.launchpad.net

Commit message

Create real cookies from fake input

To detect that new devices reported by udev are valid and have not been removed or stale while being added Libinput
matches device ids through various methods - one of them fstat(device_fd...) is currently not caught by umockdev.
Until that is resolved in umockdev we have to refrain from using that to inject user input.

This change uses fake input devices to do the same - bypassing the evdev platform in this case.

Description of the change

The original test relied on working umockdev - which isnt the case with the libinput platform anymore. So for the time being tests like those need to use the fake input devices.

At some point we might be able to move it back..

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
Alan Griffiths (alan-griffiths) wrote :

So these udev_recordings can each be replaced with a single event without changing the meaning of the tests?

review: Needs Information
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

> So these udev_recordings can each be replaced with a single event without
> changing the meaning of the tests?

The way the test is written only the last event counts.. So this test should have the same coverage.

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

Unmerged revisions

3050. By Andreas Pokorny on 2015-10-23

Add a todo - when umockdev works again we should add another test that also includes evdev input

3049. By Andreas Pokorny on 2015-10-23

Moving Cookie client test to a acceptance test and using fake input devices instead

To detect that new devices reported by udev are valid and have not been removed or stale while being added Libinput
matches device ids through various methods - one of them fstat(device_fd...) is currently not caught by umockdev.
Until that is resolved in umockdev we have to refrain from using that to inject user input.

This change uses fake input devices to do the same - bypassing the evdev platform in this case.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/acceptance-tests/CMakeLists.txt'
2--- tests/acceptance-tests/CMakeLists.txt 2015-10-07 16:41:50 +0000
3+++ tests/acceptance-tests/CMakeLists.txt 2015-10-23 08:40:13 +0000
4@@ -11,6 +11,7 @@
5 server_configuration_options.cpp
6 server_signal_handling.cpp
7 test_application_not_responding_detection.cpp
8+ test_client_cookie.cpp
9 test_client_header_version.cpp
10 test_client_input.cpp
11 test_client_library.cpp
12
13=== renamed file 'tests/umock-acceptance-tests/test_client_cookie.cpp' => 'tests/acceptance-tests/test_client_cookie.cpp'
14--- tests/umock-acceptance-tests/test_client_cookie.cpp 2015-10-15 18:40:48 +0000
15+++ tests/acceptance-tests/test_client_cookie.cpp 2015-10-23 08:40:13 +0000
16@@ -16,15 +16,23 @@
17 * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
18 */
19
20-#include "mir_test_framework/udev_environment.h"
21 #include "mir_test_framework/connected_client_with_a_surface.h"
22 #include "mir/test/wait_condition.h"
23+#include "mir_test_framework/fake_input_device.h"
24+#include "mir_test_framework/stub_server_platform_factory.h"
25+
26+#include "mir/input/device_capability.h"
27+#include "mir/input/input_device_info.h"
28 #include "mir/cookie_factory.h"
29
30-#include "boost/throw_exception.hpp"
31+#include <linux/input.h>
32+#include <boost/throw_exception.hpp>
33
34+// TODO we should have another test in the umockdev based acceptance test that also
35+// includes our prefered input platforms and setups.
36
37 namespace mtf = mir_test_framework;
38+namespace mi = mir::input;
39
40 namespace
41 {
42@@ -37,9 +45,6 @@
43 public:
44 ClientCookies()
45 {
46- // Needed because the headless server sets stub_input.so
47- add_to_environment("MIR_SERVER_PLATFORM_INPUT_LIB", nullptr);
48-
49 server.override_the_cookie_factory([this] ()
50 { return mir::cookie::CookieFactory::create_saving_secret(cookie_secret); });
51 }
52@@ -58,36 +63,24 @@
53 mir_buffer_stream_swap_buffers_sync(mir_surface_get_buffer_stream(surface));
54 }
55
56- void read_evemu_file(std::string const& evemu_file)
57- {
58- mock_devices.load_device_evemu(evemu_file);
59-
60- udev_read_recording.wait_for_at_most_seconds(max_wait);
61- if (!udev_read_recording.woken())
62- BOOST_THROW_EXCEPTION(std::runtime_error("Timeout waiting for udev to read the recording '" + evemu_file + "'"));
63- }
64
65 std::vector<uint8_t> cookie_secret;
66- mtf::UdevEnvironment mock_devices;
67 MirCookie out_cookie{0, 0};
68- mir::test::WaitCondition udev_read_recording;
69+ mir::test::WaitCondition client_input_received;
70+
71 };
72
73 // Need to setup the device before the server gets setup
74 struct ClientCookiesKeyboard : ClientCookies
75 {
76- ClientCookiesKeyboard()
77- {
78- mock_devices.add_standard_device("laptop-keyboard");
79- }
80+ std::unique_ptr<mtf::FakeInputDevice> fake_keyboard{
81+ mtf::add_fake_input_device(mi::InputDeviceInfo{"keyboard", "keyboard-uid", mi::DeviceCapability::keyboard})};
82 };
83
84 struct ClientCookiesMouse : ClientCookies
85 {
86- ClientCookiesMouse()
87- {
88- mock_devices.add_standard_device("laptop-mouse");
89- }
90+ std::unique_ptr<mtf::FakeInputDevice> fake_mouse{
91+ mtf::add_fake_input_device(mi::InputDeviceInfo{"mouse", "mouse-uid", mi::DeviceCapability::pointer})};
92 };
93
94 namespace
95@@ -104,19 +97,19 @@
96 {
97 auto kev = mir_input_event_get_keyboard_event(iev);
98 client->out_cookie = mir_keyboard_event_get_cookie(kev);
99- client->udev_read_recording.wake_up_everyone();
100+ client->client_input_received.wake_up_everyone();
101 }
102 else if (itype == mir_input_event_type_pointer)
103 {
104 auto pev = mir_input_event_get_pointer_event(iev);
105 client->out_cookie = mir_pointer_event_get_cookie(pev);
106- client->udev_read_recording.wake_up_everyone();
107+ client->client_input_received.wake_up_everyone();
108 }
109 else if (itype == mir_input_event_type_touch)
110 {
111 auto tev = mir_input_event_get_touch_event(iev);
112 client->out_cookie = mir_touch_event_get_cookie(tev);
113- client->udev_read_recording.wake_up_everyone();
114+ client->client_input_received.wake_up_everyone();
115 }
116 }
117 }
118@@ -124,7 +117,9 @@
119
120 TEST_F(ClientCookiesKeyboard, keyboard_events_have_attestable_cookies)
121 {
122- read_evemu_file("laptop-keyboard-hello");
123+ fake_keyboard->emit_event(mtf::synthesis::a_key_down_event().of_scancode(KEY_ENTER));
124+ client_input_received.wait_for_at_most_seconds(10);
125+
126 auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
127
128 EXPECT_TRUE(factory->attest_timestamp(out_cookie));
129@@ -132,7 +127,9 @@
130
131 TEST_F(ClientCookiesMouse, pointer_motion_events_do_not_have_attestable_cookies)
132 {
133- read_evemu_file("laptop-mouse-motion");
134+ fake_mouse->emit_event(mtf::synthesis::a_pointer_event().with_movement(20,-19));
135+ client_input_received.wait_for_at_most_seconds(10);
136+
137 auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
138
139 EXPECT_FALSE(factory->attest_timestamp(out_cookie));
140@@ -140,7 +137,8 @@
141
142 TEST_F(ClientCookiesMouse, pointer_click_events_have_attestable_cookies)
143 {
144- read_evemu_file("laptop-mouse-click");
145+ fake_mouse->emit_event(mtf::synthesis::a_button_down_event().of_button(BTN_LEFT));
146+ client_input_received.wait_for_at_most_seconds(10);
147 auto factory = mir::cookie::CookieFactory::create_from_secret(cookie_secret);
148
149 EXPECT_TRUE(factory->attest_timestamp(out_cookie));
150
151=== modified file 'tests/umock-acceptance-tests/CMakeLists.txt'
152--- tests/umock-acceptance-tests/CMakeLists.txt 2015-10-06 18:15:53 +0000
153+++ tests/umock-acceptance-tests/CMakeLists.txt 2015-10-23 08:40:13 +0000
154@@ -10,7 +10,6 @@
155 mir_add_wrapped_executable(
156 mir_umock_acceptance_tests
157
158- test_client_cookie.cpp
159 test_libinput.cpp
160 )
161

Subscribers

People subscribed via source and target branches