Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: gpu/command_buffer/client/fenced_allocator_test.cc

Issue 11419280: Make FencedAlloctor fail on size = 0. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add separate zero allocation tracking Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/client/fenced_allocator_test.cc
diff --git a/gpu/command_buffer/client/fenced_allocator_test.cc b/gpu/command_buffer/client/fenced_allocator_test.cc
index 381237bbe48fd4672a1d5c95cab5b7ea20f2cfba..abf8a7f32abadf40763416dd41607c7fa62e5e86 100644
--- a/gpu/command_buffer/client/fenced_allocator_test.cc
+++ b/gpu/command_buffer/client/fenced_allocator_test.cc
@@ -126,6 +126,54 @@ TEST_F(FencedAllocatorTest, TestBasic) {
EXPECT_TRUE(allocator_->CheckConsistency());
}
+TEST_F(FencedAllocatorTest, TestAllocZero) {
+ allocator_->CheckConsistency();
+ EXPECT_FALSE(allocator_->InUse());
+
+ // Checks we can alloc size 0.
+ FencedAllocator::Offset offset = allocator_->Alloc(0);
+ EXPECT_FALSE(allocator_->InUse());
+ EXPECT_NE(FencedAllocator::kInvalidOffset, offset);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+
+ // Checks 2 allocations of size 0 are not the same offset.
+ FencedAllocator::Offset offset2 = allocator_->Alloc(0);
+ EXPECT_FALSE(allocator_->InUse());
+ EXPECT_NE(FencedAllocator::kInvalidOffset, offset2);
+ EXPECT_NE(offset, offset2);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+
+ // Allocates all the memory.
+ unsigned int size = allocator_->GetLargestFreeSize();
+ FencedAllocator::Offset offset3 = allocator_->Alloc(size);
+ EXPECT_TRUE(allocator_->InUse());
+ EXPECT_NE(FencedAllocator::kInvalidOffset, offset3);
+
+ // Checks there's no memory left
+ size = allocator_->GetLargestFreeSize();
+ EXPECT_EQ(0u, size);
+
+ // Checks allocations of size 0 still succeed.
+ FencedAllocator::Offset offset4 = allocator_->Alloc(0);
+ EXPECT_NE(FencedAllocator::kInvalidOffset, offset3);
+ EXPECT_NE(offset, offset4);
+ EXPECT_NE(offset2, offset4);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+
+ allocator_->Free(offset);
+ EXPECT_TRUE(allocator_->InUse());
+ EXPECT_TRUE(allocator_->CheckConsistency());
+ allocator_->Free(offset2);
+ EXPECT_TRUE(allocator_->InUse());
+ EXPECT_TRUE(allocator_->CheckConsistency());
+ allocator_->Free(offset3);
+ EXPECT_FALSE(allocator_->InUse());
+ EXPECT_TRUE(allocator_->CheckConsistency());
+ allocator_->Free(offset4);
+ EXPECT_FALSE(allocator_->InUse());
+ EXPECT_TRUE(allocator_->CheckConsistency());
+}
+
// Checks out-of-memory condition.
TEST_F(FencedAllocatorTest, TestOutOfMemory) {
EXPECT_TRUE(allocator_->CheckConsistency());
@@ -446,6 +494,24 @@ TEST_F(FencedAllocatorWrapperTest, TestBasic) {
allocator_->Free(pointer_uint);
}
+TEST_F(FencedAllocatorWrapperTest, TestAllocZero) {
+ allocator_->CheckConsistency();
+
+ void* ptr = allocator_->Alloc(0);
+ EXPECT_TRUE(ptr != NULL);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+
+ void* ptr2 = allocator_->Alloc(0);
+ EXPECT_TRUE(ptr2 != NULL);
+ EXPECT_NE(ptr2, ptr);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+
+ allocator_->Free(ptr);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+ allocator_->Free(ptr2);
+ EXPECT_TRUE(allocator_->CheckConsistency());
+}
+
// Checks out-of-memory condition.
TEST_F(FencedAllocatorWrapperTest, TestOutOfMemory) {
allocator_->CheckConsistency();

Powered by Google App Engine
This is Rietveld 408576698