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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/client/fenced_allocator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 alloc 0 fails.
130 TEST_F(FencedAllocatorTest, TestAllocZero) {
131 FencedAllocator::Offset offset = allocator_->Alloc(0);
132 EXPECT_EQ(FencedAllocator::kInvalidOffset, offset);
133 EXPECT_FALSE(allocator_->InUse());
134 EXPECT_TRUE(allocator_->CheckConsistency());
135 }
136
129 // Checks out-of-memory condition. 137 // Checks out-of-memory condition.
130 TEST_F(FencedAllocatorTest, TestOutOfMemory) { 138 TEST_F(FencedAllocatorTest, TestOutOfMemory) {
131 EXPECT_TRUE(allocator_->CheckConsistency()); 139 EXPECT_TRUE(allocator_->CheckConsistency());
132 140
133 const unsigned int kSize = 16; 141 const unsigned int kSize = 16;
134 const unsigned int kAllocCount = kBufferSize / kSize; 142 const unsigned int kAllocCount = kBufferSize / kSize;
135 CHECK(kAllocCount * kSize == kBufferSize); 143 CHECK(kAllocCount * kSize == kBufferSize);
136 144
137 // Allocate several buffers to fill in the memory. 145 // Allocate several buffers to fill in the memory.
138 FencedAllocator::Offset offsets[kAllocCount]; 146 FencedAllocator::Offset offsets[kAllocCount];
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 EXPECT_GE(buffer_.get() + kBufferSize, 447 EXPECT_GE(buffer_.get() + kBufferSize,
440 reinterpret_cast<char *>(pointer_uint + kSize)); 448 reinterpret_cast<char *>(pointer_uint + kSize));
441 449
442 // Check that it did allocate kSize * sizeof(unsigned int). We can't tell 450 // Check that it did allocate kSize * sizeof(unsigned int). We can't tell
443 // directly, except from the remaining size. 451 // directly, except from the remaining size.
444 EXPECT_EQ(kBufferSize - kSize * sizeof(*pointer_uint), 452 EXPECT_EQ(kBufferSize - kSize * sizeof(*pointer_uint),
445 allocator_->GetLargestFreeSize()); 453 allocator_->GetLargestFreeSize());
446 allocator_->Free(pointer_uint); 454 allocator_->Free(pointer_uint);
447 } 455 }
448 456
457 // Test alloc 0 fails.
458 TEST_F(FencedAllocatorWrapperTest, TestAllocZero) {
459 allocator_->CheckConsistency();
460
461 void *pointer = allocator_->Alloc(0);
462 ASSERT_FALSE(pointer);
463 EXPECT_TRUE(allocator_->CheckConsistency());
464 }
465
449 // Checks out-of-memory condition. 466 // Checks out-of-memory condition.
450 TEST_F(FencedAllocatorWrapperTest, TestOutOfMemory) { 467 TEST_F(FencedAllocatorWrapperTest, TestOutOfMemory) {
451 allocator_->CheckConsistency(); 468 allocator_->CheckConsistency();
452 469
453 const unsigned int kSize = 16; 470 const unsigned int kSize = 16;
454 const unsigned int kAllocCount = kBufferSize / kSize; 471 const unsigned int kAllocCount = kBufferSize / kSize;
455 CHECK(kAllocCount * kSize == kBufferSize); 472 CHECK(kAllocCount * kSize == kBufferSize);
456 473
457 // Allocate several buffers to fill in the memory. 474 // Allocate several buffers to fill in the memory.
458 void *pointers[kAllocCount]; 475 void *pointers[kAllocCount];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 EXPECT_LE(token, GetToken()); 543 EXPECT_LE(token, GetToken());
527 544
528 // Free up everything. 545 // Free up everything.
529 for (unsigned int i = 0; i < kAllocCount; ++i) { 546 for (unsigned int i = 0; i < kAllocCount; ++i) {
530 allocator_->Free(pointers[i]); 547 allocator_->Free(pointers[i]);
531 EXPECT_TRUE(allocator_->CheckConsistency()); 548 EXPECT_TRUE(allocator_->CheckConsistency());
532 } 549 }
533 } 550 }
534 551
535 } // namespace gpu 552 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/fenced_allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698