OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 9 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
10 #include "gpu/command_buffer/client/fenced_allocator.h" | 10 #include "gpu/command_buffer/client/fenced_allocator.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 command_buffer_.get(), NULL, parser_, INT_MAX)); | 54 command_buffer_.get(), NULL, parser_, INT_MAX)); |
55 command_buffer_->SetPutOffsetChangeCallback(NewCallback( | 55 command_buffer_->SetPutOffsetChangeCallback(NewCallback( |
56 gpu_processor.get(), &GPUProcessor::ProcessCommands)); | 56 gpu_processor.get(), &GPUProcessor::ProcessCommands)); |
57 | 57 |
58 api_mock_->set_engine(gpu_processor.get()); | 58 api_mock_->set_engine(gpu_processor.get()); |
59 | 59 |
60 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 60 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
61 helper_->Initialize(); | 61 helper_->Initialize(); |
62 } | 62 } |
63 | 63 |
| 64 int32 GetToken() { |
| 65 return command_buffer_->GetState().token; |
| 66 } |
| 67 |
64 virtual void TearDown() { | 68 virtual void TearDown() { |
65 helper_.release(); | 69 helper_.release(); |
66 } | 70 } |
67 | 71 |
68 base::AtExitManager at_exit_manager_; | 72 base::AtExitManager at_exit_manager_; |
69 MessageLoop message_loop_; | 73 MessageLoop message_loop_; |
70 scoped_ptr<AsyncAPIMock> api_mock_; | 74 scoped_ptr<AsyncAPIMock> api_mock_; |
71 scoped_ptr<CommandBufferService> command_buffer_; | 75 scoped_ptr<CommandBufferService> command_buffer_; |
72 CommandParser* parser_; | 76 CommandParser* parser_; |
73 scoped_ptr<CommandBufferHelper> helper_; | 77 scoped_ptr<CommandBufferHelper> helper_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 EXPECT_TRUE(allocator_->CheckConsistency()); | 184 EXPECT_TRUE(allocator_->CheckConsistency()); |
181 | 185 |
182 // Free one successful allocation, pending fence. | 186 // Free one successful allocation, pending fence. |
183 int32 token = helper_.get()->InsertToken(); | 187 int32 token = helper_.get()->InsertToken(); |
184 allocator_->FreePendingToken(offsets[0], token); | 188 allocator_->FreePendingToken(offsets[0], token); |
185 EXPECT_TRUE(allocator_->CheckConsistency()); | 189 EXPECT_TRUE(allocator_->CheckConsistency()); |
186 | 190 |
187 // The way we hooked up the helper and engine, it won't process commands | 191 // The way we hooked up the helper and engine, it won't process commands |
188 // until it has to wait for something. Which means the token shouldn't have | 192 // until it has to wait for something. Which means the token shouldn't have |
189 // passed yet at this point. | 193 // passed yet at this point. |
190 EXPECT_GT(token, command_buffer_->GetToken()); | 194 EXPECT_GT(token, GetToken()); |
191 | 195 |
192 // This allocation will need to reclaim the space freed above, so that should | 196 // This allocation will need to reclaim the space freed above, so that should |
193 // process the commands until the token is passed. | 197 // process the commands until the token is passed. |
194 offsets[0] = allocator_->Alloc(kSize); | 198 offsets[0] = allocator_->Alloc(kSize); |
195 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[0]); | 199 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[0]); |
196 EXPECT_GE(kBufferSize, offsets[0]+kSize); | 200 EXPECT_GE(kBufferSize, offsets[0]+kSize); |
197 EXPECT_TRUE(allocator_->CheckConsistency()); | 201 EXPECT_TRUE(allocator_->CheckConsistency()); |
198 // Check that the token has indeed passed. | 202 // Check that the token has indeed passed. |
199 EXPECT_LE(token, command_buffer_->GetToken()); | 203 EXPECT_LE(token, GetToken()); |
200 | 204 |
201 // Free up everything. | 205 // Free up everything. |
202 for (unsigned int i = 0; i < kAllocCount; ++i) { | 206 for (unsigned int i = 0; i < kAllocCount; ++i) { |
203 allocator_->Free(offsets[i]); | 207 allocator_->Free(offsets[i]); |
204 EXPECT_TRUE(allocator_->CheckConsistency()); | 208 EXPECT_TRUE(allocator_->CheckConsistency()); |
205 } | 209 } |
206 } | 210 } |
207 | 211 |
208 // Tests GetLargestFreeSize | 212 // Tests GetLargestFreeSize |
209 TEST_F(FencedAllocatorTest, TestGetLargestFreeSize) { | 213 TEST_F(FencedAllocatorTest, TestGetLargestFreeSize) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 289 |
286 // Now all the buffers have been freed... | 290 // Now all the buffers have been freed... |
287 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); | 291 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); |
288 // .. but one is still waiting for the token. | 292 // .. but one is still waiting for the token. |
289 EXPECT_EQ(kBufferSize - 3 * kSize, | 293 EXPECT_EQ(kBufferSize - 3 * kSize, |
290 allocator_->GetLargestFreeSize()); | 294 allocator_->GetLargestFreeSize()); |
291 | 295 |
292 // The way we hooked up the helper and engine, it won't process commands | 296 // The way we hooked up the helper and engine, it won't process commands |
293 // until it has to wait for something. Which means the token shouldn't have | 297 // until it has to wait for something. Which means the token shouldn't have |
294 // passed yet at this point. | 298 // passed yet at this point. |
295 EXPECT_GT(token, command_buffer_->GetToken()); | 299 EXPECT_GT(token, GetToken()); |
296 // This allocation will need to reclaim the space freed above, so that should | 300 // This allocation will need to reclaim the space freed above, so that should |
297 // process the commands until the token is passed, but it will succeed. | 301 // process the commands until the token is passed, but it will succeed. |
298 offset = allocator_->Alloc(kBufferSize); | 302 offset = allocator_->Alloc(kBufferSize); |
299 ASSERT_NE(FencedAllocator::kInvalidOffset, offset); | 303 ASSERT_NE(FencedAllocator::kInvalidOffset, offset); |
300 // Check that the token has indeed passed. | 304 // Check that the token has indeed passed. |
301 EXPECT_LE(token, command_buffer_->GetToken()); | 305 EXPECT_LE(token, GetToken()); |
302 allocator_->Free(offset); | 306 allocator_->Free(offset); |
303 | 307 |
304 // Everything now has been freed... | 308 // Everything now has been freed... |
305 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); | 309 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); |
306 // ... for real. | 310 // ... for real. |
307 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); | 311 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); |
308 } | 312 } |
309 | 313 |
310 // Test fixture for FencedAllocatorWrapper test - Creates a | 314 // Test fixture for FencedAllocatorWrapper test - Creates a |
311 // FencedAllocatorWrapper, using a CommandBufferHelper with a mock | 315 // FencedAllocatorWrapper, using a CommandBufferHelper with a mock |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 EXPECT_TRUE(allocator_->CheckConsistency()); | 440 EXPECT_TRUE(allocator_->CheckConsistency()); |
437 | 441 |
438 // Free one successful allocation, pending fence. | 442 // Free one successful allocation, pending fence. |
439 int32 token = helper_.get()->InsertToken(); | 443 int32 token = helper_.get()->InsertToken(); |
440 allocator_->FreePendingToken(pointers[0], token); | 444 allocator_->FreePendingToken(pointers[0], token); |
441 EXPECT_TRUE(allocator_->CheckConsistency()); | 445 EXPECT_TRUE(allocator_->CheckConsistency()); |
442 | 446 |
443 // The way we hooked up the helper and engine, it won't process commands | 447 // The way we hooked up the helper and engine, it won't process commands |
444 // until it has to wait for something. Which means the token shouldn't have | 448 // until it has to wait for something. Which means the token shouldn't have |
445 // passed yet at this point. | 449 // passed yet at this point. |
446 EXPECT_GT(token, command_buffer_->GetToken()); | 450 EXPECT_GT(token, GetToken()); |
447 | 451 |
448 // This allocation will need to reclaim the space freed above, so that should | 452 // This allocation will need to reclaim the space freed above, so that should |
449 // process the commands until the token is passed. | 453 // process the commands until the token is passed. |
450 pointers[0] = allocator_->Alloc(kSize); | 454 pointers[0] = allocator_->Alloc(kSize); |
451 EXPECT_TRUE(pointers[0]); | 455 EXPECT_TRUE(pointers[0]); |
452 EXPECT_TRUE(allocator_->CheckConsistency()); | 456 EXPECT_TRUE(allocator_->CheckConsistency()); |
453 // Check that the token has indeed passed. | 457 // Check that the token has indeed passed. |
454 EXPECT_LE(token, command_buffer_->GetToken()); | 458 EXPECT_LE(token, GetToken()); |
455 | 459 |
456 // Free up everything. | 460 // Free up everything. |
457 for (unsigned int i = 0; i < kAllocCount; ++i) { | 461 for (unsigned int i = 0; i < kAllocCount; ++i) { |
458 allocator_->Free(pointers[i]); | 462 allocator_->Free(pointers[i]); |
459 EXPECT_TRUE(allocator_->CheckConsistency()); | 463 EXPECT_TRUE(allocator_->CheckConsistency()); |
460 } | 464 } |
461 } | 465 } |
462 | 466 |
463 } // namespace gpu | 467 } // namespace gpu |
OLD | NEW |