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 RingBuffer class. | 5 // This file contains the tests for the RingBuffer class. |
6 | 6 |
7 #include "gpu/command_buffer/client/ring_buffer.h" | 7 #include "gpu/command_buffer/client/ring_buffer.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 helper_->Initialize(kBufferSize); | 68 helper_->Initialize(kBufferSize); |
69 } | 69 } |
70 | 70 |
71 int32 GetToken() { | 71 int32 GetToken() { |
72 return command_buffer_->GetState().token; | 72 return command_buffer_->GetState().token; |
73 } | 73 } |
74 | 74 |
75 #if defined(OS_MACOSX) | 75 #if defined(OS_MACOSX) |
76 base::mac::ScopedNSAutoreleasePool autorelease_pool_; | 76 base::mac::ScopedNSAutoreleasePool autorelease_pool_; |
77 #endif | 77 #endif |
78 MessageLoop message_loop_; | 78 base::MessageLoop message_loop_; |
79 scoped_ptr<AsyncAPIMock> api_mock_; | 79 scoped_ptr<AsyncAPIMock> api_mock_; |
80 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 80 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
81 scoped_ptr<CommandBufferService> command_buffer_; | 81 scoped_ptr<CommandBufferService> command_buffer_; |
82 scoped_ptr<GpuScheduler> gpu_scheduler_; | 82 scoped_ptr<GpuScheduler> gpu_scheduler_; |
83 scoped_ptr<CommandBufferHelper> helper_; | 83 scoped_ptr<CommandBufferHelper> helper_; |
84 }; | 84 }; |
85 | 85 |
86 #ifndef _MSC_VER | 86 #ifndef _MSC_VER |
87 const unsigned int BaseRingBufferTest::kBaseOffset; | 87 const unsigned int BaseRingBufferTest::kBaseOffset; |
88 const unsigned int BaseRingBufferTest::kBufferSize; | 88 const unsigned int BaseRingBufferTest::kBufferSize; |
89 #endif | 89 #endif |
90 | 90 |
91 // Test fixture for RingBuffer test - Creates a RingBuffer, using a | 91 // Test fixture for RingBuffer test - Creates a RingBuffer, 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 RingBufferTest : public BaseRingBufferTest { | 95 class RingBufferTest : public BaseRingBufferTest { |
96 protected: | 96 protected: |
97 virtual void SetUp() { | 97 virtual void SetUp() { |
98 BaseRingBufferTest::SetUp(); | 98 BaseRingBufferTest::SetUp(); |
99 allocator_.reset(new RingBuffer(kBaseOffset, kBufferSize, helper_.get())); | 99 allocator_.reset(new RingBuffer(kBaseOffset, 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 BaseRingBufferTest::TearDown(); | 106 BaseRingBufferTest::TearDown(); |
107 } | 107 } |
108 | 108 |
109 scoped_ptr<RingBuffer> allocator_; | 109 scoped_ptr<RingBuffer> allocator_; |
110 }; | 110 }; |
111 | 111 |
112 // Checks basic alloc and free. | 112 // Checks basic alloc and free. |
113 TEST_F(RingBufferTest, TestBasic) { | 113 TEST_F(RingBufferTest, TestBasic) { |
114 const unsigned int kSize = 16; | 114 const unsigned int kSize = 16; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // allocations point to valid addresses, so they could be used for | 190 // allocations point to valid addresses, so they could be used for |
191 // something. | 191 // something. |
192 buffer_.reset(new int8[kBufferSize + kBaseOffset]); | 192 buffer_.reset(new int8[kBufferSize + kBaseOffset]); |
193 buffer_start_ = buffer_.get() + kBaseOffset; | 193 buffer_start_ = buffer_.get() + kBaseOffset; |
194 allocator_.reset(new RingBufferWrapper( | 194 allocator_.reset(new RingBufferWrapper( |
195 kBaseOffset, kBufferSize, helper_.get(), buffer_start_)); | 195 kBaseOffset, kBufferSize, helper_.get(), buffer_start_)); |
196 } | 196 } |
197 | 197 |
198 virtual void TearDown() { | 198 virtual void TearDown() { |
199 // If the GpuScheduler posts any tasks, this forces them to run. | 199 // If the GpuScheduler posts any tasks, this forces them to run. |
200 MessageLoop::current()->RunUntilIdle(); | 200 base::MessageLoop::current()->RunUntilIdle(); |
201 | 201 |
202 BaseRingBufferTest::TearDown(); | 202 BaseRingBufferTest::TearDown(); |
203 } | 203 } |
204 | 204 |
205 scoped_ptr<RingBufferWrapper> allocator_; | 205 scoped_ptr<RingBufferWrapper> allocator_; |
206 scoped_ptr<int8[]> buffer_; | 206 scoped_ptr<int8[]> buffer_; |
207 int8* buffer_start_; | 207 int8* buffer_start_; |
208 }; | 208 }; |
209 | 209 |
210 // Checks basic alloc and free. | 210 // Checks basic alloc and free. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); | 260 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); |
261 | 261 |
262 // Check that the token has indeed passed. | 262 // Check that the token has indeed passed. |
263 EXPECT_LE(tokens[0], GetToken()); | 263 EXPECT_LE(tokens[0], GetToken()); |
264 | 264 |
265 allocator_->FreePendingToken(pointer1, helper_->InsertToken()); | 265 allocator_->FreePendingToken(pointer1, helper_->InsertToken()); |
266 EXPECT_LE(command_buffer_->GetState().token, helper_->InsertToken()); | 266 EXPECT_LE(command_buffer_->GetState().token, helper_->InsertToken()); |
267 } | 267 } |
268 | 268 |
269 } // namespace gpu | 269 } // namespace gpu |
OLD | NEW |