Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: gpu/command_buffer/client/mapped_memory_unittest.cc

Issue 23130004: Enforce a memory limit on MappedMemoryManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix another namespace error Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/client/mapped_memory.h" 5 #include "gpu/command_buffer/client/mapped_memory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_EQ(kBufferSize - kSize, chunk_->GetLargestFreeSizeWithWaiting()); 142 EXPECT_EQ(kBufferSize - kSize, chunk_->GetLargestFreeSizeWithWaiting());
143 chunk_->Free(pointer_char); 143 chunk_->Free(pointer_char);
144 EXPECT_EQ(kBufferSize, chunk_->GetLargestFreeSizeWithoutWaiting()); 144 EXPECT_EQ(kBufferSize, chunk_->GetLargestFreeSizeWithoutWaiting());
145 EXPECT_EQ(kBufferSize, chunk_->GetLargestFreeSizeWithWaiting()); 145 EXPECT_EQ(kBufferSize, chunk_->GetLargestFreeSizeWithWaiting());
146 } 146 }
147 147
148 class MappedMemoryManagerTest : public MappedMemoryTestBase { 148 class MappedMemoryManagerTest : public MappedMemoryTestBase {
149 protected: 149 protected:
150 virtual void SetUp() { 150 virtual void SetUp() {
151 MappedMemoryTestBase::SetUp(); 151 MappedMemoryTestBase::SetUp();
152 manager_.reset(new MappedMemoryManager(helper_.get())); 152 manager_.reset(new MappedMemoryManager(
153 helper_.get(), MappedMemoryManager::kNoLimit));
153 } 154 }
154 155
155 virtual void TearDown() { 156 virtual void TearDown() {
156 // If the GpuScheduler posts any tasks, this forces them to run. 157 // If the GpuScheduler posts any tasks, this forces them to run.
157 base::MessageLoop::current()->RunUntilIdle(); 158 base::MessageLoop::current()->RunUntilIdle();
158 manager_.reset(); 159 manager_.reset();
159 MappedMemoryTestBase::TearDown(); 160 MappedMemoryTestBase::TearDown();
160 } 161 }
161 162
162 scoped_ptr<MappedMemoryManager> manager_; 163 scoped_ptr<MappedMemoryManager> manager_;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 ASSERT_TRUE(mem2); 300 ASSERT_TRUE(mem2);
300 ASSERT_TRUE(mem3); 301 ASSERT_TRUE(mem3);
301 EXPECT_NE(-1, id1); 302 EXPECT_NE(-1, id1);
302 EXPECT_EQ(id1, id2); 303 EXPECT_EQ(id1, id2);
303 EXPECT_NE(id2, id3); 304 EXPECT_NE(id2, id3);
304 EXPECT_EQ(0u, offset1); 305 EXPECT_EQ(0u, offset1);
305 EXPECT_EQ(kSize, offset2); 306 EXPECT_EQ(kSize, offset2);
306 EXPECT_EQ(0u, offset3); 307 EXPECT_EQ(0u, offset3);
307 } 308 }
308 309
310 TEST_F(MappedMemoryManagerTest, UnusedMemoryLimit) {
311 const unsigned int kChunkSize = 2048;
312 // Reset the manager with a memory limit.
313 manager_.reset(new MappedMemoryManager(helper_.get(), kChunkSize));
314 manager_->set_chunk_size_multiple(kChunkSize);
315
316 // Allocate one chunk worth of memory.
317 int32 id1 = -1;
318 unsigned int offset1 = 0xFFFFFFFFU;
319 void* mem1 = manager_->Alloc(kChunkSize, &id1, &offset1);
320 ASSERT_TRUE(mem1);
321 EXPECT_NE(-1, id1);
322 EXPECT_EQ(0u, offset1);
323
324 // Allocate half a chunk worth of memory again.
325 // The same chunk will be used.
326 int32 id2 = -1;
327 unsigned int offset2 = 0xFFFFFFFFU;
328 void* mem2 = manager_->Alloc(kChunkSize, &id2, &offset2);
329 ASSERT_TRUE(mem2);
330 EXPECT_NE(-1, id2);
331 EXPECT_EQ(0u, offset2);
332
333 // Expect two chunks to be allocated, exceeding the limit,
334 // since all memory is in use.
335 EXPECT_EQ(2 * kChunkSize, manager_->allocated_memory());
336 }
337
338 TEST_F(MappedMemoryManagerTest, MemoryLimitWithReuse) {
339 const unsigned int kSize = 1024;
340 // Reset the manager with a memory limit.
341 manager_.reset(new MappedMemoryManager(helper_.get(), kSize));
342 const unsigned int kChunkSize = 2 * 1024;
343 manager_->set_chunk_size_multiple(kChunkSize);
344
345 // Allocate half a chunk worth of memory.
346 int32 id1 = -1;
347 unsigned int offset1 = 0xFFFFFFFFU;
348 void* mem1 = manager_->Alloc(kSize, &id1, &offset1);
349 ASSERT_TRUE(mem1);
350 EXPECT_NE(-1, id1);
351 EXPECT_EQ(0u, offset1);
352
353 // Allocate half a chunk worth of memory again.
354 // The same chunk will be used.
355 int32 id2 = -1;
356 unsigned int offset2 = 0xFFFFFFFFU;
357 void* mem2 = manager_->Alloc(kSize, &id2, &offset2);
358 ASSERT_TRUE(mem2);
359 EXPECT_NE(-1, id2);
360 EXPECT_EQ(kSize, offset2);
361
362 // Free one successful allocation, pending fence.
363 int32 token = helper_.get()->InsertToken();
364 manager_->FreePendingToken(mem2, token);
365
366 // The way we hooked up the helper and engine, it won't process commands
367 // until it has to wait for something. Which means the token shouldn't have
368 // passed yet at this point.
369 EXPECT_GT(token, GetToken());
370
371 // Since we didn't call helper_.finish() the token did not pass.
372 // We won't be able to claim the free memory without waiting and
373 // as we've already met the memory limit we'll have to wait
374 // on the token.
375 int32 id3 = -1;
376 unsigned int offset3 = 0xFFFFFFFFU;
377 void* mem3 = manager_->Alloc(kSize, &id3, &offset3);
378 ASSERT_TRUE(mem3);
379 EXPECT_NE(-1, id3);
380 // It will reuse the space from the second allocation just freed.
381 EXPECT_EQ(kSize, offset3);
382
383 // Expect one chunk to be allocated
384 EXPECT_EQ(1 * kChunkSize, manager_->allocated_memory());
385 }
386
309 } // namespace gpu 387 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/mapped_memory.cc ('k') | gpu/command_buffer/client/query_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698