Skip to content

Commit e3aa5e0

Browse files
committed
feat(mem-alloc): enhance memory allocation tests and add GC test executable
1 parent f678b6c commit e3aa5e0

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.*
2+
!.gitignore
13

24
.cache
35
.clangd

tests/unit/mem-alloc/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ set(TEST_SOURCES
2424
${WAMR_RUNTIME_LIB_SOURCE}
2525
)
2626

27+
#
2728
# Create test executable
29+
#
30+
31+
## Normal test executable
2832
add_executable(mem-alloc-test ${TEST_SOURCES})
2933

3034
# Add include directories for mem-alloc internals
@@ -33,9 +37,24 @@ target_include_directories(mem-alloc-test PRIVATE
3337
${WAMR_ROOT_DIR}/core/shared/mem-alloc/ems
3438
)
3539

40+
## GC test executable
41+
add_executable(mem-alloc-gc-test ${TEST_SOURCES})
42+
43+
target_include_directories(mem-alloc-gc-test PRIVATE
44+
${WAMR_ROOT_DIR}/core/shared/mem-alloc
45+
${WAMR_ROOT_DIR}/core/shared/mem-alloc/ems
46+
)
47+
48+
target_compile_options(mem-alloc-gc-test PRIVATE -DWAMR_BUILD_GC=1 -DWAMR_BUILD_GC_VERIFY=1)
49+
50+
3651
# Link dependencies
3752
target_link_libraries(mem-alloc-test cmocka::cmocka m)
53+
target_link_libraries(mem-alloc-gc-test cmocka::cmocka m)
3854

3955
# Add to ctest
4056
add_test(NAME mem-alloc-test COMMAND mem-alloc-test)
4157
set_tests_properties(mem-alloc-test PROPERTIES TIMEOUT 60)
58+
59+
add_test(NAME mem-alloc-gc-test COMMAND mem-alloc-gc-test)
60+
set_tests_properties(mem-alloc-gc-test PROPERTIES TIMEOUT 60)

tests/unit/mem-alloc/mem_alloc_test.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ test_aligned_alloc_valid_alignments(void **state)
7272

7373
/* Test each valid alignment */
7474
int alignments[] = {8, 16, 32, 64, 128, 256, 512, 1024};
75-
for (int i = 0; i < sizeof(alignments) / sizeof(alignments[0]); i++) {
75+
int num_alignments = sizeof(alignments) / sizeof(alignments[0]);
76+
for (int i = 0; i < num_alignments; i++) {
7677
int align = alignments[i];
7778

7879
/* Allocate with size = multiple of alignment */
@@ -162,7 +163,9 @@ test_aligned_alloc_invalid_not_power_of_2(void **state)
162163

163164
/* These should all fail (zero or not power of 2) */
164165
int invalid_alignments[] = {0, 3, 5, 7, 9, 15, 17, 100};
165-
for (int i = 0; i < sizeof(invalid_alignments) / sizeof(invalid_alignments[0]); i++) {
166+
int num_invalid =
167+
sizeof(invalid_alignments) / sizeof(invalid_alignments[0]);
168+
for (int i = 0; i < num_invalid; i++) {
166169
ptr = mem_allocator_malloc_aligned(allocator, 128, invalid_alignments[i]);
167170
assert_null(ptr);
168171
}

0 commit comments

Comments
 (0)