2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2019-11-27 01:12:25 +03:00
|
|
|
#include <stdio.h>
|
2021-03-13 02:00:22 +03:00
|
|
|
#include <stdlib.h>
|
2019-11-27 01:12:25 +03:00
|
|
|
#include "allocator.h"
|
|
|
|
|
2021-03-13 02:00:22 +03:00
|
|
|
void alloc_all(int size)
|
2019-11-27 01:12:25 +03:00
|
|
|
{
|
2021-03-13 02:00:22 +03:00
|
|
|
allocator *a = new allocator(size);
|
|
|
|
for (int i = 0; i < size; i++)
|
2019-11-27 01:12:25 +03:00
|
|
|
{
|
2021-03-13 02:00:22 +03:00
|
|
|
uint64_t x = a->find_free();
|
2019-11-27 01:12:25 +03:00
|
|
|
if (x == UINT64_MAX)
|
|
|
|
{
|
2021-03-13 02:00:22 +03:00
|
|
|
printf("ran out of space %d allocated=%d\n", size, i);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (x != i)
|
|
|
|
{
|
|
|
|
printf("incorrect block allocated: expected %d, got %lu\n", i, x);
|
2019-11-27 01:12:25 +03:00
|
|
|
}
|
2021-03-28 00:16:12 +03:00
|
|
|
if (a->get(x))
|
|
|
|
{
|
|
|
|
printf("not free before set at %d\n", i);
|
|
|
|
}
|
2021-03-13 02:00:22 +03:00
|
|
|
a->set(x, true);
|
2021-03-28 00:16:12 +03:00
|
|
|
if (!a->get(x))
|
|
|
|
{
|
|
|
|
printf("free after set at %d\n", i);
|
|
|
|
}
|
2021-03-13 02:00:22 +03:00
|
|
|
}
|
|
|
|
uint64_t x = a->find_free();
|
|
|
|
if (x != UINT64_MAX)
|
|
|
|
{
|
|
|
|
printf("extra free space found: %lx (%d)\n", x, size);
|
|
|
|
exit(1);
|
2019-11-27 01:12:25 +03:00
|
|
|
}
|
2021-03-13 02:00:22 +03:00
|
|
|
delete a;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int narg, char *args[])
|
|
|
|
{
|
|
|
|
alloc_all(8192);
|
|
|
|
alloc_all(8062);
|
|
|
|
alloc_all(4096);
|
2019-11-27 01:12:25 +03:00
|
|
|
return 0;
|
|
|
|
}
|