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 <stdint.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/memory/aligned_memory.h" | 11 #include "base/memory/aligned_memory.h" |
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
11 #include "gpu/command_buffer/client/fenced_allocator.h" | 13 #include "gpu/command_buffer/client/fenced_allocator.h" |
12 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
13 #include "gpu/command_buffer/service/command_buffer_service.h" | 15 #include "gpu/command_buffer/service/command_buffer_service.h" |
14 #include "gpu/command_buffer/service/gpu_scheduler.h" | 16 #include "gpu/command_buffer/service/gpu_scheduler.h" |
15 #include "gpu/command_buffer/service/mocks.h" | 17 #include "gpu/command_buffer/service/mocks.h" |
16 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 18 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get()))); | 60 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get()))); |
59 command_buffer_->SetGetBufferChangeCallback(base::Bind( | 61 command_buffer_->SetGetBufferChangeCallback(base::Bind( |
60 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); | 62 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); |
61 | 63 |
62 api_mock_->set_engine(gpu_scheduler_.get()); | 64 api_mock_->set_engine(gpu_scheduler_.get()); |
63 | 65 |
64 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 66 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
65 helper_->Initialize(kBufferSize); | 67 helper_->Initialize(kBufferSize); |
66 } | 68 } |
67 | 69 |
68 int32 GetToken() { | 70 int32_t GetToken() { return command_buffer_->GetLastState().token; } |
69 return command_buffer_->GetLastState().token; | |
70 } | |
71 | 71 |
72 scoped_ptr<AsyncAPIMock> api_mock_; | 72 scoped_ptr<AsyncAPIMock> api_mock_; |
73 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 73 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
74 scoped_ptr<CommandBufferService> command_buffer_; | 74 scoped_ptr<CommandBufferService> command_buffer_; |
75 scoped_ptr<GpuScheduler> gpu_scheduler_; | 75 scoped_ptr<GpuScheduler> gpu_scheduler_; |
76 scoped_ptr<CommandBufferHelper> helper_; | 76 scoped_ptr<CommandBufferHelper> helper_; |
77 base::MessageLoop message_loop_; | 77 base::MessageLoop message_loop_; |
78 }; | 78 }; |
79 | 79 |
80 #ifndef _MSC_VER | 80 #ifndef _MSC_VER |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 EXPECT_GE(kBufferSize, offsets[i]+kSize); | 187 EXPECT_GE(kBufferSize, offsets[i]+kSize); |
188 EXPECT_TRUE(allocator_->CheckConsistency()); | 188 EXPECT_TRUE(allocator_->CheckConsistency()); |
189 } | 189 } |
190 | 190 |
191 // This allocation should fail. | 191 // This allocation should fail. |
192 FencedAllocator::Offset offset_failed = allocator_->Alloc(kSize); | 192 FencedAllocator::Offset offset_failed = allocator_->Alloc(kSize); |
193 EXPECT_EQ(FencedAllocator::kInvalidOffset, offset_failed); | 193 EXPECT_EQ(FencedAllocator::kInvalidOffset, offset_failed); |
194 EXPECT_TRUE(allocator_->CheckConsistency()); | 194 EXPECT_TRUE(allocator_->CheckConsistency()); |
195 | 195 |
196 // Free one successful allocation, pending fence. | 196 // Free one successful allocation, pending fence. |
197 int32 token = helper_.get()->InsertToken(); | 197 int32_t token = helper_.get()->InsertToken(); |
198 allocator_->FreePendingToken(offsets[0], token); | 198 allocator_->FreePendingToken(offsets[0], token); |
199 EXPECT_TRUE(allocator_->CheckConsistency()); | 199 EXPECT_TRUE(allocator_->CheckConsistency()); |
200 | 200 |
201 // The way we hooked up the helper and engine, it won't process commands | 201 // The way we hooked up the helper and engine, it won't process commands |
202 // until it has to wait for something. Which means the token shouldn't have | 202 // until it has to wait for something. Which means the token shouldn't have |
203 // passed yet at this point. | 203 // passed yet at this point. |
204 EXPECT_GT(token, GetToken()); | 204 EXPECT_GT(token, GetToken()); |
205 | 205 |
206 // This allocation will need to reclaim the space freed above, so that should | 206 // This allocation will need to reclaim the space freed above, so that should |
207 // process the commands until the token is passed. | 207 // process the commands until the token is passed. |
(...skipping 26 matching lines...) Expand all Loading... |
234 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[i]); | 234 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[i]); |
235 EXPECT_GE(kBufferSize, offsets[i]+kSize); | 235 EXPECT_GE(kBufferSize, offsets[i]+kSize); |
236 EXPECT_TRUE(allocator_->CheckConsistency()); | 236 EXPECT_TRUE(allocator_->CheckConsistency()); |
237 } | 237 } |
238 EXPECT_TRUE(allocator_->InUse()); | 238 EXPECT_TRUE(allocator_->InUse()); |
239 | 239 |
240 // No memory should be available. | 240 // No memory should be available. |
241 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); | 241 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); |
242 | 242 |
243 // Free one successful allocation, pending fence. | 243 // Free one successful allocation, pending fence. |
244 int32 token = helper_.get()->InsertToken(); | 244 int32_t token = helper_.get()->InsertToken(); |
245 allocator_->FreePendingToken(offsets[0], token); | 245 allocator_->FreePendingToken(offsets[0], token); |
246 EXPECT_TRUE(allocator_->CheckConsistency()); | 246 EXPECT_TRUE(allocator_->CheckConsistency()); |
247 | 247 |
248 // Force the command buffer to process the token. | 248 // Force the command buffer to process the token. |
249 helper_->Finish(); | 249 helper_->Finish(); |
250 | 250 |
251 // Tell the allocator to update what's available based on the current token. | 251 // Tell the allocator to update what's available based on the current token. |
252 allocator_->FreeUnused(); | 252 allocator_->FreeUnused(); |
253 | 253 |
254 // Check that the new largest free size takes into account the unused block. | 254 // Check that the new largest free size takes into account the unused block. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 FencedAllocator::Offset offset1 = allocator_->Alloc(kSize); | 350 FencedAllocator::Offset offset1 = allocator_->Alloc(kSize); |
351 ASSERT_NE(FencedAllocator::kInvalidOffset, offset1); | 351 ASSERT_NE(FencedAllocator::kInvalidOffset, offset1); |
352 FencedAllocator::Offset offset2 = allocator_->Alloc(kSize); | 352 FencedAllocator::Offset offset2 = allocator_->Alloc(kSize); |
353 ASSERT_NE(FencedAllocator::kInvalidOffset, offset2); | 353 ASSERT_NE(FencedAllocator::kInvalidOffset, offset2); |
354 allocator_->Free(offset); | 354 allocator_->Free(offset); |
355 allocator_->Free(offset1); | 355 allocator_->Free(offset1); |
356 EXPECT_EQ(kBufferSize - 3 * kSize, | 356 EXPECT_EQ(kBufferSize - 3 * kSize, |
357 allocator_->GetLargestFreeOrPendingSize()); | 357 allocator_->GetLargestFreeOrPendingSize()); |
358 | 358 |
359 // Free the last one, pending a token. | 359 // Free the last one, pending a token. |
360 int32 token = helper_.get()->InsertToken(); | 360 int32_t token = helper_.get()->InsertToken(); |
361 allocator_->FreePendingToken(offset2, token); | 361 allocator_->FreePendingToken(offset2, token); |
362 | 362 |
363 // Now all the buffers have been freed... | 363 // Now all the buffers have been freed... |
364 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); | 364 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); |
365 // .. but one is still waiting for the token. | 365 // .. but one is still waiting for the token. |
366 EXPECT_EQ(kBufferSize - 3 * kSize, | 366 EXPECT_EQ(kBufferSize - 3 * kSize, |
367 allocator_->GetLargestFreeSize()); | 367 allocator_->GetLargestFreeSize()); |
368 | 368 |
369 // The way we hooked up the helper and engine, it won't process commands | 369 // The way we hooked up the helper and engine, it won't process commands |
370 // until it has to wait for something. Which means the token shouldn't have | 370 // until it has to wait for something. Which means the token shouldn't have |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 EXPECT_TRUE(pointers[i]); | 538 EXPECT_TRUE(pointers[i]); |
539 EXPECT_TRUE(allocator_->CheckConsistency()); | 539 EXPECT_TRUE(allocator_->CheckConsistency()); |
540 } | 540 } |
541 | 541 |
542 // This allocation should fail. | 542 // This allocation should fail. |
543 void *pointer_failed = allocator_->Alloc(kSize); | 543 void *pointer_failed = allocator_->Alloc(kSize); |
544 EXPECT_FALSE(pointer_failed); | 544 EXPECT_FALSE(pointer_failed); |
545 EXPECT_TRUE(allocator_->CheckConsistency()); | 545 EXPECT_TRUE(allocator_->CheckConsistency()); |
546 | 546 |
547 // Free one successful allocation, pending fence. | 547 // Free one successful allocation, pending fence. |
548 int32 token = helper_.get()->InsertToken(); | 548 int32_t token = helper_.get()->InsertToken(); |
549 allocator_->FreePendingToken(pointers[0], token); | 549 allocator_->FreePendingToken(pointers[0], token); |
550 EXPECT_TRUE(allocator_->CheckConsistency()); | 550 EXPECT_TRUE(allocator_->CheckConsistency()); |
551 | 551 |
552 // The way we hooked up the helper and engine, it won't process commands | 552 // The way we hooked up the helper and engine, it won't process commands |
553 // until it has to wait for something. Which means the token shouldn't have | 553 // until it has to wait for something. Which means the token shouldn't have |
554 // passed yet at this point. | 554 // passed yet at this point. |
555 EXPECT_GT(token, GetToken()); | 555 EXPECT_GT(token, GetToken()); |
556 | 556 |
557 // This allocation will need to reclaim the space freed above, so that should | 557 // This allocation will need to reclaim the space freed above, so that should |
558 // process the commands until the token is passed. | 558 // process the commands until the token is passed. |
559 pointers[0] = allocator_->Alloc(kSize); | 559 pointers[0] = allocator_->Alloc(kSize); |
560 EXPECT_TRUE(pointers[0]); | 560 EXPECT_TRUE(pointers[0]); |
561 EXPECT_TRUE(allocator_->CheckConsistency()); | 561 EXPECT_TRUE(allocator_->CheckConsistency()); |
562 // Check that the token has indeed passed. | 562 // Check that the token has indeed passed. |
563 EXPECT_LE(token, GetToken()); | 563 EXPECT_LE(token, GetToken()); |
564 | 564 |
565 // Free up everything. | 565 // Free up everything. |
566 for (unsigned int i = 0; i < kAllocCount; ++i) { | 566 for (unsigned int i = 0; i < kAllocCount; ++i) { |
567 allocator_->Free(pointers[i]); | 567 allocator_->Free(pointers[i]); |
568 EXPECT_TRUE(allocator_->CheckConsistency()); | 568 EXPECT_TRUE(allocator_->CheckConsistency()); |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
572 } // namespace gpu | 572 } // namespace gpu |
OLD | NEW |