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
1=== modified file 'tests/integration-tests/test_surfaceloop.cpp'
2--- tests/integration-tests/test_surfaceloop.cpp 2014-06-12 13:23:29 +0000
3+++ tests/integration-tests/test_surfaceloop.cpp 2014-06-30 16:11:37 +0000
4@@ -28,7 +28,6 @@
5 #include "mir_test_framework/basic_client_server_fixture.h"
6
7 #include <thread>
8-#include <atomic>
9 #include <mutex>
10 #include <condition_variable>
11 #include <gmock/gmock.h>
12@@ -153,17 +152,21 @@
13
14 CountingStubBuffer()
15 {
16- int created = buffers_created.load();
17- while (!buffers_created.compare_exchange_weak(created, created + 1)) std::this_thread::yield();
18+ std::lock_guard<std::mutex> lock{buffers_mutex};
19+ ++buffers_created;
20+ buffers_cv.notify_one();
21 }
22 ~CountingStubBuffer()
23 {
24- int destroyed = buffers_destroyed.load();
25- while (!buffers_destroyed.compare_exchange_weak(destroyed, destroyed + 1)) std::this_thread::yield();
26+ std::lock_guard<std::mutex> lock{buffers_mutex};
27+ ++buffers_destroyed;
28+ buffers_cv.notify_one();
29 }
30
31- static std::atomic<int> buffers_created;
32- static std::atomic<int> buffers_destroyed;
33+ static std::mutex buffers_mutex;
34+ static std::condition_variable buffers_cv;
35+ static int buffers_created;
36+ static int buffers_destroyed;
37 };
38
39 class StubGraphicBufferAllocator : public mtd::StubBufferAllocator
40@@ -204,8 +207,10 @@
41 std::shared_ptr<mg::Platform> platform;
42 };
43
44-std::atomic<int> BufferCounterConfig::CountingStubBuffer::buffers_created;
45-std::atomic<int> BufferCounterConfig::CountingStubBuffer::buffers_destroyed;
46+std::mutex BufferCounterConfig::CountingStubBuffer::buffers_mutex;
47+std::condition_variable BufferCounterConfig::CountingStubBuffer::buffers_cv;
48+int BufferCounterConfig::CountingStubBuffer::buffers_created;
49+int BufferCounterConfig::CountingStubBuffer::buffers_destroyed;
50 }
51
52 struct SurfaceLoop : mtf::BasicClientServerFixture<BufferCounterConfig>
53@@ -226,8 +231,15 @@
54 {
55 mtf::BasicClientServerFixture<BufferCounterConfig>::TearDown();
56
57- EXPECT_EQ(BufferCounterConfig::CountingStubBuffer::buffers_created.load(),
58- BufferCounterConfig::CountingStubBuffer::buffers_destroyed.load());
59+ using Counter = BufferCounterConfig::CountingStubBuffer;
60+
61+ std::chrono::seconds const long_enough{4};
62+ auto const all_buffers_destroyed =
63+ []{ return Counter::buffers_created == Counter::buffers_destroyed; };
64+ std::unique_lock<std::mutex> lock{Counter::buffers_mutex};
65+
66+ EXPECT_TRUE(
67+ Counter::buffers_cv.wait_for(lock, long_enough, all_buffers_destroyed));
68 }
69 };
70

Subscribers

People subscribed via source and target branches