Skip to content

Commit 9a6979d

Browse files
committed
test(mem-alloc): add normal allocation regression test
Verify existing mem_allocator_malloc still works correctly.
1 parent 8c9a166 commit 9a6979d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tests/unit/mem-alloc/mem_alloc_test.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,29 @@ is_aligned_allocation(gc_object_t obj)
3232
return ((*magic_ptr & ALIGNED_ALLOC_MAGIC_MASK) == ALIGNED_ALLOC_MAGIC_VALUE);
3333
}
3434

35-
/* Tests will be added incrementally */
35+
/* Test: Normal allocation still works (regression) */
36+
static void
37+
test_normal_alloc_basic(void **state)
38+
{
39+
mem_allocator_t allocator;
40+
char heap_buf[64 * 1024];
41+
void *ptr;
42+
43+
allocator = mem_allocator_create(heap_buf, sizeof(heap_buf));
44+
assert_non_null(allocator);
45+
46+
/* Normal allocation should still work */
47+
ptr = mem_allocator_malloc(allocator, 128);
48+
assert_non_null(ptr);
49+
50+
/* Should be 8-byte aligned */
51+
assert_true(is_aligned(ptr, 8));
52+
53+
/* Should NOT be marked as aligned allocation */
54+
assert_false(is_aligned_allocation(ptr));
55+
56+
/* Free should work */
57+
mem_allocator_free(allocator, ptr);
58+
59+
mem_allocator_destroy(allocator);
60+
}

tests/unit/mem-alloc/test_runner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int
1616
main(void)
1717
{
1818
const struct CMUnitTest tests[] = {
19-
/* Tests will be added incrementally */
19+
cmocka_unit_test(test_normal_alloc_basic),
2020
};
2121

2222
return cmocka_run_group_tests(tests, NULL, NULL);

0 commit comments

Comments
 (0)