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

Side by Side Diff: gpu/command_buffer/common/id_allocator_test.cc

Issue 7077006: Speed up IdAllocator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Clarified description. Created 9 years, 7 months 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 has the unit tests for the IdAllocator class. 5 // This file has the unit tests for the IdAllocator class.
6 6
7 #include "gpu/command_buffer/common/id_allocator.h" 7 #include "gpu/command_buffer/common/id_allocator.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace gpu { 10 namespace gpu {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // Frees the other ID, check that it's not in use any more. 43 // Frees the other ID, check that it's not in use any more.
44 allocator->FreeID(id2); 44 allocator->FreeID(id2);
45 EXPECT_FALSE(allocator->InUse(id2)); 45 EXPECT_FALSE(allocator->InUse(id2));
46 } 46 }
47 47
48 // Checks that the resource IDs are re-used after being freed. 48 // Checks that the resource IDs are re-used after being freed.
49 TEST_F(IdAllocatorTest, TestAdvanced) { 49 TEST_F(IdAllocatorTest, TestAdvanced) {
50 IdAllocator *allocator = id_allocator(); 50 IdAllocator *allocator = id_allocator();
51 51
52 // Allocate the highest possible ID, to make life awkward.
53 allocator->AllocateIDAtOrAbove(-1);
54
52 // Allocate a significant number of resources. 55 // Allocate a significant number of resources.
53 const unsigned int kNumResources = 100; 56 const unsigned int kNumResources = 100;
54 ResourceId ids[kNumResources]; 57 ResourceId ids[kNumResources];
55 for (unsigned int i = 0; i < kNumResources; ++i) { 58 for (unsigned int i = 0; i < kNumResources; ++i) {
56 ids[i] = allocator->AllocateID(); 59 ids[i] = allocator->AllocateID();
57 EXPECT_TRUE(allocator->InUse(ids[i])); 60 EXPECT_TRUE(allocator->InUse(ids[i]));
58 } 61 }
59 62
60 // Check that a new allocation re-uses the resource we just freed. 63 // Check that a new allocation re-uses the resource we just freed.
61 ResourceId id1 = ids[kNumResources / 2]; 64 ResourceId id1 = ids[kNumResources / 2];
(...skipping 26 matching lines...) Expand all
88 const ResourceId kOffset = 123456; 91 const ResourceId kOffset = 123456;
89 IdAllocator* allocator = id_allocator(); 92 IdAllocator* allocator = id_allocator();
90 ResourceId id1 = allocator->AllocateIDAtOrAbove(kOffset); 93 ResourceId id1 = allocator->AllocateIDAtOrAbove(kOffset);
91 EXPECT_EQ(kOffset, id1); 94 EXPECT_EQ(kOffset, id1);
92 ResourceId id2 = allocator->AllocateIDAtOrAbove(kOffset); 95 ResourceId id2 = allocator->AllocateIDAtOrAbove(kOffset);
93 EXPECT_GT(id2, kOffset); 96 EXPECT_GT(id2, kOffset);
94 ResourceId id3 = allocator->AllocateIDAtOrAbove(kOffset); 97 ResourceId id3 = allocator->AllocateIDAtOrAbove(kOffset);
95 EXPECT_GT(id3, kOffset); 98 EXPECT_GT(id3, kOffset);
96 } 99 }
97 100
101 // Checks that AllocateIdAtOrAbove wraps around at the maximum 32-bit value.
102 TEST_F(IdAllocatorTest, AllocateIdAtOrAboveWrapsAround) {
103 const ResourceId kMaxPossibleOffset = -1;
104 IdAllocator* allocator = id_allocator();
105 ResourceId id1 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
106 EXPECT_EQ(kMaxPossibleOffset, id1);
107 ResourceId id2 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
108 EXPECT_EQ(1u, id2);
109 ResourceId id3 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset);
110 EXPECT_EQ(2u, id3);
111 }
112
98 } // namespace gpu 113 } // namespace gpu
OLDNEW
« gpu/command_buffer/common/id_allocator.h ('K') | « gpu/command_buffer/common/id_allocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698