add testcases for shared heap and fix POP_MEM_OFFSET of memory64 (#3916)
- add testcases for shared_heap - fix POP_MEM_OFFSET and POP_TBL_ELEM_IDX of memory64 Signed-off-by: wenlingyun1 <wenlingyun1@xiaomi.com>
This commit is contained in:
@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.14)
|
||||
project(wasm-apps)
|
||||
|
||||
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
|
||||
set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler/build)
|
||||
|
||||
set(CMAKE_SYSTEM_PROCESSOR wasm32)
|
||||
set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot)
|
||||
@ -36,4 +37,36 @@ add_custom_command(TARGET test.wasm POST_BUILD
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test.wasm
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
COMMENT "Copy test.wasm to the same directory of google test"
|
||||
)
|
||||
)
|
||||
|
||||
add_custom_command(TARGET test.wasm POST_BUILD
|
||||
COMMAND ${WAMRC_ROOT_DIR}/wamrc --opt-level=0 --enable-shared-heap --bounds-checks=1
|
||||
-o
|
||||
test.aot
|
||||
test.wasm
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test.aot
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
COMMENT "Copy test.aot to the same directory of google test"
|
||||
)
|
||||
|
||||
add_executable(test_addr_conv.wasm test_addr_conv.c)
|
||||
target_link_libraries(test.wasm)
|
||||
|
||||
add_custom_command(TARGET test_addr_conv.wasm POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.wasm
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
COMMENT "Copy test_addr_conv.wasm to the same directory of google test"
|
||||
)
|
||||
|
||||
add_custom_command(TARGET test_addr_conv.wasm POST_BUILD
|
||||
COMMAND ${WAMRC_ROOT_DIR}/wamrc --opt-level=0 --enable-shared-heap --bounds-checks=1
|
||||
-o
|
||||
test_addr_conv.aot
|
||||
test_addr_conv.wasm
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.aot
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||
COMMENT "Copy test_addr_conv.aot to the same directory of google test"
|
||||
)
|
||||
|
||||
@ -13,10 +13,22 @@ shared_heap_free(void *offset);
|
||||
int
|
||||
test()
|
||||
{
|
||||
int *ptr = (int *)shared_heap_malloc(10);
|
||||
int *ptr = (int *)shared_heap_malloc(4);
|
||||
|
||||
*ptr = 10;
|
||||
int a = *ptr;
|
||||
shared_heap_free(ptr);
|
||||
return a;
|
||||
}
|
||||
|
||||
int
|
||||
test_malloc_fail()
|
||||
{
|
||||
int *ptr = (int *)shared_heap_malloc(8192);
|
||||
|
||||
if (ptr == NULL) {
|
||||
return 1;
|
||||
}
|
||||
shared_heap_free(ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
32
tests/unit/shared-heap/wasm-apps/test_addr_conv.c
Normal file
32
tests/unit/shared-heap/wasm-apps/test_addr_conv.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern void *
|
||||
shared_heap_malloc(int size);
|
||||
extern void
|
||||
shared_heap_free(void *offset);
|
||||
extern void *
|
||||
test_addr_conv(void *ptr);
|
||||
|
||||
int
|
||||
test()
|
||||
{
|
||||
int *ptr = NULL;
|
||||
int *ptr2 = NULL;
|
||||
|
||||
ptr = (int *)shared_heap_malloc(4);
|
||||
|
||||
if (ptr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ptr2 = test_addr_conv(ptr);
|
||||
if (ptr2 != ptr) {
|
||||
return 0;
|
||||
}
|
||||
shared_heap_free(ptr);
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user