From 7df5be2131b25d638a3aed31054a58a63be66e11 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 12 Feb 2025 19:09:21 +0100 Subject: fix wrong out of memory in edge cases, just try allocate from block for one source of truth --- tests/core/mem/test_core_mem.odin | 16 +++++++++++++++- tests/core/runtime/test_core_runtime.odin | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/core/mem/test_core_mem.odin b/tests/core/mem/test_core_mem.odin index d282ae1fd..3a1517747 100644 --- a/tests/core/mem/test_core_mem.odin +++ b/tests/core/mem/test_core_mem.odin @@ -1,6 +1,7 @@ package test_core_mem import "core:mem/tlsf" +import "core:mem/virtual" import "core:testing" @test @@ -38,4 +39,17 @@ test_tlsf_bitscan :: proc(t: ^testing.T) { testing.expectf(t, res == test.exp, "Expected tlsf.fls_uint(0x%16x) == %v, got %v", test.v, test.exp, res) } } -} \ No newline at end of file +} + +@(test) +test_align_bumping_block_limit :: proc(t: ^testing.T) { + a: virtual.Arena + + data, err := virtual.arena_alloc(&a, 4193371, 1) + testing.expect_value(t, err, nil) + testing.expect(t, len(data) == 4193371) + + data, err = virtual.arena_alloc(&a, 896, 64) + testing.expect_value(t, err, nil) + testing.expect(t, len(data) == 896) +} diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin index be6c24c72..0d02ae2d8 100644 --- a/tests/core/runtime/test_core_runtime.odin +++ b/tests/core/runtime/test_core_runtime.odin @@ -31,6 +31,20 @@ test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) { testing.expect(t, err == nil) } +@(test) +test_align_bumping_block_limit :: proc(t: ^testing.T) { + a: runtime.Arena + a.minimum_block_size = 8*mem.Megabyte + + data, err := runtime.arena_alloc(&a, 4193371, 1) + testing.expect_value(t, err, nil) + testing.expect(t, len(data) == 4193371) + + data, err = runtime.arena_alloc(&a, 896, 64) + testing.expect_value(t, err, nil) + testing.expect(t, len(data) == 896) +} + @(test) test_temp_allocator_returns_correct_size :: proc(t: ^testing.T) { arena: runtime.Arena -- cgit v1.2.3 From ae0f69fbe28b3ee6764da999cccea9b14ac80e36 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 12 Feb 2025 19:13:16 +0100 Subject: cleanup test arenas --- tests/core/mem/test_core_mem.odin | 1 + tests/core/runtime/test_core_runtime.odin | 1 + 2 files changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/core/mem/test_core_mem.odin b/tests/core/mem/test_core_mem.odin index 3a1517747..4f2095fca 100644 --- a/tests/core/mem/test_core_mem.odin +++ b/tests/core/mem/test_core_mem.odin @@ -44,6 +44,7 @@ test_tlsf_bitscan :: proc(t: ^testing.T) { @(test) test_align_bumping_block_limit :: proc(t: ^testing.T) { a: virtual.Arena + defer virtual.arena_destroy(&a) data, err := virtual.arena_alloc(&a, 4193371, 1) testing.expect_value(t, err, nil) diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin index 0d02ae2d8..472a5527d 100644 --- a/tests/core/runtime/test_core_runtime.odin +++ b/tests/core/runtime/test_core_runtime.odin @@ -35,6 +35,7 @@ test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) { test_align_bumping_block_limit :: proc(t: ^testing.T) { a: runtime.Arena a.minimum_block_size = 8*mem.Megabyte + defer runtime.arena_destroy(&a) data, err := runtime.arena_alloc(&a, 4193371, 1) testing.expect_value(t, err, nil) -- cgit v1.2.3