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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 EXPECT_TRUE(allocator_->InUse()); | 119 EXPECT_TRUE(allocator_->InUse()); |
120 EXPECT_NE(FencedAllocator::kInvalidOffset, offset); | 120 EXPECT_NE(FencedAllocator::kInvalidOffset, offset); |
121 EXPECT_GE(kBufferSize, offset+kSize); | 121 EXPECT_GE(kBufferSize, offset+kSize); |
122 EXPECT_TRUE(allocator_->CheckConsistency()); | 122 EXPECT_TRUE(allocator_->CheckConsistency()); |
123 | 123 |
124 allocator_->Free(offset); | 124 allocator_->Free(offset); |
125 EXPECT_FALSE(allocator_->InUse()); | 125 EXPECT_FALSE(allocator_->InUse()); |
126 EXPECT_TRUE(allocator_->CheckConsistency()); | 126 EXPECT_TRUE(allocator_->CheckConsistency()); |
127 } | 127 } |
128 | 128 |
| 129 TEST_F(FencedAllocatorTest, TestAllocZero) { |
| 130 allocator_->CheckConsistency(); |
| 131 EXPECT_FALSE(allocator_->InUse()); |
| 132 |
| 133 // Checks we can alloc size 0. |
| 134 FencedAllocator::Offset offset = allocator_->Alloc(0); |
| 135 EXPECT_FALSE(allocator_->InUse()); |
| 136 EXPECT_NE(FencedAllocator::kInvalidOffset, offset); |
| 137 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 138 |
| 139 // Checks 2 allocations of size 0 are not the same offset. |
| 140 FencedAllocator::Offset offset2 = allocator_->Alloc(0); |
| 141 EXPECT_FALSE(allocator_->InUse()); |
| 142 EXPECT_NE(FencedAllocator::kInvalidOffset, offset2); |
| 143 EXPECT_NE(offset, offset2); |
| 144 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 145 |
| 146 // Allocates all the memory. |
| 147 unsigned int size = allocator_->GetLargestFreeSize(); |
| 148 FencedAllocator::Offset offset3 = allocator_->Alloc(size); |
| 149 EXPECT_TRUE(allocator_->InUse()); |
| 150 EXPECT_NE(FencedAllocator::kInvalidOffset, offset3); |
| 151 |
| 152 // Checks there's no memory left |
| 153 size = allocator_->GetLargestFreeSize(); |
| 154 EXPECT_EQ(0u, size); |
| 155 |
| 156 // Checks allocations of size 0 still succeed. |
| 157 FencedAllocator::Offset offset4 = allocator_->Alloc(0); |
| 158 EXPECT_NE(FencedAllocator::kInvalidOffset, offset3); |
| 159 EXPECT_NE(offset, offset4); |
| 160 EXPECT_NE(offset2, offset4); |
| 161 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 162 |
| 163 allocator_->Free(offset); |
| 164 EXPECT_TRUE(allocator_->InUse()); |
| 165 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 166 allocator_->Free(offset2); |
| 167 EXPECT_TRUE(allocator_->InUse()); |
| 168 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 169 allocator_->Free(offset3); |
| 170 EXPECT_FALSE(allocator_->InUse()); |
| 171 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 172 allocator_->Free(offset4); |
| 173 EXPECT_FALSE(allocator_->InUse()); |
| 174 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 175 } |
| 176 |
129 // Checks out-of-memory condition. | 177 // Checks out-of-memory condition. |
130 TEST_F(FencedAllocatorTest, TestOutOfMemory) { | 178 TEST_F(FencedAllocatorTest, TestOutOfMemory) { |
131 EXPECT_TRUE(allocator_->CheckConsistency()); | 179 EXPECT_TRUE(allocator_->CheckConsistency()); |
132 | 180 |
133 const unsigned int kSize = 16; | 181 const unsigned int kSize = 16; |
134 const unsigned int kAllocCount = kBufferSize / kSize; | 182 const unsigned int kAllocCount = kBufferSize / kSize; |
135 CHECK(kAllocCount * kSize == kBufferSize); | 183 CHECK(kAllocCount * kSize == kBufferSize); |
136 | 184 |
137 // Allocate several buffers to fill in the memory. | 185 // Allocate several buffers to fill in the memory. |
138 FencedAllocator::Offset offsets[kAllocCount]; | 186 FencedAllocator::Offset offsets[kAllocCount]; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 EXPECT_GE(buffer_.get() + kBufferSize, | 487 EXPECT_GE(buffer_.get() + kBufferSize, |
440 reinterpret_cast<char *>(pointer_uint + kSize)); | 488 reinterpret_cast<char *>(pointer_uint + kSize)); |
441 | 489 |
442 // Check that it did allocate kSize * sizeof(unsigned int). We can't tell | 490 // Check that it did allocate kSize * sizeof(unsigned int). We can't tell |
443 // directly, except from the remaining size. | 491 // directly, except from the remaining size. |
444 EXPECT_EQ(kBufferSize - kSize * sizeof(*pointer_uint), | 492 EXPECT_EQ(kBufferSize - kSize * sizeof(*pointer_uint), |
445 allocator_->GetLargestFreeSize()); | 493 allocator_->GetLargestFreeSize()); |
446 allocator_->Free(pointer_uint); | 494 allocator_->Free(pointer_uint); |
447 } | 495 } |
448 | 496 |
| 497 TEST_F(FencedAllocatorWrapperTest, TestAllocZero) { |
| 498 allocator_->CheckConsistency(); |
| 499 |
| 500 void* ptr = allocator_->Alloc(0); |
| 501 EXPECT_TRUE(ptr != NULL); |
| 502 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 503 |
| 504 void* ptr2 = allocator_->Alloc(0); |
| 505 EXPECT_TRUE(ptr2 != NULL); |
| 506 EXPECT_NE(ptr2, ptr); |
| 507 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 508 |
| 509 allocator_->Free(ptr); |
| 510 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 511 allocator_->Free(ptr2); |
| 512 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 513 } |
| 514 |
449 // Checks out-of-memory condition. | 515 // Checks out-of-memory condition. |
450 TEST_F(FencedAllocatorWrapperTest, TestOutOfMemory) { | 516 TEST_F(FencedAllocatorWrapperTest, TestOutOfMemory) { |
451 allocator_->CheckConsistency(); | 517 allocator_->CheckConsistency(); |
452 | 518 |
453 const unsigned int kSize = 16; | 519 const unsigned int kSize = 16; |
454 const unsigned int kAllocCount = kBufferSize / kSize; | 520 const unsigned int kAllocCount = kBufferSize / kSize; |
455 CHECK(kAllocCount * kSize == kBufferSize); | 521 CHECK(kAllocCount * kSize == kBufferSize); |
456 | 522 |
457 // Allocate several buffers to fill in the memory. | 523 // Allocate several buffers to fill in the memory. |
458 void *pointers[kAllocCount]; | 524 void *pointers[kAllocCount]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 EXPECT_LE(token, GetToken()); | 592 EXPECT_LE(token, GetToken()); |
527 | 593 |
528 // Free up everything. | 594 // Free up everything. |
529 for (unsigned int i = 0; i < kAllocCount; ++i) { | 595 for (unsigned int i = 0; i < kAllocCount; ++i) { |
530 allocator_->Free(pointers[i]); | 596 allocator_->Free(pointers[i]); |
531 EXPECT_TRUE(allocator_->CheckConsistency()); | 597 EXPECT_TRUE(allocator_->CheckConsistency()); |
532 } | 598 } |
533 } | 599 } |
534 | 600 |
535 } // namespace gpu | 601 } // namespace gpu |
OLD | NEW |