Mir

Merge lp:~kdub/mir/fix-1444047 into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 2516
Proposed branch: lp:~kdub/mir/fix-1444047
Merge into: lp:mir
Diff against target: 533 lines (+162/-37)
16 files modified
src/client/buffer_stream.cpp (+5/-0)
src/client/buffer_stream.h (+1/-0)
src/client/client_buffer_depository.cpp (+14/-3)
src/client/client_buffer_depository.h (+2/-2)
src/common/graphics/android/mir_native_window.cpp (+4/-3)
src/include/client/mir/egl_native_surface.h (+1/-0)
src/include/common/mir/graphics/android/android_driver_interpreter.h (+1/-0)
src/platforms/android/client/egl_native_surface_interpreter.cpp (+7/-0)
src/platforms/android/client/egl_native_surface_interpreter.h (+6/-5)
src/platforms/android/server/server_render_window.cpp (+5/-0)
src/platforms/android/server/server_render_window.h (+6/-5)
tests/include/mir_test_doubles/mock_egl_native_surface.h (+1/-0)
tests/include/mir_test_doubles/stub_driver_interpreter.h (+12/-4)
tests/unit-tests/client/android/test_android_native_window.cpp (+9/-0)
tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp (+21/-0)
tests/unit-tests/client/test_client_buffer_depository.cpp (+67/-15)
To merge this branch: bzr merge lp:~kdub/mir/fix-1444047
Reviewer Review Type Date Requested Status
Alberto Aguirre (community) Approve
Alan Griffiths Approve
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+257156@code.launchpad.net

Commit message

Honor the android driver's request to have a specific number of recently-seen-buffers hanging around, if that request is greater than the mf::client_buffer_cache_size.

fixes: lp: #1444047

Description of the change

Honor the android driver's request to have a specific number of recently-seen-buffers hanging around, if that request is greater than the mf::client_buffer_cache_size.

If you want to reproduce/test, the bug only appears on krillin (probably other mali drivers too), and only happens in the situation where we get an overallocation in BufferQueue due to a framedrop timeout being triggered. This is a pretty rare situation, so lp:~afrantzis/mir/reproduce-1444047 is around that forces the situation more commonly.

fixes: lp: #1444047

To post a comment you must log in.
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: Approve (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Tested for bug 1270245 on krillin. Sadly that one is still happening.

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good and works well.

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

180+void mga::ServerRenderWindow::dispatch_driver_request_buffer_count(unsigned int)
181+{
182+}

Maybe a comment to explain why there can be no bad implications to ignoring this request?

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

Ok.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/client/buffer_stream.cpp'
--- src/client/buffer_stream.cpp 2015-04-01 20:00:19 +0000
+++ src/client/buffer_stream.cpp 2015-04-27 19:10:30 +0000
@@ -398,3 +398,8 @@
398 std::unique_lock<decltype(mutex)> lock(mutex);398 std::unique_lock<decltype(mutex)> lock(mutex);
399 return protobuf_bs.has_id() && !protobuf_bs.has_error();399 return protobuf_bs.has_id() && !protobuf_bs.has_error();
400}400}
401
402void mcl::BufferStream::set_buffer_cache_size(unsigned int cache_size)
403{
404 buffer_depository.set_max_buffers(cache_size);
405}
401406
=== modified file 'src/client/buffer_stream.h'
--- src/client/buffer_stream.h 2015-04-01 20:00:19 +0000
+++ src/client/buffer_stream.h 2015-04-27 19:10:30 +0000
@@ -83,6 +83,7 @@
83 83
84 int swap_interval() const override;84 int swap_interval() const override;
85 void set_swap_interval(int interval) override;85 void set_swap_interval(int interval) override;
86 void set_buffer_cache_size(unsigned int) override;
8687
87 EGLNativeWindowType egl_native_window() override;88 EGLNativeWindowType egl_native_window() override;
88 std::shared_ptr<MemoryRegion> secure_for_cpu_write() override;89 std::shared_ptr<MemoryRegion> secure_for_cpu_write() override;
8990
=== modified file 'src/client/client_buffer_depository.cpp'
--- src/client/client_buffer_depository.cpp 2015-01-21 07:34:50 +0000
+++ src/client/client_buffer_depository.cpp 2015-04-27 19:10:30 +0000
@@ -22,16 +22,18 @@
22#include "mir/client_buffer.h"22#include "mir/client_buffer.h"
23#include "mir/client_buffer_factory.h"23#include "mir/client_buffer_factory.h"
2424
25#include <boost/throw_exception.hpp>
25#include <stdexcept>26#include <stdexcept>
26#include <memory>27#include <memory>
27#include <map>28#include <map>
2829
29namespace mcl=mir::client;30namespace mcl=mir::client;
3031
31mcl::ClientBufferDepository::ClientBufferDepository(std::shared_ptr<ClientBufferFactory> const& factory, int max_buffers)32mcl::ClientBufferDepository::ClientBufferDepository(
32 : factory(factory),33 std::shared_ptr<ClientBufferFactory> const& factory, int max_buffers) :
33 max_buffers(max_buffers)34 factory(factory)
34{35{
36 set_max_buffers(max_buffers);
35}37}
3638
37void mcl::ClientBufferDepository::deposit_package(std::shared_ptr<MirBufferPackage> const& package, int id, geometry::Size size, MirPixelFormat pf)39void mcl::ClientBufferDepository::deposit_package(std::shared_ptr<MirBufferPackage> const& package, int id, geometry::Size size, MirPixelFormat pf)
@@ -72,3 +74,12 @@
72{74{
73 return buffers.front().first;75 return buffers.front().first;
74}76}
77
78void mcl::ClientBufferDepository::set_max_buffers(unsigned int new_max_buffers)
79{
80 if (!new_max_buffers)
81 BOOST_THROW_EXCEPTION(std::logic_error("ClientBufferDepository cache size cannot be 0"));
82 max_buffers = new_max_buffers;
83 while (buffers.size() > max_buffers)
84 buffers.pop_back();
85}
7586
=== modified file 'src/client/client_buffer_depository.h'
--- src/client/client_buffer_depository.h 2014-03-06 06:05:17 +0000
+++ src/client/client_buffer_depository.h 2015-04-27 19:10:30 +0000
@@ -64,11 +64,11 @@
64 geometry::Size, MirPixelFormat);64 geometry::Size, MirPixelFormat);
65 std::shared_ptr<ClientBuffer> current_buffer();65 std::shared_ptr<ClientBuffer> current_buffer();
66 uint32_t current_buffer_id() const;66 uint32_t current_buffer_id() const;
6767 void set_max_buffers(unsigned int max_buffers);
68private:68private:
69 std::shared_ptr<ClientBufferFactory> const factory;69 std::shared_ptr<ClientBufferFactory> const factory;
70 std::list<std::pair<int, std::shared_ptr<ClientBuffer>>> buffers;70 std::list<std::pair<int, std::shared_ptr<ClientBuffer>>> buffers;
71 unsigned int const max_buffers;71 unsigned int max_buffers;
72};72};
73}73}
74}74}
7575
=== modified file 'src/common/graphics/android/mir_native_window.cpp'
--- src/common/graphics/android/mir_native_window.cpp 2015-04-24 15:52:14 +0000
+++ src/common/graphics/android/mir_native_window.cpp 2015-04-27 19:10:30 +0000
@@ -252,12 +252,13 @@
252 va_list args;252 va_list args;
253 va_copy(args, arg_list);253 va_copy(args, arg_list);
254254
255 int driver_format;
256 switch(key)255 switch(key)
257 {256 {
258 case NATIVE_WINDOW_SET_BUFFERS_FORMAT:257 case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
259 driver_format = va_arg(args, int);258 driver_interpreter->dispatch_driver_request_format(va_arg(args, int));
260 driver_interpreter->dispatch_driver_request_format(driver_format);259 break;
260 case NATIVE_WINDOW_SET_BUFFER_COUNT:
261 driver_interpreter->dispatch_driver_request_buffer_count(va_arg(args, int));
261 break;262 break;
262 default:263 default:
263 break;264 break;
264265
=== modified file 'src/include/client/mir/egl_native_surface.h'
--- src/include/client/mir/egl_native_surface.h 2015-03-31 02:35:42 +0000
+++ src/include/client/mir/egl_native_surface.h 2015-04-27 19:10:30 +0000
@@ -35,6 +35,7 @@
35 virtual std::shared_ptr<ClientBuffer> get_current_buffer() = 0;35 virtual std::shared_ptr<ClientBuffer> get_current_buffer() = 0;
36 virtual void request_and_wait_for_next_buffer() = 0;36 virtual void request_and_wait_for_next_buffer() = 0;
37 virtual void request_and_wait_for_configure(MirSurfaceAttrib a, int value) = 0;37 virtual void request_and_wait_for_configure(MirSurfaceAttrib a, int value) = 0;
38 virtual void set_buffer_cache_size(unsigned int) = 0;
3839
39 protected:40 protected:
40 EGLNativeSurface() = default;41 EGLNativeSurface() = default;
4142
=== modified file 'src/include/common/mir/graphics/android/android_driver_interpreter.h'
--- src/include/common/mir/graphics/android/android_driver_interpreter.h 2015-01-21 07:34:50 +0000
+++ src/include/common/mir/graphics/android/android_driver_interpreter.h 2015-04-27 19:10:30 +0000
@@ -35,6 +35,7 @@
35 virtual NativeBuffer* driver_requests_buffer() = 0;35 virtual NativeBuffer* driver_requests_buffer() = 0;
36 virtual void driver_returns_buffer(ANativeWindowBuffer*, int fence) = 0;36 virtual void driver_returns_buffer(ANativeWindowBuffer*, int fence) = 0;
37 virtual void dispatch_driver_request_format(int format) = 0;37 virtual void dispatch_driver_request_format(int format) = 0;
38 virtual void dispatch_driver_request_buffer_count(unsigned int count) = 0;
38 virtual int driver_requests_info(int key) const = 0;39 virtual int driver_requests_info(int key) const = 0;
39 virtual void sync_to_display(bool sync) = 0;40 virtual void sync_to_display(bool sync) = 0;
40protected:41protected:
4142
=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.cpp'
--- src/platforms/android/client/egl_native_surface_interpreter.cpp 2015-03-31 02:35:42 +0000
+++ src/platforms/android/client/egl_native_surface_interpreter.cpp 2015-04-27 19:10:30 +0000
@@ -18,6 +18,7 @@
1818
19#include "egl_native_surface_interpreter.h"19#include "egl_native_surface_interpreter.h"
20#include "mir/graphics/android/sync_fence.h"20#include "mir/graphics/android/sync_fence.h"
21#include "mir/frontend/client_constants.h"
21#include "mir/client_buffer.h"22#include "mir/client_buffer.h"
22#include <system/window.h>23#include <system/window.h>
23#include <stdexcept>24#include <stdexcept>
@@ -84,3 +85,9 @@
84{ 85{
85 surface.request_and_wait_for_configure(mir_surface_attrib_swapinterval, should_sync);86 surface.request_and_wait_for_configure(mir_surface_attrib_swapinterval, should_sync);
86}87}
88
89void mcla::EGLNativeSurfaceInterpreter::dispatch_driver_request_buffer_count(unsigned int count)
90{
91 if (count > mir::frontend::client_buffer_cache_size)
92 surface.set_buffer_cache_size(count);
93}
8794
=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.h'
--- src/platforms/android/client/egl_native_surface_interpreter.h 2015-03-31 02:35:42 +0000
+++ src/platforms/android/client/egl_native_surface_interpreter.h 2015-04-27 19:10:30 +0000
@@ -41,11 +41,12 @@
41public:41public:
42 explicit EGLNativeSurfaceInterpreter(EGLNativeSurface& surface);42 explicit EGLNativeSurfaceInterpreter(EGLNativeSurface& surface);
4343
44 graphics::NativeBuffer* driver_requests_buffer();44 graphics::NativeBuffer* driver_requests_buffer() override;
45 void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd );45 void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd) override;
46 void dispatch_driver_request_format(int format);46 void dispatch_driver_request_format(int format) override;
47 int driver_requests_info(int key) const;47 void dispatch_driver_request_buffer_count(unsigned int count) override;
48 void sync_to_display(bool);48 int driver_requests_info(int key) const override;
49 void sync_to_display(bool) override;
4950
50private:51private:
51 EGLNativeSurface& surface;52 EGLNativeSurface& surface;
5253
=== modified file 'src/platforms/android/server/server_render_window.cpp'
--- src/platforms/android/server/server_render_window.cpp 2015-03-31 02:35:42 +0000
+++ src/platforms/android/server/server_render_window.cpp 2015-04-27 19:10:30 +0000
@@ -96,3 +96,8 @@
96void mga::ServerRenderWindow::sync_to_display(bool)96void mga::ServerRenderWindow::sync_to_display(bool)
97{97{
98}98}
99
100void mga::ServerRenderWindow::dispatch_driver_request_buffer_count(unsigned int)
101{
102 //note: Haven't seen a good reason to honor this request for a fb context
103}
99104
=== modified file 'src/platforms/android/server/server_render_window.h'
--- src/platforms/android/server/server_render_window.h 2015-03-31 02:35:42 +0000
+++ src/platforms/android/server/server_render_window.h 2015-04-27 19:10:30 +0000
@@ -41,11 +41,12 @@
41 MirPixelFormat format,41 MirPixelFormat format,
42 std::shared_ptr<InterpreterResourceCache> const&);42 std::shared_ptr<InterpreterResourceCache> const&);
4343
44 graphics::NativeBuffer* driver_requests_buffer();44 graphics::NativeBuffer* driver_requests_buffer() override;
45 void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd);45 void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd) override;
46 void dispatch_driver_request_format(int format);46 void dispatch_driver_request_format(int format) override;
47 int driver_requests_info(int key) const;47 void dispatch_driver_request_buffer_count(unsigned int count) override;
48 void sync_to_display(bool sync);48 int driver_requests_info(int key) const override;
49 void sync_to_display(bool sync) override;
4950
50private:51private:
51 std::shared_ptr<FramebufferBundle> const fb_bundle;52 std::shared_ptr<FramebufferBundle> const fb_bundle;
5253
=== modified file 'tests/include/mir_test_doubles/mock_egl_native_surface.h'
--- tests/include/mir_test_doubles/mock_egl_native_surface.h 2015-03-31 02:35:42 +0000
+++ tests/include/mir_test_doubles/mock_egl_native_surface.h 2015-04-27 19:10:30 +0000
@@ -36,6 +36,7 @@
36 MOCK_METHOD0(get_current_buffer, std::shared_ptr<client::ClientBuffer>());36 MOCK_METHOD0(get_current_buffer, std::shared_ptr<client::ClientBuffer>());
37 MOCK_METHOD0(request_and_wait_for_next_buffer, void());37 MOCK_METHOD0(request_and_wait_for_next_buffer, void());
38 MOCK_METHOD2(request_and_wait_for_configure, void(MirSurfaceAttrib,int));38 MOCK_METHOD2(request_and_wait_for_configure, void(MirSurfaceAttrib,int));
39 MOCK_METHOD1(set_buffer_cache_size, void(unsigned int));
39};40};
4041
41}42}
4243
=== modified file 'tests/include/mir_test_doubles/stub_driver_interpreter.h'
--- tests/include/mir_test_doubles/stub_driver_interpreter.h 2014-03-06 06:05:17 +0000
+++ tests/include/mir_test_doubles/stub_driver_interpreter.h 2015-04-27 19:10:30 +0000
@@ -42,17 +42,20 @@
42 {42 {
43 }43 }
4444
45 mir::graphics::NativeBuffer* driver_requests_buffer()45 mir::graphics::NativeBuffer* driver_requests_buffer() override
46 {46 {
47 return nullptr;47 return nullptr;
48 }48 }
49
49 void driver_returns_buffer(ANativeWindowBuffer*, int)50 void driver_returns_buffer(ANativeWindowBuffer*, int)
50 {51 {
51 }52 }
52 void dispatch_driver_request_format(int)53
54 void dispatch_driver_request_format(int) override
53 {55 {
54 }56 }
55 int driver_requests_info(int index) const57
58 int driver_requests_info(int index) const override
56 {59 {
57 if (index == NATIVE_WINDOW_WIDTH)60 if (index == NATIVE_WINDOW_WIDTH)
58 return sz.width.as_uint32_t();61 return sz.width.as_uint32_t();
@@ -62,9 +65,14 @@
62 return visual_id;65 return visual_id;
63 return 0;66 return 0;
64 }67 }
65 void sync_to_display(bool)68
69 void sync_to_display(bool) override
66 {70 {
67 }71 }
72
73 void dispatch_driver_request_buffer_count(unsigned int) override
74 {
75 }
68private:76private:
69 mir::geometry::Size sz;77 mir::geometry::Size sz;
70 int visual_id;78 int visual_id;
7179
=== modified file 'tests/unit-tests/client/android/test_android_native_window.cpp'
--- tests/unit-tests/client/android/test_android_native_window.cpp 2015-03-31 02:35:42 +0000
+++ tests/unit-tests/client/android/test_android_native_window.cpp 2015-04-27 19:10:30 +0000
@@ -47,6 +47,7 @@
47 MOCK_METHOD1(dispatch_driver_request_format, void(int));47 MOCK_METHOD1(dispatch_driver_request_format, void(int));
48 MOCK_CONST_METHOD1(driver_requests_info, int(int));48 MOCK_CONST_METHOD1(driver_requests_info, int(int));
49 MOCK_METHOD1(sync_to_display, void(bool));49 MOCK_METHOD1(sync_to_display, void(bool));
50 MOCK_METHOD1(dispatch_driver_request_buffer_count, void(unsigned int));
5051
51 std::shared_ptr<mir::graphics::NativeBuffer> buffer;52 std::shared_ptr<mir::graphics::NativeBuffer> buffer;
52};53};
@@ -113,6 +114,14 @@
113 window.perform(&window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);114 window.perform(&window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
114}115}
115116
117TEST_F(AndroidNativeWindowTest, native_window_perform_hook_calls_set_buffer)
118{
119 int const size = 4;
120 EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_buffer_count(size));
121 ASSERT_NE(nullptr, window.perform);
122 window.perform(&window, NATIVE_WINDOW_SET_BUFFER_COUNT, size);
123}
124
116/* setSwapInterval hook tests */125/* setSwapInterval hook tests */
117TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable)126TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable)
118{127{
119128
=== modified file 'tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp'
--- tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp 2015-03-31 02:35:42 +0000
+++ tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp 2015-04-27 19:10:30 +0000
@@ -20,6 +20,7 @@
20#include "mir/graphics/android/native_buffer.h"20#include "mir/graphics/android/native_buffer.h"
21#include "mir/egl_native_surface.h"21#include "mir/egl_native_surface.h"
22#include "mir/client_buffer.h"22#include "mir/client_buffer.h"
23#include "mir/frontend/client_constants.h"
23#include "src/platforms/android/client/egl_native_surface_interpreter.h"24#include "src/platforms/android/client/egl_native_surface_interpreter.h"
24#include "mir_test_doubles/stub_android_native_buffer.h"25#include "mir_test_doubles/stub_android_native_buffer.h"
25#include "mir_test/fake_shared.h"26#include "mir_test/fake_shared.h"
@@ -79,6 +80,7 @@
79 MOCK_METHOD0(get_current_buffer, std::shared_ptr<mcl::ClientBuffer>());80 MOCK_METHOD0(get_current_buffer, std::shared_ptr<mcl::ClientBuffer>());
80 MOCK_METHOD0(request_and_wait_for_next_buffer, void());81 MOCK_METHOD0(request_and_wait_for_next_buffer, void());
81 MOCK_METHOD2(request_and_wait_for_configure, void(MirSurfaceAttrib, int));82 MOCK_METHOD2(request_and_wait_for_configure, void(MirSurfaceAttrib, int));
83 MOCK_METHOD1(set_buffer_cache_size, void(unsigned int));
82 MirSurfaceParameters params;84 MirSurfaceParameters params;
83};85};
8486
@@ -246,3 +248,22 @@
246 interpreter.sync_to_display(true); 248 interpreter.sync_to_display(true);
247 interpreter.sync_to_display(false); 249 interpreter.sync_to_display(false);
248}250}
251
252TEST_F(AndroidInterpreter, request_to_set_buffer_count_sets_cache_size)
253{
254 int new_size = 5;
255 testing::NiceMock<MockMirSurface> mock_surface{surf_params};
256 EXPECT_CALL(mock_surface, set_buffer_cache_size(new_size));
257 mcla::EGLNativeSurfaceInterpreter interpreter(mock_surface);
258 interpreter.dispatch_driver_request_buffer_count(new_size);
259}
260
261TEST_F(AndroidInterpreter, does_not_set_lower_than_mir_frontend_cache_size)
262{
263 int new_size = mir::frontend::client_buffer_cache_size - 1;
264 testing::NiceMock<MockMirSurface> mock_surface{surf_params};
265 EXPECT_CALL(mock_surface, set_buffer_cache_size(new_size))
266 .Times(0);
267 mcla::EGLNativeSurfaceInterpreter interpreter(mock_surface);
268 interpreter.dispatch_driver_request_buffer_count(new_size);
269}
249270
=== modified file 'tests/unit-tests/client/test_client_buffer_depository.cpp'
--- tests/unit-tests/client/test_client_buffer_depository.cpp 2015-01-21 07:34:50 +0000
+++ tests/unit-tests/client/test_client_buffer_depository.cpp 2015-04-27 19:10:30 +0000
@@ -26,6 +26,7 @@
2626
27#include <gtest/gtest.h>27#include <gtest/gtest.h>
28#include <gmock/gmock.h>28#include <gmock/gmock.h>
29#include <stdexcept>
2930
30namespace geom=mir::geometry;31namespace geom=mir::geometry;
31namespace mcl=mir::client;32namespace mcl=mir::client;
@@ -94,7 +95,7 @@
94 std::weak_ptr<mcl::ClientBuffer> first_allocated_buffer;95 std::weak_ptr<mcl::ClientBuffer> first_allocated_buffer;
95};96};
9697
97struct MirBufferDepositoryTest : public testing::Test98struct ClientBufferDepository : public testing::Test
98{99{
99 void SetUp()100 void SetUp()
100 {101 {
@@ -120,7 +121,7 @@
120 return value == arg;121 return value == arg;
121}122}
122123
123TEST_F(MirBufferDepositoryTest, depository_sets_width_and_height)124TEST_F(ClientBufferDepository, sets_width_and_height)
124{125{
125 using namespace testing;126 using namespace testing;
126127
@@ -131,7 +132,7 @@
131 depository.deposit_package(package, 8, size, pf);132 depository.deposit_package(package, 8, size, pf);
132}133}
133134
134TEST_F(MirBufferDepositoryTest, depository_new_deposit_changes_current_buffer)135TEST_F(ClientBufferDepository, changes_current_buffer_on_new_deposit)
135{136{
136 using namespace testing;137 using namespace testing;
137138
@@ -147,7 +148,7 @@
147 EXPECT_NE(buffer1, buffer2);148 EXPECT_NE(buffer1, buffer2);
148}149}
149150
150TEST_F(MirBufferDepositoryTest, depository_sets_buffer_age_to_zero_for_new_buffer)151TEST_F(ClientBufferDepository, sets_buffer_age_to_zero_for_new_buffer)
151{152{
152 using namespace testing;153 using namespace testing;
153154
@@ -159,7 +160,7 @@
159 EXPECT_EQ(0u, buffer1->age());160 EXPECT_EQ(0u, buffer1->age());
160}161}
161162
162TEST_F(MirBufferDepositoryTest, just_sumbitted_buffer_has_age_1)163TEST_F(ClientBufferDepository, has_age_1_for_just_sumbitted_buffer)
163{164{
164 using namespace testing;165 using namespace testing;
165166
@@ -177,7 +178,7 @@
177 EXPECT_EQ(1u, buffer1->age());178 EXPECT_EQ(1u, buffer1->age());
178}179}
179180
180TEST_F(MirBufferDepositoryTest, submitting_buffer_ages_other_buffers)181TEST_F(ClientBufferDepository, ages_other_buffers_on_new_submission)
181{182{
182 using namespace testing;183 using namespace testing;
183184
@@ -204,7 +205,7 @@
204 EXPECT_EQ(0u, buffer3->age());205 EXPECT_EQ(0u, buffer3->age());
205}206}
206207
207TEST_F(MirBufferDepositoryTest, double_buffering_reaches_steady_state_age)208TEST_F(ClientBufferDepository, reaches_steady_state_age_for_double_buffering)
208{209{
209 using namespace testing;210 using namespace testing;
210211
@@ -233,7 +234,7 @@
233 EXPECT_EQ(2u, buffer2->age());234 EXPECT_EQ(2u, buffer2->age());
234}235}
235236
236TEST_F(MirBufferDepositoryTest, triple_buffering_reaches_steady_state_age)237TEST_F(ClientBufferDepository, reaches_steady_state_age_when_triple_buffering)
237{238{
238 using namespace testing;239 using namespace testing;
239240
@@ -273,7 +274,7 @@
273 EXPECT_EQ(3u, buffer3->age());274 EXPECT_EQ(3u, buffer3->age());
274}275}
275276
276TEST_F(MirBufferDepositoryTest, depository_destroys_old_buffers)277TEST_F(ClientBufferDepository, destroys_old_buffers)
277{278{
278 using namespace testing;279 using namespace testing;
279 const int num_buffers = 3;280 const int num_buffers = 3;
@@ -295,7 +296,7 @@
295 EXPECT_TRUE(mock_factory->first_buffer_allocated_and_then_freed());296 EXPECT_TRUE(mock_factory->first_buffer_allocated_and_then_freed());
296}297}
297298
298TEST_F(MirBufferDepositoryTest, depositing_packages_implicitly_submits_current_buffer)299TEST_F(ClientBufferDepository, implicitly_submits_current_buffer_on_deposit)
299{300{
300 using namespace testing;301 using namespace testing;
301 const int num_buffers = 3;302 const int num_buffers = 3;
@@ -310,7 +311,7 @@
310 depository.deposit_package(package2, 2, size, pf);311 depository.deposit_package(package2, 2, size, pf);
311}312}
312313
313TEST_F(MirBufferDepositoryTest, depository_frees_buffers_after_reaching_capacity)314TEST_F(ClientBufferDepository, frees_buffers_after_reaching_capacity)
314{315{
315 using namespace testing;316 using namespace testing;
316 std::shared_ptr<mcl::ClientBufferDepository> depository;317 std::shared_ptr<mcl::ClientBufferDepository> depository;
@@ -334,7 +335,7 @@
334 }335 }
335}336}
336337
337TEST_F(MirBufferDepositoryTest, depository_caches_recently_seen_buffer)338TEST_F(ClientBufferDepository, caches_recently_seen_buffer)
338{339{
339 using namespace testing;340 using namespace testing;
340341
@@ -358,7 +359,7 @@
358 depository.deposit_package(package3, 8, size, pf);359 depository.deposit_package(package3, 8, size, pf);
359}360}
360361
361TEST_F(MirBufferDepositoryTest, depository_creates_new_buffer_for_different_id)362TEST_F(ClientBufferDepository, creates_new_buffer_for_different_id)
362{363{
363 using namespace testing;364 using namespace testing;
364365
@@ -374,7 +375,7 @@
374 depository.deposit_package(package2, 9, size, pf);375 depository.deposit_package(package2, 9, size, pf);
375}376}
376377
377TEST_F(MirBufferDepositoryTest, depository_keeps_last_2_buffers_regardless_of_age)378TEST_F(ClientBufferDepository, keeps_last_2_buffers_regardless_of_age)
378{379{
379 using namespace testing;380 using namespace testing;
380381
@@ -389,7 +390,7 @@
389 depository.deposit_package(package, 8, size, pf);390 depository.deposit_package(package, 8, size, pf);
390}391}
391392
392TEST_F(MirBufferDepositoryTest, depository_keeps_last_3_buffers_regardless_of_age)393TEST_F(ClientBufferDepository, keeps_last_3_buffers_regardless_of_age)
393{394{
394 using namespace testing;395 using namespace testing;
395396
@@ -406,3 +407,54 @@
406 depository.deposit_package(package, 10, size, pf);407 depository.deposit_package(package, 10, size, pf);
407 depository.deposit_package(package, 8, size, pf);408 depository.deposit_package(package, 8, size, pf);
408}409}
410
411TEST_F(ClientBufferDepository, can_decrease_cache_size)
412{
413 using namespace testing;
414 int initial_size{3};
415 int changed_size{2};
416 mcl::ClientBufferDepository depository{mock_factory, initial_size};
417 EXPECT_CALL(*mock_factory, create_buffer(_,_,_))
418 .Times(4);
419
420 depository.deposit_package(package, 8, size, pf);
421 depository.deposit_package(package, 9, size, pf);
422 depository.deposit_package(package, 10, size, pf);
423 depository.deposit_package(package, 9, size, pf);
424 depository.deposit_package(package, 10, size, pf);
425
426 depository.set_max_buffers(changed_size); //8 should be kicked out
427 depository.deposit_package(package, 8, size, pf);
428}
429
430TEST_F(ClientBufferDepository, can_increase_cache_size)
431{
432 using namespace testing;
433 int initial_size{3};
434 int changed_size{4};
435 mcl::ClientBufferDepository depository{mock_factory, initial_size};
436 EXPECT_CALL(*mock_factory, create_buffer(_,_,_))
437 .Times(4);
438
439 depository.deposit_package(package, 8, size, pf);
440 depository.deposit_package(package, 9, size, pf);
441 depository.deposit_package(package, 10, size, pf);
442 depository.deposit_package(package, 9, size, pf);
443 depository.deposit_package(package, 10, size, pf);
444 depository.set_max_buffers(changed_size);
445 depository.deposit_package(package, 7, size, pf);
446 depository.deposit_package(package, 8, size, pf);
447}
448
449TEST_F(ClientBufferDepository, cannot_have_zero_size)
450{
451 int initial_size{3};
452 EXPECT_THROW({
453 mcl::ClientBufferDepository depository(mock_factory, 0);
454 }, std::logic_error);
455
456 mcl::ClientBufferDepository depository{mock_factory, initial_size};
457 EXPECT_THROW({
458 depository.set_max_buffers(0);
459 }, std::logic_error);
460}

Subscribers

People subscribed via source and target branches