Skip to content

Commit 8c9a166

Browse files
committed
test(mem-alloc): add test runner and stubs
Create basic test infrastructure with helper functions. Fix INTERP setting and add include directories for ems headers.
1 parent 52ff880 commit 8c9a166

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

tests/unit/mem-alloc/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ add_definitions(-DWAMR_BUILD_TEST=1)
1111
# Test-specific feature configuration
1212
set(WAMR_BUILD_AOT 0)
1313
set(WAMR_BUILD_FAST_INTERP 0)
14-
set(WAMR_BUILD_INTERP 0)
14+
set(WAMR_BUILD_INTERP 1)
1515
set(WAMR_BUILD_JIT 0)
1616
set(WAMR_BUILD_LIBC_WASI 0)
1717
set(WAMR_BUILD_APP_FRAMEWORK 0)
@@ -27,6 +27,12 @@ set(TEST_SOURCES
2727
# Create test executable
2828
add_executable(mem-alloc-test ${TEST_SOURCES})
2929

30+
# Add include directories for mem-alloc internals
31+
target_include_directories(mem-alloc-test PRIVATE
32+
${WAMR_ROOT_DIR}/core/shared/mem-alloc
33+
${WAMR_ROOT_DIR}/core/shared/mem-alloc/ems
34+
)
35+
3036
# Link dependencies
3137
target_link_libraries(mem-alloc-test cmocka::cmocka m)
3238

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include <stdarg.h>
7+
#include <stddef.h>
8+
#include <setjmp.h>
9+
#include <stdint.h>
10+
#include <string.h>
11+
#include <cmocka.h>
12+
13+
#if WAMR_BUILD_TEST != 1
14+
#error "WAMR_BUILD_TEST must be defined as 1"
15+
#endif
16+
17+
#include "mem_alloc.h"
18+
#include "ems_gc_internal.h"
19+
20+
/* Test helper: Check if pointer is aligned */
21+
static inline bool
22+
is_aligned(void *ptr, size_t alignment)
23+
{
24+
return ((uintptr_t)ptr % alignment) == 0;
25+
}
26+
27+
/* Test helper: Check if allocation is aligned (has magic value) */
28+
static inline bool
29+
is_aligned_allocation(gc_object_t obj)
30+
{
31+
uint32_t *magic_ptr = (uint32_t *)((char *)obj - 4);
32+
return ((*magic_ptr & ALIGNED_ALLOC_MAGIC_MASK) == ALIGNED_ALLOC_MAGIC_VALUE);
33+
}
34+
35+
/* Tests will be added incrementally */

tests/unit/mem-alloc/test_runner.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include <stdarg.h>
7+
#include <stddef.h>
8+
#include <setjmp.h>
9+
#include <stdint.h>
10+
#include <cmocka.h>
11+
12+
/* Include test implementations */
13+
#include "mem_alloc_test.c"
14+
15+
int
16+
main(void)
17+
{
18+
const struct CMUnitTest tests[] = {
19+
/* Tests will be added incrementally */
20+
};
21+
22+
return cmocka_run_group_tests(tests, NULL, NULL);
23+
}

0 commit comments

Comments
 (0)