From 8073af6668cbcf308c83359ef2797d85d971946f Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 8 Feb 2019 13:16:53 +0100 Subject: Fix race condition in autotests The QVector m_surface is modified in both threads. Change-Id: I1818a5e1307d191f1613513b86703eaa7bda3c6e Reviewed-by: Johan Helsing --- tests/auto/client/shared_old/mockcompositor.cpp | 24 +++++++++++++++--------- tests/auto/client/shared_old/mockcompositor.h | 5 ++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/auto/client/shared_old/mockcompositor.cpp b/tests/auto/client/shared_old/mockcompositor.cpp index f6a87574..0dfaef5e 100644 --- a/tests/auto/client/shared_old/mockcompositor.cpp +++ b/tests/auto/client/shared_old/mockcompositor.cpp @@ -220,12 +220,14 @@ QSharedPointer MockCompositor::surface() { QSharedPointer result; lock(); - QVector surfaces = m_compositor->surfaces(); - foreach (Impl::Surface *surface, surfaces) { - // we don't want to mistake the cursor surface for a window surface - if (surface->isMapped()) { - result = surface->mockSurface(); - break; + { + QVector surfaces = m_compositor->surfaces(); + foreach (Impl::Surface *surface, surfaces) { + // we don't want to mistake the cursor surface for a window surface + if (surface->isMapped()) { + result = surface->mockSurface(); + break; + } } } unlock(); @@ -307,7 +309,7 @@ void *MockCompositor::run(void *data) { MockCompositor *controller = static_cast(data); - Impl::Compositor compositor; + Impl::Compositor compositor(controller); controller->m_compositor = &compositor; controller->m_waitCondition.wakeOne(); @@ -332,8 +334,8 @@ void *MockCompositor::run(void *data) namespace Impl { -Compositor::Compositor() - : m_display(wl_display_create()) +Compositor::Compositor(MockCompositor *mockCompositor) + : m_mockCompositor(mockCompositor), m_display(wl_display_create()) { if (wl_display_add_socket(m_display, 0)) { fprintf(stderr, "Fatal: Failed to open server socket\n"); @@ -445,15 +447,19 @@ uint32_t Compositor::nextSerial() void Compositor::addSurface(Surface *surface) { + m_mockCompositor->lock(); m_surfaces << surface; + m_mockCompositor->unlock(); } void Compositor::removeSurface(Surface *surface) { + m_mockCompositor->lock(); m_surfaces.removeOne(surface); m_keyboard->handleSurfaceDestroyed(surface); m_pointer->handleSurfaceDestroyed(surface); m_fullScreenShellV1->removeSurface(surface); + m_mockCompositor->unlock(); } Surface *Compositor::resolveSurface(const QVariant &v) diff --git a/tests/auto/client/shared_old/mockcompositor.h b/tests/auto/client/shared_old/mockcompositor.h index 404a18e7..2433ac00 100644 --- a/tests/auto/client/shared_old/mockcompositor.h +++ b/tests/auto/client/shared_old/mockcompositor.h @@ -45,6 +45,8 @@ #include #include +class MockCompositor; + namespace Impl { typedef void (**Implementation)(void); @@ -63,7 +65,7 @@ class XdgShellV6; class Compositor { public: - Compositor(); + Compositor(MockCompositor *mockCompositor); ~Compositor(); int fileDescriptor() const { return m_fd; } @@ -114,6 +116,7 @@ private: void initShm(); + MockCompositor *m_mockCompositor = nullptr; QRect m_outputGeometry; wl_display *m_display = nullptr; -- cgit v1.2.1