mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
add other failing test and fix them
This commit is contained in:
@@ -103,13 +103,13 @@ arena_alloc :: proc(arena: ^Arena, size, alignment: uint, loc := #caller_locatio
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if arena.curr_block == nil || (safe_add(arena.curr_block.used, size) or_else 0) > arena.curr_block.capacity {
|
needed := align_forward_uint(size, alignment)
|
||||||
size = align_forward_uint(size, alignment)
|
if arena.curr_block == nil || (safe_add(arena.curr_block.used, needed) or_else 0) > arena.curr_block.capacity {
|
||||||
if arena.minimum_block_size == 0 {
|
if arena.minimum_block_size == 0 {
|
||||||
arena.minimum_block_size = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE
|
arena.minimum_block_size = DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
block_size := max(size, arena.minimum_block_size)
|
block_size := max(needed, arena.minimum_block_size)
|
||||||
|
|
||||||
if arena.backing_allocator.procedure == nil {
|
if arena.backing_allocator.procedure == nil {
|
||||||
arena.backing_allocator = default_allocator()
|
arena.backing_allocator = default_allocator()
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ main :: proc() {
|
|||||||
|
|
||||||
test_temp_allocator_big_alloc_and_alignment(&t)
|
test_temp_allocator_big_alloc_and_alignment(&t)
|
||||||
test_temp_allocator_alignment_boundary(&t)
|
test_temp_allocator_alignment_boundary(&t)
|
||||||
|
test_temp_allocator_returns_correct_size(&t)
|
||||||
|
|
||||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
||||||
if TEST_fail > 0 {
|
if TEST_fail > 0 {
|
||||||
@@ -59,3 +60,13 @@ test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) {
|
|||||||
err := reserve(&mappy, 50000)
|
err := reserve(&mappy, 50000)
|
||||||
expect_value(t, err, nil)
|
expect_value(t, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_temp_allocator_returns_correct_size :: proc(t: ^testing.T) {
|
||||||
|
arena: runtime.Arena
|
||||||
|
context.allocator = runtime.arena_allocator(&arena)
|
||||||
|
|
||||||
|
bytes, err := mem.alloc_bytes(10, 16)
|
||||||
|
expect_value(t, err, nil)
|
||||||
|
expect_value(t, len(bytes), 10)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user