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
1=== modified file 'src/client/buffer_stream.cpp'
2--- src/client/buffer_stream.cpp 2015-04-01 20:00:19 +0000
3+++ src/client/buffer_stream.cpp 2015-04-27 19:10:30 +0000
4@@ -398,3 +398,8 @@
5 std::unique_lock<decltype(mutex)> lock(mutex);
6 return protobuf_bs.has_id() && !protobuf_bs.has_error();
7 }
8+
9+void mcl::BufferStream::set_buffer_cache_size(unsigned int cache_size)
10+{
11+ buffer_depository.set_max_buffers(cache_size);
12+}
13
14=== modified file 'src/client/buffer_stream.h'
15--- src/client/buffer_stream.h 2015-04-01 20:00:19 +0000
16+++ src/client/buffer_stream.h 2015-04-27 19:10:30 +0000
17@@ -83,6 +83,7 @@
18
19 int swap_interval() const override;
20 void set_swap_interval(int interval) override;
21+ void set_buffer_cache_size(unsigned int) override;
22
23 EGLNativeWindowType egl_native_window() override;
24 std::shared_ptr<MemoryRegion> secure_for_cpu_write() override;
25
26=== modified file 'src/client/client_buffer_depository.cpp'
27--- src/client/client_buffer_depository.cpp 2015-01-21 07:34:50 +0000
28+++ src/client/client_buffer_depository.cpp 2015-04-27 19:10:30 +0000
29@@ -22,16 +22,18 @@
30 #include "mir/client_buffer.h"
31 #include "mir/client_buffer_factory.h"
32
33+#include <boost/throw_exception.hpp>
34 #include <stdexcept>
35 #include <memory>
36 #include <map>
37
38 namespace mcl=mir::client;
39
40-mcl::ClientBufferDepository::ClientBufferDepository(std::shared_ptr<ClientBufferFactory> const& factory, int max_buffers)
41- : factory(factory),
42- max_buffers(max_buffers)
43+mcl::ClientBufferDepository::ClientBufferDepository(
44+ std::shared_ptr<ClientBufferFactory> const& factory, int max_buffers) :
45+ factory(factory)
46 {
47+ set_max_buffers(max_buffers);
48 }
49
50 void mcl::ClientBufferDepository::deposit_package(std::shared_ptr<MirBufferPackage> const& package, int id, geometry::Size size, MirPixelFormat pf)
51@@ -72,3 +74,12 @@
52 {
53 return buffers.front().first;
54 }
55+
56+void mcl::ClientBufferDepository::set_max_buffers(unsigned int new_max_buffers)
57+{
58+ if (!new_max_buffers)
59+ BOOST_THROW_EXCEPTION(std::logic_error("ClientBufferDepository cache size cannot be 0"));
60+ max_buffers = new_max_buffers;
61+ while (buffers.size() > max_buffers)
62+ buffers.pop_back();
63+}
64
65=== modified file 'src/client/client_buffer_depository.h'
66--- src/client/client_buffer_depository.h 2014-03-06 06:05:17 +0000
67+++ src/client/client_buffer_depository.h 2015-04-27 19:10:30 +0000
68@@ -64,11 +64,11 @@
69 geometry::Size, MirPixelFormat);
70 std::shared_ptr<ClientBuffer> current_buffer();
71 uint32_t current_buffer_id() const;
72-
73+ void set_max_buffers(unsigned int max_buffers);
74 private:
75 std::shared_ptr<ClientBufferFactory> const factory;
76 std::list<std::pair<int, std::shared_ptr<ClientBuffer>>> buffers;
77- unsigned int const max_buffers;
78+ unsigned int max_buffers;
79 };
80 }
81 }
82
83=== modified file 'src/common/graphics/android/mir_native_window.cpp'
84--- src/common/graphics/android/mir_native_window.cpp 2015-04-24 15:52:14 +0000
85+++ src/common/graphics/android/mir_native_window.cpp 2015-04-27 19:10:30 +0000
86@@ -252,12 +252,13 @@
87 va_list args;
88 va_copy(args, arg_list);
89
90- int driver_format;
91 switch(key)
92 {
93 case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
94- driver_format = va_arg(args, int);
95- driver_interpreter->dispatch_driver_request_format(driver_format);
96+ driver_interpreter->dispatch_driver_request_format(va_arg(args, int));
97+ break;
98+ case NATIVE_WINDOW_SET_BUFFER_COUNT:
99+ driver_interpreter->dispatch_driver_request_buffer_count(va_arg(args, int));
100 break;
101 default:
102 break;
103
104=== modified file 'src/include/client/mir/egl_native_surface.h'
105--- src/include/client/mir/egl_native_surface.h 2015-03-31 02:35:42 +0000
106+++ src/include/client/mir/egl_native_surface.h 2015-04-27 19:10:30 +0000
107@@ -35,6 +35,7 @@
108 virtual std::shared_ptr<ClientBuffer> get_current_buffer() = 0;
109 virtual void request_and_wait_for_next_buffer() = 0;
110 virtual void request_and_wait_for_configure(MirSurfaceAttrib a, int value) = 0;
111+ virtual void set_buffer_cache_size(unsigned int) = 0;
112
113 protected:
114 EGLNativeSurface() = default;
115
116=== modified file 'src/include/common/mir/graphics/android/android_driver_interpreter.h'
117--- src/include/common/mir/graphics/android/android_driver_interpreter.h 2015-01-21 07:34:50 +0000
118+++ src/include/common/mir/graphics/android/android_driver_interpreter.h 2015-04-27 19:10:30 +0000
119@@ -35,6 +35,7 @@
120 virtual NativeBuffer* driver_requests_buffer() = 0;
121 virtual void driver_returns_buffer(ANativeWindowBuffer*, int fence) = 0;
122 virtual void dispatch_driver_request_format(int format) = 0;
123+ virtual void dispatch_driver_request_buffer_count(unsigned int count) = 0;
124 virtual int driver_requests_info(int key) const = 0;
125 virtual void sync_to_display(bool sync) = 0;
126 protected:
127
128=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.cpp'
129--- src/platforms/android/client/egl_native_surface_interpreter.cpp 2015-03-31 02:35:42 +0000
130+++ src/platforms/android/client/egl_native_surface_interpreter.cpp 2015-04-27 19:10:30 +0000
131@@ -18,6 +18,7 @@
132
133 #include "egl_native_surface_interpreter.h"
134 #include "mir/graphics/android/sync_fence.h"
135+#include "mir/frontend/client_constants.h"
136 #include "mir/client_buffer.h"
137 #include <system/window.h>
138 #include <stdexcept>
139@@ -84,3 +85,9 @@
140 {
141 surface.request_and_wait_for_configure(mir_surface_attrib_swapinterval, should_sync);
142 }
143+
144+void mcla::EGLNativeSurfaceInterpreter::dispatch_driver_request_buffer_count(unsigned int count)
145+{
146+ if (count > mir::frontend::client_buffer_cache_size)
147+ surface.set_buffer_cache_size(count);
148+}
149
150=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.h'
151--- src/platforms/android/client/egl_native_surface_interpreter.h 2015-03-31 02:35:42 +0000
152+++ src/platforms/android/client/egl_native_surface_interpreter.h 2015-04-27 19:10:30 +0000
153@@ -41,11 +41,12 @@
154 public:
155 explicit EGLNativeSurfaceInterpreter(EGLNativeSurface& surface);
156
157- graphics::NativeBuffer* driver_requests_buffer();
158- void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd );
159- void dispatch_driver_request_format(int format);
160- int driver_requests_info(int key) const;
161- void sync_to_display(bool);
162+ graphics::NativeBuffer* driver_requests_buffer() override;
163+ void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd) override;
164+ void dispatch_driver_request_format(int format) override;
165+ void dispatch_driver_request_buffer_count(unsigned int count) override;
166+ int driver_requests_info(int key) const override;
167+ void sync_to_display(bool) override;
168
169 private:
170 EGLNativeSurface& surface;
171
172=== modified file 'src/platforms/android/server/server_render_window.cpp'
173--- src/platforms/android/server/server_render_window.cpp 2015-03-31 02:35:42 +0000
174+++ src/platforms/android/server/server_render_window.cpp 2015-04-27 19:10:30 +0000
175@@ -96,3 +96,8 @@
176 void mga::ServerRenderWindow::sync_to_display(bool)
177 {
178 }
179+
180+void mga::ServerRenderWindow::dispatch_driver_request_buffer_count(unsigned int)
181+{
182+ //note: Haven't seen a good reason to honor this request for a fb context
183+}
184
185=== modified file 'src/platforms/android/server/server_render_window.h'
186--- src/platforms/android/server/server_render_window.h 2015-03-31 02:35:42 +0000
187+++ src/platforms/android/server/server_render_window.h 2015-04-27 19:10:30 +0000
188@@ -41,11 +41,12 @@
189 MirPixelFormat format,
190 std::shared_ptr<InterpreterResourceCache> const&);
191
192- graphics::NativeBuffer* driver_requests_buffer();
193- void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd);
194- void dispatch_driver_request_format(int format);
195- int driver_requests_info(int key) const;
196- void sync_to_display(bool sync);
197+ graphics::NativeBuffer* driver_requests_buffer() override;
198+ void driver_returns_buffer(ANativeWindowBuffer*, int fence_fd) override;
199+ void dispatch_driver_request_format(int format) override;
200+ void dispatch_driver_request_buffer_count(unsigned int count) override;
201+ int driver_requests_info(int key) const override;
202+ void sync_to_display(bool sync) override;
203
204 private:
205 std::shared_ptr<FramebufferBundle> const fb_bundle;
206
207=== modified file 'tests/include/mir_test_doubles/mock_egl_native_surface.h'
208--- tests/include/mir_test_doubles/mock_egl_native_surface.h 2015-03-31 02:35:42 +0000
209+++ tests/include/mir_test_doubles/mock_egl_native_surface.h 2015-04-27 19:10:30 +0000
210@@ -36,6 +36,7 @@
211 MOCK_METHOD0(get_current_buffer, std::shared_ptr<client::ClientBuffer>());
212 MOCK_METHOD0(request_and_wait_for_next_buffer, void());
213 MOCK_METHOD2(request_and_wait_for_configure, void(MirSurfaceAttrib,int));
214+ MOCK_METHOD1(set_buffer_cache_size, void(unsigned int));
215 };
216
217 }
218
219=== modified file 'tests/include/mir_test_doubles/stub_driver_interpreter.h'
220--- tests/include/mir_test_doubles/stub_driver_interpreter.h 2014-03-06 06:05:17 +0000
221+++ tests/include/mir_test_doubles/stub_driver_interpreter.h 2015-04-27 19:10:30 +0000
222@@ -42,17 +42,20 @@
223 {
224 }
225
226- mir::graphics::NativeBuffer* driver_requests_buffer()
227+ mir::graphics::NativeBuffer* driver_requests_buffer() override
228 {
229 return nullptr;
230 }
231+
232 void driver_returns_buffer(ANativeWindowBuffer*, int)
233 {
234 }
235- void dispatch_driver_request_format(int)
236+
237+ void dispatch_driver_request_format(int) override
238 {
239 }
240- int driver_requests_info(int index) const
241+
242+ int driver_requests_info(int index) const override
243 {
244 if (index == NATIVE_WINDOW_WIDTH)
245 return sz.width.as_uint32_t();
246@@ -62,9 +65,14 @@
247 return visual_id;
248 return 0;
249 }
250- void sync_to_display(bool)
251+
252+ void sync_to_display(bool) override
253 {
254 }
255+
256+ void dispatch_driver_request_buffer_count(unsigned int) override
257+ {
258+ }
259 private:
260 mir::geometry::Size sz;
261 int visual_id;
262
263=== modified file 'tests/unit-tests/client/android/test_android_native_window.cpp'
264--- tests/unit-tests/client/android/test_android_native_window.cpp 2015-03-31 02:35:42 +0000
265+++ tests/unit-tests/client/android/test_android_native_window.cpp 2015-04-27 19:10:30 +0000
266@@ -47,6 +47,7 @@
267 MOCK_METHOD1(dispatch_driver_request_format, void(int));
268 MOCK_CONST_METHOD1(driver_requests_info, int(int));
269 MOCK_METHOD1(sync_to_display, void(bool));
270+ MOCK_METHOD1(dispatch_driver_request_buffer_count, void(unsigned int));
271
272 std::shared_ptr<mir::graphics::NativeBuffer> buffer;
273 };
274@@ -113,6 +114,14 @@
275 window.perform(&window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
276 }
277
278+TEST_F(AndroidNativeWindowTest, native_window_perform_hook_calls_set_buffer)
279+{
280+ int const size = 4;
281+ EXPECT_CALL(*mock_driver_interpreter, dispatch_driver_request_buffer_count(size));
282+ ASSERT_NE(nullptr, window.perform);
283+ window.perform(&window, NATIVE_WINDOW_SET_BUFFER_COUNT, size);
284+}
285+
286 /* setSwapInterval hook tests */
287 TEST_F(AndroidNativeWindowTest, native_window_setswapinterval_hook_callable)
288 {
289
290=== modified file 'tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp'
291--- tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp 2015-03-31 02:35:42 +0000
292+++ tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp 2015-04-27 19:10:30 +0000
293@@ -20,6 +20,7 @@
294 #include "mir/graphics/android/native_buffer.h"
295 #include "mir/egl_native_surface.h"
296 #include "mir/client_buffer.h"
297+#include "mir/frontend/client_constants.h"
298 #include "src/platforms/android/client/egl_native_surface_interpreter.h"
299 #include "mir_test_doubles/stub_android_native_buffer.h"
300 #include "mir_test/fake_shared.h"
301@@ -79,6 +80,7 @@
302 MOCK_METHOD0(get_current_buffer, std::shared_ptr<mcl::ClientBuffer>());
303 MOCK_METHOD0(request_and_wait_for_next_buffer, void());
304 MOCK_METHOD2(request_and_wait_for_configure, void(MirSurfaceAttrib, int));
305+ MOCK_METHOD1(set_buffer_cache_size, void(unsigned int));
306 MirSurfaceParameters params;
307 };
308
309@@ -246,3 +248,22 @@
310 interpreter.sync_to_display(true);
311 interpreter.sync_to_display(false);
312 }
313+
314+TEST_F(AndroidInterpreter, request_to_set_buffer_count_sets_cache_size)
315+{
316+ int new_size = 5;
317+ testing::NiceMock<MockMirSurface> mock_surface{surf_params};
318+ EXPECT_CALL(mock_surface, set_buffer_cache_size(new_size));
319+ mcla::EGLNativeSurfaceInterpreter interpreter(mock_surface);
320+ interpreter.dispatch_driver_request_buffer_count(new_size);
321+}
322+
323+TEST_F(AndroidInterpreter, does_not_set_lower_than_mir_frontend_cache_size)
324+{
325+ int new_size = mir::frontend::client_buffer_cache_size - 1;
326+ testing::NiceMock<MockMirSurface> mock_surface{surf_params};
327+ EXPECT_CALL(mock_surface, set_buffer_cache_size(new_size))
328+ .Times(0);
329+ mcla::EGLNativeSurfaceInterpreter interpreter(mock_surface);
330+ interpreter.dispatch_driver_request_buffer_count(new_size);
331+}
332
333=== modified file 'tests/unit-tests/client/test_client_buffer_depository.cpp'
334--- tests/unit-tests/client/test_client_buffer_depository.cpp 2015-01-21 07:34:50 +0000
335+++ tests/unit-tests/client/test_client_buffer_depository.cpp 2015-04-27 19:10:30 +0000
336@@ -26,6 +26,7 @@
337
338 #include <gtest/gtest.h>
339 #include <gmock/gmock.h>
340+#include <stdexcept>
341
342 namespace geom=mir::geometry;
343 namespace mcl=mir::client;
344@@ -94,7 +95,7 @@
345 std::weak_ptr<mcl::ClientBuffer> first_allocated_buffer;
346 };
347
348-struct MirBufferDepositoryTest : public testing::Test
349+struct ClientBufferDepository : public testing::Test
350 {
351 void SetUp()
352 {
353@@ -120,7 +121,7 @@
354 return value == arg;
355 }
356
357-TEST_F(MirBufferDepositoryTest, depository_sets_width_and_height)
358+TEST_F(ClientBufferDepository, sets_width_and_height)
359 {
360 using namespace testing;
361
362@@ -131,7 +132,7 @@
363 depository.deposit_package(package, 8, size, pf);
364 }
365
366-TEST_F(MirBufferDepositoryTest, depository_new_deposit_changes_current_buffer)
367+TEST_F(ClientBufferDepository, changes_current_buffer_on_new_deposit)
368 {
369 using namespace testing;
370
371@@ -147,7 +148,7 @@
372 EXPECT_NE(buffer1, buffer2);
373 }
374
375-TEST_F(MirBufferDepositoryTest, depository_sets_buffer_age_to_zero_for_new_buffer)
376+TEST_F(ClientBufferDepository, sets_buffer_age_to_zero_for_new_buffer)
377 {
378 using namespace testing;
379
380@@ -159,7 +160,7 @@
381 EXPECT_EQ(0u, buffer1->age());
382 }
383
384-TEST_F(MirBufferDepositoryTest, just_sumbitted_buffer_has_age_1)
385+TEST_F(ClientBufferDepository, has_age_1_for_just_sumbitted_buffer)
386 {
387 using namespace testing;
388
389@@ -177,7 +178,7 @@
390 EXPECT_EQ(1u, buffer1->age());
391 }
392
393-TEST_F(MirBufferDepositoryTest, submitting_buffer_ages_other_buffers)
394+TEST_F(ClientBufferDepository, ages_other_buffers_on_new_submission)
395 {
396 using namespace testing;
397
398@@ -204,7 +205,7 @@
399 EXPECT_EQ(0u, buffer3->age());
400 }
401
402-TEST_F(MirBufferDepositoryTest, double_buffering_reaches_steady_state_age)
403+TEST_F(ClientBufferDepository, reaches_steady_state_age_for_double_buffering)
404 {
405 using namespace testing;
406
407@@ -233,7 +234,7 @@
408 EXPECT_EQ(2u, buffer2->age());
409 }
410
411-TEST_F(MirBufferDepositoryTest, triple_buffering_reaches_steady_state_age)
412+TEST_F(ClientBufferDepository, reaches_steady_state_age_when_triple_buffering)
413 {
414 using namespace testing;
415
416@@ -273,7 +274,7 @@
417 EXPECT_EQ(3u, buffer3->age());
418 }
419
420-TEST_F(MirBufferDepositoryTest, depository_destroys_old_buffers)
421+TEST_F(ClientBufferDepository, destroys_old_buffers)
422 {
423 using namespace testing;
424 const int num_buffers = 3;
425@@ -295,7 +296,7 @@
426 EXPECT_TRUE(mock_factory->first_buffer_allocated_and_then_freed());
427 }
428
429-TEST_F(MirBufferDepositoryTest, depositing_packages_implicitly_submits_current_buffer)
430+TEST_F(ClientBufferDepository, implicitly_submits_current_buffer_on_deposit)
431 {
432 using namespace testing;
433 const int num_buffers = 3;
434@@ -310,7 +311,7 @@
435 depository.deposit_package(package2, 2, size, pf);
436 }
437
438-TEST_F(MirBufferDepositoryTest, depository_frees_buffers_after_reaching_capacity)
439+TEST_F(ClientBufferDepository, frees_buffers_after_reaching_capacity)
440 {
441 using namespace testing;
442 std::shared_ptr<mcl::ClientBufferDepository> depository;
443@@ -334,7 +335,7 @@
444 }
445 }
446
447-TEST_F(MirBufferDepositoryTest, depository_caches_recently_seen_buffer)
448+TEST_F(ClientBufferDepository, caches_recently_seen_buffer)
449 {
450 using namespace testing;
451
452@@ -358,7 +359,7 @@
453 depository.deposit_package(package3, 8, size, pf);
454 }
455
456-TEST_F(MirBufferDepositoryTest, depository_creates_new_buffer_for_different_id)
457+TEST_F(ClientBufferDepository, creates_new_buffer_for_different_id)
458 {
459 using namespace testing;
460
461@@ -374,7 +375,7 @@
462 depository.deposit_package(package2, 9, size, pf);
463 }
464
465-TEST_F(MirBufferDepositoryTest, depository_keeps_last_2_buffers_regardless_of_age)
466+TEST_F(ClientBufferDepository, keeps_last_2_buffers_regardless_of_age)
467 {
468 using namespace testing;
469
470@@ -389,7 +390,7 @@
471 depository.deposit_package(package, 8, size, pf);
472 }
473
474-TEST_F(MirBufferDepositoryTest, depository_keeps_last_3_buffers_regardless_of_age)
475+TEST_F(ClientBufferDepository, keeps_last_3_buffers_regardless_of_age)
476 {
477 using namespace testing;
478
479@@ -406,3 +407,54 @@
480 depository.deposit_package(package, 10, size, pf);
481 depository.deposit_package(package, 8, size, pf);
482 }
483+
484+TEST_F(ClientBufferDepository, can_decrease_cache_size)
485+{
486+ using namespace testing;
487+ int initial_size{3};
488+ int changed_size{2};
489+ mcl::ClientBufferDepository depository{mock_factory, initial_size};
490+ EXPECT_CALL(*mock_factory, create_buffer(_,_,_))
491+ .Times(4);
492+
493+ depository.deposit_package(package, 8, size, pf);
494+ depository.deposit_package(package, 9, size, pf);
495+ depository.deposit_package(package, 10, size, pf);
496+ depository.deposit_package(package, 9, size, pf);
497+ depository.deposit_package(package, 10, size, pf);
498+
499+ depository.set_max_buffers(changed_size); //8 should be kicked out
500+ depository.deposit_package(package, 8, size, pf);
501+}
502+
503+TEST_F(ClientBufferDepository, can_increase_cache_size)
504+{
505+ using namespace testing;
506+ int initial_size{3};
507+ int changed_size{4};
508+ mcl::ClientBufferDepository depository{mock_factory, initial_size};
509+ EXPECT_CALL(*mock_factory, create_buffer(_,_,_))
510+ .Times(4);
511+
512+ depository.deposit_package(package, 8, size, pf);
513+ depository.deposit_package(package, 9, size, pf);
514+ depository.deposit_package(package, 10, size, pf);
515+ depository.deposit_package(package, 9, size, pf);
516+ depository.deposit_package(package, 10, size, pf);
517+ depository.set_max_buffers(changed_size);
518+ depository.deposit_package(package, 7, size, pf);
519+ depository.deposit_package(package, 8, size, pf);
520+}
521+
522+TEST_F(ClientBufferDepository, cannot_have_zero_size)
523+{
524+ int initial_size{3};
525+ EXPECT_THROW({
526+ mcl::ClientBufferDepository depository(mock_factory, 0);
527+ }, std::logic_error);
528+
529+ mcl::ClientBufferDepository depository{mock_factory, initial_size};
530+ EXPECT_THROW({
531+ depository.set_max_buffers(0);
532+ }, std::logic_error);
533+}

Subscribers

People subscribed via source and target branches