~ci-train-bot/mir/mir-ubuntu-artful-3013

« back to all changes in this revision

Viewing changes to tests/unit-tests/platforms/mesa/kms/test_display.cpp

  • Committer: Bileto Bot
  • Date: 2017-06-30 12:00:17 UTC
  • mfrom: (1303.1.6 mir-0.27)
  • Revision ID: ci-train-bot@canonical.com-20170630120017-ha5i92o9moejk2b1
* New upstream release 0.27.0 (https://launchpad.net/mir/+milestone/0.27.0)
  - ABI summary:
    . mirclient ABI unchanged at 9
    . mirserver ABI bumped to 44
    . mircommon ABI unchanged at 7
    . mirplatform ABI bumped to 61
    . mirprotobuf ABI unchanged at 3
    . mirplatformgraphics ABI bumped to 13
    . mirclientplatform ABI unchanged at 5
    . mirinputplatform ABI bumped to 7
    . mircore ABI unchanged at 1
  - Enhancements:
    . Mostly groundwork required to support major enhancements coming in
      future Mir versions.
    . Removed android-input and eliminated the entire "3rd_party/" subtree.
      Now the Mir source tree contains original code only.
    . Added mir_prompt_session_new_fds_for_prompt_providers_sync API.
    . mirout: Added load and save options for keeping display configs
      on disk.
    . mirout: Added "--" support for applying configuration changes under
      Unity8.
    . Fixed failure of DRM hardware cursor {hide(); show(image);}
    . Added server option: "--cursor software" (MIR_SERVER_CURSOR=software)
    . Added letterboxing/black bars support to the GL renderer in preparation
      for generic output cloning.
    . Added client API for getting the logical size of an output.
    . Migrated MirCookie to use SHA-256.
    . Ensure RealKMSOutputConfiguration stays in sync with actual hardware
      state.
    . Added support for drag-and-drop.
    . Lots of other client API enhancements.
    . Minor clean-ups, optimizations and dead code removal.
    . Added support for building on Ubuntu 17.10 artful.
    . Update example code to use undeprecated API.
    . mesa-kms: Support hardware cursors in hybrid setups.
    . Rework and publish the graphics platform APIs
  - Bugs fixed:
    . [enhancement] Make able to get version information from client /
      server APIs (LP: #1195540)
    . Touch screen coordinates don't rotate with the screen (LP: #1349660)
    . Subpixel order not included in Mir display information (LP: #1393578)
    . [enhancement] Missing client API for relative surface movement (e.g.
      dragging client-decorated windows) (LP: #1420334) . Mir does not reset
      key states when paused or resumed (modifiers get stuck after VT
      switching) (LP: #1536279)
    . NBS never uses mc::MultiMonitorMode::single_monitor_fast, even when
      only a single monitor is plugged in (LP: #1561418)
    . Inconsistent behaviour of Num Lock (LP: #1588237)
    . A scaled (not panned or clipped) mirror/clone mode is desired
      (LP: #1639226)
    . Rotating an output left or right without restarting the
      compositor distorts the image (LP: #1643488)
    . support display scaling slider in unity8 (LP: #1645372)
    . [ FAILED ] NestedInputWithMouse.mouse_pointer_coordinates_in_nested_
      server_are_accumulated (LP: #1646375)
    . [ FAILED ] NestedInputWithMouse.mouse_pointer_position_is_in_sync_with_
      host_server (LP: #1646558)
    . abi_check doesn't check mircore (LP: #1649354)
    . [testsfail] PromptSessionClientAPI.client_pid_is_associated_with_
      session hangs and times out (LP: #1655929)
    . EDID does not change when hotplugging a monitor (LP: #1660017)
    . [regression] Mir 0.26.0 - spinner loading animation, minimize, maximize
      too fast (LP: #1661072)
    . [regression] Unity8 stutters constantly (like half frame rate) using
      Mir 0.26.0 (LP: #1661128)
    . [regression] mir_demo_server refuses to quit on Ctrl+Alt+Backspace or
      Ctrl+C in its terminal (deadlock in DefaultInputDeviceHub::add_device)
      (LP: #1661151)
    . [regression] mirout crashes when connecting to unity8 or any nested
      server: [libprotobuf FATAL
      /usr/include/google/protobuf/repeated_field.h:1408] CHECK failed:
      (index) < (current_size_): (LP: #1661163)
    . [ FAILED ] DefaultInputManagerTest.forwards_pause_continue_state_
      changes_to_platform (LP: #1661187)
    . [regression] Segfault on detect_fd_leaks during acceptance tests (in
      DisplayConfiguration/{DisplayFormatSetting,DisplaySubpixelSetting})
      (LP: #1661498)
    . [regression] Nested server segfaults or rapidly logs exceptions when a
      fullscreen client starts [in mir_presentation_chain_set_dropping_mode
      ... std::exception::what: Operation not permitted] (LP: #1661508)
    . [regression] Windowed clients of nested servers are all black
      (LP: #1661521)
    . mir_window_request_persistent_id_sync seg faults when called twice
      (LP: #1661704)
    . mir_acceptance_tests now takes 10 seconds longer (in r4002 compared to
      r4001) (LP: #1662044)
    . Mir graphics platform ABI broke in series 0.26 but sonames never
      changed (LP: #1662455)
    . libmirclient-dev missing build depndency on libmircore-dev
      (LP: #1662942)
    . [regression] mirscreencast hangs during screencast creation
      (LP: #1662997)
    . [regression] Software clients of nested servers with size >=480x480
      are all black in Mir 0.25.0 and later (or stretched and distorted under
      Unity8) (LP: #1663062)
    . mir_window_spec_set_cursor_name() doesn't trigger
      mir::scene::SurfaceObserver::cursor_image_set_to (LP: #1663197)
    . android complaint during mirscreencast of nested server (LP: #1664562)
    . qtubuntu sends wrong text as part of QKeyEvent (LP: #1664610)
    . Mir server crashed with SIGSEGV in
      mir::compositor::TemporaryBuffer::size() called from
      mir::gl::tessellate_renderable_into_rectangle() (LP: #1664760)
    . mirout reports logical size of a rotated display incorrectly
      (LP: #1665271)
    . Nested servers (Unity8) periodically stutter (half frame rate) with
      Mir 0.26.1 (LP: #1666372)
    . If the only surface in a session cannot take focus the server crashes
      (LP: #1667645)
    . [regression] OSK input shaping no longer works correctly (LP: #1669444)
    . GTK window functions `Always on Top, Move and Resize' don't work in
      Mir/Unity8 (LP: #1669524)
    . [regression] mir_proving_server mode hotkeys (Ctrl+Alt+=/-) cause the
      server to segfault (LP: #1669752)
    . Test takes minutes to complete: MediatingDisplayChangerTest.confirmed_
      configuration_doesnt_revert_after_timeout (LP: #1671033)
    . [ FAILED ] PosixRWMutex.prefer_writer_nonrecursive_prevents_writer_
      starvation (Timeout waiting to acquire write lock) (LP: #1671037)
    . [regression] Mixing screen rotation with mode changes makes the image
      squished (LP: #1672269)
    . unity-system-compositor crashed with SIGSEGV in
      libinput_device_config_accel_is_available() from
      libinput_device_config_accel_set_speed() from
      mir::input::evdev::LibInputDevice::apply_settings() (LP: #1672955)
    . Presentation chains should support various Vulkan presentation modes
      (LP: #1673533)
    . Need an extension for GBM buffers to replace
      mir_buffer_get_buffer_package() (LP: #1673534)
    . cross-compile-chroot.sh (to zesty) fails to build [cannot find -ludev]
      due to libudev.so being in a different directory to where libudev.pc
      searches for it (LP: #1674201)
    . Please transition to Boost 1.62 (LP: #1675138)
    . [regression] Mir is assigning the first output ID = 0 (==
      mir_display_output_id_invalid) (LP: #1675331)
    . Mir sending key repeat events continually to nested shell after VT
      switch (causes Unity8 lockup for a while) (LP: #1675357)
    . mirout commands don't work when followed by -- (LP: #1676320)
    . mir_demo_standalone_render_overlays fails to link (LP: #1677239)
    . [regression] doxygen processing for capnproto/protobuf broken
      (LP: #1679248)
    . mir_window_spec_set_cursor_render_surface does not work (LP: #1679836)
    . [regression] Some fullscreen apps render nothing until the window has
      been resized (LP: #1686620)
    . Correct eglsquare example: Don't paint from the window event handler.
      (LP: #1695221)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "mir/time/steady_clock.h"
28
28
#include "mir/glib_main_loop.h"
29
29
#include "mir/fatal.h"
 
30
#include "src/platforms/common/server/kms-utils/drm_mode_resources.h"
30
31
 
31
32
#include "mir/test/doubles/mock_egl.h"
32
33
#include "mir/test/doubles/mock_gl.h"
55
56
#include <atomic>
56
57
#include <mutex>
57
58
#include <condition_variable>
 
59
#include <fcntl.h>
58
60
 
59
61
namespace mg=mir::graphics;
60
62
namespace mgm=mir::graphics::mesa;
80
82
public:
81
83
    MesaDisplayTest() :
82
84
        mock_report{std::make_shared<testing::NiceMock<mtd::MockDisplayReport>>()},
83
 
        null_report{mr::null_display_report()}
 
85
        null_report{mr::null_display_report()},
 
86
        drm_fd{open(drm_device, 0, 0)}
84
87
    {
85
88
        using namespace testing;
86
89
        ON_CALL(mock_egl, eglChooseConfig(_,_,_,1,_))
95
98
         * the MockGBM destructor, and which are not handled by NiceMock<>.
96
99
         */
97
100
        EXPECT_CALL(mock_gbm, gbm_bo_get_device(_))
98
 
        .Times(AtLeast(0));
 
101
            .Times(AtLeast(0));
99
102
        EXPECT_CALL(mock_gbm, gbm_device_get_fd(_))
100
 
        .Times(AtLeast(0));
 
103
            .Times(AtLeast(0))
 
104
            .WillRepeatedly(Return(drm_fd));
101
105
 
102
106
        fake_devices.add_standard_device("standard-drm-devices");
 
107
 
 
108
        // Our standard mock devices have 2 DRM devices; kill all the outputs on
 
109
        // the second one, so we don't try to test hybrid (for now)
 
110
        mock_drm.reset("/dev/dri/card1");
103
111
    }
104
112
 
105
113
    std::shared_ptr<mgm::Platform> create_platform()
145
153
            .Times(Exactly(1))
146
154
            .WillOnce(Return(fake.bo_handle2));
147
155
 
148
 
        EXPECT_CALL(mock_drm, drmModeAddFB2(mock_drm.fake_drm.fd(),
 
156
        EXPECT_CALL(mock_drm, drmModeAddFB2(drm_fd,
149
157
                                            _, _, _,
150
158
                                            Pointee(fake.bo_handle1.u32),
151
159
                                            _, _, _, _))
152
160
            .Times(Exactly(1))
153
161
            .WillOnce(DoAll(SetArgPointee<7>(fake.fb_id1), Return(0)));
154
162
 
155
 
        EXPECT_CALL(mock_drm, drmModeAddFB2(mock_drm.fake_drm.fd(),
 
163
        EXPECT_CALL(mock_drm, drmModeAddFB2(drm_fd,
156
164
                                            _, _, _,
157
165
                                            Pointee(fake.bo_handle2.u32),
158
166
                                            _, _, _, _))
162
170
 
163
171
    uint32_t get_connected_connector_id()
164
172
    {
165
 
        auto drm_res = mock_drm.fake_drm.resources_ptr();
166
 
 
167
 
        for (int i = 0; i < drm_res->count_connectors; i++)
168
 
        {
169
 
            auto connector = mock_drm.fake_drm.find_connector(drm_res->connectors[i]);
170
 
            if (connector->connection == DRM_MODE_CONNECTED)
171
 
                return connector->connector_id;
172
 
        }
173
 
 
174
 
        return 0;
 
173
        mg::kms::DRMModeResources resources{drm_fd};
 
174
 
 
175
        int connected_id = 0;
 
176
        resources.for_each_connector(
 
177
            [&connected_id](auto const& connector)
 
178
            {
 
179
                if (connector->connection == DRM_MODE_CONNECTED)
 
180
                    connected_id = connector->connector_id;
 
181
            });
 
182
 
 
183
        return connected_id;
175
184
    }
176
185
 
177
186
    uint32_t get_connected_crtc_id()
178
187
    {
179
188
        auto connector_id = get_connected_connector_id();
180
 
        auto connector = mock_drm.fake_drm.find_connector(connector_id);
 
189
        auto connector = mg::kms::get_connector(drm_fd, connector_id);
181
190
 
182
191
        if (connector)
183
192
        {
184
 
            auto encoder = mock_drm.fake_drm.find_encoder(connector->encoder_id);
 
193
            auto encoder = mg::kms::get_encoder(drm_fd, connector->encoder_id);
185
194
            if (encoder)
186
195
                return encoder->crtc_id;
187
196
        }
217
226
    std::shared_ptr<testing::NiceMock<mtd::MockDisplayReport>> const mock_report;
218
227
    std::shared_ptr<mg::DisplayReport> const null_report;
219
228
    mtf::UdevEnvironment fake_devices;
 
229
 
 
230
    char const* const drm_device = "/dev/dri/card0";
 
231
    int const drm_fd;
220
232
};
221
233
 
222
234
}
256
268
        .WillOnce(Return(fake.bo_handle1));
257
269
 
258
270
    /* Create a a DRM FB with the DRM buffer attached */
259
 
    EXPECT_CALL(mock_drm, drmModeAddFB2(mock_drm.fake_drm.fd(),
 
271
    EXPECT_CALL(mock_drm, drmModeAddFB2(drm_fd,
260
272
                                       _, _, _,
261
273
                                       Pointee(fake.bo_handle1.u32),
262
274
                                       _, _, _, _))
264
276
        .WillOnce(DoAll(SetArgPointee<7>(fake.fb_id1), Return(0)));
265
277
 
266
278
    /* Display the DRM FB (first expectation is for cleanup) */
267
 
    EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
279
    EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
268
280
                                         crtc_id, Ne(fake.fb_id1),
269
281
                                         _, _,
270
282
                                         Pointee(connector_id),
271
283
                                         _, _))
272
284
        .Times(AtLeast(0));
273
285
 
274
 
    EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
286
    EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
275
287
                                         crtc_id, fake.fb_id1,
276
288
                                         _, _,
277
289
                                         Pointee(connector_id),
291
303
    uint32_t const fb_id{66};
292
304
 
293
305
    /* Create DRM FBs */
294
 
    EXPECT_CALL(mock_drm, drmModeAddFB2(mock_drm.fake_drm.fd(),
 
306
    EXPECT_CALL(mock_drm, drmModeAddFB2(drm_fd,
295
307
                                        _, _, _, _, _, _, _, _))
296
308
        .WillRepeatedly(DoAll(SetArgPointee<7>(fb_id), Return(0)));
297
309
 
300
312
        InSequence s;
301
313
 
302
314
        /* crtc is set */
303
 
        EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
315
        EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
304
316
                                             crtc_id, fb_id,
305
317
                                             _, _,
306
318
                                             Pointee(connector_id),
308
320
            .Times(AtLeast(1));
309
321
 
310
322
        /* crtc is reset */
311
 
        EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
323
        EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
312
324
                                             crtc_id, Ne(fb_id),
313
325
                                             _, _,
314
326
                                             Pointee(connector_id),
325
337
 
326
338
    EXPECT_CALL(mock_drm, open(_,_,_))
327
339
        .Times(AtLeast(1))
328
 
        .WillRepeatedly(Return(-1));
 
340
        .WillRepeatedly(
 
341
            DoAll(
 
342
                InvokeWithoutArgs([]() { errno = ENODEV; }),
 
343
                Return(-1)));
329
344
 
330
345
    EXPECT_CALL(mock_drm, drmClose(_))
331
346
        .Times(Exactly(0));
351
366
    EXPECT_CALL(mock_drm, drmModeFreeResources(_))
352
367
        .Times(Exactly(0));
353
368
 
 
369
    // There are 2 DRM device nodes in our mock environment.
354
370
    EXPECT_CALL(mock_drm, drmClose(_))
355
 
        .Times(Exactly(1));
 
371
        .Times(Exactly(2));
356
372
 
357
373
    EXPECT_THROW({
358
374
        auto display = create_display(platform);
371
387
        .Times(Exactly(0));
372
388
 
373
389
    EXPECT_CALL(mock_drm, drmClose(_))
374
 
        .Times(Exactly(1));
 
390
        .Times(Exactly(2));
375
391
 
376
392
    EXPECT_THROW({
377
393
        auto platform = create_platform();
381
397
namespace
382
398
{
383
399
 
384
 
ACTION_P(QueuePageFlipEvent, write_drm_fd)
 
400
ACTION_P(QueuePageFlipEvent, mock_drm)
385
401
{
386
 
    EXPECT_EQ(1, write(write_drm_fd, "a", 1));
 
402
    static_cast<mtd::MockDRM&>(mock_drm).generate_event_on("/dev/dri/card0");
387
403
}
388
404
 
389
405
ACTION_P(InvokePageFlipHandler, param)
410
426
        InSequence s;
411
427
 
412
428
        /* Flip the new FB */
413
 
        EXPECT_CALL(mock_drm, drmModePageFlip(mock_drm.fake_drm.fd(),
 
429
        EXPECT_CALL(mock_drm, drmModePageFlip(drm_fd,
414
430
                                              crtc_id,
415
431
                                              fake.fb_id2,
416
432
                                              _, _))
417
433
            .Times(Exactly(1))
418
 
            .WillOnce(DoAll(QueuePageFlipEvent(mock_drm.fake_drm.write_fd()),
 
434
            .WillOnce(DoAll(QueuePageFlipEvent(std::ref(mock_drm)),
419
435
                            SaveArg<4>(&user_data),
420
436
                            Return(0)));
421
437
 
422
438
        /* Handle the flip event */
423
 
        EXPECT_CALL(mock_drm, drmHandleEvent(mock_drm.fake_drm.fd(), _))
 
439
        EXPECT_CALL(mock_drm, drmHandleEvent(drm_fd, _))
424
440
            .Times(1)
425
441
            .WillOnce(DoAll(InvokePageFlipHandler(&user_data), Return(0)));
426
442
 
427
 
        /* Release last_flipped_bufobj (at destruction time) */
 
443
        // The initially-visible buffer will be released when the pageflip completes,
 
444
        // replacing it.
428
445
        EXPECT_CALL(mock_gbm, gbm_surface_release_buffer(mock_gbm.fake_gbm.surface, fake.bo1))
429
446
            .Times(Exactly(1));
430
 
        /* Release scheduled_bufobj (at destruction time) */
 
447
 
 
448
        /* Release scheduled_composite_frame (at destruction time) */
431
449
        EXPECT_CALL(mock_gbm, gbm_surface_release_buffer(mock_gbm.fake_gbm.surface, fake.bo2))
432
450
            .Times(Exactly(1));
433
451
    }
453
471
    setup_post_update_expectations();
454
472
 
455
473
    // clear_crtc happens at some stage. Not interesting.
456
 
    EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
474
    EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
457
475
                                         crtc_id, 0,
458
476
                                         _, _, _, _, _))
459
477
        .WillOnce(Return(0));
463
481
 
464
482
        // DisplayBuffer construction paints an empty screen.
465
483
        // That's probably less than ideal but we've always had it that way.
466
 
        EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
484
        EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
467
485
                                             crtc_id, fake.fb_id1,
468
486
                                             _, _, _, _, _))
469
487
            .WillOnce(Return(0));
470
488
 
471
489
        // New FB flip failure
472
 
        EXPECT_CALL(mock_drm, drmModePageFlip(mock_drm.fake_drm.fd(),
 
490
        EXPECT_CALL(mock_drm, drmModePageFlip(drm_fd,
473
491
                                              crtc_id,
474
492
                                              fake.fb_id2,
475
493
                                              _, _))
477
495
            .WillOnce(Return(-1));
478
496
 
479
497
        // Expect fallback to blitting
480
 
        EXPECT_CALL(mock_drm, drmModeSetCrtc(mock_drm.fake_drm.fd(),
 
498
        EXPECT_CALL(mock_drm, drmModeSetCrtc(drm_fd,
481
499
                                             crtc_id, fake.fb_id2,
482
500
                                             _, _, _, _, _))
483
501
            .WillOnce(Return(0));
621
639
    }, std::runtime_error);
622
640
}
623
641
 
624
 
TEST_F(MesaDisplayTest, constructor_throws_if_gl_oes_image_not_supported)
625
 
{
626
 
    using namespace ::testing;
627
 
 
628
 
    const char* gl_exts = "GL_OES_texture_npot GL_OES_blend_func_separate";
629
 
 
630
 
    EXPECT_CALL(mock_gl, glGetString(GL_EXTENSIONS))
631
 
    .WillOnce(Return(reinterpret_cast<const GLubyte*>(gl_exts)));
632
 
 
633
 
    EXPECT_THROW(
634
 
    {
635
 
        auto display = create_display(create_platform());
636
 
    }, std::runtime_error);
637
 
}
638
 
 
639
642
TEST_F(MesaDisplayTest, for_each_display_buffer_calls_callback)
640
643
{
641
644
    using namespace ::testing;
675
678
{
676
679
    using namespace testing;
677
680
 
678
 
    EXPECT_CALL(mock_drm, drmDropMaster(mock_drm.fake_drm.fd()))
679
 
        .Times(1);
 
681
    EXPECT_CALL(mock_drm, drmDropMaster(_))
 
682
        .Times(2);
680
683
 
681
684
    auto display = create_display(create_platform());
682
685
 
687
690
{
688
691
    using namespace testing;
689
692
 
690
 
    EXPECT_CALL(mock_drm, drmSetMaster(mock_drm.fake_drm.fd()))
691
 
        .Times(1);
 
693
    EXPECT_CALL(mock_drm, drmSetMaster(_))
 
694
        .Times(2);
692
695
 
693
696
    auto display = create_display(create_platform());
694
697
 
756
759
 
757
760
    display->register_configuration_change_handler(
758
761
        ml,
759
 
        [&call_count, &ml, &done]()
 
762
        [&call_count, &done]()
760
763
        {
761
764
            if (++call_count == expected_call_count)
762
765
            {
886
889
 
887
890
    EXPECT_TRUE(display->apply_if_configuration_preserves_display_buffers(*config));
888
891
 
 
892
    glm::mat2 const rotate_inverted(-1, 0,
 
893
                                     0,-1);
889
894
    for (auto display_buffer : initial_display_buffer_references)
890
895
    {
891
 
        EXPECT_THAT(display_buffer->orientation(), Eq(mir_orientation_inverted));
 
896
        EXPECT_THAT(display_buffer->transformation(), Eq(rotate_inverted));
892
897
    }
893
898
}