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.h" | 10 #include "base/message_loop.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 helper_->Initialize(kBufferSize); | 69 helper_->Initialize(kBufferSize); |
70 } | 70 } |
71 | 71 |
72 int32 GetToken() { | 72 int32 GetToken() { |
73 return command_buffer_->GetState().token; | 73 return command_buffer_->GetState().token; |
74 } | 74 } |
75 | 75 |
76 #if defined(OS_MACOSX) | 76 #if defined(OS_MACOSX) |
77 base::mac::ScopedNSAutoreleasePool autorelease_pool_; | 77 base::mac::ScopedNSAutoreleasePool autorelease_pool_; |
78 #endif | 78 #endif |
79 MessageLoop message_loop_; | 79 base::MessageLoop message_loop_; |
80 scoped_ptr<AsyncAPIMock> api_mock_; | 80 scoped_ptr<AsyncAPIMock> api_mock_; |
81 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 81 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
82 scoped_ptr<CommandBufferService> command_buffer_; | 82 scoped_ptr<CommandBufferService> command_buffer_; |
83 scoped_ptr<GpuScheduler> gpu_scheduler_; | 83 scoped_ptr<GpuScheduler> gpu_scheduler_; |
84 scoped_ptr<CommandBufferHelper> helper_; | 84 scoped_ptr<CommandBufferHelper> helper_; |
85 }; | 85 }; |
86 | 86 |
87 #ifndef _MSC_VER | 87 #ifndef _MSC_VER |
88 const unsigned int BaseFencedAllocatorTest::kBufferSize; | 88 const unsigned int BaseFencedAllocatorTest::kBufferSize; |
89 #endif | 89 #endif |
90 | 90 |
91 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a | 91 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a |
92 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 92 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
93 // it directly, not through the RPC mechanism), making sure Noops are ignored | 93 // it directly, not through the RPC mechanism), making sure Noops are ignored |
94 // and SetToken are properly forwarded to the engine. | 94 // and SetToken are properly forwarded to the engine. |
95 class FencedAllocatorTest : public BaseFencedAllocatorTest { | 95 class FencedAllocatorTest : public BaseFencedAllocatorTest { |
96 protected: | 96 protected: |
97 virtual void SetUp() { | 97 virtual void SetUp() { |
98 BaseFencedAllocatorTest::SetUp(); | 98 BaseFencedAllocatorTest::SetUp(); |
99 allocator_.reset(new FencedAllocator(kBufferSize, helper_.get())); | 99 allocator_.reset(new FencedAllocator(kBufferSize, helper_.get())); |
100 } | 100 } |
101 | 101 |
102 virtual void TearDown() { | 102 virtual void TearDown() { |
103 // If the GpuScheduler posts any tasks, this forces them to run. | 103 // If the GpuScheduler posts any tasks, this forces them to run. |
104 MessageLoop::current()->RunUntilIdle(); | 104 base::MessageLoop::current()->RunUntilIdle(); |
105 | 105 |
106 EXPECT_TRUE(allocator_->CheckConsistency()); | 106 EXPECT_TRUE(allocator_->CheckConsistency()); |
107 | 107 |
108 BaseFencedAllocatorTest::TearDown(); | 108 BaseFencedAllocatorTest::TearDown(); |
109 } | 109 } |
110 | 110 |
111 scoped_ptr<FencedAllocator> allocator_; | 111 scoped_ptr<FencedAllocator> allocator_; |
112 }; | 112 }; |
113 | 113 |
114 // Checks basic alloc and free. | 114 // Checks basic alloc and free. |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // allocations point to valid addresses, so they could be used for | 405 // allocations point to valid addresses, so they could be used for |
406 // something. | 406 // something. |
407 buffer_.reset(static_cast<char*>(base::AlignedAlloc( | 407 buffer_.reset(static_cast<char*>(base::AlignedAlloc( |
408 kBufferSize, kAllocAlignment))); | 408 kBufferSize, kAllocAlignment))); |
409 allocator_.reset(new FencedAllocatorWrapper(kBufferSize, helper_.get(), | 409 allocator_.reset(new FencedAllocatorWrapper(kBufferSize, helper_.get(), |
410 buffer_.get())); | 410 buffer_.get())); |
411 } | 411 } |
412 | 412 |
413 virtual void TearDown() { | 413 virtual void TearDown() { |
414 // If the GpuScheduler posts any tasks, this forces them to run. | 414 // If the GpuScheduler posts any tasks, this forces them to run. |
415 MessageLoop::current()->RunUntilIdle(); | 415 base::MessageLoop::current()->RunUntilIdle(); |
416 | 416 |
417 EXPECT_TRUE(allocator_->CheckConsistency()); | 417 EXPECT_TRUE(allocator_->CheckConsistency()); |
418 | 418 |
419 BaseFencedAllocatorTest::TearDown(); | 419 BaseFencedAllocatorTest::TearDown(); |
420 } | 420 } |
421 | 421 |
422 scoped_ptr<FencedAllocatorWrapper> allocator_; | 422 scoped_ptr<FencedAllocatorWrapper> allocator_; |
423 scoped_ptr_malloc<char, base::ScopedPtrAlignedFree> buffer_; | 423 scoped_ptr_malloc<char, base::ScopedPtrAlignedFree> buffer_; |
424 }; | 424 }; |
425 | 425 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 EXPECT_LE(token, GetToken()); | 569 EXPECT_LE(token, GetToken()); |
570 | 570 |
571 // Free up everything. | 571 // Free up everything. |
572 for (unsigned int i = 0; i < kAllocCount; ++i) { | 572 for (unsigned int i = 0; i < kAllocCount; ++i) { |
573 allocator_->Free(pointers[i]); | 573 allocator_->Free(pointers[i]); |
574 EXPECT_TRUE(allocator_->CheckConsistency()); | 574 EXPECT_TRUE(allocator_->CheckConsistency()); |
575 } | 575 } |
576 } | 576 } |
577 | 577 |
578 } // namespace gpu | 578 } // namespace gpu |
OLD | NEW |