1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2024-12-01 13:24:20 +01:00

started writing some unit tests for CPA as it's finnicky

This commit is contained in:
Unknown 2020-03-07 18:07:07 +00:00
parent 1092d59612
commit db18a1695c
2 changed files with 51 additions and 2 deletions

View File

@ -46,7 +46,9 @@ void destroyConsecutivePoolAllocator(ConsecutivePoolAllocator* pa)
//allocate numBlocks consecutive memory
void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks)
{
assert(pa);
assert(pa->buf);
assert(numBlocks);
//CPAdebugPrint(pa);
@ -85,7 +87,7 @@ void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks)
}
//TODO debug stuff, not for release
memset(ptr, 0, numBlocks * pa->blockSize);
if(ptr) memset(ptr, 0, numBlocks * pa->blockSize);
return ptr;
}
@ -93,6 +95,7 @@ void* consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks)
//free numBlocks consecutive memory
void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBlocks)
{
assert(pa);
assert(pa->buf);
assert(p);
assert(numBlocks);
@ -166,6 +169,11 @@ void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBloc
void* consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks)
{
assert(pa);
assert(pa->buf);
assert(currentMem);
assert(currNumBlocks);
fprintf(stderr, "CPA realloc\n");
uint32_t* nextCandidate = (char*)currentMem + pa->blockSize * currNumBlocks;

View File

@ -52,8 +52,49 @@ void simpleTest()
CPAdebugPrint(&cpa);
}
void allocTest(uint32_t numToAlloc)
{
uint32_t blocksize = 16;
uint32_t numblocks = 8;
uint32_t size = numblocks * blocksize;
ConsecutivePoolAllocator cpa = createConsecutivePoolAllocator((char*)malloc(size), blocksize, size);
//CPAdebugPrint(&cpa);
void* mem1 = consecutivePoolAllocate(&cpa, numToAlloc);
CPAdebugPrint(&cpa);
fprintf(stderr, "\nmem %p\n", mem1);
}
void freeOneTest(uint32_t which)
{
uint32_t blocksize = 16;
uint32_t numblocks = 8;
uint32_t size = numblocks * blocksize;
ConsecutivePoolAllocator cpa = createConsecutivePoolAllocator((char*)malloc(size), blocksize, size);
//CPAdebugPrint(&cpa);
void* mem[8];
for(uint32_t c = 0; c < 8; ++c)
{
mem[c] = consecutivePoolAllocate(&cpa, 1);
}
consecutivePoolFree(&cpa, mem[which], 1);
CPAdebugPrint(&cpa);
//fprintf(stderr, "\nmem %p\n", mem);
}
int main() {
simpleTest();
//simpleTest();
allocTest(1);
allocTest(3);
allocTest(8);
allocTest(9);
return 0;
}