OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 using testing::DoAll; | 30 using testing::DoAll; |
31 using testing::Invoke; | 31 using testing::Invoke; |
32 using testing::InvokeWithoutArgs; | 32 using testing::InvokeWithoutArgs; |
33 using testing::_; | 33 using testing::_; |
34 | 34 |
35 class BaseFencedAllocatorTest : public testing::Test { | 35 class BaseFencedAllocatorTest : public testing::Test { |
36 protected: | 36 protected: |
37 static const unsigned int kBufferSize = 1024; | 37 static const unsigned int kBufferSize = 1024; |
38 static const int kAllocAlignment = 16; | 38 static const int kAllocAlignment = 16; |
39 | 39 |
40 virtual void SetUp() { | 40 void SetUp() override { |
41 api_mock_.reset(new AsyncAPIMock(true)); | 41 api_mock_.reset(new AsyncAPIMock(true)); |
42 // 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 |
43 // helper. | 43 // helper. |
44 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) | 44 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) |
45 .WillRepeatedly(Return(error::kNoError)); | 45 .WillRepeatedly(Return(error::kNoError)); |
46 // Forward the SetToken calls to the engine | 46 // Forward the SetToken calls to the engine |
47 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) | 47 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) |
48 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), | 48 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), |
49 Return(error::kNoError))); | 49 Return(error::kNoError))); |
50 | 50 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void EmptyPoll() { | 93 void EmptyPoll() { |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a | 97 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a |
98 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 98 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
99 // 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 |
100 // and SetToken are properly forwarded to the engine. | 100 // and SetToken are properly forwarded to the engine. |
101 class FencedAllocatorTest : public BaseFencedAllocatorTest { | 101 class FencedAllocatorTest : public BaseFencedAllocatorTest { |
102 protected: | 102 protected: |
103 virtual void SetUp() { | 103 void SetUp() override { |
104 BaseFencedAllocatorTest::SetUp(); | 104 BaseFencedAllocatorTest::SetUp(); |
105 allocator_.reset(new FencedAllocator(kBufferSize, | 105 allocator_.reset(new FencedAllocator(kBufferSize, |
106 helper_.get(), | 106 helper_.get(), |
107 base::Bind(&EmptyPoll))); | 107 base::Bind(&EmptyPoll))); |
108 } | 108 } |
109 | 109 |
110 virtual void TearDown() { | 110 void TearDown() override { |
111 // If the GpuScheduler posts any tasks, this forces them to run. | 111 // If the GpuScheduler posts any tasks, this forces them to run. |
112 base::MessageLoop::current()->RunUntilIdle(); | 112 base::MessageLoop::current()->RunUntilIdle(); |
113 | 113 |
114 EXPECT_TRUE(allocator_->CheckConsistency()); | 114 EXPECT_TRUE(allocator_->CheckConsistency()); |
115 | 115 |
116 BaseFencedAllocatorTest::TearDown(); | 116 BaseFencedAllocatorTest::TearDown(); |
117 } | 117 } |
118 | 118 |
119 scoped_ptr<FencedAllocator> allocator_; | 119 scoped_ptr<FencedAllocator> allocator_; |
120 }; | 120 }; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 allocator.reset(); | 456 allocator.reset(); |
457 } | 457 } |
458 | 458 |
459 // Test fixture for FencedAllocatorWrapper test - Creates a | 459 // Test fixture for FencedAllocatorWrapper test - Creates a |
460 // FencedAllocatorWrapper, using a CommandBufferHelper with a mock | 460 // FencedAllocatorWrapper, using a CommandBufferHelper with a mock |
461 // AsyncAPIInterface for its interface (calling it directly, not through the | 461 // AsyncAPIInterface for its interface (calling it directly, not through the |
462 // RPC mechanism), making sure Noops are ignored and SetToken are properly | 462 // RPC mechanism), making sure Noops are ignored and SetToken are properly |
463 // forwarded to the engine. | 463 // forwarded to the engine. |
464 class FencedAllocatorWrapperTest : public BaseFencedAllocatorTest { | 464 class FencedAllocatorWrapperTest : public BaseFencedAllocatorTest { |
465 protected: | 465 protected: |
466 virtual void SetUp() { | 466 void SetUp() override { |
467 BaseFencedAllocatorTest::SetUp(); | 467 BaseFencedAllocatorTest::SetUp(); |
468 | 468 |
469 // Though allocating this buffer isn't strictly necessary, it makes | 469 // Though allocating this buffer isn't strictly necessary, it makes |
470 // allocations point to valid addresses, so they could be used for | 470 // allocations point to valid addresses, so they could be used for |
471 // something. | 471 // something. |
472 buffer_.reset(static_cast<char*>(base::AlignedAlloc( | 472 buffer_.reset(static_cast<char*>(base::AlignedAlloc( |
473 kBufferSize, kAllocAlignment))); | 473 kBufferSize, kAllocAlignment))); |
474 allocator_.reset(new FencedAllocatorWrapper(kBufferSize, | 474 allocator_.reset(new FencedAllocatorWrapper(kBufferSize, |
475 helper_.get(), | 475 helper_.get(), |
476 base::Bind(&EmptyPoll), | 476 base::Bind(&EmptyPoll), |
477 buffer_.get())); | 477 buffer_.get())); |
478 } | 478 } |
479 | 479 |
480 virtual void TearDown() { | 480 void TearDown() override { |
481 // If the GpuScheduler posts any tasks, this forces them to run. | 481 // If the GpuScheduler posts any tasks, this forces them to run. |
482 base::MessageLoop::current()->RunUntilIdle(); | 482 base::MessageLoop::current()->RunUntilIdle(); |
483 | 483 |
484 EXPECT_TRUE(allocator_->CheckConsistency()); | 484 EXPECT_TRUE(allocator_->CheckConsistency()); |
485 | 485 |
486 BaseFencedAllocatorTest::TearDown(); | 486 BaseFencedAllocatorTest::TearDown(); |
487 } | 487 } |
488 | 488 |
489 scoped_ptr<FencedAllocatorWrapper> allocator_; | 489 scoped_ptr<FencedAllocatorWrapper> allocator_; |
490 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; | 490 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 EXPECT_LE(token, GetToken()); | 636 EXPECT_LE(token, GetToken()); |
637 | 637 |
638 // Free up everything. | 638 // Free up everything. |
639 for (unsigned int i = 0; i < kAllocCount; ++i) { | 639 for (unsigned int i = 0; i < kAllocCount; ++i) { |
640 allocator_->Free(pointers[i]); | 640 allocator_->Free(pointers[i]); |
641 EXPECT_TRUE(allocator_->CheckConsistency()); | 641 EXPECT_TRUE(allocator_->CheckConsistency()); |
642 } | 642 } |
643 } | 643 } |
644 | 644 |
645 } // namespace gpu | 645 } // namespace gpu |
OLD | NEW |