add failing test for runtime arena edge case

This commit is contained in:
Laytan Laats
2023-12-18 14:40:49 +01:00
parent 67d02043fe
commit 6024af172c
3 changed files with 71 additions and 1 deletions

View File

@@ -20,7 +20,8 @@ all: c_libc_test \
reflect_test \
slice_test \
strings_test \
thread_test
thread_test \
runtime_test
download_test_assets:
$(PYTHON) download_assets.py
@@ -84,3 +85,6 @@ fmt_test:
thread_test:
$(ODIN) run thread -out:test_core_thread
runtime_test:
$(ODIN) run runtime -out:test_core_runtime

View File

@@ -95,3 +95,8 @@ echo ---
echo Running core:thread tests
echo ---
%PATH_TO_ODIN% run thread %COMMON% %COLLECTION% -out:test_core_thread.exe || exit /b
echo ---
echo Running core:runtime tests
echo ---
%PATH_TO_ODIN% run runtime %COMMON% %COLLECTION% -out:test_core_runtime.exe || exit /b

View File

@@ -0,0 +1,61 @@
package test_core_runtime
import "core:fmt"
import "core:intrinsics"
import "core:mem"
import "core:os"
import "core:reflect"
import "core:runtime"
import "core:testing"
TEST_count := 0
TEST_fail := 0
when ODIN_TEST {
expect_value :: testing.expect_value
} else {
expect_value :: proc(t: ^testing.T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) {
TEST_count += 1
ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected)
if !ok {
TEST_fail += 1
fmt.printf("[%v] expected %v, got %v\n", loc, expected, value)
}
return ok
}
}
main :: proc() {
t := testing.T{}
test_temp_allocator_alignment_boundary(&t)
test_temp_allocator_big_alloc_and_alignment(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
os.exit(1)
}
}
// Tests that having space for the allocation, but not for the allocation and alignment
// is handled correctly.
@(test)
test_temp_allocator_alignment_boundary :: proc(t: ^testing.T) {
arena: runtime.Arena
context.allocator = runtime.arena_allocator(&arena)
_, _ = mem.alloc(int(runtime.DEFAULT_ARENA_GROWING_MINIMUM_BLOCK_SIZE)-120)
_, err := mem.alloc(112, 32)
expect_value(t, err, nil)
}
// Tests that big allocations with big alignments are handled correctly.
@(test)
test_temp_allocator_big_alloc_and_alignment :: proc(t: ^testing.T) {
arena: runtime.Arena
context.allocator = runtime.arena_allocator(&arena)
mappy: map[[8]int]int
err := reserve(&mappy, 50000)
expect_value(t, err, nil)
}