@@ -106,9 +106,8 @@ class AllocatorHandler
106
106
alctr = AlctrType (reservedSpace, randAllocParams.offset , randAllocParams.alignOffset , randAllocParams.maxAlign , randAllocParams.addressSpaceSize , randAllocParams.blockSz );
107
107
}
108
108
109
- // variable shadowing and other problems @Przemog
110
- testsCnt = rng.getRndAllocCnt ();
111
- for (size_t i = 0 ; i < testsCnt; i++)
109
+ uint32_t subTestsCnt = rng.getRndAllocCnt ();
110
+ for (size_t i = 0 ; i < subTestsCnt; i++)
112
111
executeForFrame (alctr, randAllocParams);
113
112
114
113
if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t >>::value)
@@ -122,6 +121,19 @@ class AllocatorHandler
122
121
uint32_t outAddr = AlctrType::invalid_address;
123
122
uint32_t size = 0u ;
124
123
uint32_t align = 0u ;
124
+
125
+ inline bool operator ==(const AllocationData& other) const
126
+ {
127
+ return outAddr==other.outAddr ;
128
+ }
129
+
130
+ struct Hash
131
+ {
132
+ inline size_t operator ()(const AllocationData& _this) const
133
+ {
134
+ return std::hash<uint32_t >()(_this.outAddr );
135
+ }
136
+ };
125
137
};
126
138
127
139
struct RandParams
@@ -146,11 +158,13 @@ class AllocatorHandler
146
158
Traits::multi_alloc_addr (alctr, addressesToAllcate, allocDataSoA.outAddresses .data (), allocDataSoA.sizes .data (), allocDataSoA.alignments .data ());
147
159
148
160
// record all successful alloc addresses to the `core::vector`
161
+ if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t >>::value)
149
162
for (uint32_t j = 0u ; j < allocDataSoA.size ; j++)
150
163
{
151
164
if (allocDataSoA.outAddresses [j] != AlctrType::invalid_address)
152
165
results.push_back ({ allocDataSoA.outAddresses [j], allocDataSoA.sizes [j], allocDataSoA.alignments [j] });
153
166
}
167
+ checkStillIteratable (alctr);
154
168
155
169
// run random dealloc function
156
170
randFreeAllocatedAddresses (alctr);
@@ -173,10 +187,7 @@ class AllocatorHandler
173
187
}
174
188
}
175
189
else
176
- {
177
190
alctr.reset ();
178
- results.clear ();
179
- }
180
191
}
181
192
182
193
// random dealloc function
@@ -188,10 +199,8 @@ class AllocatorHandler
188
199
// randomly decide how many calls to `multi_free`
189
200
const uint32_t multiFreeCnt = rng.getRandomNumber (1u , results.size ());
190
201
191
- if (std::is_same<AlctrType, core::GeneralpurposeAddressAllocator<uint32_t >>::value)
192
- {
202
+ if constexpr (Traits::supportsArbitraryOrderFrees)
193
203
std::shuffle (results.begin (), results.end (), rng.getMt ());
194
- }
195
204
196
205
for (uint32_t i = 0u ; (i < multiFreeCnt) && results.size (); i++)
197
206
{
@@ -210,6 +219,7 @@ class AllocatorHandler
210
219
211
220
Traits::multi_free_addr (alctr, addressesToFreeCnt, allocDataSoA.outAddresses .data (), allocDataSoA.sizes .data ());
212
221
results.erase (results.end () - addressesToFreeCnt, results.end ());
222
+ checkStillIteratable (alctr);
213
223
}
214
224
}
215
225
@@ -231,6 +241,19 @@ class AllocatorHandler
231
241
232
242
private:
233
243
core::vector<AllocationData> results;
244
+ inline void checkStillIteratable (const AlctrType& alctr)
245
+ {
246
+ if constexpr (std::is_same<AlctrType, core::IteratablePoolAddressAllocator<uint32_t >>::value)
247
+ {
248
+ core::unordered_set<AllocationData,AllocationData::Hash> allocationSet (results.begin (),results.end ());
249
+ for (auto addr : alctr)
250
+ {
251
+ AllocationData dummy; dummy.outAddr = addr;
252
+ if (allocationSet.find (dummy)==allocationSet.end ())
253
+ exit (34 );
254
+ }
255
+ }
256
+ }
234
257
235
258
// these hold inputs for `multi_alloc_addr` and `multi_free_addr`
236
259
@@ -247,7 +270,7 @@ class AllocatorHandler
247
270
{
248
271
// randomly decide sizes (but always less than `address_allocator_traits::max_size`)
249
272
250
- if constexpr (std::is_same <AlctrType, core::PoolAddressAllocator<uint32_t >>::value )
273
+ if constexpr (std::is_same_v <AlctrType,core::PoolAddressAllocator<uint32_t >>||std::is_same_v<AlctrType,core::IteratablePoolAddressAllocator< uint32_t >> )
251
274
{
252
275
sizes[j] = randAllocParams.blockSz ;
253
276
alignments[j] = randAllocParams.blockSz ;
@@ -310,6 +333,11 @@ int main()
310
333
poolAlctrHandler.executeAllocatorTest ();
311
334
}
312
335
336
+ {
337
+ AllocatorHandler<core::IteratablePoolAddressAllocator<uint32_t >> iterPoolAlctrHandler;
338
+ iterPoolAlctrHandler.executeAllocatorTest ();
339
+ }
340
+
313
341
{
314
342
AllocatorHandler<core::LinearAddressAllocator<uint32_t >> linearAlctrHandler;
315
343
linearAlctrHandler.executeAllocatorTest ();
@@ -336,6 +364,8 @@ int main()
336
364
nbl::core::address_allocator_traits<core::StackAddressAllocatorST<uint32_t > >::printDebugInfo ();
337
365
printf (" Pool \n " );
338
366
nbl::core::address_allocator_traits<core::PoolAddressAllocatorST<uint32_t > >::printDebugInfo ();
367
+ printf (" IteratablePool \n " );
368
+ nbl::core::address_allocator_traits<core::IteratablePoolAddressAllocatorST<uint32_t > >::printDebugInfo ();
339
369
printf (" General \n " );
340
370
nbl::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorST<uint32_t > >::printDebugInfo ();
341
371
@@ -344,6 +374,8 @@ int main()
344
374
nbl::core::address_allocator_traits<core::LinearAddressAllocatorMT<uint32_t , std::recursive_mutex> >::printDebugInfo ();
345
375
printf (" Pool \n " );
346
376
nbl::core::address_allocator_traits<core::PoolAddressAllocatorMT<uint32_t , std::recursive_mutex> >::printDebugInfo ();
377
+ printf (" Iteratable Pool \n " );
378
+ nbl::core::address_allocator_traits<core::IteratablePoolAddressAllocatorMT<uint32_t , std::recursive_mutex> >::printDebugInfo ();
347
379
printf (" General \n " );
348
380
nbl::core::address_allocator_traits<core::GeneralpurposeAddressAllocatorMT<uint32_t , std::recursive_mutex> >::printDebugInfo ();
349
381
}
0 commit comments