79 lines
2.5 KiB
C
79 lines
2.5 KiB
C
#include "malunal/allocators/arena.h"
|
|
#include "malunal/microtest.h"
|
|
|
|
MICROTEST(arena_allocator, can_init_and_free) {
|
|
error_t result = {};
|
|
arena_allocator_t allocator = {};
|
|
malunal_uint32_t temporary = 0;
|
|
|
|
result = arena_allocator_init(500, &allocator);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
|
|
result = arena_allocator_size(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, platform_page_size());
|
|
|
|
result = arena_allocator_used(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 16);
|
|
|
|
result = arena_allocator_free(&allocator);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
|
|
result = arena_allocator_size(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 0);
|
|
|
|
result = arena_allocator_used(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 0);
|
|
}
|
|
|
|
MICROTEST(arena_allocator, can_acquire_and_dispose) {
|
|
error_t result = {};
|
|
arena_allocator_t allocator = {};
|
|
malunal_mptr_t address = null;
|
|
malunal_uint32_t temporary = 0;
|
|
|
|
arena_allocator_init(500, &allocator);
|
|
result = arena_allocator_acquire(&allocator, 64, &address);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_ASSERT_NOT_NULL(address);
|
|
|
|
result = arena_allocator_used(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 80);
|
|
|
|
result = arena_allocator_dispose(&allocator, address, 64);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
|
|
result = arena_allocator_used(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 80);
|
|
arena_allocator_free(&allocator);
|
|
}
|
|
|
|
MICROTEST(arena_allocator, can_reset_allocator) {
|
|
error_t result = {};
|
|
arena_allocator_t allocator = {};
|
|
malunal_mptr_t address = null;
|
|
malunal_uint32_t temporary = 0;
|
|
|
|
arena_allocator_init(500, &allocator);
|
|
result = arena_allocator_acquire(&allocator, 64, &address);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_ASSERT_NOT_NULL(address);
|
|
|
|
result = arena_allocator_used(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 80);
|
|
|
|
result = arena_allocator_reset(&allocator);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
|
|
result = arena_allocator_used(&allocator, &temporary);
|
|
MICROTEST_EXPECT_NULL(result.domain);
|
|
MICROTEST_EXPECT_EQ(temporary, 16);
|
|
arena_allocator_free(&allocator);
|
|
}
|