Mir

Merge lp:~alan-griffiths/mir/fix-1514884 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 3151
Proposed branch: lp:~alan-griffiths/mir/fix-1514884
Merge into: lp:mir
Diff against target: 63 lines (+17/-11)
2 files modified
include/test/mir/test/doubles/mock_egl.h (+10/-8)
tests/mir_test_doubles/mock_egl.cpp (+7/-3)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1514884
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Review via email: mp+278961@code.launchpad.net

Commit message

tests: fix racy access to MockEGL::current_contexts

Description of the change

tests: fix racy access to MockEGL::current_contexts

To post a comment you must log in.
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

^-- Another instance of https://bugs.launchpad.net/mir/+bug/1520217

Top-approving again.

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/test/mir/test/doubles/mock_egl.h'
--- include/test/mir/test/doubles/mock_egl.h 2015-11-13 19:46:42 +0000
+++ include/test/mir/test/doubles/mock_egl.h 2015-11-30 13:56:32 +0000
@@ -21,8 +21,9 @@
2121
22#include <gmock/gmock.h>22#include <gmock/gmock.h>
2323
24#include <mutex>
25#include <thread>
24#include <unordered_map>26#include <unordered_map>
25#include <thread>
2627
27#define GL_GLEXT_PROTOTYPES28#define GL_GLEXT_PROTOTYPES
28#define EGL_EGLEXT_PROTOTYPES29#define EGL_EGLEXT_PROTOTYPES
@@ -150,13 +151,14 @@
150 MOCK_METHOD2(eglDestroySyncKHR, EGLBoolean(EGLDisplay, EGLSyncKHR));151 MOCK_METHOD2(eglDestroySyncKHR, EGLBoolean(EGLDisplay, EGLSyncKHR));
151 MOCK_METHOD4(eglClientWaitSyncKHR, EGLint(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR));152 MOCK_METHOD4(eglClientWaitSyncKHR, EGLint(EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR));
152153
153 EGLDisplay fake_egl_display;154 EGLDisplay const fake_egl_display;
154 EGLConfig* fake_configs;155 EGLConfig const* const fake_configs;
155 EGLint fake_configs_num;156 EGLint const fake_configs_num;
156 EGLSurface fake_egl_surface;157 EGLSurface const fake_egl_surface;
157 EGLContext fake_egl_context;158 EGLContext const fake_egl_context;
158 EGLImageKHR fake_egl_image;159 EGLImageKHR const fake_egl_image;
159 int fake_visual_id;160 int const fake_visual_id;
161 std::mutex mutable current_contexts_mutex;
160 std::unordered_map<std::thread::id,EGLContext> current_contexts;162 std::unordered_map<std::thread::id,EGLContext> current_contexts;
161};163};
162164
163165
=== modified file 'tests/mir_test_doubles/mock_egl.cpp'
--- tests/mir_test_doubles/mock_egl.cpp 2015-11-13 19:46:42 +0000
+++ tests/mir_test_doubles/mock_egl.cpp 2015-11-30 13:56:32 +0000
@@ -108,15 +108,19 @@
108108
109 ON_CALL(*this, eglMakeCurrent(_,_,_,_))109 ON_CALL(*this, eglMakeCurrent(_,_,_,_))
110 .WillByDefault(Invoke(110 .WillByDefault(Invoke(
111 [&] (EGLDisplay, EGLSurface, EGLSurface, EGLContext context)111 [this] (EGLDisplay, EGLSurface, EGLSurface, EGLContext context)
112 {112 {
113 std::lock_guard<decltype(current_contexts_mutex)> lock{current_contexts_mutex};
113 current_contexts[std::this_thread::get_id()] = context;114 current_contexts[std::this_thread::get_id()] = context;
114 return EGL_TRUE;115 return EGL_TRUE;
115 }));116 }));
116117
117 ON_CALL(*this, eglGetCurrentContext())118 ON_CALL(*this, eglGetCurrentContext())
118 .WillByDefault(Invoke(119 .WillByDefault(Invoke([this]
119 [&] { return current_contexts[std::this_thread::get_id()]; }));120 {
121 std::lock_guard<decltype(current_contexts_mutex)> lock{current_contexts_mutex};
122 return current_contexts[std::this_thread::get_id()];
123 }));
120124
121 ON_CALL(*this, eglSwapBuffers(_,_))125 ON_CALL(*this, eglSwapBuffers(_,_))
122 .WillByDefault(Return(EGL_TRUE)); 126 .WillByDefault(Return(EGL_TRUE));

Subscribers

People subscribed via source and target branches