Skip to content

Commit 0bca5d7

Browse files
committed
Corrections
1 parent e575e6a commit 0bca5d7

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

examples_tests/10.AllocatorTest/main.cpp

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ using namespace core;
1212

1313
#define kHardwareInstancesTOTAL (kNumHardwareInstancesX*kNumHardwareInstancesY*kNumHardwareInstancesZ)
1414

15-
16-
//!Same As Last Example
1715
class MyEventReceiver : public IEventReceiver
1816
{
1917
public:
@@ -42,8 +40,8 @@ class MyEventReceiver : public IEventReceiver
4240
private:
4341
};
4442

45-
constexpr size_t minTestsCnt = 10000u;
46-
constexpr size_t maxTestsCnt = 20000u;
43+
constexpr size_t minTestsCnt = 100u;
44+
constexpr size_t maxTestsCnt = 200u;
4745
constexpr size_t maxAlignmentExp = 12u; // 4096
4846
constexpr size_t minVirtualMemoryBufferSize = 2048; // 2kB
4947
constexpr size_t maxVirtualMemoryBufferSize = 2147483648; // 2GB
@@ -89,9 +87,32 @@ class AllocatorHandler
8987
public:
9088
void executeAllocatorTest()
9189
{
92-
const uint32_t testsCnt = rng.getRndAllocCnt();
93-
for (size_t i = 0; i < testsCnt; ++i)
94-
executeForFrame();
90+
uint32_t testsCnt = rng.getRndAllocCnt();
91+
92+
for (size_t i = 0; i < testsCnt; i++)
93+
{
94+
AlctrType alctr;
95+
RandParams randAllocParams = getRandParams();
96+
void* reservedSpace = nullptr;
97+
98+
if constexpr (std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t>>::value)
99+
{
100+
alctr = AlctrType(nullptr, randAllocParams.offset, randAllocParams.alignOffset, randAllocParams.maxAlign, randAllocParams.addressSpaceSize);
101+
}
102+
else
103+
{
104+
const auto reservedSize = AlctrType::reserved_size(randAllocParams.maxAlign, randAllocParams.addressSpaceSize, randAllocParams.blockSz);
105+
reservedSpace = _NBL_ALIGNED_MALLOC(reservedSize, _NBL_SIMD_ALIGNMENT);
106+
alctr = AlctrType(reservedSpace, randAllocParams.offset, randAllocParams.alignOffset, randAllocParams.maxAlign, randAllocParams.addressSpaceSize, randAllocParams.blockSz);
107+
}
108+
109+
testsCnt = rng.getRndAllocCnt();
110+
for (size_t i = 0; i < testsCnt; i++)
111+
executeForFrame(alctr, randAllocParams);
112+
113+
if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t>>::value)
114+
_NBL_ALIGNED_FREE(reservedSpace);
115+
}
95116
}
96117

97118
private:
@@ -112,23 +133,8 @@ class AllocatorHandler
112133
};
113134

114135
private:
115-
void executeForFrame()
136+
void executeForFrame(AlctrType& alctr, RandParams& randAllocParams)
116137
{
117-
RandParams randAllocParams = getRandParams();
118-
void* reservedSpace = nullptr;
119-
AlctrType alctr;
120-
121-
if constexpr (std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t>>::value)
122-
{
123-
alctr = AlctrType(nullptr, randAllocParams.offset, randAllocParams.alignOffset, randAllocParams.maxAlign, randAllocParams.addressSpaceSize);
124-
}
125-
else
126-
{
127-
const auto reservedSize = AlctrType::reserved_size(randAllocParams.maxAlign, randAllocParams.addressSpaceSize, randAllocParams.blockSz);
128-
reservedSpace = _NBL_ALIGNED_MALLOC(reservedSize, _NBL_SIMD_ALIGNMENT);
129-
alctr = AlctrType(reservedSpace, randAllocParams.offset, randAllocParams.alignOffset, randAllocParams.maxAlign, randAllocParams.addressSpaceSize, randAllocParams.blockSz);
130-
}
131-
132138
// randomly decide how many `multi_allocs` to do
133139
const uint32_t multiAllocCnt = rng.getRandomNumber(1u, 500u);
134140
for (uint32_t i = 0u; i < multiAllocCnt; i++)
@@ -166,10 +172,11 @@ class AllocatorHandler
166172
randFreeAllocatedAddresses(alctr);
167173
}
168174
}
169-
170-
if constexpr (!std::is_same<AlctrType, core::LinearAddressAllocator<uint32_t>>::value)
171-
_NBL_ALIGNED_FREE(reservedSpace);
172-
175+
else
176+
{
177+
alctr.reset();
178+
results.clear();
179+
}
173180
}
174181

175182
// random dealloc function
@@ -284,13 +291,18 @@ class AllocatorHandler
284291
template<>
285292
void AllocatorHandler<core::LinearAddressAllocator<uint32_t>>::randFreeAllocatedAddresses(core::LinearAddressAllocator<uint32_t>& alctr)
286293
{
287-
alctr.reset();
288-
results.clear();
294+
const bool performReset = rng.getRandomNumber(1, 10) == 1 ? true : false;
295+
296+
if (performReset)
297+
{
298+
alctr.reset();
299+
results.clear();
300+
}
289301
}
290302

291303
int main()
292304
{
293-
305+
294306
// Allocator test
295307
{
296308
{

0 commit comments

Comments
 (0)