diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 9c1a4a5d53..562fa8789f 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -14,7 +14,30 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.5) SET(CMAKE_BUILD_TYPE Debug) -# add_definitions (-m32) +set(CMAKE_CXX_STANDARD 17) + +#TODO: modularization me +# Detect Hosting target info +string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") @@ -65,8 +88,9 @@ add_subdirectory(gc) add_subdirectory(tid-allocator) add_subdirectory(unsupported-features) add_subdirectory(smart-tests) +add_subdirectory (running-modes) -if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") +if(WAMR_BUILD_TARGET STREQUAL "X86_64") add_subdirectory(aot-stack-frame) # should enable 32-bit llvm when X86_32 @@ -74,11 +98,22 @@ if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") add_subdirectory (custom-section) add_subdirectory (compilation) - # Fast-JIT or mem64 is not supported on X86_32 - add_subdirectory (running-modes) add_subdirectory (memory64) add_subdirectory (shared-heap) # HW_BOUND_CHECK is not supported on X86_32 + add_subdirectory (runtime-common) +endif() + +if(WAMR_BUILD_TARGET STREQUAL "AARCH64") + add_subdirectory(aot-stack-frame) + + add_subdirectory (aot) + add_subdirectory (custom-section) + add_subdirectory (compilation) + + add_subdirectory (memory64) + add_subdirectory (shared-heap) + add_subdirectory (runtime-common) endif () diff --git a/tests/unit/common/test_helper.h b/tests/unit/common/test_helper.h index 4db465fc8d..8f54a592c0 100644 --- a/tests/unit/common/test_helper.h +++ b/tests/unit/common/test_helper.h @@ -11,6 +11,20 @@ #include #include #include +#include +#include +#include + +static inline std::string +get_test_binary_dir() +{ + char cwd[PATH_MAX] = { 0 }; + if (!getcwd(cwd, sizeof(cwd))) { + return std::string(); + } + + return std::string(cwd); +} template class WAMRRuntimeRAII diff --git a/tests/unit/compilation/aot_compiler_test.cc b/tests/unit/compilation/aot_compiler_test.cc index 6fbccbb176..7c5df9c34a 100644 --- a/tests/unit/compilation/aot_compiler_test.cc +++ b/tests/unit/compilation/aot_compiler_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - extern "C" { char * aot_generate_tempfile_name(const char *prefix, const char *extension, @@ -50,7 +33,7 @@ class aot_compiler_test_suit : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } @@ -117,8 +100,13 @@ TEST_F(aot_compiler_test_suit, aot_emit_object_file) // Test size_level in range from 0 to 3. option.opt_level = 3; - for (i = 0; i <= 3; i++) { - option.size_level = i; +#if defined(__aarch64__) || defined(_M_ARM64) + std::vector size_levels = { 0, 3 }; +#else + std::vector size_levels = { 0, 1, 2, 3 }; +#endif + for (auto size_level : size_levels) { + option.size_level = size_level; test_aot_emit_object_file_with_option(&option); } diff --git a/tests/unit/compilation/aot_emit_aot_file_test.cc b/tests/unit/compilation/aot_emit_aot_file_test.cc index 8b0f63a8ed..c94b15402e 100644 --- a/tests/unit/compilation/aot_emit_aot_file_test.cc +++ b/tests/unit/compilation/aot_emit_aot_file_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - extern "C" { uint8 * aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data, @@ -50,7 +33,7 @@ class aot_emit_aot_file_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_control_test.cc b/tests/unit/compilation/aot_emit_control_test.cc index 849189c907..c8a47554cf 100644 --- a/tests/unit/compilation/aot_emit_control_test.cc +++ b/tests/unit/compilation/aot_emit_control_test.cc @@ -15,23 +15,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_control_test_suite : public testing::Test { protected: @@ -45,7 +28,7 @@ class aot_emit_control_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_function_test.cc b/tests/unit/compilation/aot_emit_function_test.cc index d10d639a15..db67c3b20a 100644 --- a/tests/unit/compilation/aot_emit_function_test.cc +++ b/tests/unit/compilation/aot_emit_function_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_function_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_emit_function_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_memory_test.cc b/tests/unit/compilation/aot_emit_memory_test.cc index 0e8e86f21d..840a30f6d9 100644 --- a/tests/unit/compilation/aot_emit_memory_test.cc +++ b/tests/unit/compilation/aot_emit_memory_test.cc @@ -16,29 +16,12 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class compilation_aot_emit_memory_test : public testing::Test { protected: void SetUp() override { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); AOTCompOption option = { 0 }; diff --git a/tests/unit/compilation/aot_emit_numberic_test.cc b/tests/unit/compilation/aot_emit_numberic_test.cc index 70f119f9e5..22a62505df 100644 --- a/tests/unit/compilation/aot_emit_numberic_test.cc +++ b/tests/unit/compilation/aot_emit_numberic_test.cc @@ -15,23 +15,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_numberic_test_suite : public testing::Test { protected: @@ -45,7 +28,7 @@ class aot_emit_numberic_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_parametric_test.cc b/tests/unit/compilation/aot_emit_parametric_test.cc index aa7b08df3a..4ecac1894f 100644 --- a/tests/unit/compilation/aot_emit_parametric_test.cc +++ b/tests/unit/compilation/aot_emit_parametric_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_parametric_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_emit_parametric_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_table_test.cc b/tests/unit/compilation/aot_emit_table_test.cc index c77d16c6d1..457e1073ad 100644 --- a/tests/unit/compilation/aot_emit_table_test.cc +++ b/tests/unit/compilation/aot_emit_table_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_table_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_emit_table_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_llvm_test.cc b/tests/unit/compilation/aot_llvm_test.cc index de4ab17c4a..83714130c5 100644 --- a/tests/unit/compilation/aot_llvm_test.cc +++ b/tests/unit/compilation/aot_llvm_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_llvm_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_llvm_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/gc/gc_test.cc b/tests/unit/gc/gc_test.cc index 196ddba65a..971f2ecf4e 100644 --- a/tests/unit/gc/gc_test.cc +++ b/tests/unit/gc/gc_test.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include "test_helper.h" #include "gtest/gtest.h" #include "bh_platform.h" #include "bh_read_file.h" @@ -10,27 +11,10 @@ class WasmGCTest : public testing::Test { - private: - std::string get_binary_path() - { - char cwd[1024] = { 0 }; - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - return NULL; - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); - } - protected: void SetUp() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); memset(&init_args, 0, sizeof(RuntimeInitArgs)); diff --git a/tests/unit/linear-memory-aot/build_aot.sh b/tests/unit/linear-memory-aot/build_aot.sh index 8f2b29edee..12c10c33f9 100755 --- a/tests/unit/linear-memory-aot/build_aot.sh +++ b/tests/unit/linear-memory-aot/build_aot.sh @@ -31,15 +31,42 @@ if [ ! -s "$WAST2WASM" ]; then echo "please install wabt first" && exit -1 fi +# Detect host architecture +HOST_ARCH=$(uname -m) +echo "Detected host architecture: $HOST_ARCH" + # Iterate over the files array -rm -r build +rm -r build 2>/dev/null mkdir build for file_name in "${file_names[@]}"; do # wast to wasm $WAST2WASM "${file_name}.wast" -o "build/${file_name}.wasm" - # compile the aot files, x86-64, x86-32, no_hw_bounds, no_hw_bounds_x32 - $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" - $WAMRC --target=i386 -o "build/${file_name}_32.aot" "build/${file_name}.wasm" - $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" - $WAMRC --bounds-checks=1 --target=i386 -o "build/${file_name}_no_hw_bounds_32.aot" "build/${file_name}.wasm" + + # Determine compilation configurations based on host architecture + case "$HOST_ARCH" in + x86_64) + # x86-64 host: compile both x86-64 and x86-32 + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --target=i386 -o "build/${file_name}_32.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 --target=i386 -o "build/${file_name}_no_hw_bounds_32.aot" "build/${file_name}.wasm" + ;; + i386|i686) + # x86-32 host: compile only x86-32 + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + ;; + aarch64|arm64) + # ARM64 host: compile only aarch64 + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + ;; + *) + echo "Warning: Unsupported architecture '$HOST_ARCH'. Using default target." + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + ;; + esac done + +echo "AOT compilation completed for architecture: $HOST_ARCH" diff --git a/tests/unit/linear-memory-aot/linear_memory_aot_test.cc b/tests/unit/linear-memory-aot/linear_memory_aot_test.cc index 198dfbc917..b365721fea 100644 --- a/tests/unit/linear-memory-aot/linear_memory_aot_test.cc +++ b/tests/unit/linear-memory-aot/linear_memory_aot_test.cc @@ -11,23 +11,6 @@ static std::string CWD; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - #if WASM_DISABLE_HW_BOUND_CHECK != 0 #define TEST_SUITE_NAME linear_memory_test_suite_aot_no_hw_bound #else @@ -45,7 +28,7 @@ class TEST_SUITE_NAME : public testing::Test // Otherwise, this can be skipped. virtual void SetUp() {} - static void SetUpTestCase() { CWD = get_binary_path(); } + static void SetUpTestCase() { CWD = get_test_binary_dir(); } // virtual void TearDown() will be called after each test is run. // You should define it if there is cleanup work to do. Otherwise, diff --git a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc index a5db0e0335..d55f1926ff 100644 --- a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc +++ b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc @@ -11,23 +11,6 @@ static std::string CWD; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - #if WASM_DISABLE_HW_BOUND_CHECK != 0 #define TEST_SUITE_NAME linear_memory_test_suite_wasm_no_hw_bound #else @@ -45,7 +28,7 @@ class TEST_SUITE_NAME : public testing::Test // Otherwise, this can be skipped. virtual void SetUp() {} - static void SetUpTestCase() { CWD = get_binary_path(); } + static void SetUpTestCase() { CWD = get_test_binary_dir(); } // virtual void TearDown() will be called after each test is run. // You should define it if there is cleanup work to do. Otherwise, @@ -135,7 +118,7 @@ TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) struct ret_env tmp_module_env; unsigned int num_normal_wasm = 9; unsigned int num_error_wasm = 10; - const char *wasm_file_normal[num_normal_wasm] = { + const char *wasm_file_normal[9] = { "/wasm_mem_page_01.wasm", "/wasm_mem_page_02.wasm", "/wasm_mem_page_05.wasm", "/wasm_mem_page_07.wasm", "/wasm_mem_page_08.wasm", "/wasm_mem_page_09.wasm", @@ -143,7 +126,7 @@ TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) "/wasm_mem_page_14.wasm" }; - const char *wasm_file_error[num_error_wasm] = { + const char *wasm_file_error[10] = { "/wasm_mem_page_03.wasm", "/wasm_mem_page_04.wasm", "/wasm_mem_page_06.wasm", "/wasm_mem_page_11.wasm", "/wasm_mem_page_13.wasm", "/wasm_mem_page_15.wasm", diff --git a/tests/unit/linux-perf/CMakeLists.txt b/tests/unit/linux-perf/CMakeLists.txt index e5e2d56921..baf9863c27 100644 --- a/tests/unit/linux-perf/CMakeLists.txt +++ b/tests/unit/linux-perf/CMakeLists.txt @@ -32,9 +32,4 @@ include (${IWASM_DIR}/compilation/iwasm_compl.cmake) add_executable (linux_perf_test test_sort_func_ptrs.cc) target_compile_options(linux_perf_test PUBLIC -fpermissive) target_link_libraries(linux_perf_test ${LLVM_AVAILABLE_LIBS} gtest_main ) -target_link_options(linux_perf_test - PUBLIC - LINKER:--unresolved-symbols=ignore-all -) - gtest_discover_tests(linux_perf_test) diff --git a/tests/unit/linux-perf/test_sort_func_ptrs.cc b/tests/unit/linux-perf/test_sort_func_ptrs.cc index 68f4b850f0..45380267fc 100644 --- a/tests/unit/linux-perf/test_sort_func_ptrs.cc +++ b/tests/unit/linux-perf/test_sort_func_ptrs.cc @@ -33,7 +33,7 @@ sort_func_ptrs(const AOTModule *module, char *error_buf, uint32 error_buf_size) unsigned i; content_len = (uint64)sizeof(struct func_info) * module->func_count; - sorted_func_ptrs = wasm_runtime_malloc(content_len); + sorted_func_ptrs = (struct func_info *)wasm_runtime_malloc(content_len); if (!sorted_func_ptrs) { snprintf(error_buf, error_buf_size, "allocate memory failed when creating perf map"); @@ -63,23 +63,17 @@ wasm_runtime_free(void* ptr) return free(ptr); } -int -b_memcpy_s(void *s1, unsigned int s1max, const void *s2, unsigned int n) -{ - return memcpy(s1, s2, n); -} } TEST(TestSortFuncPtrs, qsort) { - void *p = sort_func_ptrs; - ASSERT_NE(p, nullptr); + ASSERT_NE(sort_func_ptrs, nullptr); void *funcs[5] = { (void *)0x1024, (void *)0x10, (void *)0x24, (void *)0x102, (void *)0x4, }; - AOTModule module = { 0 }; + AOTModule module = {}; module.func_count = 5; module.func_ptrs = &funcs[0]; diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index 3a5ca4745a..d7ebaed095 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -26,8 +26,12 @@ set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_MULTI_MODULE 0) set(WAMR_BUILD_LIBC_WASI 1) set(WAMR_BUILD_APP_FRAMEWORK 0) -set(WAMR_BUILD_JIT 1) -set(WAMR_BUILD_FAST_JIT 1) +set(WAMR_BUILD_AOT 1) +set(WAMR_BUILD_INTERP 1) +if(WAMR_BUILD_TARGET STREQUAL "x86_64") + set(WAMR_BUILD_JIT 1) + sset(WAMR_BUILD_FAST_JIT 1) +endif() set(WAMR_BUILD_REF_TYPES 1) # if only load this CMake other than load it as subdirectory diff --git a/tests/unit/running-modes/wasm_running_modes_test.cc b/tests/unit/running-modes/wasm_running_modes_test.cc index 5f370dd649..5dc4803c02 100644 --- a/tests/unit/running-modes/wasm_running_modes_test.cc +++ b/tests/unit/running-modes/wasm_running_modes_test.cc @@ -39,22 +39,6 @@ std::vector running_mode_supported = { Mode_Interp, class wasm_running_modes_test_suite : public testing::TestWithParam { private: - std::string get_binary_path() - { - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); - } - bool load_wasm_file(const char *wasm_file) { const char *file; @@ -199,7 +183,7 @@ class wasm_running_modes_test_suite : public testing::TestWithParam // Otherwise, this can be skipped. virtual void SetUp() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE_1 = strdup((CWD + TEST_WASM1).c_str()); WASM_FILE_2 = strdup((CWD + TEST_WASM2).c_str()); diff --git a/tests/unit/runtime-common/wasm_runtime_common_test.cc b/tests/unit/runtime-common/wasm_runtime_common_test.cc index b1282091c5..3e2fb1429a 100644 --- a/tests/unit/runtime-common/wasm_runtime_common_test.cc +++ b/tests/unit/runtime-common/wasm_runtime_common_test.cc @@ -36,23 +36,6 @@ static std::string MAIN_AOT = "/main.aot"; static char *WASM_FILE_1; static char *AOT_FILE_1; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class wasm_runtime_common_test_suite : public testing::Test { protected: @@ -66,7 +49,7 @@ class wasm_runtime_common_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE_1 = strdup((CWD + MAIN_WASM).c_str()); AOT_FILE_1 = strdup((CWD + MAIN_AOT).c_str()); } diff --git a/tests/unit/runtime-common/wasm_runtime_init_test.cc b/tests/unit/runtime-common/wasm_runtime_init_test.cc index f7ff26ae44..5632ca4cfe 100644 --- a/tests/unit/runtime-common/wasm_runtime_init_test.cc +++ b/tests/unit/runtime-common/wasm_runtime_init_test.cc @@ -48,23 +48,6 @@ static NativeSymbol native_symbols[] = { { "(ii)i" // the function prototype signature } }; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class wasm_runtime_init_test_suite : public testing::Test { protected: @@ -78,7 +61,7 @@ class wasm_runtime_init_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE_1 = strdup((CWD + MAIN_WASM).c_str()); AOT_FILE_1 = strdup((CWD + MAIN_AOT).c_str()); } diff --git a/tests/unit/shared-heap/CMakeLists.txt b/tests/unit/shared-heap/CMakeLists.txt index c275ac6385..5de15b4428 100644 --- a/tests/unit/shared-heap/CMakeLists.txt +++ b/tests/unit/shared-heap/CMakeLists.txt @@ -16,14 +16,34 @@ set(WAMR_BUILD_MEMORY64 0) set(WAMR_BUILD_SHARED_HEAP 1) # Compile wasm modules -add_subdirectory(wasm-apps) +set(WASI_SDK_DIR "/opt/wasi-sdk") +set(WASISDK_TOOLCHAIN "${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake") -if (WAMR_BUILD_MEMORY64 EQUAL 1) - add_subdirectory(wasm-apps/memory64) -endif () +include(ExternalProject) +ExternalProject_Add( + shared_heap_wasm_apps + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps + BUILD_ALWAYS YES + CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps -B build + -DWASI_SDK_PREFIX=${WASI_SDK_DIR} + -DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN} + BUILD_COMMAND ${CMAKE_COMMAND} --build build + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} +) + +ExternalProject_Add( + shared_heap_wasm_apps_bulk_memory + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/bulk-memory + BUILD_ALWAYS YES + CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/bulk-memory -B build + -DWASI_SDK_PREFIX=${WASI_SDK_DIR} + -DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN} + BUILD_COMMAND ${CMAKE_COMMAND} --build build + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} +) # if only load this CMake other than load it as subdirectory -include(../unit_common.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../unit_common.cmake) include(${IWASM_DIR}/compilation/iwasm_compl.cmake) diff --git a/tests/unit/shared-heap/shared_heap_test.cc b/tests/unit/shared-heap/shared_heap_test.cc index 4b5a8e991b..a66cfc68b1 100644 --- a/tests/unit/shared-heap/shared_heap_test.cc +++ b/tests/unit/shared-heap/shared_heap_test.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include "platform_internal.h" #include "test_helper.h" #include "gtest/gtest.h" @@ -11,6 +12,7 @@ #include "bh_platform.h" #include +#include class shared_heap_test : public testing::Test { @@ -195,10 +197,15 @@ TEST_F(shared_heap_test, test_preallocated_shared_heap_malloc_fail) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); /* create a preallocated shared heap */ - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { @@ -256,7 +263,7 @@ TEST_F(shared_heap_test, test_preallocated_shared_runtime_api) } size = (uint64_t)UINT32_MAX + 0x2000; - printf("offset %lx size: %lx\n", offset, size); + printf("offset %llx size: %llx\n", offset, size); ASSERT_EQ(false, wasm_runtime_validate_app_addr( tmp_module_env.wasm_module_inst, offset, size)); @@ -329,10 +336,15 @@ TEST_F(shared_heap_test, test_shared_heap_rmw) { WASMSharedHeap *shared_heap = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; uint32 start1, end1; - create_test_shared_heap(preallocated_buf, BUF_SIZE, &shared_heap); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + + create_test_shared_heap(preallocated_buf_ptr, BUF_SIZE, &shared_heap); /* app addr for shared heap */ start1 = UINT32_MAX - BUF_SIZE + 1; @@ -368,11 +380,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -416,11 +438,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -471,11 +503,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory_oob) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -553,10 +595,19 @@ TEST_F(shared_heap_test, test_shared_heap_rmw_oob) { WASMSharedHeap *shared_heap = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap(preallocated_buf, BUF_SIZE, &shared_heap); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap(preallocated_buf_ptr, BUF_SIZE, &shared_heap); /* app addr for shared heap */ start1 = UINT32_MAX - BUF_SIZE + 1; @@ -587,11 +638,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_oob) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -620,11 +681,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint64 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT64_MAX - 2 * BUF_SIZE + 1; @@ -667,11 +738,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw_oob) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint64 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT64_MAX - 2 * BUF_SIZE + 1; @@ -759,7 +840,11 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob) WASMSharedHeap *shared_heap = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(), app_addr = 0xFFFFFFFF - BUF_SIZE; - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; /* create a preallocated shared heap */ @@ -769,7 +854,7 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob) FAIL() << "Failed to register natives"; } - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { @@ -799,7 +884,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -816,7 +905,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -865,7 +954,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); struct ret_env tmp_module_env; args.size = 1024; @@ -875,7 +968,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -907,7 +1000,15 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap3 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); args.size = 1024; shared_heap = wasm_runtime_create_shared_heap(&args); @@ -916,7 +1017,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -930,7 +1031,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf2; + args.pre_allocated_addr = preallocated_buf2_ptr; args.size = BUF_SIZE; shared_heap3 = wasm_runtime_create_shared_heap(&args); if (!shared_heap3) { @@ -952,7 +1053,15 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap3 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); args.size = 1024; shared_heap = wasm_runtime_create_shared_heap(&args); @@ -961,7 +1070,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -975,7 +1084,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf2; + args.pre_allocated_addr = preallocated_buf2_ptr; args.size = BUF_SIZE; shared_heap3 = wasm_runtime_create_shared_heap(&args); if (!shared_heap3) { @@ -1007,7 +1116,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed) uint64 offset = 0, offset_after_reset = 0; void *native_ptr = nullptr, *native_ptr_after_reset = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); struct ret_env tmp_module_env; args.size = 4096; @@ -1017,7 +1130,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed) } args.size = BUF_SIZE; - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { FAIL() << "Failed to create second shared heap"; @@ -1085,17 +1198,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_preallocated) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap = nullptr; uint32 BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); uint8 set_val = 0xA5; - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { FAIL() << "Create preallocated shared heap failed.\n"; } - memset(preallocated_buf, set_val, BUF_SIZE); + memset(preallocated_buf_ptr, set_val, BUF_SIZE); for (uint32 i = 0; i < BUF_SIZE; i++) { EXPECT_EQ(set_val, preallocated_buf[i]); } @@ -1146,7 +1263,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -1163,7 +1284,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -1203,7 +1324,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -1212,7 +1337,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) FAIL() << "Failed to register natives"; } - args.size = 4096; + args.size = os_getpagesize(); shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { FAIL() << "Failed to create shared heap"; @@ -1220,7 +1345,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -1234,14 +1359,14 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) } /* test wasm */ - argv[0] = 0xFFFFFFFF - BUF_SIZE - 4096; + argv[0] = 0xFFFFFFFF - BUF_SIZE - os_getpagesize(); EXPECT_NONFATAL_FAILURE(test_shared_heap(shared_heap_chain, "test_addr_conv.wasm", "test_preallocated", 1, argv), "Exception: out of bounds memory access"); /* test aot */ - argv[0] = 0xFFFFFFFF - BUF_SIZE - 4096; + argv[0] = 0xFFFFFFFF - BUF_SIZE - os_getpagesize(); EXPECT_NONFATAL_FAILURE(test_shared_heap(shared_heap_chain, "test_addr_conv_chain.aot", "test_preallocated", 1, argv), diff --git a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt index 985cf18aeb..b0482888f9 100644 --- a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt @@ -5,105 +5,67 @@ 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) - -if (NOT DEFINED WASI_SDK_DIR) - set(WASI_SDK_DIR "/opt/wasi-sdk") -endif () - -set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib -O0") -set(CMAKE_C_COMPILER_TARGET "wasm32") -set(CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") - -set(DEFINED_SYMBOLS - "${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt") - -set(CMAKE_EXE_LINKER_FLAGS - "-Wl,--no-entry \ - -Wl,--initial-memory=65536 \ - -Wl,--export-all \ - -Wl,--allow-undefined" - ) +# Find WAMRC +set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) +find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/build REQUIRED) +# Set architecture-specific WAMRC flags if (WAMR_BUILD_TARGET STREQUAL "X86_32") - set (WAMR_COMPILER_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap --target=i386) - set (WAMR_COMPILER_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain --target=i386) + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap --target=i386) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain --target=i386) else () - set (WAMR_COMPILER_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) - set (WAMR_COMPILER_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) endif () -function(copy_wasm TARGET_NAME) - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMENT "Copy ${TARGET_NAME} to the same directory of google test" - ) -endfunction() - -function(compile_and_copy_aot_from TARGET_NAME) - string(REPLACE ".wasm" ".aot" AOT_TARGET ${TARGET_NAME}) - string(REPLACE ".wasm" "_chain.aot" AOT_CHAIN_TARGET ${TARGET_NAME}) - - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_FLAGS} - -o ${AOT_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_CHAIN_FLAGS} - -o ${AOT_CHAIN_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_CHAIN_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMENT "Compile and copy ${AOT_TARGET} to the same directory of google test" - ) -endfunction() - +# +# C -> Wasm +# add_executable(test.wasm test.c) -target_link_libraries(test.wasm) -copy_wasm(test.wasm) -compile_and_copy_aot_from(test.wasm) +target_compile_options(test.wasm PUBLIC -nostdlib -O0 -pthread) +target_link_options(test.wasm PRIVATE + -nostdlib + LINKER:--no-entry + LINKER:--initial-memory=65536 + LINKER:--allow-undefined + LINKER:--export-all + -z stack-size=1024 +) add_executable(test_addr_conv.wasm test_addr_conv.c) -target_link_libraries(test_addr_conv.wasm) -copy_wasm(test_addr_conv.wasm) -compile_and_copy_aot_from(test_addr_conv.wasm) - -# copy and compile aot for bulk memory test -set(SOURCE_WASM ${CMAKE_CURRENT_SOURCE_DIR}/bulk-memory/test_bulk_memory.wasm) -set(BUILD_WASM ${CMAKE_CURRENT_BINARY_DIR}/../test_bulk_memory.wasm) -set(OUTPUT_AOT ${CMAKE_CURRENT_BINARY_DIR}/../test_bulk_memory.aot) -set(OUTPUT_CHAIN_AOT ${CMAKE_CURRENT_BINARY_DIR}/../test_bulk_memory_chain.aot) - -add_custom_command( - OUTPUT ${BUILD_WASM} - COMMAND ${CMAKE_COMMAND} -E copy - ${SOURCE_WASM} - ${BUILD_WASM} - DEPENDS ${SOURCE_WASM} - COMMENT "Copying bulk memory WASM to build directory" +target_compile_options(test_addr_conv.wasm PUBLIC -nostdlib -O0 -pthread) +target_link_options(test_addr_conv.wasm PRIVATE + -nostdlib + LINKER:--no-entry + LINKER:--initial-memory=65536 + LINKER:--allow-undefined + LINKER:--export-all + -z stack-size=1024 ) -add_custom_command( - OUTPUT ${OUTPUT_AOT} - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_FLAGS} - -o ${OUTPUT_AOT} - ${BUILD_WASM} - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_CHAIN_FLAGS} - -o ${OUTPUT_CHAIN_AOT} - ${BUILD_WASM} - DEPENDS ${BUILD_WASM} - COMMENT "Compiling bulk memory AOT from copied WASM" +# Compile AOT files (combined target) +add_custom_target(compile_aot ALL + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test.aot test.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_chain.aot test.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test_addr_conv.aot test_addr_conv.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_addr_conv_chain.aot test_addr_conv.wasm + DEPENDS test.wasm test_addr_conv.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) -add_custom_target(compile_bulk_memory_aot ALL - DEPENDS ${OUTPUT_AOT} +# Install WASM files +set(WASM_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test.wasm + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) + +# Install AOT files +set(AOT_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_chain.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv_chain.aot ) +install(FILES ${AOT_FILES} DESTINATION .) diff --git a/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt new file mode 100644 index 0000000000..8dd0deca7a --- /dev/null +++ b/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright (C) 2024 Xiaomi Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.14) +project(wasm-apps-bulk-memory) + +# Find WAMRC +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) +set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) +find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/build REQUIRED) + +# Set architecture-specific WAMRC flags +if (WAMR_BUILD_TARGET STREQUAL "X86_32") + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap --target=i386) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain --target=i386) +else () + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) +endif () + +# Compile AOT files (combined target) +add_custom_target(compile_aot ALL + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test_bulk_memory.aot ${CMAKE_CURRENT_SOURCE_DIR}/test_bulk_memory.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_bulk_memory_chain.aot ${CMAKE_CURRENT_SOURCE_DIR}/test_bulk_memory.wasm + DEPENDS test_bulk_memory.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Install WASM file +set(WASM_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/test_bulk_memory.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) + +# Install AOT files +set(AOT_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test_bulk_memory.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_bulk_memory_chain.aot +) +install(FILES ${AOT_FILES} DESTINATION .) diff --git a/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt index a82788b586..912990a890 100644 --- a/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt @@ -5,64 +5,45 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps-wasm64) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) -set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler/build) -set(CMAKE_SYSTEM_PROCESSOR wasm64) -set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot) +# Find WAMRC +set(WAMRC_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +find_program(WAMRC_BIN wamrc HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../../wamr-compiler/build REQUIRED) -if (NOT DEFINED WASI_SDK_DIR) - set(WASI_SDK_DIR "/opt/wasi-sdk") -endif () - -set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib -O0 --target=wasm64") -set(CMAKE_C_COMPILER_TARGET "wasm64") -set(CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") - -set(DEFINED_SYMBOLS - "${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt") - -set(CMAKE_EXE_LINKER_FLAGS - "-Wl,--no-entry \ - -Wl,--initial-memory=65536 \ - -Wl,--export-all \ - -Wl,--allow-undefined" - ) - -set (WAMR_COMPILER_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) -set (WAMR_COMPILER_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) - -function(copy_wasm TARGET_NAME) - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - ${CMAKE_CURRENT_BINARY_DIR}/../../ - COMMENT "Copy ${TARGET_NAME} to the same directory of google test" - ) -endfunction() - -function(compile_and_copy_aot_from TARGET_NAME) - string(REPLACE ".wasm" ".aot" AOT_TARGET ${TARGET_NAME}) - string(REPLACE ".wasm" "_chain.aot" AOT_CHAIN_TARGET ${TARGET_NAME}) - - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_FLAGS} - -o ${AOT_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../../ - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_CHAIN_FLAGS} - -o ${AOT_CHAIN_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_CHAIN_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../../ - COMMENT "Compile and copy ${AOT_TARGET} ${AOT_CHAIN_TARGET} to the same directory of google test" - ) -endfunction() +# Set WAMRC flags for memory64 +set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) +set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) +# +# C -> Wasm +# add_executable(test64.wasm ../test.c) -target_link_libraries(test64.wasm) -copy_wasm(test64.wasm) -compile_and_copy_aot_from(test64.wasm) +target_compile_options(test64.wasm PUBLIC -nostdlib -O0 -pthread --target=wasm64) +target_link_options(test64.wasm PRIVATE + -nostdlib + LINKER:--no-entry + LINKER:--initial-memory=65536 + LINKER:--export-all + LINKER:--allow-undefined +) + +# Compile AOT files (combined target) +add_custom_target(compile_aot ALL + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test64.aot test64.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test64_chain.aot test64.wasm + DEPENDS test64.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Install WASM file +set(WASM_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test64.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) + +# Install AOT files +set(AOT_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test64.aot + ${CMAKE_CURRENT_BINARY_DIR}/test64_chain.aot +) +install(FILES ${AOT_FILES} DESTINATION .) diff --git a/tests/unit/tid-allocator/CMakeLists.txt b/tests/unit/tid-allocator/CMakeLists.txt index be62340a3c..87cf08654a 100644 --- a/tests/unit/tid-allocator/CMakeLists.txt +++ b/tests/unit/tid-allocator/CMakeLists.txt @@ -13,10 +13,6 @@ if (NOT DEFINED WAMR_BUILD_INTERP) set (WAMR_BUILD_INTERP 1) endif () -if (NOT DEFINED WAMR_BUILD_PLATFORM) - string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) -endif () - include (../unit_common.cmake) add_library (tid_allocator_vmlib ${WAMR_RUNTIME_LIB_SOURCE}) diff --git a/tests/unit/unit_common.cmake b/tests/unit/unit_common.cmake index 53e9ae50df..b6692c62eb 100644 --- a/tests/unit/unit_common.cmake +++ b/tests/unit/unit_common.cmake @@ -1,27 +1,11 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -if (NOT DEFINED WAMR_BUILD_PLATFORM) - set (WAMR_BUILD_PLATFORM "linux") -endif () - enable_language (ASM) # Usually, test cases should identify their unique # complation flags to implement their test plan -# Set WAMR_BUILD_TARGET, currently values supported: -# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" -if (NOT DEFINED WAMR_BUILD_TARGET) - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - # Build as X86_64 by default in 64-bit platform - set (WAMR_BUILD_TARGET "X86_64") - else () - # Build as X86_32 by default in 32-bit platform - set (WAMR_BUILD_TARGET "X86_32") - endif () -endif () - set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) # include the build config template file diff --git a/tests/unit/wasm-c-api/CMakeLists.txt b/tests/unit/wasm-c-api/CMakeLists.txt index 3150c93254..d4d83d0ec3 100644 --- a/tests/unit/wasm-c-api/CMakeLists.txt +++ b/tests/unit/wasm-c-api/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required (VERSION 3.14) project (wasm_c_api_test) -set(WAMR_BUILD_PLATFORM "linux") - # WAMR features switch if (NOT DEFINED WAMR_BUILD_TARGET) set(WAMR_BUILD_TARGET "X86_64")