Mir

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

Proposed by Alan Griffiths
Status: Merged
Approved by: Cemil Azizoglu
Approved revision: no longer in the source branch.
Merged at revision: 1736
Proposed branch: lp:~alan-griffiths/mir/fix-1335747
Merge into: lp:mir
Diff against target: 69 lines (+23/-11)
1 file modified
tests/integration-tests/test_surfaceloop.cpp (+23/-11)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1335747
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Cemil Azizoglu (community) Approve
Kevin DuBois (community) Approve
Review via email: mp+225006@code.launchpad.net

Commit message

tests: synchronize use of counters correctly

Description of the change

tests: synchronize use of counters correctly

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

To give an idea of the infrequence and scale of the problem here's some output from my investigation:

DEBUG run=188, i=938
DEBUG run=1306, i=662
DEBUG run=5562, i=1444
DEBUG run=12271, i=5
DEBUG run=12604, i=1810
DEBUG run=14656, i=2012
DEBUG run=23680, i=4
DEBUG run=31931, i=474
DEBUG run=35833, i=978
DEBUG run=39250, i=1176
DEBUG run=44260, i=1547
DEBUG run=47337, i=1214
DEBUG run=51397, i=1146
DEBUG run=58659, i=76
DEBUG run=58691, i=8700
DEBUG run=60875, i=1
DEBUG run=70940, i=2093
DEBUG run=75398, i=1137
DEBUG run=80812, i=4
DEBUG run=81348, i=7
DEBUG run=82227, i=94
DEBUG run=83219, i=1424
DEBUG run=90168, i=2145
DEBUG run=90484, i=908
DEBUG run=101722, i=224
DEBUG run=105501, i=1901

Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

It'd be better if we synchronized properly. 10000 seems safe but who knows what would happen under a different/heavy load.

review: Disapprove
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> It'd be better if we synchronized properly. 10000 seems safe but who knows
> what would happen under a different/heavy load.

"Disapprove" seems harsh - wasn't "Needs Fixing" enough?

Anyway, fixed.

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

lgtm

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Looks good.

review: Approve
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :
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 'tests/integration-tests/test_surfaceloop.cpp'
--- tests/integration-tests/test_surfaceloop.cpp 2014-06-12 13:23:29 +0000
+++ tests/integration-tests/test_surfaceloop.cpp 2014-06-30 16:11:37 +0000
@@ -28,7 +28,6 @@
28#include "mir_test_framework/basic_client_server_fixture.h"28#include "mir_test_framework/basic_client_server_fixture.h"
2929
30#include <thread>30#include <thread>
31#include <atomic>
32#include <mutex>31#include <mutex>
33#include <condition_variable>32#include <condition_variable>
34#include <gmock/gmock.h>33#include <gmock/gmock.h>
@@ -153,17 +152,21 @@
153152
154 CountingStubBuffer()153 CountingStubBuffer()
155 {154 {
156 int created = buffers_created.load();155 std::lock_guard<std::mutex> lock{buffers_mutex};
157 while (!buffers_created.compare_exchange_weak(created, created + 1)) std::this_thread::yield();156 ++buffers_created;
157 buffers_cv.notify_one();
158 }158 }
159 ~CountingStubBuffer()159 ~CountingStubBuffer()
160 {160 {
161 int destroyed = buffers_destroyed.load();161 std::lock_guard<std::mutex> lock{buffers_mutex};
162 while (!buffers_destroyed.compare_exchange_weak(destroyed, destroyed + 1)) std::this_thread::yield();162 ++buffers_destroyed;
163 buffers_cv.notify_one();
163 }164 }
164165
165 static std::atomic<int> buffers_created;166 static std::mutex buffers_mutex;
166 static std::atomic<int> buffers_destroyed;167 static std::condition_variable buffers_cv;
168 static int buffers_created;
169 static int buffers_destroyed;
167 };170 };
168171
169 class StubGraphicBufferAllocator : public mtd::StubBufferAllocator172 class StubGraphicBufferAllocator : public mtd::StubBufferAllocator
@@ -204,8 +207,10 @@
204 std::shared_ptr<mg::Platform> platform;207 std::shared_ptr<mg::Platform> platform;
205};208};
206209
207std::atomic<int> BufferCounterConfig::CountingStubBuffer::buffers_created;210std::mutex BufferCounterConfig::CountingStubBuffer::buffers_mutex;
208std::atomic<int> BufferCounterConfig::CountingStubBuffer::buffers_destroyed;211std::condition_variable BufferCounterConfig::CountingStubBuffer::buffers_cv;
212int BufferCounterConfig::CountingStubBuffer::buffers_created;
213int BufferCounterConfig::CountingStubBuffer::buffers_destroyed;
209}214}
210215
211struct SurfaceLoop : mtf::BasicClientServerFixture<BufferCounterConfig>216struct SurfaceLoop : mtf::BasicClientServerFixture<BufferCounterConfig>
@@ -226,8 +231,15 @@
226 {231 {
227 mtf::BasicClientServerFixture<BufferCounterConfig>::TearDown();232 mtf::BasicClientServerFixture<BufferCounterConfig>::TearDown();
228233
229 EXPECT_EQ(BufferCounterConfig::CountingStubBuffer::buffers_created.load(),234 using Counter = BufferCounterConfig::CountingStubBuffer;
230 BufferCounterConfig::CountingStubBuffer::buffers_destroyed.load());235
236 std::chrono::seconds const long_enough{4};
237 auto const all_buffers_destroyed =
238 []{ return Counter::buffers_created == Counter::buffers_destroyed; };
239 std::unique_lock<std::mutex> lock{Counter::buffers_mutex};
240
241 EXPECT_TRUE(
242 Counter::buffers_cv.wait_for(lock, long_enough, all_buffers_destroyed));
231 }243 }
232};244};
233245

Subscribers

People subscribed via source and target branches