Add standalone cases (#3536)

This commit is contained in:
Zhang, Yi
2024-06-19 16:40:37 +08:00
committed by GitHub
parent 7f94d183ac
commit 16e70f99aa
129 changed files with 3880 additions and 3 deletions

View File

@ -0,0 +1,32 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.0)
project(wasm-app)
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
if (APPLE)
set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
set (CMAKE_C_LINK_FLAGS "")
set (CMAKE_CXX_LINK_FLAGS "")
endif ()
set (CMAKE_SYSTEM_PROCESSOR wasm32)
if (NOT DEFINED WASI_SDK_DIR)
set (WASI_SDK_DIR "/opt/wasi-sdk")
endif ()
set (CMAKE_C_COMPILER_TARGET "wasm32")
set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
set (CMAKE_EXE_LINKER_FLAGS
"-Wl,--max-memory=131072 -z stack-size=8192 \
-Wl,--export=malloc \
-Wl,--export=free \
-Wl,--allow-undefined"
)
add_executable(test.wasm main.c)
target_link_libraries(test.wasm)

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
void *
test_module_malloc(unsigned buf_size);
void
test_module_free(void *buf);
int
main(int argc, char **argv)
{
char *buf = NULL;
printf("Hello World!\n");
buf = test_module_malloc(1024);
if (buf) {
printf("module_malloc(1024) success, return %p\n", buf);
snprintf(buf, 1024, "%s", "Hello world!\n");
}
else {
printf("module_malloc(1024) failed!\n");
return -1;
}
test_module_free(buf);
buf = test_module_malloc(32 * 1024 * 1024);
if (!buf) {
printf("module_malloc(32MB) failed => expected, not an issue\n");
}
else {
printf("module_malloc(32MB) success, unexpected!\n");
return -1;
}
return 0;
}