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

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

3049. By Andreas Pokorny

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

Subscribers

People subscribed via source and target branches