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

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

Issue 684093008: command_buffer: Implement IdAllocator by recording ranges in an AVL tree Base URL: https://chromium.googlesource.com/chromium/src.git@new-05-path-fragment-input-gen
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « gpu/command_buffer/common/id_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) 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 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 allocator->FreeID(1); 158 allocator->FreeID(1);
159 allocator->FreeID(15); 159 allocator->FreeID(15);
160 allocator->FreeIDRange(2, 107); 160 allocator->FreeIDRange(2, 107);
161 ResourceId id11 = allocator->AllocateIDRange(100); 161 ResourceId id11 = allocator->AllocateIDRange(100);
162 EXPECT_EQ(1u, id11); 162 EXPECT_EQ(1u, id11);
163 allocator->FreeID(kMaxPossibleOffset); 163 allocator->FreeID(kMaxPossibleOffset);
164 ResourceId id12 = allocator->AllocateIDRange(100); 164 ResourceId id12 = allocator->AllocateIDRange(100);
165 EXPECT_EQ(101u, id12); 165 EXPECT_EQ(101u, id12);
166 166
167 ResourceId id13 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset - 2u); 167 ResourceId id13 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset - 2u);
168 EXPECT_EQ(kMaxPossibleOffset, id13); 168 EXPECT_EQ(kMaxPossibleOffset - 2u, id13);
169 ResourceId id14 = allocator->AllocateIDRange(3); 169 ResourceId id14 = allocator->AllocateIDRange(3);
170 EXPECT_EQ(201u, id14); 170 EXPECT_EQ(201u, id14);
171 } 171 }
172 172
173 TEST_F(IdAllocatorTest, AllocateIDRangeNoWrapInRange) { 173 TEST_F(IdAllocatorTest, AllocateIDRangeEndNoEffect) {
174 const ResourceId kMaxPossibleOffset = ~static_cast<ResourceId>(0); 174 const ResourceId kMaxPossibleOffset = ~static_cast<ResourceId>(0);
175 175
176 IdAllocator* allocator = id_allocator(); 176 IdAllocator* allocator = id_allocator();
177 ResourceId id1 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset - 2u); 177 ResourceId id1 = allocator->AllocateIDAtOrAbove(kMaxPossibleOffset - 2u);
178 EXPECT_EQ(kMaxPossibleOffset - 2u, id1); 178 EXPECT_EQ(kMaxPossibleOffset - 2u, id1);
179 ResourceId id3 = allocator->AllocateIDRange(3); 179 ResourceId id3 = allocator->AllocateIDRange(3);
180 EXPECT_EQ(1u, id3); 180 EXPECT_EQ(1u, id3);
181 ResourceId id2 = allocator->AllocateIDRange(2); 181 ResourceId id2 = allocator->AllocateIDRange(2);
182 EXPECT_EQ(kMaxPossibleOffset - 1, id2); 182 EXPECT_EQ(4u, id2);
183 }
184
185 TEST_F(IdAllocatorTest, AllocateFullIDRange) {
186 const uint32_t kMaxPossibleRange = ~static_cast<uint32_t>(0u);
187 const ResourceId kFreedId = 555u;
188 IdAllocator* allocator = id_allocator();
189
190 ResourceId id1 = allocator->AllocateIDRange(kMaxPossibleRange);
191 EXPECT_EQ(1u, id1);
192 ResourceId id2 = allocator->AllocateID();
193 EXPECT_EQ(0u, id2);
194 allocator->FreeID(kFreedId);
195 ResourceId id3 = allocator->AllocateID();
196 EXPECT_EQ(kFreedId, id3);
197 ResourceId id4 = allocator->AllocateID();
198 EXPECT_EQ(0u, id4);
199 allocator->FreeID(kFreedId + 1u);
200 allocator->FreeID(kFreedId + 3u);
201 allocator->FreeID(kFreedId + 2u);
202 allocator->FreeID(kFreedId + 5u);
203 allocator->FreeID(kFreedId + 4u);
204 ResourceId id5 = allocator->AllocateIDRange(5);
205 EXPECT_EQ(kFreedId + 1u, id5);
206 }
207
208 TEST_F(IdAllocatorTest, AllocateIDRangeNoWrapInRange) {
209 const uint32_t kMaxPossibleRange = ~static_cast<uint32_t>(0u);
210 const ResourceId kAllocId = 10u;
211 IdAllocator* allocator = id_allocator();
212
213 ResourceId id1 = allocator->AllocateIDAtOrAbove(kAllocId);
214 EXPECT_EQ(kAllocId, id1);
215 ResourceId id2 = allocator->AllocateIDRange(kMaxPossibleRange - 5u);
216 EXPECT_EQ(0u, id2);
217 }
218 TEST_F(IdAllocatorTest, AllocateIdMax) {
219 IdAllocator* allocator = id_allocator();
220 ResourceId id =
221 allocator->AllocateIDRange(std::numeric_limits<uint32_t>::max());
222 EXPECT_EQ(1u, id);
223 allocator->FreeIDRange(id, std::numeric_limits<uint32_t>::max() - 1u);
224 ResourceId id2 =
225 allocator->AllocateIDRange(std::numeric_limits<uint32_t>::max());
226 EXPECT_EQ(0u, id2);
227 allocator->FreeIDRange(id, std::numeric_limits<uint32_t>::max());
228 ResourceId id3 =
229 allocator->AllocateIDRange(std::numeric_limits<uint32_t>::max());
230 EXPECT_EQ(1u, id3);
183 } 231 }
184 232
185 } // namespace gpu 233 } // namespace gpu
OLDNEW
« no previous file with comments | « 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