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

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

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unset texture and texture_ref after deleting Created 6 years, 9 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 // This file contains the tests for the FencedAllocator class. 5 // This file contains the tests for the FencedAllocator class.
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/aligned_memory.h" 9 #include "base/memory/aligned_memory.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 11 matching lines...) Expand all
22 #endif 22 #endif
23 23
24 namespace gpu { 24 namespace gpu {
25 25
26 using testing::Return; 26 using testing::Return;
27 using testing::Mock; 27 using testing::Mock;
28 using testing::Truly; 28 using testing::Truly;
29 using testing::Sequence; 29 using testing::Sequence;
30 using testing::DoAll; 30 using testing::DoAll;
31 using testing::Invoke; 31 using testing::Invoke;
32 using testing::InvokeWithoutArgs;
32 using testing::_; 33 using testing::_;
33 34
34 class BaseFencedAllocatorTest : public testing::Test { 35 class BaseFencedAllocatorTest : public testing::Test {
35 protected: 36 protected:
36 static const unsigned int kBufferSize = 1024; 37 static const unsigned int kBufferSize = 1024;
37 static const int kAllocAlignment = 16; 38 static const int kAllocAlignment = 16;
38 39
39 virtual void SetUp() { 40 virtual void SetUp() {
40 api_mock_.reset(new AsyncAPIMock); 41 api_mock_.reset(new AsyncAPIMock);
41 // ignore noops in the mock - we don't want to inspect the internals of the 42 // ignore noops in the mock - we don't want to inspect the internals of the
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 82 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
82 scoped_ptr<CommandBufferService> command_buffer_; 83 scoped_ptr<CommandBufferService> command_buffer_;
83 scoped_ptr<GpuScheduler> gpu_scheduler_; 84 scoped_ptr<GpuScheduler> gpu_scheduler_;
84 scoped_ptr<CommandBufferHelper> helper_; 85 scoped_ptr<CommandBufferHelper> helper_;
85 }; 86 };
86 87
87 #ifndef _MSC_VER 88 #ifndef _MSC_VER
88 const unsigned int BaseFencedAllocatorTest::kBufferSize; 89 const unsigned int BaseFencedAllocatorTest::kBufferSize;
89 #endif 90 #endif
90 91
92 namespace {
93 void EmptyPoll() {
94 }
95 }
96
91 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a 97 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a
92 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling 98 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling
93 // it directly, not through the RPC mechanism), making sure Noops are ignored 99 // it directly, not through the RPC mechanism), making sure Noops are ignored
94 // and SetToken are properly forwarded to the engine. 100 // and SetToken are properly forwarded to the engine.
95 class FencedAllocatorTest : public BaseFencedAllocatorTest { 101 class FencedAllocatorTest : public BaseFencedAllocatorTest {
96 protected: 102 protected:
97 virtual void SetUp() { 103 virtual void SetUp() {
98 BaseFencedAllocatorTest::SetUp(); 104 BaseFencedAllocatorTest::SetUp();
99 allocator_.reset(new FencedAllocator(kBufferSize, helper_.get())); 105 allocator_.reset(new FencedAllocator(kBufferSize,
106 helper_.get(),
107 base::Bind(&EmptyPoll)));
100 } 108 }
101 109
102 virtual void TearDown() { 110 virtual void TearDown() {
103 // If the GpuScheduler posts any tasks, this forces them to run. 111 // If the GpuScheduler posts any tasks, this forces them to run.
104 base::MessageLoop::current()->RunUntilIdle(); 112 base::MessageLoop::current()->RunUntilIdle();
105 113
106 EXPECT_TRUE(allocator_->CheckConsistency()); 114 EXPECT_TRUE(allocator_->CheckConsistency());
107 115
108 BaseFencedAllocatorTest::TearDown(); 116 BaseFencedAllocatorTest::TearDown();
109 } 117 }
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // Check that the token has indeed passed. 392 // Check that the token has indeed passed.
385 EXPECT_LE(token, GetToken()); 393 EXPECT_LE(token, GetToken());
386 allocator_->Free(offset); 394 allocator_->Free(offset);
387 395
388 // Everything now has been freed... 396 // Everything now has been freed...
389 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); 397 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize());
390 // ... for real. 398 // ... for real.
391 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); 399 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize());
392 } 400 }
393 401
402 class FencedAllocatorPollTest : public BaseFencedAllocatorTest {
403 public:
404 static const unsigned int kAllocSize = 128;
405
406 MOCK_METHOD0(MockedPoll, void());
407
408 protected:
409 virtual void TearDown() {
410 // If the GpuScheduler posts any tasks, this forces them to run.
411 base::MessageLoop::current()->RunUntilIdle();
412
413 BaseFencedAllocatorTest::TearDown();
414 }
415 };
416
417 TEST_F(FencedAllocatorPollTest, TestPoll) {
418 scoped_ptr<FencedAllocator> allocator(
419 new FencedAllocator(kBufferSize,
420 helper_.get(),
421 base::Bind(&FencedAllocatorPollTest::MockedPoll,
422 base::Unretained(this))));
423
424 FencedAllocator::Offset mem1 = allocator->Alloc(kAllocSize);
425 FencedAllocator::Offset mem2 = allocator->Alloc(kAllocSize);
426 EXPECT_NE(mem1, FencedAllocator::kInvalidOffset);
427 EXPECT_NE(mem2, FencedAllocator::kInvalidOffset);
428 EXPECT_TRUE(allocator->CheckConsistency());
429 EXPECT_EQ(allocator->bytes_in_use(), kAllocSize * 2);
430
431 // Check that no-op Poll doesn't affect the state.
432 EXPECT_CALL(*this, MockedPoll()).RetiresOnSaturation();
433 allocator->FreeUnused();
434 EXPECT_TRUE(allocator->CheckConsistency());
435 EXPECT_EQ(allocator->bytes_in_use(), kAllocSize * 2);
436
437 // Check that freeing in Poll works.
438 base::Closure free_mem1_closure =
439 base::Bind(&FencedAllocator::Free,
440 base::Unretained(allocator.get()),
441 mem1);
442 EXPECT_CALL(*this, MockedPoll())
443 .WillOnce(InvokeWithoutArgs(&free_mem1_closure, &base::Closure::Run))
444 .RetiresOnSaturation();
445 allocator->FreeUnused();
446 EXPECT_TRUE(allocator->CheckConsistency());
447 EXPECT_EQ(allocator->bytes_in_use(), kAllocSize * 1);
448
449 // Check that freeing still works.
450 EXPECT_CALL(*this, MockedPoll()).RetiresOnSaturation();
451 allocator->Free(mem2);
452 allocator->FreeUnused();
453 EXPECT_TRUE(allocator->CheckConsistency());
454 EXPECT_EQ(allocator->bytes_in_use(), 0u);
455
456 allocator.reset();
457 }
458
394 // Test fixture for FencedAllocatorWrapper test - Creates a 459 // Test fixture for FencedAllocatorWrapper test - Creates a
395 // FencedAllocatorWrapper, using a CommandBufferHelper with a mock 460 // FencedAllocatorWrapper, using a CommandBufferHelper with a mock
396 // AsyncAPIInterface for its interface (calling it directly, not through the 461 // AsyncAPIInterface for its interface (calling it directly, not through the
397 // RPC mechanism), making sure Noops are ignored and SetToken are properly 462 // RPC mechanism), making sure Noops are ignored and SetToken are properly
398 // forwarded to the engine. 463 // forwarded to the engine.
399 class FencedAllocatorWrapperTest : public BaseFencedAllocatorTest { 464 class FencedAllocatorWrapperTest : public BaseFencedAllocatorTest {
400 protected: 465 protected:
401 virtual void SetUp() { 466 virtual void SetUp() {
402 BaseFencedAllocatorTest::SetUp(); 467 BaseFencedAllocatorTest::SetUp();
403 468
404 // Though allocating this buffer isn't strictly necessary, it makes 469 // Though allocating this buffer isn't strictly necessary, it makes
405 // allocations point to valid addresses, so they could be used for 470 // allocations point to valid addresses, so they could be used for
406 // something. 471 // something.
407 buffer_.reset(static_cast<char*>(base::AlignedAlloc( 472 buffer_.reset(static_cast<char*>(base::AlignedAlloc(
408 kBufferSize, kAllocAlignment))); 473 kBufferSize, kAllocAlignment)));
409 allocator_.reset(new FencedAllocatorWrapper(kBufferSize, helper_.get(), 474 allocator_.reset(new FencedAllocatorWrapper(kBufferSize,
475 helper_.get(),
476 base::Bind(&EmptyPoll),
410 buffer_.get())); 477 buffer_.get()));
411 } 478 }
412 479
413 virtual void TearDown() { 480 virtual void TearDown() {
414 // If the GpuScheduler posts any tasks, this forces them to run. 481 // If the GpuScheduler posts any tasks, this forces them to run.
415 base::MessageLoop::current()->RunUntilIdle(); 482 base::MessageLoop::current()->RunUntilIdle();
416 483
417 EXPECT_TRUE(allocator_->CheckConsistency()); 484 EXPECT_TRUE(allocator_->CheckConsistency());
418 485
419 BaseFencedAllocatorTest::TearDown(); 486 BaseFencedAllocatorTest::TearDown();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 EXPECT_LE(token, GetToken()); 636 EXPECT_LE(token, GetToken());
570 637
571 // Free up everything. 638 // Free up everything.
572 for (unsigned int i = 0; i < kAllocCount; ++i) { 639 for (unsigned int i = 0; i < kAllocCount; ++i) {
573 allocator_->Free(pointers[i]); 640 allocator_->Free(pointers[i]);
574 EXPECT_TRUE(allocator_->CheckConsistency()); 641 EXPECT_TRUE(allocator_->CheckConsistency());
575 } 642 }
576 } 643 }
577 644
578 } // namespace gpu 645 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/fenced_allocator.cc ('k') | gpu/command_buffer/client/gles2_c_lib_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698