From d7e98ba82a8e7173371dfffbfdfe9ef889023a9b Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:26:11 -0400 Subject: Add test for issue #2694 --- tests/issues/run.bat | 1 + tests/issues/run.sh | 1 + tests/issues/test_issue_2694.odin | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/issues/test_issue_2694.odin (limited to 'tests') diff --git a/tests/issues/run.bat b/tests/issues/run.bat index 8e71c3f3d..76d8f58b6 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -16,6 +16,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style ..\..\..\odin test ..\test_issue_2615.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_2637.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_2666.odin %COMMON% || exit /b +..\..\..\odin test ..\test_issue_2694.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_4210.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_4364.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_4584.odin %COMMON% || exit /b diff --git a/tests/issues/run.sh b/tests/issues/run.sh index fc8ab513f..305329e7d 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -17,6 +17,7 @@ $ODIN test ../test_issue_2466.odin $COMMON $ODIN test ../test_issue_2615.odin $COMMON $ODIN test ../test_issue_2637.odin $COMMON $ODIN test ../test_issue_2666.odin $COMMON +$ODIN test ../test_issue_2694.odin $COMMON $ODIN test ../test_issue_4210.odin $COMMON $ODIN test ../test_issue_4364.odin $COMMON $ODIN test ../test_issue_4584.odin $COMMON diff --git a/tests/issues/test_issue_2694.odin b/tests/issues/test_issue_2694.odin new file mode 100644 index 000000000..01860d603 --- /dev/null +++ b/tests/issues/test_issue_2694.odin @@ -0,0 +1,42 @@ +package test_issues + +import "core:fmt" +import "core:encoding/json" +import "core:log" +import "core:mem" +import "core:testing" + +// This is a minimal reproduction of the code in #2694. +// It exemplifies the original problem as briefly as possible. + +SAMPLE_JSON :: ` +{ + "foo": 0, + "things": [ + { "a": "ZZZZ"}, + ] +} +` + +@test +test_issue_2694 :: proc(t: ^testing.T) { + into: struct { + foo: int, + things: []json.Object, + } + + scratch := new(mem.Scratch_Allocator) + defer free(scratch) + if mem.scratch_allocator_init(scratch, 4 * mem.Megabyte) != .None { + log.error("unable to initialize scratch allocator") + return + } + defer mem.scratch_allocator_destroy(scratch) + + err := json.unmarshal_string(SAMPLE_JSON, &into, allocator = mem.scratch_allocator(scratch)) + testing.expect(t, err == nil) + + output := fmt.tprintf("%v", into) + expected := `{foo = 0, things = [map[a="ZZZZ"]]}` + testing.expectf(t, output == expected, "\n\texpected: %q\n\tgot: %q", expected, output) +} -- cgit v1.2.3 From 0b2cf9a4ca7e84fb7920a8d7b0d58b7d61f24a10 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Sun, 15 Jun 2025 13:16:19 -0400 Subject: Add a tiny sanity test for `core:mem` allocators --- tests/core/mem/test_core_mem.odin | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'tests') diff --git a/tests/core/mem/test_core_mem.odin b/tests/core/mem/test_core_mem.odin index bd072b4e9..c1cb59c68 100644 --- a/tests/core/mem/test_core_mem.odin +++ b/tests/core/mem/test_core_mem.odin @@ -193,3 +193,111 @@ fail_if_allocations_overlap :: proc(t: ^testing.T, a, b: []byte) { testing.fail_now(t, "Allocations overlapped") } } + + +// This merely does a few simple operations to test basic sanity. +// +// A serious test of an allocator would require hooking it up to a benchmark or +// a large, complicated program in order to get all manner of usage patterns. +basic_sanity_test :: proc(t: ^testing.T, allocator: mem.Allocator, limit: int, loc := #caller_location) -> bool { + context.allocator = allocator + + { + a := make([dynamic]u8) + for i in 0..