| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/mac/scoped_nsautorelease_pool.h" | 9 #include "base/mac/scoped_nsautorelease_pool.h" |
| 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 BaseFencedAllocatorTest::TearDown(); | 99 BaseFencedAllocatorTest::TearDown(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 scoped_ptr<FencedAllocator> allocator_; | 102 scoped_ptr<FencedAllocator> allocator_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // Checks basic alloc and free. | 105 // Checks basic alloc and free. |
| 106 TEST_F(FencedAllocatorTest, TestBasic) { | 106 TEST_F(FencedAllocatorTest, TestBasic) { |
| 107 allocator_->CheckConsistency(); | 107 allocator_->CheckConsistency(); |
| 108 EXPECT_FALSE(allocator_->InUse()); |
| 108 | 109 |
| 109 const unsigned int kSize = 16; | 110 const unsigned int kSize = 16; |
| 110 FencedAllocator::Offset offset = allocator_->Alloc(kSize); | 111 FencedAllocator::Offset offset = allocator_->Alloc(kSize); |
| 112 EXPECT_TRUE(allocator_->InUse()); |
| 111 EXPECT_NE(FencedAllocator::kInvalidOffset, offset); | 113 EXPECT_NE(FencedAllocator::kInvalidOffset, offset); |
| 112 EXPECT_GE(kBufferSize, offset+kSize); | 114 EXPECT_GE(kBufferSize, offset+kSize); |
| 113 EXPECT_TRUE(allocator_->CheckConsistency()); | 115 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 114 | 116 |
| 115 allocator_->Free(offset); | 117 allocator_->Free(offset); |
| 118 EXPECT_FALSE(allocator_->InUse()); |
| 116 EXPECT_TRUE(allocator_->CheckConsistency()); | 119 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 117 } | 120 } |
| 118 | 121 |
| 119 // Checks out-of-memory condition. | 122 // Checks out-of-memory condition. |
| 120 TEST_F(FencedAllocatorTest, TestOutOfMemory) { | 123 TEST_F(FencedAllocatorTest, TestOutOfMemory) { |
| 121 EXPECT_TRUE(allocator_->CheckConsistency()); | 124 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 122 | 125 |
| 123 const unsigned int kSize = 16; | 126 const unsigned int kSize = 16; |
| 124 const unsigned int kAllocCount = kBufferSize / kSize; | 127 const unsigned int kAllocCount = kBufferSize / kSize; |
| 125 CHECK(kAllocCount * kSize == kBufferSize); | 128 CHECK(kAllocCount * kSize == kBufferSize); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 CHECK(kAllocCount * kSize == kBufferSize); | 218 CHECK(kAllocCount * kSize == kBufferSize); |
| 216 | 219 |
| 217 // Allocate several buffers to fill in the memory. | 220 // Allocate several buffers to fill in the memory. |
| 218 FencedAllocator::Offset offsets[kAllocCount]; | 221 FencedAllocator::Offset offsets[kAllocCount]; |
| 219 for (unsigned int i = 0; i < kAllocCount; ++i) { | 222 for (unsigned int i = 0; i < kAllocCount; ++i) { |
| 220 offsets[i] = allocator_->Alloc(kSize); | 223 offsets[i] = allocator_->Alloc(kSize); |
| 221 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[i]); | 224 EXPECT_NE(FencedAllocator::kInvalidOffset, offsets[i]); |
| 222 EXPECT_GE(kBufferSize, offsets[i]+kSize); | 225 EXPECT_GE(kBufferSize, offsets[i]+kSize); |
| 223 EXPECT_TRUE(allocator_->CheckConsistency()); | 226 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 224 } | 227 } |
| 228 EXPECT_TRUE(allocator_->InUse()); |
| 225 | 229 |
| 226 // No memory should be available. | 230 // No memory should be available. |
| 227 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); | 231 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); |
| 228 | 232 |
| 229 // Free one successful allocation, pending fence. | 233 // Free one successful allocation, pending fence. |
| 230 int32 token = helper_.get()->InsertToken(); | 234 int32 token = helper_.get()->InsertToken(); |
| 231 allocator_->FreePendingToken(offsets[0], token); | 235 allocator_->FreePendingToken(offsets[0], token); |
| 232 EXPECT_TRUE(allocator_->CheckConsistency()); | 236 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 233 | 237 |
| 234 // Force the command buffer to process the token. | 238 // Force the command buffer to process the token. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 251 EXPECT_EQ(kSize, allocator_->GetLargestFreeSize()); | 255 EXPECT_EQ(kSize, allocator_->GetLargestFreeSize()); |
| 252 | 256 |
| 253 // Force the command buffer to process the token. | 257 // Force the command buffer to process the token. |
| 254 helper_->Finish(); | 258 helper_->Finish(); |
| 255 | 259 |
| 256 // Tell the allocator to update what's available based on the current token. | 260 // Tell the allocator to update what's available based on the current token. |
| 257 allocator_->FreeUnused(); | 261 allocator_->FreeUnused(); |
| 258 | 262 |
| 259 // Check that the new largest free size takes into account the unused blocks. | 263 // Check that the new largest free size takes into account the unused blocks. |
| 260 EXPECT_EQ(kSize * 3, allocator_->GetLargestFreeSize()); | 264 EXPECT_EQ(kSize * 3, allocator_->GetLargestFreeSize()); |
| 265 EXPECT_TRUE(allocator_->InUse()); |
| 261 | 266 |
| 262 // Free up everything. | 267 // Free up everything. |
| 263 for (unsigned int i = 3; i < kAllocCount; ++i) { | 268 for (unsigned int i = 3; i < kAllocCount; ++i) { |
| 264 allocator_->Free(offsets[i]); | 269 allocator_->Free(offsets[i]); |
| 265 EXPECT_TRUE(allocator_->CheckConsistency()); | 270 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 266 } | 271 } |
| 272 EXPECT_FALSE(allocator_->InUse()); |
| 267 } | 273 } |
| 268 | 274 |
| 269 // Tests GetLargestFreeSize | 275 // Tests GetLargestFreeSize |
| 270 TEST_F(FencedAllocatorTest, TestGetLargestFreeSize) { | 276 TEST_F(FencedAllocatorTest, TestGetLargestFreeSize) { |
| 271 EXPECT_TRUE(allocator_->CheckConsistency()); | 277 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 272 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); | 278 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSize()); |
| 273 | 279 |
| 274 FencedAllocator::Offset offset = allocator_->Alloc(kBufferSize); | 280 FencedAllocator::Offset offset = allocator_->Alloc(kBufferSize); |
| 275 ASSERT_NE(FencedAllocator::kInvalidOffset, offset); | 281 ASSERT_NE(FencedAllocator::kInvalidOffset, offset); |
| 276 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); | 282 EXPECT_EQ(0u, allocator_->GetLargestFreeSize()); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 EXPECT_LE(token, GetToken()); | 519 EXPECT_LE(token, GetToken()); |
| 514 | 520 |
| 515 // Free up everything. | 521 // Free up everything. |
| 516 for (unsigned int i = 0; i < kAllocCount; ++i) { | 522 for (unsigned int i = 0; i < kAllocCount; ++i) { |
| 517 allocator_->Free(pointers[i]); | 523 allocator_->Free(pointers[i]); |
| 518 EXPECT_TRUE(allocator_->CheckConsistency()); | 524 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 519 } | 525 } |
| 520 } | 526 } |
| 521 | 527 |
| 522 } // namespace gpu | 528 } // namespace gpu |
| OLD | NEW |